UNPKG

2.57 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2018 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 = void 0;
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
44 _stream.DecodeStream.call(this, maybeLength);
45 }
46
47 Jbig2Stream.prototype = Object.create(_stream.DecodeStream.prototype);
48 Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
49 get: function get() {
50 return (0, _util.shadow)(this, 'bytes', this.stream.getBytes(this.maybeLength));
51 },
52 configurable: true
53 });
54
55 Jbig2Stream.prototype.ensureBuffer = function (requested) {};
56
57 Jbig2Stream.prototype.readBlock = function () {
58 if (this.eof) {
59 return;
60 }
61
62 var jbig2Image = new _jbig.Jbig2Image();
63 var chunks = [];
64
65 if ((0, _primitives.isDict)(this.params)) {
66 var globalsStream = this.params.get('JBIG2Globals');
67
68 if ((0, _primitives.isStream)(globalsStream)) {
69 var globals = globalsStream.getBytes();
70 chunks.push({
71 data: globals,
72 start: 0,
73 end: globals.length
74 });
75 }
76 }
77
78 chunks.push({
79 data: this.bytes,
80 start: 0,
81 end: this.bytes.length
82 });
83 var data = jbig2Image.parseChunks(chunks);
84 var dataLength = data.length;
85
86 for (var i = 0; i < dataLength; i++) {
87 data[i] ^= 0xFF;
88 }
89
90 this.buffer = data;
91 this.bufferLength = dataLength;
92 this.eof = true;
93 };
94
95 return Jbig2Stream;
96}();
97
98exports.Jbig2Stream = Jbig2Stream;
\No newline at end of file