UNPKG

2.37 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * JavaScript code in this page
4 *
5 * Copyright 2022 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 _base_stream = require("./base_stream.js");
30
31var _decode_stream = require("./decode_stream.js");
32
33var _primitives = require("./primitives.js");
34
35var _jbig = require("./jbig2.js");
36
37var _util = require("../shared/util.js");
38
39class Jbig2Stream extends _decode_stream.DecodeStream {
40 constructor(stream, maybeLength, params) {
41 super(maybeLength);
42 this.stream = stream;
43 this.dict = stream.dict;
44 this.maybeLength = maybeLength;
45 this.params = params;
46 }
47
48 get bytes() {
49 return (0, _util.shadow)(this, "bytes", this.stream.getBytes(this.maybeLength));
50 }
51
52 ensureBuffer(requested) {}
53
54 readBlock() {
55 if (this.eof) {
56 return;
57 }
58
59 const jbig2Image = new _jbig.Jbig2Image();
60 const chunks = [];
61
62 if (this.params instanceof _primitives.Dict) {
63 const globalsStream = this.params.get("JBIG2Globals");
64
65 if (globalsStream instanceof _base_stream.BaseStream) {
66 const globals = globalsStream.getBytes();
67 chunks.push({
68 data: globals,
69 start: 0,
70 end: globals.length
71 });
72 }
73 }
74
75 chunks.push({
76 data: this.bytes,
77 start: 0,
78 end: this.bytes.length
79 });
80 const data = jbig2Image.parseChunks(chunks);
81 const dataLength = data.length;
82
83 for (let i = 0; i < dataLength; i++) {
84 data[i] ^= 0xff;
85 }
86
87 this.buffer = data;
88 this.bufferLength = dataLength;
89 this.eof = true;
90 }
91
92}
93
94exports.Jbig2Stream = Jbig2Stream;
\No newline at end of file