2
0

jbig2_stream.js 2.3 KB

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