jbig2_stream.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2019 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.Jbig2Stream = void 0;
  27. var _primitives = require("./primitives");
  28. var _stream = require("./stream");
  29. var _jbig = require("./jbig2");
  30. var _util = require("../shared/util");
  31. var Jbig2Stream = function Jbig2StreamClosure() {
  32. function Jbig2Stream(stream, maybeLength, dict, params) {
  33. this.stream = stream;
  34. this.maybeLength = maybeLength;
  35. this.dict = dict;
  36. this.params = params;
  37. _stream.DecodeStream.call(this, maybeLength);
  38. }
  39. Jbig2Stream.prototype = Object.create(_stream.DecodeStream.prototype);
  40. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  41. get: function get() {
  42. return (0, _util.shadow)(this, 'bytes', this.stream.getBytes(this.maybeLength));
  43. },
  44. configurable: true
  45. });
  46. Jbig2Stream.prototype.ensureBuffer = function (requested) {};
  47. Jbig2Stream.prototype.readBlock = function () {
  48. if (this.eof) {
  49. return;
  50. }
  51. var jbig2Image = new _jbig.Jbig2Image();
  52. var chunks = [];
  53. if ((0, _primitives.isDict)(this.params)) {
  54. var globalsStream = this.params.get('JBIG2Globals');
  55. if ((0, _primitives.isStream)(globalsStream)) {
  56. var globals = globalsStream.getBytes();
  57. chunks.push({
  58. data: globals,
  59. start: 0,
  60. end: globals.length
  61. });
  62. }
  63. }
  64. chunks.push({
  65. data: this.bytes,
  66. start: 0,
  67. end: this.bytes.length
  68. });
  69. var data = jbig2Image.parseChunks(chunks);
  70. var dataLength = data.length;
  71. for (var i = 0; i < dataLength; i++) {
  72. data[i] ^= 0xFF;
  73. }
  74. this.buffer = data;
  75. this.bufferLength = dataLength;
  76. this.eof = true;
  77. };
  78. return Jbig2Stream;
  79. }();
  80. exports.Jbig2Stream = Jbig2Stream;