UNPKG

2.56 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2017 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
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.Jbig2Stream = undefined;
28
29var _primitives = require('./primitives');
30
31var _stream = require('./stream');
32
33var _jbig = require('./jbig2');
34
35var _util = require('../shared/util');
36
37var Jbig2Stream = function Jbig2StreamClosure() {
38 function Jbig2Stream(stream, maybeLength, dict, params) {
39 this.stream = stream;
40 this.maybeLength = maybeLength;
41 this.dict = dict;
42 this.params = params;
43 _stream.DecodeStream.call(this, maybeLength);
44 }
45 Jbig2Stream.prototype = Object.create(_stream.DecodeStream.prototype);
46 Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
47 get: function get() {
48 return (0, _util.shadow)(this, 'bytes', this.stream.getBytes(this.maybeLength));
49 },
50
51 configurable: true
52 });
53 Jbig2Stream.prototype.ensureBuffer = function (requested) {};
54 Jbig2Stream.prototype.readBlock = function () {
55 if (this.eof) {
56 return;
57 }
58 var jbig2Image = new _jbig.Jbig2Image();
59 var chunks = [];
60 if ((0, _primitives.isDict)(this.params)) {
61 var globalsStream = this.params.get('JBIG2Globals');
62 if ((0, _primitives.isStream)(globalsStream)) {
63 var globals = globalsStream.getBytes();
64 chunks.push({
65 data: globals,
66 start: 0,
67 end: globals.length
68 });
69 }
70 }
71 chunks.push({
72 data: this.bytes,
73 start: 0,
74 end: this.bytes.length
75 });
76 var data = jbig2Image.parseChunks(chunks);
77 var dataLength = data.length;
78 for (var i = 0; i < dataLength; i++) {
79 data[i] ^= 0xFF;
80 }
81 this.buffer = data;
82 this.bufferLength = dataLength;
83 this.eof = true;
84 };
85 return Jbig2Stream;
86}();
87exports.Jbig2Stream = Jbig2Stream;
\No newline at end of file