2
0

jbig2_stream.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 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.js");
  28. var _decode_stream = require("./decode_stream.js");
  29. var _jbig = require("./jbig2.js");
  30. var _util = require("../shared/util.js");
  31. class Jbig2Stream extends _decode_stream.DecodeStream {
  32. constructor(stream, maybeLength, params) {
  33. super(maybeLength);
  34. this.stream = stream;
  35. this.dict = stream.dict;
  36. this.maybeLength = maybeLength;
  37. this.params = params;
  38. }
  39. get bytes() {
  40. return (0, _util.shadow)(this, "bytes", this.stream.getBytes(this.maybeLength));
  41. }
  42. ensureBuffer(requested) {}
  43. readBlock() {
  44. if (this.eof) {
  45. return;
  46. }
  47. const jbig2Image = new _jbig.Jbig2Image();
  48. const chunks = [];
  49. if ((0, _primitives.isDict)(this.params)) {
  50. const globalsStream = this.params.get("JBIG2Globals");
  51. if ((0, _primitives.isStream)(globalsStream)) {
  52. const globals = globalsStream.getBytes();
  53. chunks.push({
  54. data: globals,
  55. start: 0,
  56. end: globals.length
  57. });
  58. }
  59. }
  60. chunks.push({
  61. data: this.bytes,
  62. start: 0,
  63. end: this.bytes.length
  64. });
  65. const data = jbig2Image.parseChunks(chunks);
  66. const dataLength = data.length;
  67. for (let i = 0; i < dataLength; i++) {
  68. data[i] ^= 0xff;
  69. }
  70. this.buffer = data;
  71. this.bufferLength = dataLength;
  72. this.eof = true;
  73. }
  74. }
  75. exports.Jbig2Stream = Jbig2Stream;