UNPKG

248 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
23(function webpackUniversalModuleDefinition(root, factory) {
24 if(typeof exports === 'object' && typeof module === 'object')
25 module.exports = factory();
26 else if(typeof define === 'function' && define.amd)
27 define("pdfjs-dist/image_decoders/pdf.image_decoders", [], factory);
28 else if(typeof exports === 'object')
29 exports["pdfjs-dist/image_decoders/pdf.image_decoders"] = factory();
30 else
31 root["pdfjs-dist/image_decoders/pdf.image_decoders"] = root.pdfjsImageDecoders = factory();
32})(globalThis, () => {
33return /******/ (() => { // webpackBootstrap
34/******/ "use strict";
35/******/ var __webpack_modules__ = ([
36/* 0 */,
37/* 1 */
38/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
39
40
41
42Object.defineProperty(exports, "__esModule", ({
43 value: true
44}));
45exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.UNSUPPORTED_FEATURES = exports.TextRenderingMode = exports.StreamType = exports.RenderingIntentFlag = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.LINE_FACTOR = exports.LINE_DESCENT_FACTOR = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FontType = exports.FeatureTest = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationEditorType = exports.AnnotationEditorPrefix = exports.AnnotationEditorParamsType = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
46exports.arrayByteLength = arrayByteLength;
47exports.arraysToBytes = arraysToBytes;
48exports.assert = assert;
49exports.bytesToString = bytesToString;
50exports.createPromiseCapability = createPromiseCapability;
51exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
52exports.escapeString = escapeString;
53exports.getModificationDate = getModificationDate;
54exports.getVerbosityLevel = getVerbosityLevel;
55exports.info = info;
56exports.isArrayBuffer = isArrayBuffer;
57exports.isArrayEqual = isArrayEqual;
58exports.isAscii = isAscii;
59exports.objectFromMap = objectFromMap;
60exports.objectSize = objectSize;
61exports.setVerbosityLevel = setVerbosityLevel;
62exports.shadow = shadow;
63exports.string32 = string32;
64exports.stringToBytes = stringToBytes;
65exports.stringToPDFString = stringToPDFString;
66exports.stringToUTF16BEString = stringToUTF16BEString;
67exports.stringToUTF8String = stringToUTF8String;
68exports.unreachable = unreachable;
69exports.utf8StringToString = utf8StringToString;
70exports.warn = warn;
71
72__w_pdfjs_require__(2);
73
74const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
75exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
76const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
77exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
78const LINE_FACTOR = 1.35;
79exports.LINE_FACTOR = LINE_FACTOR;
80const LINE_DESCENT_FACTOR = 0.35;
81exports.LINE_DESCENT_FACTOR = LINE_DESCENT_FACTOR;
82const RenderingIntentFlag = {
83 ANY: 0x01,
84 DISPLAY: 0x02,
85 PRINT: 0x04,
86 ANNOTATIONS_FORMS: 0x10,
87 ANNOTATIONS_STORAGE: 0x20,
88 ANNOTATIONS_DISABLE: 0x40,
89 OPLIST: 0x100
90};
91exports.RenderingIntentFlag = RenderingIntentFlag;
92const AnnotationMode = {
93 DISABLE: 0,
94 ENABLE: 1,
95 ENABLE_FORMS: 2,
96 ENABLE_STORAGE: 3
97};
98exports.AnnotationMode = AnnotationMode;
99const AnnotationEditorPrefix = "pdfjs_internal_editor_";
100exports.AnnotationEditorPrefix = AnnotationEditorPrefix;
101const AnnotationEditorType = {
102 DISABLE: -1,
103 NONE: 0,
104 FREETEXT: 3,
105 INK: 15
106};
107exports.AnnotationEditorType = AnnotationEditorType;
108const AnnotationEditorParamsType = {
109 FREETEXT_SIZE: 1,
110 FREETEXT_COLOR: 2,
111 FREETEXT_OPACITY: 3,
112 INK_COLOR: 11,
113 INK_THICKNESS: 12,
114 INK_OPACITY: 13
115};
116exports.AnnotationEditorParamsType = AnnotationEditorParamsType;
117const PermissionFlag = {
118 PRINT: 0x04,
119 MODIFY_CONTENTS: 0x08,
120 COPY: 0x10,
121 MODIFY_ANNOTATIONS: 0x20,
122 FILL_INTERACTIVE_FORMS: 0x100,
123 COPY_FOR_ACCESSIBILITY: 0x200,
124 ASSEMBLE: 0x400,
125 PRINT_HIGH_QUALITY: 0x800
126};
127exports.PermissionFlag = PermissionFlag;
128const TextRenderingMode = {
129 FILL: 0,
130 STROKE: 1,
131 FILL_STROKE: 2,
132 INVISIBLE: 3,
133 FILL_ADD_TO_PATH: 4,
134 STROKE_ADD_TO_PATH: 5,
135 FILL_STROKE_ADD_TO_PATH: 6,
136 ADD_TO_PATH: 7,
137 FILL_STROKE_MASK: 3,
138 ADD_TO_PATH_FLAG: 4
139};
140exports.TextRenderingMode = TextRenderingMode;
141const ImageKind = {
142 GRAYSCALE_1BPP: 1,
143 RGB_24BPP: 2,
144 RGBA_32BPP: 3
145};
146exports.ImageKind = ImageKind;
147const AnnotationType = {
148 TEXT: 1,
149 LINK: 2,
150 FREETEXT: 3,
151 LINE: 4,
152 SQUARE: 5,
153 CIRCLE: 6,
154 POLYGON: 7,
155 POLYLINE: 8,
156 HIGHLIGHT: 9,
157 UNDERLINE: 10,
158 SQUIGGLY: 11,
159 STRIKEOUT: 12,
160 STAMP: 13,
161 CARET: 14,
162 INK: 15,
163 POPUP: 16,
164 FILEATTACHMENT: 17,
165 SOUND: 18,
166 MOVIE: 19,
167 WIDGET: 20,
168 SCREEN: 21,
169 PRINTERMARK: 22,
170 TRAPNET: 23,
171 WATERMARK: 24,
172 THREED: 25,
173 REDACT: 26
174};
175exports.AnnotationType = AnnotationType;
176const AnnotationStateModelType = {
177 MARKED: "Marked",
178 REVIEW: "Review"
179};
180exports.AnnotationStateModelType = AnnotationStateModelType;
181const AnnotationMarkedState = {
182 MARKED: "Marked",
183 UNMARKED: "Unmarked"
184};
185exports.AnnotationMarkedState = AnnotationMarkedState;
186const AnnotationReviewState = {
187 ACCEPTED: "Accepted",
188 REJECTED: "Rejected",
189 CANCELLED: "Cancelled",
190 COMPLETED: "Completed",
191 NONE: "None"
192};
193exports.AnnotationReviewState = AnnotationReviewState;
194const AnnotationReplyType = {
195 GROUP: "Group",
196 REPLY: "R"
197};
198exports.AnnotationReplyType = AnnotationReplyType;
199const AnnotationFlag = {
200 INVISIBLE: 0x01,
201 HIDDEN: 0x02,
202 PRINT: 0x04,
203 NOZOOM: 0x08,
204 NOROTATE: 0x10,
205 NOVIEW: 0x20,
206 READONLY: 0x40,
207 LOCKED: 0x80,
208 TOGGLENOVIEW: 0x100,
209 LOCKEDCONTENTS: 0x200
210};
211exports.AnnotationFlag = AnnotationFlag;
212const AnnotationFieldFlag = {
213 READONLY: 0x0000001,
214 REQUIRED: 0x0000002,
215 NOEXPORT: 0x0000004,
216 MULTILINE: 0x0001000,
217 PASSWORD: 0x0002000,
218 NOTOGGLETOOFF: 0x0004000,
219 RADIO: 0x0008000,
220 PUSHBUTTON: 0x0010000,
221 COMBO: 0x0020000,
222 EDIT: 0x0040000,
223 SORT: 0x0080000,
224 FILESELECT: 0x0100000,
225 MULTISELECT: 0x0200000,
226 DONOTSPELLCHECK: 0x0400000,
227 DONOTSCROLL: 0x0800000,
228 COMB: 0x1000000,
229 RICHTEXT: 0x2000000,
230 RADIOSINUNISON: 0x2000000,
231 COMMITONSELCHANGE: 0x4000000
232};
233exports.AnnotationFieldFlag = AnnotationFieldFlag;
234const AnnotationBorderStyleType = {
235 SOLID: 1,
236 DASHED: 2,
237 BEVELED: 3,
238 INSET: 4,
239 UNDERLINE: 5
240};
241exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
242const AnnotationActionEventType = {
243 E: "Mouse Enter",
244 X: "Mouse Exit",
245 D: "Mouse Down",
246 U: "Mouse Up",
247 Fo: "Focus",
248 Bl: "Blur",
249 PO: "PageOpen",
250 PC: "PageClose",
251 PV: "PageVisible",
252 PI: "PageInvisible",
253 K: "Keystroke",
254 F: "Format",
255 V: "Validate",
256 C: "Calculate"
257};
258exports.AnnotationActionEventType = AnnotationActionEventType;
259const DocumentActionEventType = {
260 WC: "WillClose",
261 WS: "WillSave",
262 DS: "DidSave",
263 WP: "WillPrint",
264 DP: "DidPrint"
265};
266exports.DocumentActionEventType = DocumentActionEventType;
267const PageActionEventType = {
268 O: "PageOpen",
269 C: "PageClose"
270};
271exports.PageActionEventType = PageActionEventType;
272const StreamType = {
273 UNKNOWN: "UNKNOWN",
274 FLATE: "FLATE",
275 LZW: "LZW",
276 DCT: "DCT",
277 JPX: "JPX",
278 JBIG: "JBIG",
279 A85: "A85",
280 AHX: "AHX",
281 CCF: "CCF",
282 RLX: "RLX"
283};
284exports.StreamType = StreamType;
285const FontType = {
286 UNKNOWN: "UNKNOWN",
287 TYPE1: "TYPE1",
288 TYPE1STANDARD: "TYPE1STANDARD",
289 TYPE1C: "TYPE1C",
290 CIDFONTTYPE0: "CIDFONTTYPE0",
291 CIDFONTTYPE0C: "CIDFONTTYPE0C",
292 TRUETYPE: "TRUETYPE",
293 CIDFONTTYPE2: "CIDFONTTYPE2",
294 TYPE3: "TYPE3",
295 OPENTYPE: "OPENTYPE",
296 TYPE0: "TYPE0",
297 MMTYPE1: "MMTYPE1"
298};
299exports.FontType = FontType;
300const VerbosityLevel = {
301 ERRORS: 0,
302 WARNINGS: 1,
303 INFOS: 5
304};
305exports.VerbosityLevel = VerbosityLevel;
306const CMapCompressionType = {
307 NONE: 0,
308 BINARY: 1,
309 STREAM: 2
310};
311exports.CMapCompressionType = CMapCompressionType;
312const OPS = {
313 dependency: 1,
314 setLineWidth: 2,
315 setLineCap: 3,
316 setLineJoin: 4,
317 setMiterLimit: 5,
318 setDash: 6,
319 setRenderingIntent: 7,
320 setFlatness: 8,
321 setGState: 9,
322 save: 10,
323 restore: 11,
324 transform: 12,
325 moveTo: 13,
326 lineTo: 14,
327 curveTo: 15,
328 curveTo2: 16,
329 curveTo3: 17,
330 closePath: 18,
331 rectangle: 19,
332 stroke: 20,
333 closeStroke: 21,
334 fill: 22,
335 eoFill: 23,
336 fillStroke: 24,
337 eoFillStroke: 25,
338 closeFillStroke: 26,
339 closeEOFillStroke: 27,
340 endPath: 28,
341 clip: 29,
342 eoClip: 30,
343 beginText: 31,
344 endText: 32,
345 setCharSpacing: 33,
346 setWordSpacing: 34,
347 setHScale: 35,
348 setLeading: 36,
349 setFont: 37,
350 setTextRenderingMode: 38,
351 setTextRise: 39,
352 moveText: 40,
353 setLeadingMoveText: 41,
354 setTextMatrix: 42,
355 nextLine: 43,
356 showText: 44,
357 showSpacedText: 45,
358 nextLineShowText: 46,
359 nextLineSetSpacingShowText: 47,
360 setCharWidth: 48,
361 setCharWidthAndBounds: 49,
362 setStrokeColorSpace: 50,
363 setFillColorSpace: 51,
364 setStrokeColor: 52,
365 setStrokeColorN: 53,
366 setFillColor: 54,
367 setFillColorN: 55,
368 setStrokeGray: 56,
369 setFillGray: 57,
370 setStrokeRGBColor: 58,
371 setFillRGBColor: 59,
372 setStrokeCMYKColor: 60,
373 setFillCMYKColor: 61,
374 shadingFill: 62,
375 beginInlineImage: 63,
376 beginImageData: 64,
377 endInlineImage: 65,
378 paintXObject: 66,
379 markPoint: 67,
380 markPointProps: 68,
381 beginMarkedContent: 69,
382 beginMarkedContentProps: 70,
383 endMarkedContent: 71,
384 beginCompat: 72,
385 endCompat: 73,
386 paintFormXObjectBegin: 74,
387 paintFormXObjectEnd: 75,
388 beginGroup: 76,
389 endGroup: 77,
390 beginAnnotations: 78,
391 endAnnotations: 79,
392 beginAnnotation: 80,
393 endAnnotation: 81,
394 paintJpegXObject: 82,
395 paintImageMaskXObject: 83,
396 paintImageMaskXObjectGroup: 84,
397 paintImageXObject: 85,
398 paintInlineImageXObject: 86,
399 paintInlineImageXObjectGroup: 87,
400 paintImageXObjectRepeat: 88,
401 paintImageMaskXObjectRepeat: 89,
402 paintSolidColorImageMask: 90,
403 constructPath: 91
404};
405exports.OPS = OPS;
406const UNSUPPORTED_FEATURES = {
407 unknown: "unknown",
408 forms: "forms",
409 javaScript: "javaScript",
410 signatures: "signatures",
411 smask: "smask",
412 shadingPattern: "shadingPattern",
413 font: "font",
414 errorTilingPattern: "errorTilingPattern",
415 errorExtGState: "errorExtGState",
416 errorXObject: "errorXObject",
417 errorFontLoadType3: "errorFontLoadType3",
418 errorFontState: "errorFontState",
419 errorFontMissing: "errorFontMissing",
420 errorFontTranslate: "errorFontTranslate",
421 errorColorSpace: "errorColorSpace",
422 errorOperatorList: "errorOperatorList",
423 errorFontToUnicode: "errorFontToUnicode",
424 errorFontLoadNative: "errorFontLoadNative",
425 errorFontBuildPath: "errorFontBuildPath",
426 errorFontGetPath: "errorFontGetPath",
427 errorMarkedContent: "errorMarkedContent",
428 errorContentSubStream: "errorContentSubStream"
429};
430exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
431const PasswordResponses = {
432 NEED_PASSWORD: 1,
433 INCORRECT_PASSWORD: 2
434};
435exports.PasswordResponses = PasswordResponses;
436let verbosity = VerbosityLevel.WARNINGS;
437
438function setVerbosityLevel(level) {
439 if (Number.isInteger(level)) {
440 verbosity = level;
441 }
442}
443
444function getVerbosityLevel() {
445 return verbosity;
446}
447
448function info(msg) {
449 if (verbosity >= VerbosityLevel.INFOS) {
450 console.log(`Info: ${msg}`);
451 }
452}
453
454function warn(msg) {
455 if (verbosity >= VerbosityLevel.WARNINGS) {
456 console.log(`Warning: ${msg}`);
457 }
458}
459
460function unreachable(msg) {
461 throw new Error(msg);
462}
463
464function assert(cond, msg) {
465 if (!cond) {
466 unreachable(msg);
467 }
468}
469
470function _isValidProtocol(url) {
471 if (!url) {
472 return false;
473 }
474
475 switch (url.protocol) {
476 case "http:":
477 case "https:":
478 case "ftp:":
479 case "mailto:":
480 case "tel:":
481 return true;
482
483 default:
484 return false;
485 }
486}
487
488function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
489 if (!url) {
490 return null;
491 }
492
493 try {
494 if (options && typeof url === "string") {
495 if (options.addDefaultProtocol && url.startsWith("www.")) {
496 const dots = url.match(/\./g);
497
498 if (dots && dots.length >= 2) {
499 url = `http://${url}`;
500 }
501 }
502
503 if (options.tryConvertEncoding) {
504 try {
505 url = stringToUTF8String(url);
506 } catch (ex) {}
507 }
508 }
509
510 const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
511
512 if (_isValidProtocol(absoluteUrl)) {
513 return absoluteUrl;
514 }
515 } catch (ex) {}
516
517 return null;
518}
519
520function shadow(obj, prop, value) {
521 Object.defineProperty(obj, prop, {
522 value,
523 enumerable: true,
524 configurable: true,
525 writable: false
526 });
527 return value;
528}
529
530const BaseException = function BaseExceptionClosure() {
531 function BaseException(message, name) {
532 if (this.constructor === BaseException) {
533 unreachable("Cannot initialize BaseException.");
534 }
535
536 this.message = message;
537 this.name = name;
538 }
539
540 BaseException.prototype = new Error();
541 BaseException.constructor = BaseException;
542 return BaseException;
543}();
544
545exports.BaseException = BaseException;
546
547class PasswordException extends BaseException {
548 constructor(msg, code) {
549 super(msg, "PasswordException");
550 this.code = code;
551 }
552
553}
554
555exports.PasswordException = PasswordException;
556
557class UnknownErrorException extends BaseException {
558 constructor(msg, details) {
559 super(msg, "UnknownErrorException");
560 this.details = details;
561 }
562
563}
564
565exports.UnknownErrorException = UnknownErrorException;
566
567class InvalidPDFException extends BaseException {
568 constructor(msg) {
569 super(msg, "InvalidPDFException");
570 }
571
572}
573
574exports.InvalidPDFException = InvalidPDFException;
575
576class MissingPDFException extends BaseException {
577 constructor(msg) {
578 super(msg, "MissingPDFException");
579 }
580
581}
582
583exports.MissingPDFException = MissingPDFException;
584
585class UnexpectedResponseException extends BaseException {
586 constructor(msg, status) {
587 super(msg, "UnexpectedResponseException");
588 this.status = status;
589 }
590
591}
592
593exports.UnexpectedResponseException = UnexpectedResponseException;
594
595class FormatError extends BaseException {
596 constructor(msg) {
597 super(msg, "FormatError");
598 }
599
600}
601
602exports.FormatError = FormatError;
603
604class AbortException extends BaseException {
605 constructor(msg) {
606 super(msg, "AbortException");
607 }
608
609}
610
611exports.AbortException = AbortException;
612
613function bytesToString(bytes) {
614 if (typeof bytes !== "object" || bytes === null || bytes.length === undefined) {
615 unreachable("Invalid argument for bytesToString");
616 }
617
618 const length = bytes.length;
619 const MAX_ARGUMENT_COUNT = 8192;
620
621 if (length < MAX_ARGUMENT_COUNT) {
622 return String.fromCharCode.apply(null, bytes);
623 }
624
625 const strBuf = [];
626
627 for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
628 const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
629 const chunk = bytes.subarray(i, chunkEnd);
630 strBuf.push(String.fromCharCode.apply(null, chunk));
631 }
632
633 return strBuf.join("");
634}
635
636function stringToBytes(str) {
637 if (typeof str !== "string") {
638 unreachable("Invalid argument for stringToBytes");
639 }
640
641 const length = str.length;
642 const bytes = new Uint8Array(length);
643
644 for (let i = 0; i < length; ++i) {
645 bytes[i] = str.charCodeAt(i) & 0xff;
646 }
647
648 return bytes;
649}
650
651function arrayByteLength(arr) {
652 if (arr.length !== undefined) {
653 return arr.length;
654 }
655
656 if (arr.byteLength !== undefined) {
657 return arr.byteLength;
658 }
659
660 unreachable("Invalid argument for arrayByteLength");
661}
662
663function arraysToBytes(arr) {
664 const length = arr.length;
665
666 if (length === 1 && arr[0] instanceof Uint8Array) {
667 return arr[0];
668 }
669
670 let resultLength = 0;
671
672 for (let i = 0; i < length; i++) {
673 resultLength += arrayByteLength(arr[i]);
674 }
675
676 let pos = 0;
677 const data = new Uint8Array(resultLength);
678
679 for (let i = 0; i < length; i++) {
680 let item = arr[i];
681
682 if (!(item instanceof Uint8Array)) {
683 if (typeof item === "string") {
684 item = stringToBytes(item);
685 } else {
686 item = new Uint8Array(item);
687 }
688 }
689
690 const itemLength = item.byteLength;
691 data.set(item, pos);
692 pos += itemLength;
693 }
694
695 return data;
696}
697
698function string32(value) {
699 return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
700}
701
702function objectSize(obj) {
703 return Object.keys(obj).length;
704}
705
706function objectFromMap(map) {
707 const obj = Object.create(null);
708
709 for (const [key, value] of map) {
710 obj[key] = value;
711 }
712
713 return obj;
714}
715
716function isLittleEndian() {
717 const buffer8 = new Uint8Array(4);
718 buffer8[0] = 1;
719 const view32 = new Uint32Array(buffer8.buffer, 0, 1);
720 return view32[0] === 1;
721}
722
723function isEvalSupported() {
724 try {
725 new Function("");
726 return true;
727 } catch (e) {
728 return false;
729 }
730}
731
732class FeatureTest {
733 static get isLittleEndian() {
734 return shadow(this, "isLittleEndian", isLittleEndian());
735 }
736
737 static get isEvalSupported() {
738 return shadow(this, "isEvalSupported", isEvalSupported());
739 }
740
741 static get isOffscreenCanvasSupported() {
742 return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
743 }
744
745}
746
747exports.FeatureTest = FeatureTest;
748const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
749
750class Util {
751 static makeHexColor(r, g, b) {
752 return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
753 }
754
755 static scaleMinMax(transform, minMax) {
756 let temp;
757
758 if (transform[0]) {
759 if (transform[0] < 0) {
760 temp = minMax[0];
761 minMax[0] = minMax[1];
762 minMax[1] = temp;
763 }
764
765 minMax[0] *= transform[0];
766 minMax[1] *= transform[0];
767
768 if (transform[3] < 0) {
769 temp = minMax[2];
770 minMax[2] = minMax[3];
771 minMax[3] = temp;
772 }
773
774 minMax[2] *= transform[3];
775 minMax[3] *= transform[3];
776 } else {
777 temp = minMax[0];
778 minMax[0] = minMax[2];
779 minMax[2] = temp;
780 temp = minMax[1];
781 minMax[1] = minMax[3];
782 minMax[3] = temp;
783
784 if (transform[1] < 0) {
785 temp = minMax[2];
786 minMax[2] = minMax[3];
787 minMax[3] = temp;
788 }
789
790 minMax[2] *= transform[1];
791 minMax[3] *= transform[1];
792
793 if (transform[2] < 0) {
794 temp = minMax[0];
795 minMax[0] = minMax[1];
796 minMax[1] = temp;
797 }
798
799 minMax[0] *= transform[2];
800 minMax[1] *= transform[2];
801 }
802
803 minMax[0] += transform[4];
804 minMax[1] += transform[4];
805 minMax[2] += transform[5];
806 minMax[3] += transform[5];
807 }
808
809 static transform(m1, m2) {
810 return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]];
811 }
812
813 static applyTransform(p, m) {
814 const xt = p[0] * m[0] + p[1] * m[2] + m[4];
815 const yt = p[0] * m[1] + p[1] * m[3] + m[5];
816 return [xt, yt];
817 }
818
819 static applyInverseTransform(p, m) {
820 const d = m[0] * m[3] - m[1] * m[2];
821 const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
822 const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
823 return [xt, yt];
824 }
825
826 static getAxialAlignedBoundingBox(r, m) {
827 const p1 = Util.applyTransform(r, m);
828 const p2 = Util.applyTransform(r.slice(2, 4), m);
829 const p3 = Util.applyTransform([r[0], r[3]], m);
830 const p4 = Util.applyTransform([r[2], r[1]], m);
831 return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])];
832 }
833
834 static inverseTransform(m) {
835 const d = m[0] * m[3] - m[1] * m[2];
836 return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
837 }
838
839 static apply3dTransform(m, v) {
840 return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]];
841 }
842
843 static singularValueDecompose2dScale(m) {
844 const transpose = [m[0], m[2], m[1], m[3]];
845 const a = m[0] * transpose[0] + m[1] * transpose[2];
846 const b = m[0] * transpose[1] + m[1] * transpose[3];
847 const c = m[2] * transpose[0] + m[3] * transpose[2];
848 const d = m[2] * transpose[1] + m[3] * transpose[3];
849 const first = (a + d) / 2;
850 const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
851 const sx = first + second || 1;
852 const sy = first - second || 1;
853 return [Math.sqrt(sx), Math.sqrt(sy)];
854 }
855
856 static normalizeRect(rect) {
857 const r = rect.slice(0);
858
859 if (rect[0] > rect[2]) {
860 r[0] = rect[2];
861 r[2] = rect[0];
862 }
863
864 if (rect[1] > rect[3]) {
865 r[1] = rect[3];
866 r[3] = rect[1];
867 }
868
869 return r;
870 }
871
872 static intersect(rect1, rect2) {
873 const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
874 const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
875
876 if (xLow > xHigh) {
877 return null;
878 }
879
880 const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
881 const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
882
883 if (yLow > yHigh) {
884 return null;
885 }
886
887 return [xLow, yLow, xHigh, yHigh];
888 }
889
890 static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
891 const tvalues = [],
892 bounds = [[], []];
893 let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
894
895 for (let i = 0; i < 2; ++i) {
896 if (i === 0) {
897 b = 6 * x0 - 12 * x1 + 6 * x2;
898 a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
899 c = 3 * x1 - 3 * x0;
900 } else {
901 b = 6 * y0 - 12 * y1 + 6 * y2;
902 a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
903 c = 3 * y1 - 3 * y0;
904 }
905
906 if (Math.abs(a) < 1e-12) {
907 if (Math.abs(b) < 1e-12) {
908 continue;
909 }
910
911 t = -c / b;
912
913 if (0 < t && t < 1) {
914 tvalues.push(t);
915 }
916
917 continue;
918 }
919
920 b2ac = b * b - 4 * c * a;
921 sqrtb2ac = Math.sqrt(b2ac);
922
923 if (b2ac < 0) {
924 continue;
925 }
926
927 t1 = (-b + sqrtb2ac) / (2 * a);
928
929 if (0 < t1 && t1 < 1) {
930 tvalues.push(t1);
931 }
932
933 t2 = (-b - sqrtb2ac) / (2 * a);
934
935 if (0 < t2 && t2 < 1) {
936 tvalues.push(t2);
937 }
938 }
939
940 let j = tvalues.length,
941 mt;
942 const jlen = j;
943
944 while (j--) {
945 t = tvalues[j];
946 mt = 1 - t;
947 bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
948 bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
949 }
950
951 bounds[0][jlen] = x0;
952 bounds[1][jlen] = y0;
953 bounds[0][jlen + 1] = x3;
954 bounds[1][jlen + 1] = y3;
955 bounds[0].length = bounds[1].length = jlen + 2;
956 return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
957 }
958
959}
960
961exports.Util = Util;
962const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2d8, 0x2c7, 0x2c6, 0x2d9, 0x2dd, 0x2db, 0x2da, 0x2dc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018, 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x141, 0x152, 0x160, 0x178, 0x17d, 0x131, 0x142, 0x153, 0x161, 0x17e, 0, 0x20ac];
963
964function stringToPDFString(str) {
965 if (str[0] >= "\xEF") {
966 let encoding;
967
968 if (str[0] === "\xFE" && str[1] === "\xFF") {
969 encoding = "utf-16be";
970 } else if (str[0] === "\xFF" && str[1] === "\xFE") {
971 encoding = "utf-16le";
972 } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
973 encoding = "utf-8";
974 }
975
976 if (encoding) {
977 try {
978 const decoder = new TextDecoder(encoding, {
979 fatal: true
980 });
981 const buffer = stringToBytes(str);
982 return decoder.decode(buffer);
983 } catch (ex) {
984 warn(`stringToPDFString: "${ex}".`);
985 }
986 }
987 }
988
989 const strBuf = [];
990
991 for (let i = 0, ii = str.length; i < ii; i++) {
992 const code = PDFStringTranslateTable[str.charCodeAt(i)];
993 strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
994 }
995
996 return strBuf.join("");
997}
998
999function escapeString(str) {
1000 return str.replace(/([()\\\n\r])/g, match => {
1001 if (match === "\n") {
1002 return "\\n";
1003 } else if (match === "\r") {
1004 return "\\r";
1005 }
1006
1007 return `\\${match}`;
1008 });
1009}
1010
1011function isAscii(str) {
1012 return /^[\x00-\x7F]*$/.test(str);
1013}
1014
1015function stringToUTF16BEString(str) {
1016 const buf = ["\xFE\xFF"];
1017
1018 for (let i = 0, ii = str.length; i < ii; i++) {
1019 const char = str.charCodeAt(i);
1020 buf.push(String.fromCharCode(char >> 8 & 0xff), String.fromCharCode(char & 0xff));
1021 }
1022
1023 return buf.join("");
1024}
1025
1026function stringToUTF8String(str) {
1027 return decodeURIComponent(escape(str));
1028}
1029
1030function utf8StringToString(str) {
1031 return unescape(encodeURIComponent(str));
1032}
1033
1034function isArrayBuffer(v) {
1035 return typeof v === "object" && v !== null && v.byteLength !== undefined;
1036}
1037
1038function isArrayEqual(arr1, arr2) {
1039 if (arr1.length !== arr2.length) {
1040 return false;
1041 }
1042
1043 for (let i = 0, ii = arr1.length; i < ii; i++) {
1044 if (arr1[i] !== arr2[i]) {
1045 return false;
1046 }
1047 }
1048
1049 return true;
1050}
1051
1052function getModificationDate(date = new Date()) {
1053 const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")];
1054 return buffer.join("");
1055}
1056
1057function createPromiseCapability() {
1058 const capability = Object.create(null);
1059 let isSettled = false;
1060 Object.defineProperty(capability, "settled", {
1061 get() {
1062 return isSettled;
1063 }
1064
1065 });
1066 capability.promise = new Promise(function (resolve, reject) {
1067 capability.resolve = function (data) {
1068 isSettled = true;
1069 resolve(data);
1070 };
1071
1072 capability.reject = function (reason) {
1073 isSettled = true;
1074 reject(reason);
1075 };
1076 });
1077 return capability;
1078}
1079
1080/***/ }),
1081/* 2 */
1082/***/ ((__unused_webpack_module, __unused_webpack_exports, __w_pdfjs_require__) => {
1083
1084
1085
1086var _is_node = __w_pdfjs_require__(3);
1087
1088;
1089
1090/***/ }),
1091/* 3 */
1092/***/ ((__unused_webpack_module, exports) => {
1093
1094
1095
1096Object.defineProperty(exports, "__esModule", ({
1097 value: true
1098}));
1099exports.isNodeJS = void 0;
1100const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
1101exports.isNodeJS = isNodeJS;
1102
1103/***/ }),
1104/* 4 */
1105/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
1106
1107
1108
1109Object.defineProperty(exports, "__esModule", ({
1110 value: true
1111}));
1112exports.Jbig2Image = void 0;
1113
1114var _util = __w_pdfjs_require__(1);
1115
1116var _core_utils = __w_pdfjs_require__(5);
1117
1118var _arithmetic_decoder = __w_pdfjs_require__(8);
1119
1120var _ccitt = __w_pdfjs_require__(9);
1121
1122class Jbig2Error extends _util.BaseException {
1123 constructor(msg) {
1124 super(`JBIG2 error: ${msg}`, "Jbig2Error");
1125 }
1126
1127}
1128
1129class ContextCache {
1130 getContexts(id) {
1131 if (id in this) {
1132 return this[id];
1133 }
1134
1135 return this[id] = new Int8Array(1 << 16);
1136 }
1137
1138}
1139
1140class DecodingContext {
1141 constructor(data, start, end) {
1142 this.data = data;
1143 this.start = start;
1144 this.end = end;
1145 }
1146
1147 get decoder() {
1148 const decoder = new _arithmetic_decoder.ArithmeticDecoder(this.data, this.start, this.end);
1149 return (0, _util.shadow)(this, "decoder", decoder);
1150 }
1151
1152 get contextCache() {
1153 const cache = new ContextCache();
1154 return (0, _util.shadow)(this, "contextCache", cache);
1155 }
1156
1157}
1158
1159function decodeInteger(contextCache, procedure, decoder) {
1160 const contexts = contextCache.getContexts(procedure);
1161 let prev = 1;
1162
1163 function readBits(length) {
1164 let v = 0;
1165
1166 for (let i = 0; i < length; i++) {
1167 const bit = decoder.readBit(contexts, prev);
1168 prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
1169 v = v << 1 | bit;
1170 }
1171
1172 return v >>> 0;
1173 }
1174
1175 const sign = readBits(1);
1176 const value = readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(32) + 4436 : readBits(12) + 340 : readBits(8) + 84 : readBits(6) + 20 : readBits(4) + 4 : readBits(2);
1177
1178 if (sign === 0) {
1179 return value;
1180 } else if (value > 0) {
1181 return -value;
1182 }
1183
1184 return null;
1185}
1186
1187function decodeIAID(contextCache, decoder, codeLength) {
1188 const contexts = contextCache.getContexts("IAID");
1189 let prev = 1;
1190
1191 for (let i = 0; i < codeLength; i++) {
1192 const bit = decoder.readBit(contexts, prev);
1193 prev = prev << 1 | bit;
1194 }
1195
1196 if (codeLength < 31) {
1197 return prev & (1 << codeLength) - 1;
1198 }
1199
1200 return prev & 0x7fffffff;
1201}
1202
1203const SegmentTypes = ["SymbolDictionary", null, null, null, "IntermediateTextRegion", null, "ImmediateTextRegion", "ImmediateLosslessTextRegion", null, null, null, null, null, null, null, null, "PatternDictionary", null, null, null, "IntermediateHalftoneRegion", null, "ImmediateHalftoneRegion", "ImmediateLosslessHalftoneRegion", null, null, null, null, null, null, null, null, null, null, null, null, "IntermediateGenericRegion", null, "ImmediateGenericRegion", "ImmediateLosslessGenericRegion", "IntermediateGenericRefinementRegion", null, "ImmediateGenericRefinementRegion", "ImmediateLosslessGenericRefinementRegion", null, null, null, null, "PageInformation", "EndOfPage", "EndOfStripe", "EndOfFile", "Profiles", "Tables", null, null, null, null, null, null, null, null, "Extension"];
1204const CodingTemplates = [[{
1205 x: -1,
1206 y: -2
1207}, {
1208 x: 0,
1209 y: -2
1210}, {
1211 x: 1,
1212 y: -2
1213}, {
1214 x: -2,
1215 y: -1
1216}, {
1217 x: -1,
1218 y: -1
1219}, {
1220 x: 0,
1221 y: -1
1222}, {
1223 x: 1,
1224 y: -1
1225}, {
1226 x: 2,
1227 y: -1
1228}, {
1229 x: -4,
1230 y: 0
1231}, {
1232 x: -3,
1233 y: 0
1234}, {
1235 x: -2,
1236 y: 0
1237}, {
1238 x: -1,
1239 y: 0
1240}], [{
1241 x: -1,
1242 y: -2
1243}, {
1244 x: 0,
1245 y: -2
1246}, {
1247 x: 1,
1248 y: -2
1249}, {
1250 x: 2,
1251 y: -2
1252}, {
1253 x: -2,
1254 y: -1
1255}, {
1256 x: -1,
1257 y: -1
1258}, {
1259 x: 0,
1260 y: -1
1261}, {
1262 x: 1,
1263 y: -1
1264}, {
1265 x: 2,
1266 y: -1
1267}, {
1268 x: -3,
1269 y: 0
1270}, {
1271 x: -2,
1272 y: 0
1273}, {
1274 x: -1,
1275 y: 0
1276}], [{
1277 x: -1,
1278 y: -2
1279}, {
1280 x: 0,
1281 y: -2
1282}, {
1283 x: 1,
1284 y: -2
1285}, {
1286 x: -2,
1287 y: -1
1288}, {
1289 x: -1,
1290 y: -1
1291}, {
1292 x: 0,
1293 y: -1
1294}, {
1295 x: 1,
1296 y: -1
1297}, {
1298 x: -2,
1299 y: 0
1300}, {
1301 x: -1,
1302 y: 0
1303}], [{
1304 x: -3,
1305 y: -1
1306}, {
1307 x: -2,
1308 y: -1
1309}, {
1310 x: -1,
1311 y: -1
1312}, {
1313 x: 0,
1314 y: -1
1315}, {
1316 x: 1,
1317 y: -1
1318}, {
1319 x: -4,
1320 y: 0
1321}, {
1322 x: -3,
1323 y: 0
1324}, {
1325 x: -2,
1326 y: 0
1327}, {
1328 x: -1,
1329 y: 0
1330}]];
1331const RefinementTemplates = [{
1332 coding: [{
1333 x: 0,
1334 y: -1
1335 }, {
1336 x: 1,
1337 y: -1
1338 }, {
1339 x: -1,
1340 y: 0
1341 }],
1342 reference: [{
1343 x: 0,
1344 y: -1
1345 }, {
1346 x: 1,
1347 y: -1
1348 }, {
1349 x: -1,
1350 y: 0
1351 }, {
1352 x: 0,
1353 y: 0
1354 }, {
1355 x: 1,
1356 y: 0
1357 }, {
1358 x: -1,
1359 y: 1
1360 }, {
1361 x: 0,
1362 y: 1
1363 }, {
1364 x: 1,
1365 y: 1
1366 }]
1367}, {
1368 coding: [{
1369 x: -1,
1370 y: -1
1371 }, {
1372 x: 0,
1373 y: -1
1374 }, {
1375 x: 1,
1376 y: -1
1377 }, {
1378 x: -1,
1379 y: 0
1380 }],
1381 reference: [{
1382 x: 0,
1383 y: -1
1384 }, {
1385 x: -1,
1386 y: 0
1387 }, {
1388 x: 0,
1389 y: 0
1390 }, {
1391 x: 1,
1392 y: 0
1393 }, {
1394 x: 0,
1395 y: 1
1396 }, {
1397 x: 1,
1398 y: 1
1399 }]
1400}];
1401const ReusedContexts = [0x9b25, 0x0795, 0x00e5, 0x0195];
1402const RefinementReusedContexts = [0x0020, 0x0008];
1403
1404function decodeBitmapTemplate0(width, height, decodingContext) {
1405 const decoder = decodingContext.decoder;
1406 const contexts = decodingContext.contextCache.getContexts("GB");
1407 const bitmap = [];
1408 let contextLabel, i, j, pixel, row, row1, row2;
1409 const OLD_PIXEL_MASK = 0x7bf7;
1410
1411 for (i = 0; i < height; i++) {
1412 row = bitmap[i] = new Uint8Array(width);
1413 row1 = i < 1 ? row : bitmap[i - 1];
1414 row2 = i < 2 ? row : bitmap[i - 2];
1415 contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
1416
1417 for (j = 0; j < width; j++) {
1418 row[j] = pixel = decoder.readBit(contexts, contextLabel);
1419 contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
1420 }
1421 }
1422
1423 return bitmap;
1424}
1425
1426function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
1427 if (mmr) {
1428 const input = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
1429 return decodeMMRBitmap(input, width, height, false);
1430 }
1431
1432 if (templateIndex === 0 && !skip && !prediction && at.length === 4 && at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 && at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
1433 return decodeBitmapTemplate0(width, height, decodingContext);
1434 }
1435
1436 const useskip = !!skip;
1437 const template = CodingTemplates[templateIndex].concat(at);
1438 template.sort(function (a, b) {
1439 return a.y - b.y || a.x - b.x;
1440 });
1441 const templateLength = template.length;
1442 const templateX = new Int8Array(templateLength);
1443 const templateY = new Int8Array(templateLength);
1444 const changingTemplateEntries = [];
1445 let reuseMask = 0,
1446 minX = 0,
1447 maxX = 0,
1448 minY = 0;
1449 let c, k;
1450
1451 for (k = 0; k < templateLength; k++) {
1452 templateX[k] = template[k].x;
1453 templateY[k] = template[k].y;
1454 minX = Math.min(minX, template[k].x);
1455 maxX = Math.max(maxX, template[k].x);
1456 minY = Math.min(minY, template[k].y);
1457
1458 if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
1459 reuseMask |= 1 << templateLength - 1 - k;
1460 } else {
1461 changingTemplateEntries.push(k);
1462 }
1463 }
1464
1465 const changingEntriesLength = changingTemplateEntries.length;
1466 const changingTemplateX = new Int8Array(changingEntriesLength);
1467 const changingTemplateY = new Int8Array(changingEntriesLength);
1468 const changingTemplateBit = new Uint16Array(changingEntriesLength);
1469
1470 for (c = 0; c < changingEntriesLength; c++) {
1471 k = changingTemplateEntries[c];
1472 changingTemplateX[c] = template[k].x;
1473 changingTemplateY[c] = template[k].y;
1474 changingTemplateBit[c] = 1 << templateLength - 1 - k;
1475 }
1476
1477 const sbb_left = -minX;
1478 const sbb_top = -minY;
1479 const sbb_right = width - maxX;
1480 const pseudoPixelContext = ReusedContexts[templateIndex];
1481 let row = new Uint8Array(width);
1482 const bitmap = [];
1483 const decoder = decodingContext.decoder;
1484 const contexts = decodingContext.contextCache.getContexts("GB");
1485 let ltp = 0,
1486 j,
1487 i0,
1488 j0,
1489 contextLabel = 0,
1490 bit,
1491 shift;
1492
1493 for (let i = 0; i < height; i++) {
1494 if (prediction) {
1495 const sltp = decoder.readBit(contexts, pseudoPixelContext);
1496 ltp ^= sltp;
1497
1498 if (ltp) {
1499 bitmap.push(row);
1500 continue;
1501 }
1502 }
1503
1504 row = new Uint8Array(row);
1505 bitmap.push(row);
1506
1507 for (j = 0; j < width; j++) {
1508 if (useskip && skip[i][j]) {
1509 row[j] = 0;
1510 continue;
1511 }
1512
1513 if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
1514 contextLabel = contextLabel << 1 & reuseMask;
1515
1516 for (k = 0; k < changingEntriesLength; k++) {
1517 i0 = i + changingTemplateY[k];
1518 j0 = j + changingTemplateX[k];
1519 bit = bitmap[i0][j0];
1520
1521 if (bit) {
1522 bit = changingTemplateBit[k];
1523 contextLabel |= bit;
1524 }
1525 }
1526 } else {
1527 contextLabel = 0;
1528 shift = templateLength - 1;
1529
1530 for (k = 0; k < templateLength; k++, shift--) {
1531 j0 = j + templateX[k];
1532
1533 if (j0 >= 0 && j0 < width) {
1534 i0 = i + templateY[k];
1535
1536 if (i0 >= 0) {
1537 bit = bitmap[i0][j0];
1538
1539 if (bit) {
1540 contextLabel |= bit << shift;
1541 }
1542 }
1543 }
1544 }
1545 }
1546
1547 const pixel = decoder.readBit(contexts, contextLabel);
1548 row[j] = pixel;
1549 }
1550 }
1551
1552 return bitmap;
1553}
1554
1555function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
1556 let codingTemplate = RefinementTemplates[templateIndex].coding;
1557
1558 if (templateIndex === 0) {
1559 codingTemplate = codingTemplate.concat([at[0]]);
1560 }
1561
1562 const codingTemplateLength = codingTemplate.length;
1563 const codingTemplateX = new Int32Array(codingTemplateLength);
1564 const codingTemplateY = new Int32Array(codingTemplateLength);
1565 let k;
1566
1567 for (k = 0; k < codingTemplateLength; k++) {
1568 codingTemplateX[k] = codingTemplate[k].x;
1569 codingTemplateY[k] = codingTemplate[k].y;
1570 }
1571
1572 let referenceTemplate = RefinementTemplates[templateIndex].reference;
1573
1574 if (templateIndex === 0) {
1575 referenceTemplate = referenceTemplate.concat([at[1]]);
1576 }
1577
1578 const referenceTemplateLength = referenceTemplate.length;
1579 const referenceTemplateX = new Int32Array(referenceTemplateLength);
1580 const referenceTemplateY = new Int32Array(referenceTemplateLength);
1581
1582 for (k = 0; k < referenceTemplateLength; k++) {
1583 referenceTemplateX[k] = referenceTemplate[k].x;
1584 referenceTemplateY[k] = referenceTemplate[k].y;
1585 }
1586
1587 const referenceWidth = referenceBitmap[0].length;
1588 const referenceHeight = referenceBitmap.length;
1589 const pseudoPixelContext = RefinementReusedContexts[templateIndex];
1590 const bitmap = [];
1591 const decoder = decodingContext.decoder;
1592 const contexts = decodingContext.contextCache.getContexts("GR");
1593 let ltp = 0;
1594
1595 for (let i = 0; i < height; i++) {
1596 if (prediction) {
1597 const sltp = decoder.readBit(contexts, pseudoPixelContext);
1598 ltp ^= sltp;
1599
1600 if (ltp) {
1601 throw new Jbig2Error("prediction is not supported");
1602 }
1603 }
1604
1605 const row = new Uint8Array(width);
1606 bitmap.push(row);
1607
1608 for (let j = 0; j < width; j++) {
1609 let i0, j0;
1610 let contextLabel = 0;
1611
1612 for (k = 0; k < codingTemplateLength; k++) {
1613 i0 = i + codingTemplateY[k];
1614 j0 = j + codingTemplateX[k];
1615
1616 if (i0 < 0 || j0 < 0 || j0 >= width) {
1617 contextLabel <<= 1;
1618 } else {
1619 contextLabel = contextLabel << 1 | bitmap[i0][j0];
1620 }
1621 }
1622
1623 for (k = 0; k < referenceTemplateLength; k++) {
1624 i0 = i + referenceTemplateY[k] - offsetY;
1625 j0 = j + referenceTemplateX[k] - offsetX;
1626
1627 if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
1628 contextLabel <<= 1;
1629 } else {
1630 contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
1631 }
1632 }
1633
1634 const pixel = decoder.readBit(contexts, contextLabel);
1635 row[j] = pixel;
1636 }
1637 }
1638
1639 return bitmap;
1640}
1641
1642function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext, huffmanInput) {
1643 if (huffman && refinement) {
1644 throw new Jbig2Error("symbol refinement with Huffman is not supported");
1645 }
1646
1647 const newSymbols = [];
1648 let currentHeight = 0;
1649 let symbolCodeLength = (0, _core_utils.log2)(symbols.length + numberOfNewSymbols);
1650 const decoder = decodingContext.decoder;
1651 const contextCache = decodingContext.contextCache;
1652 let tableB1, symbolWidths;
1653
1654 if (huffman) {
1655 tableB1 = getStandardTable(1);
1656 symbolWidths = [];
1657 symbolCodeLength = Math.max(symbolCodeLength, 1);
1658 }
1659
1660 while (newSymbols.length < numberOfNewSymbols) {
1661 const deltaHeight = huffman ? huffmanTables.tableDeltaHeight.decode(huffmanInput) : decodeInteger(contextCache, "IADH", decoder);
1662 currentHeight += deltaHeight;
1663 let currentWidth = 0,
1664 totalWidth = 0;
1665 const firstSymbol = huffman ? symbolWidths.length : 0;
1666
1667 while (true) {
1668 const deltaWidth = huffman ? huffmanTables.tableDeltaWidth.decode(huffmanInput) : decodeInteger(contextCache, "IADW", decoder);
1669
1670 if (deltaWidth === null) {
1671 break;
1672 }
1673
1674 currentWidth += deltaWidth;
1675 totalWidth += currentWidth;
1676 let bitmap;
1677
1678 if (refinement) {
1679 const numberOfInstances = decodeInteger(contextCache, "IAAI", decoder);
1680
1681 if (numberOfInstances > 1) {
1682 bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, symbols.concat(newSymbols), symbolCodeLength, 0, 0, 1, 0, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, 0, huffmanInput);
1683 } else {
1684 const symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
1685 const rdx = decodeInteger(contextCache, "IARDX", decoder);
1686 const rdy = decodeInteger(contextCache, "IARDY", decoder);
1687 const symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
1688 bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
1689 }
1690
1691 newSymbols.push(bitmap);
1692 } else if (huffman) {
1693 symbolWidths.push(currentWidth);
1694 } else {
1695 bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
1696 newSymbols.push(bitmap);
1697 }
1698 }
1699
1700 if (huffman && !refinement) {
1701 const bitmapSize = huffmanTables.tableBitmapSize.decode(huffmanInput);
1702 huffmanInput.byteAlign();
1703 let collectiveBitmap;
1704
1705 if (bitmapSize === 0) {
1706 collectiveBitmap = readUncompressedBitmap(huffmanInput, totalWidth, currentHeight);
1707 } else {
1708 const originalEnd = huffmanInput.end;
1709 const bitmapEnd = huffmanInput.position + bitmapSize;
1710 huffmanInput.end = bitmapEnd;
1711 collectiveBitmap = decodeMMRBitmap(huffmanInput, totalWidth, currentHeight, false);
1712 huffmanInput.end = originalEnd;
1713 huffmanInput.position = bitmapEnd;
1714 }
1715
1716 const numberOfSymbolsDecoded = symbolWidths.length;
1717
1718 if (firstSymbol === numberOfSymbolsDecoded - 1) {
1719 newSymbols.push(collectiveBitmap);
1720 } else {
1721 let i,
1722 y,
1723 xMin = 0,
1724 xMax,
1725 bitmapWidth,
1726 symbolBitmap;
1727
1728 for (i = firstSymbol; i < numberOfSymbolsDecoded; i++) {
1729 bitmapWidth = symbolWidths[i];
1730 xMax = xMin + bitmapWidth;
1731 symbolBitmap = [];
1732
1733 for (y = 0; y < currentHeight; y++) {
1734 symbolBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
1735 }
1736
1737 newSymbols.push(symbolBitmap);
1738 xMin = xMax;
1739 }
1740 }
1741 }
1742 }
1743
1744 const exportedSymbols = [],
1745 flags = [];
1746 let currentFlag = false,
1747 i,
1748 ii;
1749 const totalSymbolsLength = symbols.length + numberOfNewSymbols;
1750
1751 while (flags.length < totalSymbolsLength) {
1752 let runLength = huffman ? tableB1.decode(huffmanInput) : decodeInteger(contextCache, "IAEX", decoder);
1753
1754 while (runLength--) {
1755 flags.push(currentFlag);
1756 }
1757
1758 currentFlag = !currentFlag;
1759 }
1760
1761 for (i = 0, ii = symbols.length; i < ii; i++) {
1762 if (flags[i]) {
1763 exportedSymbols.push(symbols[i]);
1764 }
1765 }
1766
1767 for (let j = 0; j < numberOfNewSymbols; i++, j++) {
1768 if (flags[i]) {
1769 exportedSymbols.push(newSymbols[j]);
1770 }
1771 }
1772
1773 return exportedSymbols;
1774}
1775
1776function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, logStripSize, huffmanInput) {
1777 if (huffman && refinement) {
1778 throw new Jbig2Error("refinement with Huffman is not supported");
1779 }
1780
1781 const bitmap = [];
1782 let i, row;
1783
1784 for (i = 0; i < height; i++) {
1785 row = new Uint8Array(width);
1786
1787 if (defaultPixelValue) {
1788 for (let j = 0; j < width; j++) {
1789 row[j] = defaultPixelValue;
1790 }
1791 }
1792
1793 bitmap.push(row);
1794 }
1795
1796 const decoder = decodingContext.decoder;
1797 const contextCache = decodingContext.contextCache;
1798 let stripT = huffman ? -huffmanTables.tableDeltaT.decode(huffmanInput) : -decodeInteger(contextCache, "IADT", decoder);
1799 let firstS = 0;
1800 i = 0;
1801
1802 while (i < numberOfSymbolInstances) {
1803 const deltaT = huffman ? huffmanTables.tableDeltaT.decode(huffmanInput) : decodeInteger(contextCache, "IADT", decoder);
1804 stripT += deltaT;
1805 const deltaFirstS = huffman ? huffmanTables.tableFirstS.decode(huffmanInput) : decodeInteger(contextCache, "IAFS", decoder);
1806 firstS += deltaFirstS;
1807 let currentS = firstS;
1808
1809 do {
1810 let currentT = 0;
1811
1812 if (stripSize > 1) {
1813 currentT = huffman ? huffmanInput.readBits(logStripSize) : decodeInteger(contextCache, "IAIT", decoder);
1814 }
1815
1816 const t = stripSize * stripT + currentT;
1817 const symbolId = huffman ? huffmanTables.symbolIDTable.decode(huffmanInput) : decodeIAID(contextCache, decoder, symbolCodeLength);
1818 const applyRefinement = refinement && (huffman ? huffmanInput.readBit() : decodeInteger(contextCache, "IARI", decoder));
1819 let symbolBitmap = inputSymbols[symbolId];
1820 let symbolWidth = symbolBitmap[0].length;
1821 let symbolHeight = symbolBitmap.length;
1822
1823 if (applyRefinement) {
1824 const rdw = decodeInteger(contextCache, "IARDW", decoder);
1825 const rdh = decodeInteger(contextCache, "IARDH", decoder);
1826 const rdx = decodeInteger(contextCache, "IARDX", decoder);
1827 const rdy = decodeInteger(contextCache, "IARDY", decoder);
1828 symbolWidth += rdw;
1829 symbolHeight += rdh;
1830 symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
1831 }
1832
1833 const offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight - 1);
1834 const offsetS = currentS - (referenceCorner & 2 ? symbolWidth - 1 : 0);
1835 let s2, t2, symbolRow;
1836
1837 if (transposed) {
1838 for (s2 = 0; s2 < symbolHeight; s2++) {
1839 row = bitmap[offsetS + s2];
1840
1841 if (!row) {
1842 continue;
1843 }
1844
1845 symbolRow = symbolBitmap[s2];
1846 const maxWidth = Math.min(width - offsetT, symbolWidth);
1847
1848 switch (combinationOperator) {
1849 case 0:
1850 for (t2 = 0; t2 < maxWidth; t2++) {
1851 row[offsetT + t2] |= symbolRow[t2];
1852 }
1853
1854 break;
1855
1856 case 2:
1857 for (t2 = 0; t2 < maxWidth; t2++) {
1858 row[offsetT + t2] ^= symbolRow[t2];
1859 }
1860
1861 break;
1862
1863 default:
1864 throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
1865 }
1866 }
1867
1868 currentS += symbolHeight - 1;
1869 } else {
1870 for (t2 = 0; t2 < symbolHeight; t2++) {
1871 row = bitmap[offsetT + t2];
1872
1873 if (!row) {
1874 continue;
1875 }
1876
1877 symbolRow = symbolBitmap[t2];
1878
1879 switch (combinationOperator) {
1880 case 0:
1881 for (s2 = 0; s2 < symbolWidth; s2++) {
1882 row[offsetS + s2] |= symbolRow[s2];
1883 }
1884
1885 break;
1886
1887 case 2:
1888 for (s2 = 0; s2 < symbolWidth; s2++) {
1889 row[offsetS + s2] ^= symbolRow[s2];
1890 }
1891
1892 break;
1893
1894 default:
1895 throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
1896 }
1897 }
1898
1899 currentS += symbolWidth - 1;
1900 }
1901
1902 i++;
1903 const deltaS = huffman ? huffmanTables.tableDeltaS.decode(huffmanInput) : decodeInteger(contextCache, "IADS", decoder);
1904
1905 if (deltaS === null) {
1906 break;
1907 }
1908
1909 currentS += deltaS + dsOffset;
1910 } while (true);
1911 }
1912
1913 return bitmap;
1914}
1915
1916function decodePatternDictionary(mmr, patternWidth, patternHeight, maxPatternIndex, template, decodingContext) {
1917 const at = [];
1918
1919 if (!mmr) {
1920 at.push({
1921 x: -patternWidth,
1922 y: 0
1923 });
1924
1925 if (template === 0) {
1926 at.push({
1927 x: -3,
1928 y: -1
1929 }, {
1930 x: 2,
1931 y: -2
1932 }, {
1933 x: -2,
1934 y: -2
1935 });
1936 }
1937 }
1938
1939 const collectiveWidth = (maxPatternIndex + 1) * patternWidth;
1940 const collectiveBitmap = decodeBitmap(mmr, collectiveWidth, patternHeight, template, false, null, at, decodingContext);
1941 const patterns = [];
1942
1943 for (let i = 0; i <= maxPatternIndex; i++) {
1944 const patternBitmap = [];
1945 const xMin = patternWidth * i;
1946 const xMax = xMin + patternWidth;
1947
1948 for (let y = 0; y < patternHeight; y++) {
1949 patternBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
1950 }
1951
1952 patterns.push(patternBitmap);
1953 }
1954
1955 return patterns;
1956}
1957
1958function decodeHalftoneRegion(mmr, patterns, template, regionWidth, regionHeight, defaultPixelValue, enableSkip, combinationOperator, gridWidth, gridHeight, gridOffsetX, gridOffsetY, gridVectorX, gridVectorY, decodingContext) {
1959 const skip = null;
1960
1961 if (enableSkip) {
1962 throw new Jbig2Error("skip is not supported");
1963 }
1964
1965 if (combinationOperator !== 0) {
1966 throw new Jbig2Error(`operator "${combinationOperator}" is not supported in halftone region`);
1967 }
1968
1969 const regionBitmap = [];
1970 let i, j, row;
1971
1972 for (i = 0; i < regionHeight; i++) {
1973 row = new Uint8Array(regionWidth);
1974
1975 if (defaultPixelValue) {
1976 for (j = 0; j < regionWidth; j++) {
1977 row[j] = defaultPixelValue;
1978 }
1979 }
1980
1981 regionBitmap.push(row);
1982 }
1983
1984 const numberOfPatterns = patterns.length;
1985 const pattern0 = patterns[0];
1986 const patternWidth = pattern0[0].length,
1987 patternHeight = pattern0.length;
1988 const bitsPerValue = (0, _core_utils.log2)(numberOfPatterns);
1989 const at = [];
1990
1991 if (!mmr) {
1992 at.push({
1993 x: template <= 1 ? 3 : 2,
1994 y: -1
1995 });
1996
1997 if (template === 0) {
1998 at.push({
1999 x: -3,
2000 y: -1
2001 }, {
2002 x: 2,
2003 y: -2
2004 }, {
2005 x: -2,
2006 y: -2
2007 });
2008 }
2009 }
2010
2011 const grayScaleBitPlanes = [];
2012 let mmrInput, bitmap;
2013
2014 if (mmr) {
2015 mmrInput = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
2016 }
2017
2018 for (i = bitsPerValue - 1; i >= 0; i--) {
2019 if (mmr) {
2020 bitmap = decodeMMRBitmap(mmrInput, gridWidth, gridHeight, true);
2021 } else {
2022 bitmap = decodeBitmap(false, gridWidth, gridHeight, template, false, skip, at, decodingContext);
2023 }
2024
2025 grayScaleBitPlanes[i] = bitmap;
2026 }
2027
2028 let mg, ng, bit, patternIndex, patternBitmap, x, y, patternRow, regionRow;
2029
2030 for (mg = 0; mg < gridHeight; mg++) {
2031 for (ng = 0; ng < gridWidth; ng++) {
2032 bit = 0;
2033 patternIndex = 0;
2034
2035 for (j = bitsPerValue - 1; j >= 0; j--) {
2036 bit ^= grayScaleBitPlanes[j][mg][ng];
2037 patternIndex |= bit << j;
2038 }
2039
2040 patternBitmap = patterns[patternIndex];
2041 x = gridOffsetX + mg * gridVectorY + ng * gridVectorX >> 8;
2042 y = gridOffsetY + mg * gridVectorX - ng * gridVectorY >> 8;
2043
2044 if (x >= 0 && x + patternWidth <= regionWidth && y >= 0 && y + patternHeight <= regionHeight) {
2045 for (i = 0; i < patternHeight; i++) {
2046 regionRow = regionBitmap[y + i];
2047 patternRow = patternBitmap[i];
2048
2049 for (j = 0; j < patternWidth; j++) {
2050 regionRow[x + j] |= patternRow[j];
2051 }
2052 }
2053 } else {
2054 let regionX, regionY;
2055
2056 for (i = 0; i < patternHeight; i++) {
2057 regionY = y + i;
2058
2059 if (regionY < 0 || regionY >= regionHeight) {
2060 continue;
2061 }
2062
2063 regionRow = regionBitmap[regionY];
2064 patternRow = patternBitmap[i];
2065
2066 for (j = 0; j < patternWidth; j++) {
2067 regionX = x + j;
2068
2069 if (regionX >= 0 && regionX < regionWidth) {
2070 regionRow[regionX] |= patternRow[j];
2071 }
2072 }
2073 }
2074 }
2075 }
2076 }
2077
2078 return regionBitmap;
2079}
2080
2081function readSegmentHeader(data, start) {
2082 const segmentHeader = {};
2083 segmentHeader.number = (0, _core_utils.readUint32)(data, start);
2084 const flags = data[start + 4];
2085 const segmentType = flags & 0x3f;
2086
2087 if (!SegmentTypes[segmentType]) {
2088 throw new Jbig2Error("invalid segment type: " + segmentType);
2089 }
2090
2091 segmentHeader.type = segmentType;
2092 segmentHeader.typeName = SegmentTypes[segmentType];
2093 segmentHeader.deferredNonRetain = !!(flags & 0x80);
2094 const pageAssociationFieldSize = !!(flags & 0x40);
2095 const referredFlags = data[start + 5];
2096 let referredToCount = referredFlags >> 5 & 7;
2097 const retainBits = [referredFlags & 31];
2098 let position = start + 6;
2099
2100 if (referredFlags === 7) {
2101 referredToCount = (0, _core_utils.readUint32)(data, position - 1) & 0x1fffffff;
2102 position += 3;
2103 let bytes = referredToCount + 7 >> 3;
2104 retainBits[0] = data[position++];
2105
2106 while (--bytes > 0) {
2107 retainBits.push(data[position++]);
2108 }
2109 } else if (referredFlags === 5 || referredFlags === 6) {
2110 throw new Jbig2Error("invalid referred-to flags");
2111 }
2112
2113 segmentHeader.retainBits = retainBits;
2114 let referredToSegmentNumberSize = 4;
2115
2116 if (segmentHeader.number <= 256) {
2117 referredToSegmentNumberSize = 1;
2118 } else if (segmentHeader.number <= 65536) {
2119 referredToSegmentNumberSize = 2;
2120 }
2121
2122 const referredTo = [];
2123 let i, ii;
2124
2125 for (i = 0; i < referredToCount; i++) {
2126 let number;
2127
2128 if (referredToSegmentNumberSize === 1) {
2129 number = data[position];
2130 } else if (referredToSegmentNumberSize === 2) {
2131 number = (0, _core_utils.readUint16)(data, position);
2132 } else {
2133 number = (0, _core_utils.readUint32)(data, position);
2134 }
2135
2136 referredTo.push(number);
2137 position += referredToSegmentNumberSize;
2138 }
2139
2140 segmentHeader.referredTo = referredTo;
2141
2142 if (!pageAssociationFieldSize) {
2143 segmentHeader.pageAssociation = data[position++];
2144 } else {
2145 segmentHeader.pageAssociation = (0, _core_utils.readUint32)(data, position);
2146 position += 4;
2147 }
2148
2149 segmentHeader.length = (0, _core_utils.readUint32)(data, position);
2150 position += 4;
2151
2152 if (segmentHeader.length === 0xffffffff) {
2153 if (segmentType === 38) {
2154 const genericRegionInfo = readRegionSegmentInformation(data, position);
2155 const genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
2156 const genericRegionMmr = !!(genericRegionSegmentFlags & 1);
2157 const searchPatternLength = 6;
2158 const searchPattern = new Uint8Array(searchPatternLength);
2159
2160 if (!genericRegionMmr) {
2161 searchPattern[0] = 0xff;
2162 searchPattern[1] = 0xac;
2163 }
2164
2165 searchPattern[2] = genericRegionInfo.height >>> 24 & 0xff;
2166 searchPattern[3] = genericRegionInfo.height >> 16 & 0xff;
2167 searchPattern[4] = genericRegionInfo.height >> 8 & 0xff;
2168 searchPattern[5] = genericRegionInfo.height & 0xff;
2169
2170 for (i = position, ii = data.length; i < ii; i++) {
2171 let j = 0;
2172
2173 while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
2174 j++;
2175 }
2176
2177 if (j === searchPatternLength) {
2178 segmentHeader.length = i + searchPatternLength;
2179 break;
2180 }
2181 }
2182
2183 if (segmentHeader.length === 0xffffffff) {
2184 throw new Jbig2Error("segment end was not found");
2185 }
2186 } else {
2187 throw new Jbig2Error("invalid unknown segment length");
2188 }
2189 }
2190
2191 segmentHeader.headerEnd = position;
2192 return segmentHeader;
2193}
2194
2195function readSegments(header, data, start, end) {
2196 const segments = [];
2197 let position = start;
2198
2199 while (position < end) {
2200 const segmentHeader = readSegmentHeader(data, position);
2201 position = segmentHeader.headerEnd;
2202 const segment = {
2203 header: segmentHeader,
2204 data
2205 };
2206
2207 if (!header.randomAccess) {
2208 segment.start = position;
2209 position += segmentHeader.length;
2210 segment.end = position;
2211 }
2212
2213 segments.push(segment);
2214
2215 if (segmentHeader.type === 51) {
2216 break;
2217 }
2218 }
2219
2220 if (header.randomAccess) {
2221 for (let i = 0, ii = segments.length; i < ii; i++) {
2222 segments[i].start = position;
2223 position += segments[i].header.length;
2224 segments[i].end = position;
2225 }
2226 }
2227
2228 return segments;
2229}
2230
2231function readRegionSegmentInformation(data, start) {
2232 return {
2233 width: (0, _core_utils.readUint32)(data, start),
2234 height: (0, _core_utils.readUint32)(data, start + 4),
2235 x: (0, _core_utils.readUint32)(data, start + 8),
2236 y: (0, _core_utils.readUint32)(data, start + 12),
2237 combinationOperator: data[start + 16] & 7
2238 };
2239}
2240
2241const RegionSegmentInformationFieldLength = 17;
2242
2243function processSegment(segment, visitor) {
2244 const header = segment.header;
2245 const data = segment.data,
2246 end = segment.end;
2247 let position = segment.start;
2248 let args, at, i, atLength;
2249
2250 switch (header.type) {
2251 case 0:
2252 const dictionary = {};
2253 const dictionaryFlags = (0, _core_utils.readUint16)(data, position);
2254 dictionary.huffman = !!(dictionaryFlags & 1);
2255 dictionary.refinement = !!(dictionaryFlags & 2);
2256 dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
2257 dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
2258 dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
2259 dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
2260 dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
2261 dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
2262 dictionary.template = dictionaryFlags >> 10 & 3;
2263 dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
2264 position += 2;
2265
2266 if (!dictionary.huffman) {
2267 atLength = dictionary.template === 0 ? 4 : 1;
2268 at = [];
2269
2270 for (i = 0; i < atLength; i++) {
2271 at.push({
2272 x: (0, _core_utils.readInt8)(data, position),
2273 y: (0, _core_utils.readInt8)(data, position + 1)
2274 });
2275 position += 2;
2276 }
2277
2278 dictionary.at = at;
2279 }
2280
2281 if (dictionary.refinement && !dictionary.refinementTemplate) {
2282 at = [];
2283
2284 for (i = 0; i < 2; i++) {
2285 at.push({
2286 x: (0, _core_utils.readInt8)(data, position),
2287 y: (0, _core_utils.readInt8)(data, position + 1)
2288 });
2289 position += 2;
2290 }
2291
2292 dictionary.refinementAt = at;
2293 }
2294
2295 dictionary.numberOfExportedSymbols = (0, _core_utils.readUint32)(data, position);
2296 position += 4;
2297 dictionary.numberOfNewSymbols = (0, _core_utils.readUint32)(data, position);
2298 position += 4;
2299 args = [dictionary, header.number, header.referredTo, data, position, end];
2300 break;
2301
2302 case 6:
2303 case 7:
2304 const textRegion = {};
2305 textRegion.info = readRegionSegmentInformation(data, position);
2306 position += RegionSegmentInformationFieldLength;
2307 const textRegionSegmentFlags = (0, _core_utils.readUint16)(data, position);
2308 position += 2;
2309 textRegion.huffman = !!(textRegionSegmentFlags & 1);
2310 textRegion.refinement = !!(textRegionSegmentFlags & 2);
2311 textRegion.logStripSize = textRegionSegmentFlags >> 2 & 3;
2312 textRegion.stripSize = 1 << textRegion.logStripSize;
2313 textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
2314 textRegion.transposed = !!(textRegionSegmentFlags & 64);
2315 textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
2316 textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
2317 textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
2318 textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
2319
2320 if (textRegion.huffman) {
2321 const textRegionHuffmanFlags = (0, _core_utils.readUint16)(data, position);
2322 position += 2;
2323 textRegion.huffmanFS = textRegionHuffmanFlags & 3;
2324 textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
2325 textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
2326 textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
2327 textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
2328 textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
2329 textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
2330 textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 0x4000);
2331 }
2332
2333 if (textRegion.refinement && !textRegion.refinementTemplate) {
2334 at = [];
2335
2336 for (i = 0; i < 2; i++) {
2337 at.push({
2338 x: (0, _core_utils.readInt8)(data, position),
2339 y: (0, _core_utils.readInt8)(data, position + 1)
2340 });
2341 position += 2;
2342 }
2343
2344 textRegion.refinementAt = at;
2345 }
2346
2347 textRegion.numberOfSymbolInstances = (0, _core_utils.readUint32)(data, position);
2348 position += 4;
2349 args = [textRegion, header.referredTo, data, position, end];
2350 break;
2351
2352 case 16:
2353 const patternDictionary = {};
2354 const patternDictionaryFlags = data[position++];
2355 patternDictionary.mmr = !!(patternDictionaryFlags & 1);
2356 patternDictionary.template = patternDictionaryFlags >> 1 & 3;
2357 patternDictionary.patternWidth = data[position++];
2358 patternDictionary.patternHeight = data[position++];
2359 patternDictionary.maxPatternIndex = (0, _core_utils.readUint32)(data, position);
2360 position += 4;
2361 args = [patternDictionary, header.number, data, position, end];
2362 break;
2363
2364 case 22:
2365 case 23:
2366 const halftoneRegion = {};
2367 halftoneRegion.info = readRegionSegmentInformation(data, position);
2368 position += RegionSegmentInformationFieldLength;
2369 const halftoneRegionFlags = data[position++];
2370 halftoneRegion.mmr = !!(halftoneRegionFlags & 1);
2371 halftoneRegion.template = halftoneRegionFlags >> 1 & 3;
2372 halftoneRegion.enableSkip = !!(halftoneRegionFlags & 8);
2373 halftoneRegion.combinationOperator = halftoneRegionFlags >> 4 & 7;
2374 halftoneRegion.defaultPixelValue = halftoneRegionFlags >> 7 & 1;
2375 halftoneRegion.gridWidth = (0, _core_utils.readUint32)(data, position);
2376 position += 4;
2377 halftoneRegion.gridHeight = (0, _core_utils.readUint32)(data, position);
2378 position += 4;
2379 halftoneRegion.gridOffsetX = (0, _core_utils.readUint32)(data, position) & 0xffffffff;
2380 position += 4;
2381 halftoneRegion.gridOffsetY = (0, _core_utils.readUint32)(data, position) & 0xffffffff;
2382 position += 4;
2383 halftoneRegion.gridVectorX = (0, _core_utils.readUint16)(data, position);
2384 position += 2;
2385 halftoneRegion.gridVectorY = (0, _core_utils.readUint16)(data, position);
2386 position += 2;
2387 args = [halftoneRegion, header.referredTo, data, position, end];
2388 break;
2389
2390 case 38:
2391 case 39:
2392 const genericRegion = {};
2393 genericRegion.info = readRegionSegmentInformation(data, position);
2394 position += RegionSegmentInformationFieldLength;
2395 const genericRegionSegmentFlags = data[position++];
2396 genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
2397 genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
2398 genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
2399
2400 if (!genericRegion.mmr) {
2401 atLength = genericRegion.template === 0 ? 4 : 1;
2402 at = [];
2403
2404 for (i = 0; i < atLength; i++) {
2405 at.push({
2406 x: (0, _core_utils.readInt8)(data, position),
2407 y: (0, _core_utils.readInt8)(data, position + 1)
2408 });
2409 position += 2;
2410 }
2411
2412 genericRegion.at = at;
2413 }
2414
2415 args = [genericRegion, data, position, end];
2416 break;
2417
2418 case 48:
2419 const pageInfo = {
2420 width: (0, _core_utils.readUint32)(data, position),
2421 height: (0, _core_utils.readUint32)(data, position + 4),
2422 resolutionX: (0, _core_utils.readUint32)(data, position + 8),
2423 resolutionY: (0, _core_utils.readUint32)(data, position + 12)
2424 };
2425
2426 if (pageInfo.height === 0xffffffff) {
2427 delete pageInfo.height;
2428 }
2429
2430 const pageSegmentFlags = data[position + 16];
2431 (0, _core_utils.readUint16)(data, position + 17);
2432 pageInfo.lossless = !!(pageSegmentFlags & 1);
2433 pageInfo.refinement = !!(pageSegmentFlags & 2);
2434 pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
2435 pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
2436 pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
2437 pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
2438 args = [pageInfo];
2439 break;
2440
2441 case 49:
2442 break;
2443
2444 case 50:
2445 break;
2446
2447 case 51:
2448 break;
2449
2450 case 53:
2451 args = [header.number, data, position, end];
2452 break;
2453
2454 case 62:
2455 break;
2456
2457 default:
2458 throw new Jbig2Error(`segment type ${header.typeName}(${header.type}) is not implemented`);
2459 }
2460
2461 const callbackName = "on" + header.typeName;
2462
2463 if (callbackName in visitor) {
2464 visitor[callbackName].apply(visitor, args);
2465 }
2466}
2467
2468function processSegments(segments, visitor) {
2469 for (let i = 0, ii = segments.length; i < ii; i++) {
2470 processSegment(segments[i], visitor);
2471 }
2472}
2473
2474function parseJbig2Chunks(chunks) {
2475 const visitor = new SimpleSegmentVisitor();
2476
2477 for (let i = 0, ii = chunks.length; i < ii; i++) {
2478 const chunk = chunks[i];
2479 const segments = readSegments({}, chunk.data, chunk.start, chunk.end);
2480 processSegments(segments, visitor);
2481 }
2482
2483 return visitor.buffer;
2484}
2485
2486function parseJbig2(data) {
2487 const end = data.length;
2488 let position = 0;
2489
2490 if (data[position] !== 0x97 || data[position + 1] !== 0x4a || data[position + 2] !== 0x42 || data[position + 3] !== 0x32 || data[position + 4] !== 0x0d || data[position + 5] !== 0x0a || data[position + 6] !== 0x1a || data[position + 7] !== 0x0a) {
2491 throw new Jbig2Error("parseJbig2 - invalid header.");
2492 }
2493
2494 const header = Object.create(null);
2495 position += 8;
2496 const flags = data[position++];
2497 header.randomAccess = !(flags & 1);
2498
2499 if (!(flags & 2)) {
2500 header.numberOfPages = (0, _core_utils.readUint32)(data, position);
2501 position += 4;
2502 }
2503
2504 const segments = readSegments(header, data, position, end);
2505 const visitor = new SimpleSegmentVisitor();
2506 processSegments(segments, visitor);
2507 const {
2508 width,
2509 height
2510 } = visitor.currentPageInfo;
2511 const bitPacked = visitor.buffer;
2512 const imgData = new Uint8ClampedArray(width * height);
2513 let q = 0,
2514 k = 0;
2515
2516 for (let i = 0; i < height; i++) {
2517 let mask = 0,
2518 buffer;
2519
2520 for (let j = 0; j < width; j++) {
2521 if (!mask) {
2522 mask = 128;
2523 buffer = bitPacked[k++];
2524 }
2525
2526 imgData[q++] = buffer & mask ? 0 : 255;
2527 mask >>= 1;
2528 }
2529 }
2530
2531 return {
2532 imgData,
2533 width,
2534 height
2535 };
2536}
2537
2538class SimpleSegmentVisitor {
2539 onPageInformation(info) {
2540 this.currentPageInfo = info;
2541 const rowSize = info.width + 7 >> 3;
2542 const buffer = new Uint8ClampedArray(rowSize * info.height);
2543
2544 if (info.defaultPixelValue) {
2545 buffer.fill(0xff);
2546 }
2547
2548 this.buffer = buffer;
2549 }
2550
2551 drawBitmap(regionInfo, bitmap) {
2552 const pageInfo = this.currentPageInfo;
2553 const width = regionInfo.width,
2554 height = regionInfo.height;
2555 const rowSize = pageInfo.width + 7 >> 3;
2556 const combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
2557 const buffer = this.buffer;
2558 const mask0 = 128 >> (regionInfo.x & 7);
2559 let offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
2560 let i, j, mask, offset;
2561
2562 switch (combinationOperator) {
2563 case 0:
2564 for (i = 0; i < height; i++) {
2565 mask = mask0;
2566 offset = offset0;
2567
2568 for (j = 0; j < width; j++) {
2569 if (bitmap[i][j]) {
2570 buffer[offset] |= mask;
2571 }
2572
2573 mask >>= 1;
2574
2575 if (!mask) {
2576 mask = 128;
2577 offset++;
2578 }
2579 }
2580
2581 offset0 += rowSize;
2582 }
2583
2584 break;
2585
2586 case 2:
2587 for (i = 0; i < height; i++) {
2588 mask = mask0;
2589 offset = offset0;
2590
2591 for (j = 0; j < width; j++) {
2592 if (bitmap[i][j]) {
2593 buffer[offset] ^= mask;
2594 }
2595
2596 mask >>= 1;
2597
2598 if (!mask) {
2599 mask = 128;
2600 offset++;
2601 }
2602 }
2603
2604 offset0 += rowSize;
2605 }
2606
2607 break;
2608
2609 default:
2610 throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
2611 }
2612 }
2613
2614 onImmediateGenericRegion(region, data, start, end) {
2615 const regionInfo = region.info;
2616 const decodingContext = new DecodingContext(data, start, end);
2617 const bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
2618 this.drawBitmap(regionInfo, bitmap);
2619 }
2620
2621 onImmediateLosslessGenericRegion() {
2622 this.onImmediateGenericRegion.apply(this, arguments);
2623 }
2624
2625 onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
2626 let huffmanTables, huffmanInput;
2627
2628 if (dictionary.huffman) {
2629 huffmanTables = getSymbolDictionaryHuffmanTables(dictionary, referredSegments, this.customTables);
2630 huffmanInput = new Reader(data, start, end);
2631 }
2632
2633 let symbols = this.symbols;
2634
2635 if (!symbols) {
2636 this.symbols = symbols = {};
2637 }
2638
2639 const inputSymbols = [];
2640
2641 for (const referredSegment of referredSegments) {
2642 const referredSymbols = symbols[referredSegment];
2643
2644 if (referredSymbols) {
2645 inputSymbols.push(...referredSymbols);
2646 }
2647 }
2648
2649 const decodingContext = new DecodingContext(data, start, end);
2650 symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext, huffmanInput);
2651 }
2652
2653 onImmediateTextRegion(region, referredSegments, data, start, end) {
2654 const regionInfo = region.info;
2655 let huffmanTables, huffmanInput;
2656 const symbols = this.symbols;
2657 const inputSymbols = [];
2658
2659 for (const referredSegment of referredSegments) {
2660 const referredSymbols = symbols[referredSegment];
2661
2662 if (referredSymbols) {
2663 inputSymbols.push(...referredSymbols);
2664 }
2665 }
2666
2667 const symbolCodeLength = (0, _core_utils.log2)(inputSymbols.length);
2668
2669 if (region.huffman) {
2670 huffmanInput = new Reader(data, start, end);
2671 huffmanTables = getTextRegionHuffmanTables(region, referredSegments, this.customTables, inputSymbols.length, huffmanInput);
2672 }
2673
2674 const decodingContext = new DecodingContext(data, start, end);
2675 const bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext, region.logStripSize, huffmanInput);
2676 this.drawBitmap(regionInfo, bitmap);
2677 }
2678
2679 onImmediateLosslessTextRegion() {
2680 this.onImmediateTextRegion.apply(this, arguments);
2681 }
2682
2683 onPatternDictionary(dictionary, currentSegment, data, start, end) {
2684 let patterns = this.patterns;
2685
2686 if (!patterns) {
2687 this.patterns = patterns = {};
2688 }
2689
2690 const decodingContext = new DecodingContext(data, start, end);
2691 patterns[currentSegment] = decodePatternDictionary(dictionary.mmr, dictionary.patternWidth, dictionary.patternHeight, dictionary.maxPatternIndex, dictionary.template, decodingContext);
2692 }
2693
2694 onImmediateHalftoneRegion(region, referredSegments, data, start, end) {
2695 const patterns = this.patterns[referredSegments[0]];
2696 const regionInfo = region.info;
2697 const decodingContext = new DecodingContext(data, start, end);
2698 const bitmap = decodeHalftoneRegion(region.mmr, patterns, region.template, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.enableSkip, region.combinationOperator, region.gridWidth, region.gridHeight, region.gridOffsetX, region.gridOffsetY, region.gridVectorX, region.gridVectorY, decodingContext);
2699 this.drawBitmap(regionInfo, bitmap);
2700 }
2701
2702 onImmediateLosslessHalftoneRegion() {
2703 this.onImmediateHalftoneRegion.apply(this, arguments);
2704 }
2705
2706 onTables(currentSegment, data, start, end) {
2707 let customTables = this.customTables;
2708
2709 if (!customTables) {
2710 this.customTables = customTables = {};
2711 }
2712
2713 customTables[currentSegment] = decodeTablesSegment(data, start, end);
2714 }
2715
2716}
2717
2718class HuffmanLine {
2719 constructor(lineData) {
2720 if (lineData.length === 2) {
2721 this.isOOB = true;
2722 this.rangeLow = 0;
2723 this.prefixLength = lineData[0];
2724 this.rangeLength = 0;
2725 this.prefixCode = lineData[1];
2726 this.isLowerRange = false;
2727 } else {
2728 this.isOOB = false;
2729 this.rangeLow = lineData[0];
2730 this.prefixLength = lineData[1];
2731 this.rangeLength = lineData[2];
2732 this.prefixCode = lineData[3];
2733 this.isLowerRange = lineData[4] === "lower";
2734 }
2735 }
2736
2737}
2738
2739class HuffmanTreeNode {
2740 constructor(line) {
2741 this.children = [];
2742
2743 if (line) {
2744 this.isLeaf = true;
2745 this.rangeLength = line.rangeLength;
2746 this.rangeLow = line.rangeLow;
2747 this.isLowerRange = line.isLowerRange;
2748 this.isOOB = line.isOOB;
2749 } else {
2750 this.isLeaf = false;
2751 }
2752 }
2753
2754 buildTree(line, shift) {
2755 const bit = line.prefixCode >> shift & 1;
2756
2757 if (shift <= 0) {
2758 this.children[bit] = new HuffmanTreeNode(line);
2759 } else {
2760 let node = this.children[bit];
2761
2762 if (!node) {
2763 this.children[bit] = node = new HuffmanTreeNode(null);
2764 }
2765
2766 node.buildTree(line, shift - 1);
2767 }
2768 }
2769
2770 decodeNode(reader) {
2771 if (this.isLeaf) {
2772 if (this.isOOB) {
2773 return null;
2774 }
2775
2776 const htOffset = reader.readBits(this.rangeLength);
2777 return this.rangeLow + (this.isLowerRange ? -htOffset : htOffset);
2778 }
2779
2780 const node = this.children[reader.readBit()];
2781
2782 if (!node) {
2783 throw new Jbig2Error("invalid Huffman data");
2784 }
2785
2786 return node.decodeNode(reader);
2787 }
2788
2789}
2790
2791class HuffmanTable {
2792 constructor(lines, prefixCodesDone) {
2793 if (!prefixCodesDone) {
2794 this.assignPrefixCodes(lines);
2795 }
2796
2797 this.rootNode = new HuffmanTreeNode(null);
2798
2799 for (let i = 0, ii = lines.length; i < ii; i++) {
2800 const line = lines[i];
2801
2802 if (line.prefixLength > 0) {
2803 this.rootNode.buildTree(line, line.prefixLength - 1);
2804 }
2805 }
2806 }
2807
2808 decode(reader) {
2809 return this.rootNode.decodeNode(reader);
2810 }
2811
2812 assignPrefixCodes(lines) {
2813 const linesLength = lines.length;
2814 let prefixLengthMax = 0;
2815
2816 for (let i = 0; i < linesLength; i++) {
2817 prefixLengthMax = Math.max(prefixLengthMax, lines[i].prefixLength);
2818 }
2819
2820 const histogram = new Uint32Array(prefixLengthMax + 1);
2821
2822 for (let i = 0; i < linesLength; i++) {
2823 histogram[lines[i].prefixLength]++;
2824 }
2825
2826 let currentLength = 1,
2827 firstCode = 0,
2828 currentCode,
2829 currentTemp,
2830 line;
2831 histogram[0] = 0;
2832
2833 while (currentLength <= prefixLengthMax) {
2834 firstCode = firstCode + histogram[currentLength - 1] << 1;
2835 currentCode = firstCode;
2836 currentTemp = 0;
2837
2838 while (currentTemp < linesLength) {
2839 line = lines[currentTemp];
2840
2841 if (line.prefixLength === currentLength) {
2842 line.prefixCode = currentCode;
2843 currentCode++;
2844 }
2845
2846 currentTemp++;
2847 }
2848
2849 currentLength++;
2850 }
2851 }
2852
2853}
2854
2855function decodeTablesSegment(data, start, end) {
2856 const flags = data[start];
2857 const lowestValue = (0, _core_utils.readUint32)(data, start + 1) & 0xffffffff;
2858 const highestValue = (0, _core_utils.readUint32)(data, start + 5) & 0xffffffff;
2859 const reader = new Reader(data, start + 9, end);
2860 const prefixSizeBits = (flags >> 1 & 7) + 1;
2861 const rangeSizeBits = (flags >> 4 & 7) + 1;
2862 const lines = [];
2863 let prefixLength,
2864 rangeLength,
2865 currentRangeLow = lowestValue;
2866
2867 do {
2868 prefixLength = reader.readBits(prefixSizeBits);
2869 rangeLength = reader.readBits(rangeSizeBits);
2870 lines.push(new HuffmanLine([currentRangeLow, prefixLength, rangeLength, 0]));
2871 currentRangeLow += 1 << rangeLength;
2872 } while (currentRangeLow < highestValue);
2873
2874 prefixLength = reader.readBits(prefixSizeBits);
2875 lines.push(new HuffmanLine([lowestValue - 1, prefixLength, 32, 0, "lower"]));
2876 prefixLength = reader.readBits(prefixSizeBits);
2877 lines.push(new HuffmanLine([highestValue, prefixLength, 32, 0]));
2878
2879 if (flags & 1) {
2880 prefixLength = reader.readBits(prefixSizeBits);
2881 lines.push(new HuffmanLine([prefixLength, 0]));
2882 }
2883
2884 return new HuffmanTable(lines, false);
2885}
2886
2887const standardTablesCache = {};
2888
2889function getStandardTable(number) {
2890 let table = standardTablesCache[number];
2891
2892 if (table) {
2893 return table;
2894 }
2895
2896 let lines;
2897
2898 switch (number) {
2899 case 1:
2900 lines = [[0, 1, 4, 0x0], [16, 2, 8, 0x2], [272, 3, 16, 0x6], [65808, 3, 32, 0x7]];
2901 break;
2902
2903 case 2:
2904 lines = [[0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xe], [11, 5, 6, 0x1e], [75, 6, 32, 0x3e], [6, 0x3f]];
2905 break;
2906
2907 case 3:
2908 lines = [[-256, 8, 8, 0xfe], [0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xe], [11, 5, 6, 0x1e], [-257, 8, 32, 0xff, "lower"], [75, 7, 32, 0x7e], [6, 0x3e]];
2909 break;
2910
2911 case 4:
2912 lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xe], [12, 5, 6, 0x1e], [76, 5, 32, 0x1f]];
2913 break;
2914
2915 case 5:
2916 lines = [[-255, 7, 8, 0x7e], [1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xe], [12, 5, 6, 0x1e], [-256, 7, 32, 0x7f, "lower"], [76, 6, 32, 0x3e]];
2917 break;
2918
2919 case 6:
2920 lines = [[-2048, 5, 10, 0x1c], [-1024, 4, 9, 0x8], [-512, 4, 8, 0x9], [-256, 4, 7, 0xa], [-128, 5, 6, 0x1d], [-64, 5, 5, 0x1e], [-32, 4, 5, 0xb], [0, 2, 7, 0x0], [128, 3, 7, 0x2], [256, 3, 8, 0x3], [512, 4, 9, 0xc], [1024, 4, 10, 0xd], [-2049, 6, 32, 0x3e, "lower"], [2048, 6, 32, 0x3f]];
2921 break;
2922
2923 case 7:
2924 lines = [[-1024, 4, 9, 0x8], [-512, 3, 8, 0x0], [-256, 4, 7, 0x9], [-128, 5, 6, 0x1a], [-64, 5, 5, 0x1b], [-32, 4, 5, 0xa], [0, 4, 5, 0xb], [32, 5, 5, 0x1c], [64, 5, 6, 0x1d], [128, 4, 7, 0xc], [256, 3, 8, 0x1], [512, 3, 9, 0x2], [1024, 3, 10, 0x3], [-1025, 5, 32, 0x1e, "lower"], [2048, 5, 32, 0x1f]];
2925 break;
2926
2927 case 8:
2928 lines = [[-15, 8, 3, 0xfc], [-7, 9, 1, 0x1fc], [-5, 8, 1, 0xfd], [-3, 9, 0, 0x1fd], [-2, 7, 0, 0x7c], [-1, 4, 0, 0xa], [0, 2, 1, 0x0], [2, 5, 0, 0x1a], [3, 6, 0, 0x3a], [4, 3, 4, 0x4], [20, 6, 1, 0x3b], [22, 4, 4, 0xb], [38, 4, 5, 0xc], [70, 5, 6, 0x1b], [134, 5, 7, 0x1c], [262, 6, 7, 0x3c], [390, 7, 8, 0x7d], [646, 6, 10, 0x3d], [-16, 9, 32, 0x1fe, "lower"], [1670, 9, 32, 0x1ff], [2, 0x1]];
2929 break;
2930
2931 case 9:
2932 lines = [[-31, 8, 4, 0xfc], [-15, 9, 2, 0x1fc], [-11, 8, 2, 0xfd], [-7, 9, 1, 0x1fd], [-5, 7, 1, 0x7c], [-3, 4, 1, 0xa], [-1, 3, 1, 0x2], [1, 3, 1, 0x3], [3, 5, 1, 0x1a], [5, 6, 1, 0x3a], [7, 3, 5, 0x4], [39, 6, 2, 0x3b], [43, 4, 5, 0xb], [75, 4, 6, 0xc], [139, 5, 7, 0x1b], [267, 5, 8, 0x1c], [523, 6, 8, 0x3c], [779, 7, 9, 0x7d], [1291, 6, 11, 0x3d], [-32, 9, 32, 0x1fe, "lower"], [3339, 9, 32, 0x1ff], [2, 0x0]];
2933 break;
2934
2935 case 10:
2936 lines = [[-21, 7, 4, 0x7a], [-5, 8, 0, 0xfc], [-4, 7, 0, 0x7b], [-3, 5, 0, 0x18], [-2, 2, 2, 0x0], [2, 5, 0, 0x19], [3, 6, 0, 0x36], [4, 7, 0, 0x7c], [5, 8, 0, 0xfd], [6, 2, 6, 0x1], [70, 5, 5, 0x1a], [102, 6, 5, 0x37], [134, 6, 6, 0x38], [198, 6, 7, 0x39], [326, 6, 8, 0x3a], [582, 6, 9, 0x3b], [1094, 6, 10, 0x3c], [2118, 7, 11, 0x7d], [-22, 8, 32, 0xfe, "lower"], [4166, 8, 32, 0xff], [2, 0x2]];
2937 break;
2938
2939 case 11:
2940 lines = [[1, 1, 0, 0x0], [2, 2, 1, 0x2], [4, 4, 0, 0xc], [5, 4, 1, 0xd], [7, 5, 1, 0x1c], [9, 5, 2, 0x1d], [13, 6, 2, 0x3c], [17, 7, 2, 0x7a], [21, 7, 3, 0x7b], [29, 7, 4, 0x7c], [45, 7, 5, 0x7d], [77, 7, 6, 0x7e], [141, 7, 32, 0x7f]];
2941 break;
2942
2943 case 12:
2944 lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 1, 0x6], [5, 5, 0, 0x1c], [6, 5, 1, 0x1d], [8, 6, 1, 0x3c], [10, 7, 0, 0x7a], [11, 7, 1, 0x7b], [13, 7, 2, 0x7c], [17, 7, 3, 0x7d], [25, 7, 4, 0x7e], [41, 8, 5, 0xfe], [73, 8, 32, 0xff]];
2945 break;
2946
2947 case 13:
2948 lines = [[1, 1, 0, 0x0], [2, 3, 0, 0x4], [3, 4, 0, 0xc], [4, 5, 0, 0x1c], [5, 4, 1, 0xd], [7, 3, 3, 0x5], [15, 6, 1, 0x3a], [17, 6, 2, 0x3b], [21, 6, 3, 0x3c], [29, 6, 4, 0x3d], [45, 6, 5, 0x3e], [77, 7, 6, 0x7e], [141, 7, 32, 0x7f]];
2949 break;
2950
2951 case 14:
2952 lines = [[-2, 3, 0, 0x4], [-1, 3, 0, 0x5], [0, 1, 0, 0x0], [1, 3, 0, 0x6], [2, 3, 0, 0x7]];
2953 break;
2954
2955 case 15:
2956 lines = [[-24, 7, 4, 0x7c], [-8, 6, 2, 0x3c], [-4, 5, 1, 0x1c], [-2, 4, 0, 0xc], [-1, 3, 0, 0x4], [0, 1, 0, 0x0], [1, 3, 0, 0x5], [2, 4, 0, 0xd], [3, 5, 1, 0x1d], [5, 6, 2, 0x3d], [9, 7, 4, 0x7d], [-25, 7, 32, 0x7e, "lower"], [25, 7, 32, 0x7f]];
2957 break;
2958
2959 default:
2960 throw new Jbig2Error(`standard table B.${number} does not exist`);
2961 }
2962
2963 for (let i = 0, ii = lines.length; i < ii; i++) {
2964 lines[i] = new HuffmanLine(lines[i]);
2965 }
2966
2967 table = new HuffmanTable(lines, true);
2968 standardTablesCache[number] = table;
2969 return table;
2970}
2971
2972class Reader {
2973 constructor(data, start, end) {
2974 this.data = data;
2975 this.start = start;
2976 this.end = end;
2977 this.position = start;
2978 this.shift = -1;
2979 this.currentByte = 0;
2980 }
2981
2982 readBit() {
2983 if (this.shift < 0) {
2984 if (this.position >= this.end) {
2985 throw new Jbig2Error("end of data while reading bit");
2986 }
2987
2988 this.currentByte = this.data[this.position++];
2989 this.shift = 7;
2990 }
2991
2992 const bit = this.currentByte >> this.shift & 1;
2993 this.shift--;
2994 return bit;
2995 }
2996
2997 readBits(numBits) {
2998 let result = 0,
2999 i;
3000
3001 for (i = numBits - 1; i >= 0; i--) {
3002 result |= this.readBit() << i;
3003 }
3004
3005 return result;
3006 }
3007
3008 byteAlign() {
3009 this.shift = -1;
3010 }
3011
3012 next() {
3013 if (this.position >= this.end) {
3014 return -1;
3015 }
3016
3017 return this.data[this.position++];
3018 }
3019
3020}
3021
3022function getCustomHuffmanTable(index, referredTo, customTables) {
3023 let currentIndex = 0;
3024
3025 for (let i = 0, ii = referredTo.length; i < ii; i++) {
3026 const table = customTables[referredTo[i]];
3027
3028 if (table) {
3029 if (index === currentIndex) {
3030 return table;
3031 }
3032
3033 currentIndex++;
3034 }
3035 }
3036
3037 throw new Jbig2Error("can't find custom Huffman table");
3038}
3039
3040function getTextRegionHuffmanTables(textRegion, referredTo, customTables, numberOfSymbols, reader) {
3041 const codes = [];
3042
3043 for (let i = 0; i <= 34; i++) {
3044 const codeLength = reader.readBits(4);
3045 codes.push(new HuffmanLine([i, codeLength, 0, 0]));
3046 }
3047
3048 const runCodesTable = new HuffmanTable(codes, false);
3049 codes.length = 0;
3050
3051 for (let i = 0; i < numberOfSymbols;) {
3052 const codeLength = runCodesTable.decode(reader);
3053
3054 if (codeLength >= 32) {
3055 let repeatedLength, numberOfRepeats, j;
3056
3057 switch (codeLength) {
3058 case 32:
3059 if (i === 0) {
3060 throw new Jbig2Error("no previous value in symbol ID table");
3061 }
3062
3063 numberOfRepeats = reader.readBits(2) + 3;
3064 repeatedLength = codes[i - 1].prefixLength;
3065 break;
3066
3067 case 33:
3068 numberOfRepeats = reader.readBits(3) + 3;
3069 repeatedLength = 0;
3070 break;
3071
3072 case 34:
3073 numberOfRepeats = reader.readBits(7) + 11;
3074 repeatedLength = 0;
3075 break;
3076
3077 default:
3078 throw new Jbig2Error("invalid code length in symbol ID table");
3079 }
3080
3081 for (j = 0; j < numberOfRepeats; j++) {
3082 codes.push(new HuffmanLine([i, repeatedLength, 0, 0]));
3083 i++;
3084 }
3085 } else {
3086 codes.push(new HuffmanLine([i, codeLength, 0, 0]));
3087 i++;
3088 }
3089 }
3090
3091 reader.byteAlign();
3092 const symbolIDTable = new HuffmanTable(codes, false);
3093 let customIndex = 0,
3094 tableFirstS,
3095 tableDeltaS,
3096 tableDeltaT;
3097
3098 switch (textRegion.huffmanFS) {
3099 case 0:
3100 case 1:
3101 tableFirstS = getStandardTable(textRegion.huffmanFS + 6);
3102 break;
3103
3104 case 3:
3105 tableFirstS = getCustomHuffmanTable(customIndex, referredTo, customTables);
3106 customIndex++;
3107 break;
3108
3109 default:
3110 throw new Jbig2Error("invalid Huffman FS selector");
3111 }
3112
3113 switch (textRegion.huffmanDS) {
3114 case 0:
3115 case 1:
3116 case 2:
3117 tableDeltaS = getStandardTable(textRegion.huffmanDS + 8);
3118 break;
3119
3120 case 3:
3121 tableDeltaS = getCustomHuffmanTable(customIndex, referredTo, customTables);
3122 customIndex++;
3123 break;
3124
3125 default:
3126 throw new Jbig2Error("invalid Huffman DS selector");
3127 }
3128
3129 switch (textRegion.huffmanDT) {
3130 case 0:
3131 case 1:
3132 case 2:
3133 tableDeltaT = getStandardTable(textRegion.huffmanDT + 11);
3134 break;
3135
3136 case 3:
3137 tableDeltaT = getCustomHuffmanTable(customIndex, referredTo, customTables);
3138 customIndex++;
3139 break;
3140
3141 default:
3142 throw new Jbig2Error("invalid Huffman DT selector");
3143 }
3144
3145 if (textRegion.refinement) {
3146 throw new Jbig2Error("refinement with Huffman is not supported");
3147 }
3148
3149 return {
3150 symbolIDTable,
3151 tableFirstS,
3152 tableDeltaS,
3153 tableDeltaT
3154 };
3155}
3156
3157function getSymbolDictionaryHuffmanTables(dictionary, referredTo, customTables) {
3158 let customIndex = 0,
3159 tableDeltaHeight,
3160 tableDeltaWidth;
3161
3162 switch (dictionary.huffmanDHSelector) {
3163 case 0:
3164 case 1:
3165 tableDeltaHeight = getStandardTable(dictionary.huffmanDHSelector + 4);
3166 break;
3167
3168 case 3:
3169 tableDeltaHeight = getCustomHuffmanTable(customIndex, referredTo, customTables);
3170 customIndex++;
3171 break;
3172
3173 default:
3174 throw new Jbig2Error("invalid Huffman DH selector");
3175 }
3176
3177 switch (dictionary.huffmanDWSelector) {
3178 case 0:
3179 case 1:
3180 tableDeltaWidth = getStandardTable(dictionary.huffmanDWSelector + 2);
3181 break;
3182
3183 case 3:
3184 tableDeltaWidth = getCustomHuffmanTable(customIndex, referredTo, customTables);
3185 customIndex++;
3186 break;
3187
3188 default:
3189 throw new Jbig2Error("invalid Huffman DW selector");
3190 }
3191
3192 let tableBitmapSize, tableAggregateInstances;
3193
3194 if (dictionary.bitmapSizeSelector) {
3195 tableBitmapSize = getCustomHuffmanTable(customIndex, referredTo, customTables);
3196 customIndex++;
3197 } else {
3198 tableBitmapSize = getStandardTable(1);
3199 }
3200
3201 if (dictionary.aggregationInstancesSelector) {
3202 tableAggregateInstances = getCustomHuffmanTable(customIndex, referredTo, customTables);
3203 } else {
3204 tableAggregateInstances = getStandardTable(1);
3205 }
3206
3207 return {
3208 tableDeltaHeight,
3209 tableDeltaWidth,
3210 tableBitmapSize,
3211 tableAggregateInstances
3212 };
3213}
3214
3215function readUncompressedBitmap(reader, width, height) {
3216 const bitmap = [];
3217
3218 for (let y = 0; y < height; y++) {
3219 const row = new Uint8Array(width);
3220 bitmap.push(row);
3221
3222 for (let x = 0; x < width; x++) {
3223 row[x] = reader.readBit();
3224 }
3225
3226 reader.byteAlign();
3227 }
3228
3229 return bitmap;
3230}
3231
3232function decodeMMRBitmap(input, width, height, endOfBlock) {
3233 const params = {
3234 K: -1,
3235 Columns: width,
3236 Rows: height,
3237 BlackIs1: true,
3238 EndOfBlock: endOfBlock
3239 };
3240 const decoder = new _ccitt.CCITTFaxDecoder(input, params);
3241 const bitmap = [];
3242 let currentByte,
3243 eof = false;
3244
3245 for (let y = 0; y < height; y++) {
3246 const row = new Uint8Array(width);
3247 bitmap.push(row);
3248 let shift = -1;
3249
3250 for (let x = 0; x < width; x++) {
3251 if (shift < 0) {
3252 currentByte = decoder.readNextChar();
3253
3254 if (currentByte === -1) {
3255 currentByte = 0;
3256 eof = true;
3257 }
3258
3259 shift = 7;
3260 }
3261
3262 row[x] = currentByte >> shift & 1;
3263 shift--;
3264 }
3265 }
3266
3267 if (endOfBlock && !eof) {
3268 const lookForEOFLimit = 5;
3269
3270 for (let i = 0; i < lookForEOFLimit; i++) {
3271 if (decoder.readNextChar() === -1) {
3272 break;
3273 }
3274 }
3275 }
3276
3277 return bitmap;
3278}
3279
3280class Jbig2Image {
3281 parseChunks(chunks) {
3282 return parseJbig2Chunks(chunks);
3283 }
3284
3285 parse(data) {
3286 const {
3287 imgData,
3288 width,
3289 height
3290 } = parseJbig2(data);
3291 this.width = width;
3292 this.height = height;
3293 return imgData;
3294 }
3295
3296}
3297
3298exports.Jbig2Image = Jbig2Image;
3299
3300/***/ }),
3301/* 5 */
3302/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
3303
3304
3305
3306Object.defineProperty(exports, "__esModule", ({
3307 value: true
3308}));
3309exports.XRefParseException = exports.XRefEntryException = exports.ParserEOFException = exports.MissingDataException = exports.DocStats = void 0;
3310exports.collectActions = collectActions;
3311exports.encodeToXmlString = encodeToXmlString;
3312exports.escapePDFName = escapePDFName;
3313exports.getArrayLookupTableFactory = getArrayLookupTableFactory;
3314exports.getInheritableProperty = getInheritableProperty;
3315exports.getLookupTableFactory = getLookupTableFactory;
3316exports.getNewAnnotationsMap = getNewAnnotationsMap;
3317exports.isWhiteSpace = isWhiteSpace;
3318exports.log2 = log2;
3319exports.numberToString = numberToString;
3320exports.parseXFAPath = parseXFAPath;
3321exports.readInt8 = readInt8;
3322exports.readUint16 = readUint16;
3323exports.readUint32 = readUint32;
3324exports.recoverJsURL = recoverJsURL;
3325exports.toRomanNumerals = toRomanNumerals;
3326exports.validateCSSFont = validateCSSFont;
3327
3328var _util = __w_pdfjs_require__(1);
3329
3330var _primitives = __w_pdfjs_require__(6);
3331
3332var _base_stream = __w_pdfjs_require__(7);
3333
3334function getLookupTableFactory(initializer) {
3335 let lookup;
3336 return function () {
3337 if (initializer) {
3338 lookup = Object.create(null);
3339 initializer(lookup);
3340 initializer = null;
3341 }
3342
3343 return lookup;
3344 };
3345}
3346
3347function getArrayLookupTableFactory(initializer) {
3348 let lookup;
3349 return function () {
3350 if (initializer) {
3351 let arr = initializer();
3352 initializer = null;
3353 lookup = Object.create(null);
3354
3355 for (let i = 0, ii = arr.length; i < ii; i += 2) {
3356 lookup[arr[i]] = arr[i + 1];
3357 }
3358
3359 arr = null;
3360 }
3361
3362 return lookup;
3363 };
3364}
3365
3366class MissingDataException extends _util.BaseException {
3367 constructor(begin, end) {
3368 super(`Missing data [${begin}, ${end})`, "MissingDataException");
3369 this.begin = begin;
3370 this.end = end;
3371 }
3372
3373}
3374
3375exports.MissingDataException = MissingDataException;
3376
3377class ParserEOFException extends _util.BaseException {
3378 constructor(msg) {
3379 super(msg, "ParserEOFException");
3380 }
3381
3382}
3383
3384exports.ParserEOFException = ParserEOFException;
3385
3386class XRefEntryException extends _util.BaseException {
3387 constructor(msg) {
3388 super(msg, "XRefEntryException");
3389 }
3390
3391}
3392
3393exports.XRefEntryException = XRefEntryException;
3394
3395class XRefParseException extends _util.BaseException {
3396 constructor(msg) {
3397 super(msg, "XRefParseException");
3398 }
3399
3400}
3401
3402exports.XRefParseException = XRefParseException;
3403
3404class DocStats {
3405 constructor(handler) {
3406 this._handler = handler;
3407 this._streamTypes = new Set();
3408 this._fontTypes = new Set();
3409 }
3410
3411 _send() {
3412 const streamTypes = Object.create(null),
3413 fontTypes = Object.create(null);
3414
3415 for (const type of this._streamTypes) {
3416 streamTypes[type] = true;
3417 }
3418
3419 for (const type of this._fontTypes) {
3420 fontTypes[type] = true;
3421 }
3422
3423 this._handler.send("DocStats", {
3424 streamTypes,
3425 fontTypes
3426 });
3427 }
3428
3429 addStreamType(type) {
3430 if (this._streamTypes.has(type)) {
3431 return;
3432 }
3433
3434 this._streamTypes.add(type);
3435
3436 this._send();
3437 }
3438
3439 addFontType(type) {
3440 if (this._fontTypes.has(type)) {
3441 return;
3442 }
3443
3444 this._fontTypes.add(type);
3445
3446 this._send();
3447 }
3448
3449}
3450
3451exports.DocStats = DocStats;
3452
3453function getInheritableProperty({
3454 dict,
3455 key,
3456 getArray = false,
3457 stopWhenFound = true
3458}) {
3459 let values;
3460 const visited = new _primitives.RefSet();
3461
3462 while (dict instanceof _primitives.Dict && !(dict.objId && visited.has(dict.objId))) {
3463 if (dict.objId) {
3464 visited.put(dict.objId);
3465 }
3466
3467 const value = getArray ? dict.getArray(key) : dict.get(key);
3468
3469 if (value !== undefined) {
3470 if (stopWhenFound) {
3471 return value;
3472 }
3473
3474 if (!values) {
3475 values = [];
3476 }
3477
3478 values.push(value);
3479 }
3480
3481 dict = dict.get("Parent");
3482 }
3483
3484 return values;
3485}
3486
3487const ROMAN_NUMBER_MAP = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"];
3488
3489function toRomanNumerals(number, lowerCase = false) {
3490 (0, _util.assert)(Number.isInteger(number) && number > 0, "The number should be a positive integer.");
3491 const romanBuf = [];
3492 let pos;
3493
3494 while (number >= 1000) {
3495 number -= 1000;
3496 romanBuf.push("M");
3497 }
3498
3499 pos = number / 100 | 0;
3500 number %= 100;
3501 romanBuf.push(ROMAN_NUMBER_MAP[pos]);
3502 pos = number / 10 | 0;
3503 number %= 10;
3504 romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
3505 romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
3506 const romanStr = romanBuf.join("");
3507 return lowerCase ? romanStr.toLowerCase() : romanStr;
3508}
3509
3510function log2(x) {
3511 if (x <= 0) {
3512 return 0;
3513 }
3514
3515 return Math.ceil(Math.log2(x));
3516}
3517
3518function readInt8(data, offset) {
3519 return data[offset] << 24 >> 24;
3520}
3521
3522function readUint16(data, offset) {
3523 return data[offset] << 8 | data[offset + 1];
3524}
3525
3526function readUint32(data, offset) {
3527 return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
3528}
3529
3530function isWhiteSpace(ch) {
3531 return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a;
3532}
3533
3534function parseXFAPath(path) {
3535 const positionPattern = /(.+)\[(\d+)\]$/;
3536 return path.split(".").map(component => {
3537 const m = component.match(positionPattern);
3538
3539 if (m) {
3540 return {
3541 name: m[1],
3542 pos: parseInt(m[2], 10)
3543 };
3544 }
3545
3546 return {
3547 name: component,
3548 pos: 0
3549 };
3550 });
3551}
3552
3553function escapePDFName(str) {
3554 const buffer = [];
3555 let start = 0;
3556
3557 for (let i = 0, ii = str.length; i < ii; i++) {
3558 const char = str.charCodeAt(i);
3559
3560 if (char < 0x21 || char > 0x7e || char === 0x23 || char === 0x28 || char === 0x29 || char === 0x3c || char === 0x3e || char === 0x5b || char === 0x5d || char === 0x7b || char === 0x7d || char === 0x2f || char === 0x25) {
3561 if (start < i) {
3562 buffer.push(str.substring(start, i));
3563 }
3564
3565 buffer.push(`#${char.toString(16)}`);
3566 start = i + 1;
3567 }
3568 }
3569
3570 if (buffer.length === 0) {
3571 return str;
3572 }
3573
3574 if (start < str.length) {
3575 buffer.push(str.substring(start, str.length));
3576 }
3577
3578 return buffer.join("");
3579}
3580
3581function _collectJS(entry, xref, list, parents) {
3582 if (!entry) {
3583 return;
3584 }
3585
3586 let parent = null;
3587
3588 if (entry instanceof _primitives.Ref) {
3589 if (parents.has(entry)) {
3590 return;
3591 }
3592
3593 parent = entry;
3594 parents.put(parent);
3595 entry = xref.fetch(entry);
3596 }
3597
3598 if (Array.isArray(entry)) {
3599 for (const element of entry) {
3600 _collectJS(element, xref, list, parents);
3601 }
3602 } else if (entry instanceof _primitives.Dict) {
3603 if ((0, _primitives.isName)(entry.get("S"), "JavaScript")) {
3604 const js = entry.get("JS");
3605 let code;
3606
3607 if (js instanceof _base_stream.BaseStream) {
3608 code = js.getString();
3609 } else if (typeof js === "string") {
3610 code = js;
3611 }
3612
3613 code = code && (0, _util.stringToPDFString)(code).replace(/\u0000/g, "");
3614
3615 if (code) {
3616 list.push(code);
3617 }
3618 }
3619
3620 _collectJS(entry.getRaw("Next"), xref, list, parents);
3621 }
3622
3623 if (parent) {
3624 parents.remove(parent);
3625 }
3626}
3627
3628function collectActions(xref, dict, eventType) {
3629 const actions = Object.create(null);
3630 const additionalActionsDicts = getInheritableProperty({
3631 dict,
3632 key: "AA",
3633 stopWhenFound: false
3634 });
3635
3636 if (additionalActionsDicts) {
3637 for (let i = additionalActionsDicts.length - 1; i >= 0; i--) {
3638 const additionalActions = additionalActionsDicts[i];
3639
3640 if (!(additionalActions instanceof _primitives.Dict)) {
3641 continue;
3642 }
3643
3644 for (const key of additionalActions.getKeys()) {
3645 const action = eventType[key];
3646
3647 if (!action) {
3648 continue;
3649 }
3650
3651 const actionDict = additionalActions.getRaw(key);
3652 const parents = new _primitives.RefSet();
3653 const list = [];
3654
3655 _collectJS(actionDict, xref, list, parents);
3656
3657 if (list.length > 0) {
3658 actions[action] = list;
3659 }
3660 }
3661 }
3662 }
3663
3664 if (dict.has("A")) {
3665 const actionDict = dict.get("A");
3666 const parents = new _primitives.RefSet();
3667 const list = [];
3668
3669 _collectJS(actionDict, xref, list, parents);
3670
3671 if (list.length > 0) {
3672 actions.Action = list;
3673 }
3674 }
3675
3676 return (0, _util.objectSize)(actions) > 0 ? actions : null;
3677}
3678
3679const XMLEntities = {
3680 0x3c: "&lt;",
3681 0x3e: "&gt;",
3682 0x26: "&amp;",
3683 0x22: "&quot;",
3684 0x27: "&apos;"
3685};
3686
3687function encodeToXmlString(str) {
3688 const buffer = [];
3689 let start = 0;
3690
3691 for (let i = 0, ii = str.length; i < ii; i++) {
3692 const char = str.codePointAt(i);
3693
3694 if (0x20 <= char && char <= 0x7e) {
3695 const entity = XMLEntities[char];
3696
3697 if (entity) {
3698 if (start < i) {
3699 buffer.push(str.substring(start, i));
3700 }
3701
3702 buffer.push(entity);
3703 start = i + 1;
3704 }
3705 } else {
3706 if (start < i) {
3707 buffer.push(str.substring(start, i));
3708 }
3709
3710 buffer.push(`&#x${char.toString(16).toUpperCase()};`);
3711
3712 if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
3713 i++;
3714 }
3715
3716 start = i + 1;
3717 }
3718 }
3719
3720 if (buffer.length === 0) {
3721 return str;
3722 }
3723
3724 if (start < str.length) {
3725 buffer.push(str.substring(start, str.length));
3726 }
3727
3728 return buffer.join("");
3729}
3730
3731function validateCSSFont(cssFontInfo) {
3732 const DEFAULT_CSS_FONT_OBLIQUE = "14";
3733 const DEFAULT_CSS_FONT_WEIGHT = "400";
3734 const CSS_FONT_WEIGHT_VALUES = new Set(["100", "200", "300", "400", "500", "600", "700", "800", "900", "1000", "normal", "bold", "bolder", "lighter"]);
3735 const {
3736 fontFamily,
3737 fontWeight,
3738 italicAngle
3739 } = cssFontInfo;
3740
3741 if (/^".*"$/.test(fontFamily)) {
3742 if (/[^\\]"/.test(fontFamily.slice(1, fontFamily.length - 1))) {
3743 (0, _util.warn)(`XFA - FontFamily contains some unescaped ": ${fontFamily}.`);
3744 return false;
3745 }
3746 } else if (/^'.*'$/.test(fontFamily)) {
3747 if (/[^\\]'/.test(fontFamily.slice(1, fontFamily.length - 1))) {
3748 (0, _util.warn)(`XFA - FontFamily contains some unescaped ': ${fontFamily}.`);
3749 return false;
3750 }
3751 } else {
3752 for (const ident of fontFamily.split(/[ \t]+/)) {
3753 if (/^(\d|(-(\d|-)))/.test(ident) || !/^[\w-\\]+$/.test(ident)) {
3754 (0, _util.warn)(`XFA - FontFamily contains some invalid <custom-ident>: ${fontFamily}.`);
3755 return false;
3756 }
3757 }
3758 }
3759
3760 const weight = fontWeight ? fontWeight.toString() : "";
3761 cssFontInfo.fontWeight = CSS_FONT_WEIGHT_VALUES.has(weight) ? weight : DEFAULT_CSS_FONT_WEIGHT;
3762 const angle = parseFloat(italicAngle);
3763 cssFontInfo.italicAngle = isNaN(angle) || angle < -90 || angle > 90 ? DEFAULT_CSS_FONT_OBLIQUE : italicAngle.toString();
3764 return true;
3765}
3766
3767function recoverJsURL(str) {
3768 const URL_OPEN_METHODS = ["app.launchURL", "window.open", "xfa.host.gotoURL"];
3769 const regex = new RegExp("^\\s*(" + URL_OPEN_METHODS.join("|").split(".").join("\\.") + ")\\((?:'|\")([^'\"]*)(?:'|\")(?:,\\s*(\\w+)\\)|\\))", "i");
3770 const jsUrl = regex.exec(str);
3771
3772 if (jsUrl && jsUrl[2]) {
3773 const url = jsUrl[2];
3774 let newWindow = false;
3775
3776 if (jsUrl[3] === "true" && jsUrl[1] === "app.launchURL") {
3777 newWindow = true;
3778 }
3779
3780 return {
3781 url,
3782 newWindow
3783 };
3784 }
3785
3786 return null;
3787}
3788
3789function numberToString(value) {
3790 if (Number.isInteger(value)) {
3791 return value.toString();
3792 }
3793
3794 const roundedValue = Math.round(value * 100);
3795
3796 if (roundedValue % 100 === 0) {
3797 return (roundedValue / 100).toString();
3798 }
3799
3800 if (roundedValue % 10 === 0) {
3801 return value.toFixed(1);
3802 }
3803
3804 return value.toFixed(2);
3805}
3806
3807function getNewAnnotationsMap(annotationStorage) {
3808 if (!annotationStorage) {
3809 return null;
3810 }
3811
3812 const newAnnotationsByPage = new Map();
3813
3814 for (const [key, value] of annotationStorage) {
3815 if (!key.startsWith(_util.AnnotationEditorPrefix)) {
3816 continue;
3817 }
3818
3819 let annotations = newAnnotationsByPage.get(value.pageIndex);
3820
3821 if (!annotations) {
3822 annotations = [];
3823 newAnnotationsByPage.set(value.pageIndex, annotations);
3824 }
3825
3826 annotations.push(value);
3827 }
3828
3829 return newAnnotationsByPage.size > 0 ? newAnnotationsByPage : null;
3830}
3831
3832/***/ }),
3833/* 6 */
3834/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
3835
3836
3837
3838Object.defineProperty(exports, "__esModule", ({
3839 value: true
3840}));
3841exports.RefSetCache = exports.RefSet = exports.Ref = exports.Name = exports.EOF = exports.Dict = exports.Cmd = exports.CIRCULAR_REF = void 0;
3842exports.clearPrimitiveCaches = clearPrimitiveCaches;
3843exports.isCmd = isCmd;
3844exports.isDict = isDict;
3845exports.isName = isName;
3846exports.isRefsEqual = isRefsEqual;
3847
3848var _util = __w_pdfjs_require__(1);
3849
3850const CIRCULAR_REF = Symbol("CIRCULAR_REF");
3851exports.CIRCULAR_REF = CIRCULAR_REF;
3852const EOF = Symbol("EOF");
3853exports.EOF = EOF;
3854
3855const Name = function NameClosure() {
3856 let nameCache = Object.create(null);
3857
3858 class Name {
3859 constructor(name) {
3860 this.name = name;
3861 }
3862
3863 static get(name) {
3864 return nameCache[name] || (nameCache[name] = new Name(name));
3865 }
3866
3867 static _clearCache() {
3868 nameCache = Object.create(null);
3869 }
3870
3871 }
3872
3873 return Name;
3874}();
3875
3876exports.Name = Name;
3877
3878const Cmd = function CmdClosure() {
3879 let cmdCache = Object.create(null);
3880
3881 class Cmd {
3882 constructor(cmd) {
3883 this.cmd = cmd;
3884 }
3885
3886 static get(cmd) {
3887 return cmdCache[cmd] || (cmdCache[cmd] = new Cmd(cmd));
3888 }
3889
3890 static _clearCache() {
3891 cmdCache = Object.create(null);
3892 }
3893
3894 }
3895
3896 return Cmd;
3897}();
3898
3899exports.Cmd = Cmd;
3900
3901const nonSerializable = function nonSerializableClosure() {
3902 return nonSerializable;
3903};
3904
3905class Dict {
3906 constructor(xref = null) {
3907 this._map = Object.create(null);
3908 this.xref = xref;
3909 this.objId = null;
3910 this.suppressEncryption = false;
3911 this.__nonSerializable__ = nonSerializable;
3912 }
3913
3914 assignXref(newXref) {
3915 this.xref = newXref;
3916 }
3917
3918 get size() {
3919 return Object.keys(this._map).length;
3920 }
3921
3922 get(key1, key2, key3) {
3923 let value = this._map[key1];
3924
3925 if (value === undefined && key2 !== undefined) {
3926 value = this._map[key2];
3927
3928 if (value === undefined && key3 !== undefined) {
3929 value = this._map[key3];
3930 }
3931 }
3932
3933 if (value instanceof Ref && this.xref) {
3934 return this.xref.fetch(value, this.suppressEncryption);
3935 }
3936
3937 return value;
3938 }
3939
3940 async getAsync(key1, key2, key3) {
3941 let value = this._map[key1];
3942
3943 if (value === undefined && key2 !== undefined) {
3944 value = this._map[key2];
3945
3946 if (value === undefined && key3 !== undefined) {
3947 value = this._map[key3];
3948 }
3949 }
3950
3951 if (value instanceof Ref && this.xref) {
3952 return this.xref.fetchAsync(value, this.suppressEncryption);
3953 }
3954
3955 return value;
3956 }
3957
3958 getArray(key1, key2, key3) {
3959 let value = this._map[key1];
3960
3961 if (value === undefined && key2 !== undefined) {
3962 value = this._map[key2];
3963
3964 if (value === undefined && key3 !== undefined) {
3965 value = this._map[key3];
3966 }
3967 }
3968
3969 if (value instanceof Ref && this.xref) {
3970 value = this.xref.fetch(value, this.suppressEncryption);
3971 }
3972
3973 if (Array.isArray(value)) {
3974 value = value.slice();
3975
3976 for (let i = 0, ii = value.length; i < ii; i++) {
3977 if (value[i] instanceof Ref && this.xref) {
3978 value[i] = this.xref.fetch(value[i], this.suppressEncryption);
3979 }
3980 }
3981 }
3982
3983 return value;
3984 }
3985
3986 getRaw(key) {
3987 return this._map[key];
3988 }
3989
3990 getKeys() {
3991 return Object.keys(this._map);
3992 }
3993
3994 getRawValues() {
3995 return Object.values(this._map);
3996 }
3997
3998 set(key, value) {
3999 this._map[key] = value;
4000 }
4001
4002 has(key) {
4003 return this._map[key] !== undefined;
4004 }
4005
4006 forEach(callback) {
4007 for (const key in this._map) {
4008 callback(key, this.get(key));
4009 }
4010 }
4011
4012 static get empty() {
4013 const emptyDict = new Dict(null);
4014
4015 emptyDict.set = (key, value) => {
4016 (0, _util.unreachable)("Should not call `set` on the empty dictionary.");
4017 };
4018
4019 return (0, _util.shadow)(this, "empty", emptyDict);
4020 }
4021
4022 static merge({
4023 xref,
4024 dictArray,
4025 mergeSubDicts = false
4026 }) {
4027 const mergedDict = new Dict(xref),
4028 properties = new Map();
4029
4030 for (const dict of dictArray) {
4031 if (!(dict instanceof Dict)) {
4032 continue;
4033 }
4034
4035 for (const [key, value] of Object.entries(dict._map)) {
4036 let property = properties.get(key);
4037
4038 if (property === undefined) {
4039 property = [];
4040 properties.set(key, property);
4041 } else if (!mergeSubDicts || !(value instanceof Dict)) {
4042 continue;
4043 }
4044
4045 property.push(value);
4046 }
4047 }
4048
4049 for (const [name, values] of properties) {
4050 if (values.length === 1 || !(values[0] instanceof Dict)) {
4051 mergedDict._map[name] = values[0];
4052 continue;
4053 }
4054
4055 const subDict = new Dict(xref);
4056
4057 for (const dict of values) {
4058 for (const [key, value] of Object.entries(dict._map)) {
4059 if (subDict._map[key] === undefined) {
4060 subDict._map[key] = value;
4061 }
4062 }
4063 }
4064
4065 if (subDict.size > 0) {
4066 mergedDict._map[name] = subDict;
4067 }
4068 }
4069
4070 properties.clear();
4071 return mergedDict.size > 0 ? mergedDict : Dict.empty;
4072 }
4073
4074}
4075
4076exports.Dict = Dict;
4077
4078const Ref = function RefClosure() {
4079 let refCache = Object.create(null);
4080
4081 class Ref {
4082 constructor(num, gen) {
4083 this.num = num;
4084 this.gen = gen;
4085 }
4086
4087 toString() {
4088 if (this.gen === 0) {
4089 return `${this.num}R`;
4090 }
4091
4092 return `${this.num}R${this.gen}`;
4093 }
4094
4095 static get(num, gen) {
4096 const key = gen === 0 ? `${num}R` : `${num}R${gen}`;
4097 return refCache[key] || (refCache[key] = new Ref(num, gen));
4098 }
4099
4100 static _clearCache() {
4101 refCache = Object.create(null);
4102 }
4103
4104 }
4105
4106 return Ref;
4107}();
4108
4109exports.Ref = Ref;
4110
4111class RefSet {
4112 constructor(parent = null) {
4113 this._set = new Set(parent && parent._set);
4114 }
4115
4116 has(ref) {
4117 return this._set.has(ref.toString());
4118 }
4119
4120 put(ref) {
4121 this._set.add(ref.toString());
4122 }
4123
4124 remove(ref) {
4125 this._set.delete(ref.toString());
4126 }
4127
4128 [Symbol.iterator]() {
4129 return this._set.values();
4130 }
4131
4132 clear() {
4133 this._set.clear();
4134 }
4135
4136}
4137
4138exports.RefSet = RefSet;
4139
4140class RefSetCache {
4141 constructor() {
4142 this._map = new Map();
4143 }
4144
4145 get size() {
4146 return this._map.size;
4147 }
4148
4149 get(ref) {
4150 return this._map.get(ref.toString());
4151 }
4152
4153 has(ref) {
4154 return this._map.has(ref.toString());
4155 }
4156
4157 put(ref, obj) {
4158 this._map.set(ref.toString(), obj);
4159 }
4160
4161 putAlias(ref, aliasRef) {
4162 this._map.set(ref.toString(), this.get(aliasRef));
4163 }
4164
4165 [Symbol.iterator]() {
4166 return this._map.values();
4167 }
4168
4169 clear() {
4170 this._map.clear();
4171 }
4172
4173}
4174
4175exports.RefSetCache = RefSetCache;
4176
4177function isName(v, name) {
4178 return v instanceof Name && (name === undefined || v.name === name);
4179}
4180
4181function isCmd(v, cmd) {
4182 return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
4183}
4184
4185function isDict(v, type) {
4186 return v instanceof Dict && (type === undefined || isName(v.get("Type"), type));
4187}
4188
4189function isRefsEqual(v1, v2) {
4190 return v1.num === v2.num && v1.gen === v2.gen;
4191}
4192
4193function clearPrimitiveCaches() {
4194 Cmd._clearCache();
4195
4196 Name._clearCache();
4197
4198 Ref._clearCache();
4199}
4200
4201/***/ }),
4202/* 7 */
4203/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
4204
4205
4206
4207Object.defineProperty(exports, "__esModule", ({
4208 value: true
4209}));
4210exports.BaseStream = void 0;
4211
4212var _util = __w_pdfjs_require__(1);
4213
4214class BaseStream {
4215 constructor() {
4216 if (this.constructor === BaseStream) {
4217 (0, _util.unreachable)("Cannot initialize BaseStream.");
4218 }
4219 }
4220
4221 get length() {
4222 (0, _util.unreachable)("Abstract getter `length` accessed");
4223 }
4224
4225 get isEmpty() {
4226 (0, _util.unreachable)("Abstract getter `isEmpty` accessed");
4227 }
4228
4229 get isDataLoaded() {
4230 return (0, _util.shadow)(this, "isDataLoaded", true);
4231 }
4232
4233 getByte() {
4234 (0, _util.unreachable)("Abstract method `getByte` called");
4235 }
4236
4237 getBytes(length) {
4238 (0, _util.unreachable)("Abstract method `getBytes` called");
4239 }
4240
4241 peekByte() {
4242 const peekedByte = this.getByte();
4243
4244 if (peekedByte !== -1) {
4245 this.pos--;
4246 }
4247
4248 return peekedByte;
4249 }
4250
4251 peekBytes(length) {
4252 const bytes = this.getBytes(length);
4253 this.pos -= bytes.length;
4254 return bytes;
4255 }
4256
4257 getUint16() {
4258 const b0 = this.getByte();
4259 const b1 = this.getByte();
4260
4261 if (b0 === -1 || b1 === -1) {
4262 return -1;
4263 }
4264
4265 return (b0 << 8) + b1;
4266 }
4267
4268 getInt32() {
4269 const b0 = this.getByte();
4270 const b1 = this.getByte();
4271 const b2 = this.getByte();
4272 const b3 = this.getByte();
4273 return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
4274 }
4275
4276 getByteRange(begin, end) {
4277 (0, _util.unreachable)("Abstract method `getByteRange` called");
4278 }
4279
4280 getString(length) {
4281 return (0, _util.bytesToString)(this.getBytes(length));
4282 }
4283
4284 skip(n) {
4285 this.pos += n || 1;
4286 }
4287
4288 reset() {
4289 (0, _util.unreachable)("Abstract method `reset` called");
4290 }
4291
4292 moveStart() {
4293 (0, _util.unreachable)("Abstract method `moveStart` called");
4294 }
4295
4296 makeSubStream(start, length, dict = null) {
4297 (0, _util.unreachable)("Abstract method `makeSubStream` called");
4298 }
4299
4300 getBaseStreams() {
4301 return null;
4302 }
4303
4304}
4305
4306exports.BaseStream = BaseStream;
4307
4308/***/ }),
4309/* 8 */
4310/***/ ((__unused_webpack_module, exports) => {
4311
4312
4313
4314Object.defineProperty(exports, "__esModule", ({
4315 value: true
4316}));
4317exports.ArithmeticDecoder = void 0;
4318const QeTable = [{
4319 qe: 0x5601,
4320 nmps: 1,
4321 nlps: 1,
4322 switchFlag: 1
4323}, {
4324 qe: 0x3401,
4325 nmps: 2,
4326 nlps: 6,
4327 switchFlag: 0
4328}, {
4329 qe: 0x1801,
4330 nmps: 3,
4331 nlps: 9,
4332 switchFlag: 0
4333}, {
4334 qe: 0x0ac1,
4335 nmps: 4,
4336 nlps: 12,
4337 switchFlag: 0
4338}, {
4339 qe: 0x0521,
4340 nmps: 5,
4341 nlps: 29,
4342 switchFlag: 0
4343}, {
4344 qe: 0x0221,
4345 nmps: 38,
4346 nlps: 33,
4347 switchFlag: 0
4348}, {
4349 qe: 0x5601,
4350 nmps: 7,
4351 nlps: 6,
4352 switchFlag: 1
4353}, {
4354 qe: 0x5401,
4355 nmps: 8,
4356 nlps: 14,
4357 switchFlag: 0
4358}, {
4359 qe: 0x4801,
4360 nmps: 9,
4361 nlps: 14,
4362 switchFlag: 0
4363}, {
4364 qe: 0x3801,
4365 nmps: 10,
4366 nlps: 14,
4367 switchFlag: 0
4368}, {
4369 qe: 0x3001,
4370 nmps: 11,
4371 nlps: 17,
4372 switchFlag: 0
4373}, {
4374 qe: 0x2401,
4375 nmps: 12,
4376 nlps: 18,
4377 switchFlag: 0
4378}, {
4379 qe: 0x1c01,
4380 nmps: 13,
4381 nlps: 20,
4382 switchFlag: 0
4383}, {
4384 qe: 0x1601,
4385 nmps: 29,
4386 nlps: 21,
4387 switchFlag: 0
4388}, {
4389 qe: 0x5601,
4390 nmps: 15,
4391 nlps: 14,
4392 switchFlag: 1
4393}, {
4394 qe: 0x5401,
4395 nmps: 16,
4396 nlps: 14,
4397 switchFlag: 0
4398}, {
4399 qe: 0x5101,
4400 nmps: 17,
4401 nlps: 15,
4402 switchFlag: 0
4403}, {
4404 qe: 0x4801,
4405 nmps: 18,
4406 nlps: 16,
4407 switchFlag: 0
4408}, {
4409 qe: 0x3801,
4410 nmps: 19,
4411 nlps: 17,
4412 switchFlag: 0
4413}, {
4414 qe: 0x3401,
4415 nmps: 20,
4416 nlps: 18,
4417 switchFlag: 0
4418}, {
4419 qe: 0x3001,
4420 nmps: 21,
4421 nlps: 19,
4422 switchFlag: 0
4423}, {
4424 qe: 0x2801,
4425 nmps: 22,
4426 nlps: 19,
4427 switchFlag: 0
4428}, {
4429 qe: 0x2401,
4430 nmps: 23,
4431 nlps: 20,
4432 switchFlag: 0
4433}, {
4434 qe: 0x2201,
4435 nmps: 24,
4436 nlps: 21,
4437 switchFlag: 0
4438}, {
4439 qe: 0x1c01,
4440 nmps: 25,
4441 nlps: 22,
4442 switchFlag: 0
4443}, {
4444 qe: 0x1801,
4445 nmps: 26,
4446 nlps: 23,
4447 switchFlag: 0
4448}, {
4449 qe: 0x1601,
4450 nmps: 27,
4451 nlps: 24,
4452 switchFlag: 0
4453}, {
4454 qe: 0x1401,
4455 nmps: 28,
4456 nlps: 25,
4457 switchFlag: 0
4458}, {
4459 qe: 0x1201,
4460 nmps: 29,
4461 nlps: 26,
4462 switchFlag: 0
4463}, {
4464 qe: 0x1101,
4465 nmps: 30,
4466 nlps: 27,
4467 switchFlag: 0
4468}, {
4469 qe: 0x0ac1,
4470 nmps: 31,
4471 nlps: 28,
4472 switchFlag: 0
4473}, {
4474 qe: 0x09c1,
4475 nmps: 32,
4476 nlps: 29,
4477 switchFlag: 0
4478}, {
4479 qe: 0x08a1,
4480 nmps: 33,
4481 nlps: 30,
4482 switchFlag: 0
4483}, {
4484 qe: 0x0521,
4485 nmps: 34,
4486 nlps: 31,
4487 switchFlag: 0
4488}, {
4489 qe: 0x0441,
4490 nmps: 35,
4491 nlps: 32,
4492 switchFlag: 0
4493}, {
4494 qe: 0x02a1,
4495 nmps: 36,
4496 nlps: 33,
4497 switchFlag: 0
4498}, {
4499 qe: 0x0221,
4500 nmps: 37,
4501 nlps: 34,
4502 switchFlag: 0
4503}, {
4504 qe: 0x0141,
4505 nmps: 38,
4506 nlps: 35,
4507 switchFlag: 0
4508}, {
4509 qe: 0x0111,
4510 nmps: 39,
4511 nlps: 36,
4512 switchFlag: 0
4513}, {
4514 qe: 0x0085,
4515 nmps: 40,
4516 nlps: 37,
4517 switchFlag: 0
4518}, {
4519 qe: 0x0049,
4520 nmps: 41,
4521 nlps: 38,
4522 switchFlag: 0
4523}, {
4524 qe: 0x0025,
4525 nmps: 42,
4526 nlps: 39,
4527 switchFlag: 0
4528}, {
4529 qe: 0x0015,
4530 nmps: 43,
4531 nlps: 40,
4532 switchFlag: 0
4533}, {
4534 qe: 0x0009,
4535 nmps: 44,
4536 nlps: 41,
4537 switchFlag: 0
4538}, {
4539 qe: 0x0005,
4540 nmps: 45,
4541 nlps: 42,
4542 switchFlag: 0
4543}, {
4544 qe: 0x0001,
4545 nmps: 45,
4546 nlps: 43,
4547 switchFlag: 0
4548}, {
4549 qe: 0x5601,
4550 nmps: 46,
4551 nlps: 46,
4552 switchFlag: 0
4553}];
4554
4555class ArithmeticDecoder {
4556 constructor(data, start, end) {
4557 this.data = data;
4558 this.bp = start;
4559 this.dataEnd = end;
4560 this.chigh = data[start];
4561 this.clow = 0;
4562 this.byteIn();
4563 this.chigh = this.chigh << 7 & 0xffff | this.clow >> 9 & 0x7f;
4564 this.clow = this.clow << 7 & 0xffff;
4565 this.ct -= 7;
4566 this.a = 0x8000;
4567 }
4568
4569 byteIn() {
4570 const data = this.data;
4571 let bp = this.bp;
4572
4573 if (data[bp] === 0xff) {
4574 if (data[bp + 1] > 0x8f) {
4575 this.clow += 0xff00;
4576 this.ct = 8;
4577 } else {
4578 bp++;
4579 this.clow += data[bp] << 9;
4580 this.ct = 7;
4581 this.bp = bp;
4582 }
4583 } else {
4584 bp++;
4585 this.clow += bp < this.dataEnd ? data[bp] << 8 : 0xff00;
4586 this.ct = 8;
4587 this.bp = bp;
4588 }
4589
4590 if (this.clow > 0xffff) {
4591 this.chigh += this.clow >> 16;
4592 this.clow &= 0xffff;
4593 }
4594 }
4595
4596 readBit(contexts, pos) {
4597 let cx_index = contexts[pos] >> 1,
4598 cx_mps = contexts[pos] & 1;
4599 const qeTableIcx = QeTable[cx_index];
4600 const qeIcx = qeTableIcx.qe;
4601 let d;
4602 let a = this.a - qeIcx;
4603
4604 if (this.chigh < qeIcx) {
4605 if (a < qeIcx) {
4606 a = qeIcx;
4607 d = cx_mps;
4608 cx_index = qeTableIcx.nmps;
4609 } else {
4610 a = qeIcx;
4611 d = 1 ^ cx_mps;
4612
4613 if (qeTableIcx.switchFlag === 1) {
4614 cx_mps = d;
4615 }
4616
4617 cx_index = qeTableIcx.nlps;
4618 }
4619 } else {
4620 this.chigh -= qeIcx;
4621
4622 if ((a & 0x8000) !== 0) {
4623 this.a = a;
4624 return cx_mps;
4625 }
4626
4627 if (a < qeIcx) {
4628 d = 1 ^ cx_mps;
4629
4630 if (qeTableIcx.switchFlag === 1) {
4631 cx_mps = d;
4632 }
4633
4634 cx_index = qeTableIcx.nlps;
4635 } else {
4636 d = cx_mps;
4637 cx_index = qeTableIcx.nmps;
4638 }
4639 }
4640
4641 do {
4642 if (this.ct === 0) {
4643 this.byteIn();
4644 }
4645
4646 a <<= 1;
4647 this.chigh = this.chigh << 1 & 0xffff | this.clow >> 15 & 1;
4648 this.clow = this.clow << 1 & 0xffff;
4649 this.ct--;
4650 } while ((a & 0x8000) === 0);
4651
4652 this.a = a;
4653 contexts[pos] = cx_index << 1 | cx_mps;
4654 return d;
4655 }
4656
4657}
4658
4659exports.ArithmeticDecoder = ArithmeticDecoder;
4660
4661/***/ }),
4662/* 9 */
4663/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
4664
4665
4666
4667Object.defineProperty(exports, "__esModule", ({
4668 value: true
4669}));
4670exports.CCITTFaxDecoder = void 0;
4671
4672var _util = __w_pdfjs_require__(1);
4673
4674const ccittEOL = -2;
4675const ccittEOF = -1;
4676const twoDimPass = 0;
4677const twoDimHoriz = 1;
4678const twoDimVert0 = 2;
4679const twoDimVertR1 = 3;
4680const twoDimVertL1 = 4;
4681const twoDimVertR2 = 5;
4682const twoDimVertL2 = 6;
4683const twoDimVertR3 = 7;
4684const twoDimVertL3 = 8;
4685const twoDimTable = [[-1, -1], [-1, -1], [7, twoDimVertL3], [7, twoDimVertR3], [6, twoDimVertL2], [6, twoDimVertL2], [6, twoDimVertR2], [6, twoDimVertR2], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0]];
4686const whiteTable1 = [[-1, -1], [12, ccittEOL], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [11, 1792], [11, 1792], [12, 1984], [12, 2048], [12, 2112], [12, 2176], [12, 2240], [12, 2304], [11, 1856], [11, 1856], [11, 1920], [11, 1920], [12, 2368], [12, 2432], [12, 2496], [12, 2560]];
4687const whiteTable2 = [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [8, 29], [8, 29], [8, 30], [8, 30], [8, 45], [8, 45], [8, 46], [8, 46], [7, 22], [7, 22], [7, 22], [7, 22], [7, 23], [7, 23], [7, 23], [7, 23], [8, 47], [8, 47], [8, 48], [8, 48], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [7, 20], [7, 20], [7, 20], [7, 20], [8, 33], [8, 33], [8, 34], [8, 34], [8, 35], [8, 35], [8, 36], [8, 36], [8, 37], [8, 37], [8, 38], [8, 38], [7, 19], [7, 19], [7, 19], [7, 19], [8, 31], [8, 31], [8, 32], [8, 32], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [8, 53], [8, 53], [8, 54], [8, 54], [7, 26], [7, 26], [7, 26], [7, 26], [8, 39], [8, 39], [8, 40], [8, 40], [8, 41], [8, 41], [8, 42], [8, 42], [8, 43], [8, 43], [8, 44], [8, 44], [7, 21], [7, 21], [7, 21], [7, 21], [7, 28], [7, 28], [7, 28], [7, 28], [8, 61], [8, 61], [8, 62], [8, 62], [8, 63], [8, 63], [8, 0], [8, 0], [8, 320], [8, 320], [8, 384], [8, 384], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [7, 27], [7, 27], [7, 27], [7, 27], [8, 59], [8, 59], [8, 60], [8, 60], [9, 1472], [9, 1536], [9, 1600], [9, 1728], [7, 18], [7, 18], [7, 18], [7, 18], [7, 24], [7, 24], [7, 24], [7, 24], [8, 49], [8, 49], [8, 50], [8, 50], [8, 51], [8, 51], [8, 52], [8, 52], [7, 25], [7, 25], [7, 25], [7, 25], [8, 55], [8, 55], [8, 56], [8, 56], [8, 57], [8, 57], [8, 58], [8, 58], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [8, 448], [8, 448], [8, 512], [8, 512], [9, 704], [9, 768], [8, 640], [8, 640], [8, 576], [8, 576], [9, 832], [9, 896], [9, 960], [9, 1024], [9, 1088], [9, 1152], [9, 1216], [9, 1280], [9, 1344], [9, 1408], [7, 256], [7, 256], [7, 256], [7, 256], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7]];
4688const blackTable1 = [[-1, -1], [-1, -1], [12, ccittEOL], [12, ccittEOL], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [11, 1792], [11, 1792], [11, 1792], [11, 1792], [12, 1984], [12, 1984], [12, 2048], [12, 2048], [12, 2112], [12, 2112], [12, 2176], [12, 2176], [12, 2240], [12, 2240], [12, 2304], [12, 2304], [11, 1856], [11, 1856], [11, 1856], [11, 1856], [11, 1920], [11, 1920], [11, 1920], [11, 1920], [12, 2368], [12, 2368], [12, 2432], [12, 2432], [12, 2496], [12, 2496], [12, 2560], [12, 2560], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [12, 52], [12, 52], [13, 640], [13, 704], [13, 768], [13, 832], [12, 55], [12, 55], [12, 56], [12, 56], [13, 1280], [13, 1344], [13, 1408], [13, 1472], [12, 59], [12, 59], [12, 60], [12, 60], [13, 1536], [13, 1600], [11, 24], [11, 24], [11, 24], [11, 24], [11, 25], [11, 25], [11, 25], [11, 25], [13, 1664], [13, 1728], [12, 320], [12, 320], [12, 384], [12, 384], [12, 448], [12, 448], [13, 512], [13, 576], [12, 53], [12, 53], [12, 54], [12, 54], [13, 896], [13, 960], [13, 1024], [13, 1088], [13, 1152], [13, 1216], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64]];
4689const blackTable2 = [[8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [11, 23], [11, 23], [12, 50], [12, 51], [12, 44], [12, 45], [12, 46], [12, 47], [12, 57], [12, 58], [12, 61], [12, 256], [10, 16], [10, 16], [10, 16], [10, 16], [10, 17], [10, 17], [10, 17], [10, 17], [12, 48], [12, 49], [12, 62], [12, 63], [12, 30], [12, 31], [12, 32], [12, 33], [12, 40], [12, 41], [11, 22], [11, 22], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [12, 128], [12, 192], [12, 26], [12, 27], [12, 28], [12, 29], [11, 19], [11, 19], [11, 20], [11, 20], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 39], [11, 21], [11, 21], [12, 42], [12, 43], [10, 0], [10, 0], [10, 0], [10, 0], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12]];
4690const blackTable3 = [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [6, 9], [6, 8], [5, 7], [5, 7], [4, 6], [4, 6], [4, 6], [4, 6], [4, 5], [4, 5], [4, 5], [4, 5], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2]];
4691
4692class CCITTFaxDecoder {
4693 constructor(source, options = {}) {
4694 if (!source || typeof source.next !== "function") {
4695 throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
4696 }
4697
4698 this.source = source;
4699 this.eof = false;
4700 this.encoding = options.K || 0;
4701 this.eoline = options.EndOfLine || false;
4702 this.byteAlign = options.EncodedByteAlign || false;
4703 this.columns = options.Columns || 1728;
4704 this.rows = options.Rows || 0;
4705 let eoblock = options.EndOfBlock;
4706
4707 if (eoblock === null || eoblock === undefined) {
4708 eoblock = true;
4709 }
4710
4711 this.eoblock = eoblock;
4712 this.black = options.BlackIs1 || false;
4713 this.codingLine = new Uint32Array(this.columns + 1);
4714 this.refLine = new Uint32Array(this.columns + 2);
4715 this.codingLine[0] = this.columns;
4716 this.codingPos = 0;
4717 this.row = 0;
4718 this.nextLine2D = this.encoding < 0;
4719 this.inputBits = 0;
4720 this.inputBuf = 0;
4721 this.outputBits = 0;
4722 this.rowsDone = false;
4723 let code1;
4724
4725 while ((code1 = this._lookBits(12)) === 0) {
4726 this._eatBits(1);
4727 }
4728
4729 if (code1 === 1) {
4730 this._eatBits(12);
4731 }
4732
4733 if (this.encoding > 0) {
4734 this.nextLine2D = !this._lookBits(1);
4735
4736 this._eatBits(1);
4737 }
4738 }
4739
4740 readNextChar() {
4741 if (this.eof) {
4742 return -1;
4743 }
4744
4745 const refLine = this.refLine;
4746 const codingLine = this.codingLine;
4747 const columns = this.columns;
4748 let refPos, blackPixels, bits, i;
4749
4750 if (this.outputBits === 0) {
4751 if (this.rowsDone) {
4752 this.eof = true;
4753 }
4754
4755 if (this.eof) {
4756 return -1;
4757 }
4758
4759 this.err = false;
4760 let code1, code2, code3;
4761
4762 if (this.nextLine2D) {
4763 for (i = 0; codingLine[i] < columns; ++i) {
4764 refLine[i] = codingLine[i];
4765 }
4766
4767 refLine[i++] = columns;
4768 refLine[i] = columns;
4769 codingLine[0] = 0;
4770 this.codingPos = 0;
4771 refPos = 0;
4772 blackPixels = 0;
4773
4774 while (codingLine[this.codingPos] < columns) {
4775 code1 = this._getTwoDimCode();
4776
4777 switch (code1) {
4778 case twoDimPass:
4779 this._addPixels(refLine[refPos + 1], blackPixels);
4780
4781 if (refLine[refPos + 1] < columns) {
4782 refPos += 2;
4783 }
4784
4785 break;
4786
4787 case twoDimHoriz:
4788 code1 = code2 = 0;
4789
4790 if (blackPixels) {
4791 do {
4792 code1 += code3 = this._getBlackCode();
4793 } while (code3 >= 64);
4794
4795 do {
4796 code2 += code3 = this._getWhiteCode();
4797 } while (code3 >= 64);
4798 } else {
4799 do {
4800 code1 += code3 = this._getWhiteCode();
4801 } while (code3 >= 64);
4802
4803 do {
4804 code2 += code3 = this._getBlackCode();
4805 } while (code3 >= 64);
4806 }
4807
4808 this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
4809
4810 if (codingLine[this.codingPos] < columns) {
4811 this._addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
4812 }
4813
4814 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
4815 refPos += 2;
4816 }
4817
4818 break;
4819
4820 case twoDimVertR3:
4821 this._addPixels(refLine[refPos] + 3, blackPixels);
4822
4823 blackPixels ^= 1;
4824
4825 if (codingLine[this.codingPos] < columns) {
4826 ++refPos;
4827
4828 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
4829 refPos += 2;
4830 }
4831 }
4832
4833 break;
4834
4835 case twoDimVertR2:
4836 this._addPixels(refLine[refPos] + 2, blackPixels);
4837
4838 blackPixels ^= 1;
4839
4840 if (codingLine[this.codingPos] < columns) {
4841 ++refPos;
4842
4843 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
4844 refPos += 2;
4845 }
4846 }
4847
4848 break;
4849
4850 case twoDimVertR1:
4851 this._addPixels(refLine[refPos] + 1, blackPixels);
4852
4853 blackPixels ^= 1;
4854
4855 if (codingLine[this.codingPos] < columns) {
4856 ++refPos;
4857
4858 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
4859 refPos += 2;
4860 }
4861 }
4862
4863 break;
4864
4865 case twoDimVert0:
4866 this._addPixels(refLine[refPos], blackPixels);
4867
4868 blackPixels ^= 1;
4869
4870 if (codingLine[this.codingPos] < columns) {
4871 ++refPos;
4872
4873 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
4874 refPos += 2;
4875 }
4876 }
4877
4878 break;
4879
4880 case twoDimVertL3:
4881 this._addPixelsNeg(refLine[refPos] - 3, blackPixels);
4882
4883 blackPixels ^= 1;
4884
4885 if (codingLine[this.codingPos] < columns) {
4886 if (refPos > 0) {
4887 --refPos;
4888 } else {
4889 ++refPos;
4890 }
4891
4892 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
4893 refPos += 2;
4894 }
4895 }
4896
4897 break;
4898
4899 case twoDimVertL2:
4900 this._addPixelsNeg(refLine[refPos] - 2, blackPixels);
4901
4902 blackPixels ^= 1;
4903
4904 if (codingLine[this.codingPos] < columns) {
4905 if (refPos > 0) {
4906 --refPos;
4907 } else {
4908 ++refPos;
4909 }
4910
4911 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
4912 refPos += 2;
4913 }
4914 }
4915
4916 break;
4917
4918 case twoDimVertL1:
4919 this._addPixelsNeg(refLine[refPos] - 1, blackPixels);
4920
4921 blackPixels ^= 1;
4922
4923 if (codingLine[this.codingPos] < columns) {
4924 if (refPos > 0) {
4925 --refPos;
4926 } else {
4927 ++refPos;
4928 }
4929
4930 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
4931 refPos += 2;
4932 }
4933 }
4934
4935 break;
4936
4937 case ccittEOF:
4938 this._addPixels(columns, 0);
4939
4940 this.eof = true;
4941 break;
4942
4943 default:
4944 (0, _util.info)("bad 2d code");
4945
4946 this._addPixels(columns, 0);
4947
4948 this.err = true;
4949 }
4950 }
4951 } else {
4952 codingLine[0] = 0;
4953 this.codingPos = 0;
4954 blackPixels = 0;
4955
4956 while (codingLine[this.codingPos] < columns) {
4957 code1 = 0;
4958
4959 if (blackPixels) {
4960 do {
4961 code1 += code3 = this._getBlackCode();
4962 } while (code3 >= 64);
4963 } else {
4964 do {
4965 code1 += code3 = this._getWhiteCode();
4966 } while (code3 >= 64);
4967 }
4968
4969 this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
4970
4971 blackPixels ^= 1;
4972 }
4973 }
4974
4975 let gotEOL = false;
4976
4977 if (this.byteAlign) {
4978 this.inputBits &= ~7;
4979 }
4980
4981 if (!this.eoblock && this.row === this.rows - 1) {
4982 this.rowsDone = true;
4983 } else {
4984 code1 = this._lookBits(12);
4985
4986 if (this.eoline) {
4987 while (code1 !== ccittEOF && code1 !== 1) {
4988 this._eatBits(1);
4989
4990 code1 = this._lookBits(12);
4991 }
4992 } else {
4993 while (code1 === 0) {
4994 this._eatBits(1);
4995
4996 code1 = this._lookBits(12);
4997 }
4998 }
4999
5000 if (code1 === 1) {
5001 this._eatBits(12);
5002
5003 gotEOL = true;
5004 } else if (code1 === ccittEOF) {
5005 this.eof = true;
5006 }
5007 }
5008
5009 if (!this.eof && this.encoding > 0 && !this.rowsDone) {
5010 this.nextLine2D = !this._lookBits(1);
5011
5012 this._eatBits(1);
5013 }
5014
5015 if (this.eoblock && gotEOL && this.byteAlign) {
5016 code1 = this._lookBits(12);
5017
5018 if (code1 === 1) {
5019 this._eatBits(12);
5020
5021 if (this.encoding > 0) {
5022 this._lookBits(1);
5023
5024 this._eatBits(1);
5025 }
5026
5027 if (this.encoding >= 0) {
5028 for (i = 0; i < 4; ++i) {
5029 code1 = this._lookBits(12);
5030
5031 if (code1 !== 1) {
5032 (0, _util.info)("bad rtc code: " + code1);
5033 }
5034
5035 this._eatBits(12);
5036
5037 if (this.encoding > 0) {
5038 this._lookBits(1);
5039
5040 this._eatBits(1);
5041 }
5042 }
5043 }
5044
5045 this.eof = true;
5046 }
5047 } else if (this.err && this.eoline) {
5048 while (true) {
5049 code1 = this._lookBits(13);
5050
5051 if (code1 === ccittEOF) {
5052 this.eof = true;
5053 return -1;
5054 }
5055
5056 if (code1 >> 1 === 1) {
5057 break;
5058 }
5059
5060 this._eatBits(1);
5061 }
5062
5063 this._eatBits(12);
5064
5065 if (this.encoding > 0) {
5066 this._eatBits(1);
5067
5068 this.nextLine2D = !(code1 & 1);
5069 }
5070 }
5071
5072 if (codingLine[0] > 0) {
5073 this.outputBits = codingLine[this.codingPos = 0];
5074 } else {
5075 this.outputBits = codingLine[this.codingPos = 1];
5076 }
5077
5078 this.row++;
5079 }
5080
5081 let c;
5082
5083 if (this.outputBits >= 8) {
5084 c = this.codingPos & 1 ? 0 : 0xff;
5085 this.outputBits -= 8;
5086
5087 if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
5088 this.codingPos++;
5089 this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
5090 }
5091 } else {
5092 bits = 8;
5093 c = 0;
5094
5095 do {
5096 if (typeof this.outputBits !== "number") {
5097 throw new _util.FormatError('Invalid /CCITTFaxDecode data, "outputBits" must be a number.');
5098 }
5099
5100 if (this.outputBits > bits) {
5101 c <<= bits;
5102
5103 if (!(this.codingPos & 1)) {
5104 c |= 0xff >> 8 - bits;
5105 }
5106
5107 this.outputBits -= bits;
5108 bits = 0;
5109 } else {
5110 c <<= this.outputBits;
5111
5112 if (!(this.codingPos & 1)) {
5113 c |= 0xff >> 8 - this.outputBits;
5114 }
5115
5116 bits -= this.outputBits;
5117 this.outputBits = 0;
5118
5119 if (codingLine[this.codingPos] < columns) {
5120 this.codingPos++;
5121 this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
5122 } else if (bits > 0) {
5123 c <<= bits;
5124 bits = 0;
5125 }
5126 }
5127 } while (bits);
5128 }
5129
5130 if (this.black) {
5131 c ^= 0xff;
5132 }
5133
5134 return c;
5135 }
5136
5137 _addPixels(a1, blackPixels) {
5138 const codingLine = this.codingLine;
5139 let codingPos = this.codingPos;
5140
5141 if (a1 > codingLine[codingPos]) {
5142 if (a1 > this.columns) {
5143 (0, _util.info)("row is wrong length");
5144 this.err = true;
5145 a1 = this.columns;
5146 }
5147
5148 if (codingPos & 1 ^ blackPixels) {
5149 ++codingPos;
5150 }
5151
5152 codingLine[codingPos] = a1;
5153 }
5154
5155 this.codingPos = codingPos;
5156 }
5157
5158 _addPixelsNeg(a1, blackPixels) {
5159 const codingLine = this.codingLine;
5160 let codingPos = this.codingPos;
5161
5162 if (a1 > codingLine[codingPos]) {
5163 if (a1 > this.columns) {
5164 (0, _util.info)("row is wrong length");
5165 this.err = true;
5166 a1 = this.columns;
5167 }
5168
5169 if (codingPos & 1 ^ blackPixels) {
5170 ++codingPos;
5171 }
5172
5173 codingLine[codingPos] = a1;
5174 } else if (a1 < codingLine[codingPos]) {
5175 if (a1 < 0) {
5176 (0, _util.info)("invalid code");
5177 this.err = true;
5178 a1 = 0;
5179 }
5180
5181 while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
5182 --codingPos;
5183 }
5184
5185 codingLine[codingPos] = a1;
5186 }
5187
5188 this.codingPos = codingPos;
5189 }
5190
5191 _findTableCode(start, end, table, limit) {
5192 const limitValue = limit || 0;
5193
5194 for (let i = start; i <= end; ++i) {
5195 let code = this._lookBits(i);
5196
5197 if (code === ccittEOF) {
5198 return [true, 1, false];
5199 }
5200
5201 if (i < end) {
5202 code <<= end - i;
5203 }
5204
5205 if (!limitValue || code >= limitValue) {
5206 const p = table[code - limitValue];
5207
5208 if (p[0] === i) {
5209 this._eatBits(i);
5210
5211 return [true, p[1], true];
5212 }
5213 }
5214 }
5215
5216 return [false, 0, false];
5217 }
5218
5219 _getTwoDimCode() {
5220 let code = 0;
5221 let p;
5222
5223 if (this.eoblock) {
5224 code = this._lookBits(7);
5225 p = twoDimTable[code];
5226
5227 if (p && p[0] > 0) {
5228 this._eatBits(p[0]);
5229
5230 return p[1];
5231 }
5232 } else {
5233 const result = this._findTableCode(1, 7, twoDimTable);
5234
5235 if (result[0] && result[2]) {
5236 return result[1];
5237 }
5238 }
5239
5240 (0, _util.info)("Bad two dim code");
5241 return ccittEOF;
5242 }
5243
5244 _getWhiteCode() {
5245 let code = 0;
5246 let p;
5247
5248 if (this.eoblock) {
5249 code = this._lookBits(12);
5250
5251 if (code === ccittEOF) {
5252 return 1;
5253 }
5254
5255 if (code >> 5 === 0) {
5256 p = whiteTable1[code];
5257 } else {
5258 p = whiteTable2[code >> 3];
5259 }
5260
5261 if (p[0] > 0) {
5262 this._eatBits(p[0]);
5263
5264 return p[1];
5265 }
5266 } else {
5267 let result = this._findTableCode(1, 9, whiteTable2);
5268
5269 if (result[0]) {
5270 return result[1];
5271 }
5272
5273 result = this._findTableCode(11, 12, whiteTable1);
5274
5275 if (result[0]) {
5276 return result[1];
5277 }
5278 }
5279
5280 (0, _util.info)("bad white code");
5281
5282 this._eatBits(1);
5283
5284 return 1;
5285 }
5286
5287 _getBlackCode() {
5288 let code, p;
5289
5290 if (this.eoblock) {
5291 code = this._lookBits(13);
5292
5293 if (code === ccittEOF) {
5294 return 1;
5295 }
5296
5297 if (code >> 7 === 0) {
5298 p = blackTable1[code];
5299 } else if (code >> 9 === 0 && code >> 7 !== 0) {
5300 p = blackTable2[(code >> 1) - 64];
5301 } else {
5302 p = blackTable3[code >> 7];
5303 }
5304
5305 if (p[0] > 0) {
5306 this._eatBits(p[0]);
5307
5308 return p[1];
5309 }
5310 } else {
5311 let result = this._findTableCode(2, 6, blackTable3);
5312
5313 if (result[0]) {
5314 return result[1];
5315 }
5316
5317 result = this._findTableCode(7, 12, blackTable2, 64);
5318
5319 if (result[0]) {
5320 return result[1];
5321 }
5322
5323 result = this._findTableCode(10, 13, blackTable1);
5324
5325 if (result[0]) {
5326 return result[1];
5327 }
5328 }
5329
5330 (0, _util.info)("bad black code");
5331
5332 this._eatBits(1);
5333
5334 return 1;
5335 }
5336
5337 _lookBits(n) {
5338 let c;
5339
5340 while (this.inputBits < n) {
5341 if ((c = this.source.next()) === -1) {
5342 if (this.inputBits === 0) {
5343 return ccittEOF;
5344 }
5345
5346 return this.inputBuf << n - this.inputBits & 0xffff >> 16 - n;
5347 }
5348
5349 this.inputBuf = this.inputBuf << 8 | c;
5350 this.inputBits += 8;
5351 }
5352
5353 return this.inputBuf >> this.inputBits - n & 0xffff >> 16 - n;
5354 }
5355
5356 _eatBits(n) {
5357 if ((this.inputBits -= n) < 0) {
5358 this.inputBits = 0;
5359 }
5360 }
5361
5362}
5363
5364exports.CCITTFaxDecoder = CCITTFaxDecoder;
5365
5366/***/ }),
5367/* 10 */
5368/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
5369
5370
5371
5372Object.defineProperty(exports, "__esModule", ({
5373 value: true
5374}));
5375exports.JpegImage = void 0;
5376
5377var _util = __w_pdfjs_require__(1);
5378
5379var _core_utils = __w_pdfjs_require__(5);
5380
5381class JpegError extends _util.BaseException {
5382 constructor(msg) {
5383 super(`JPEG error: ${msg}`, "JpegError");
5384 }
5385
5386}
5387
5388class DNLMarkerError extends _util.BaseException {
5389 constructor(message, scanLines) {
5390 super(message, "DNLMarkerError");
5391 this.scanLines = scanLines;
5392 }
5393
5394}
5395
5396class EOIMarkerError extends _util.BaseException {
5397 constructor(msg) {
5398 super(msg, "EOIMarkerError");
5399 }
5400
5401}
5402
5403const dctZigZag = new Uint8Array([0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63]);
5404const dctCos1 = 4017;
5405const dctSin1 = 799;
5406const dctCos3 = 3406;
5407const dctSin3 = 2276;
5408const dctCos6 = 1567;
5409const dctSin6 = 3784;
5410const dctSqrt2 = 5793;
5411const dctSqrt1d2 = 2896;
5412
5413function buildHuffmanTable(codeLengths, values) {
5414 let k = 0,
5415 i,
5416 j,
5417 length = 16;
5418
5419 while (length > 0 && !codeLengths[length - 1]) {
5420 length--;
5421 }
5422
5423 const code = [{
5424 children: [],
5425 index: 0
5426 }];
5427 let p = code[0],
5428 q;
5429
5430 for (i = 0; i < length; i++) {
5431 for (j = 0; j < codeLengths[i]; j++) {
5432 p = code.pop();
5433 p.children[p.index] = values[k];
5434
5435 while (p.index > 0) {
5436 p = code.pop();
5437 }
5438
5439 p.index++;
5440 code.push(p);
5441
5442 while (code.length <= i) {
5443 code.push(q = {
5444 children: [],
5445 index: 0
5446 });
5447 p.children[p.index] = q.children;
5448 p = q;
5449 }
5450
5451 k++;
5452 }
5453
5454 if (i + 1 < length) {
5455 code.push(q = {
5456 children: [],
5457 index: 0
5458 });
5459 p.children[p.index] = q.children;
5460 p = q;
5461 }
5462 }
5463
5464 return code[0].children;
5465}
5466
5467function getBlockBufferOffset(component, row, col) {
5468 return 64 * ((component.blocksPerLine + 1) * row + col);
5469}
5470
5471function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive, parseDNLMarker = false) {
5472 const mcusPerLine = frame.mcusPerLine;
5473 const progressive = frame.progressive;
5474 const startOffset = offset;
5475 let bitsData = 0,
5476 bitsCount = 0;
5477
5478 function readBit() {
5479 if (bitsCount > 0) {
5480 bitsCount--;
5481 return bitsData >> bitsCount & 1;
5482 }
5483
5484 bitsData = data[offset++];
5485
5486 if (bitsData === 0xff) {
5487 const nextByte = data[offset++];
5488
5489 if (nextByte) {
5490 if (nextByte === 0xdc && parseDNLMarker) {
5491 offset += 2;
5492 const scanLines = (0, _core_utils.readUint16)(data, offset);
5493 offset += 2;
5494
5495 if (scanLines > 0 && scanLines !== frame.scanLines) {
5496 throw new DNLMarkerError("Found DNL marker (0xFFDC) while parsing scan data", scanLines);
5497 }
5498 } else if (nextByte === 0xd9) {
5499 if (parseDNLMarker) {
5500 const maybeScanLines = blockRow * (frame.precision === 8 ? 8 : 0);
5501
5502 if (maybeScanLines > 0 && Math.round(frame.scanLines / maybeScanLines) >= 10) {
5503 throw new DNLMarkerError("Found EOI marker (0xFFD9) while parsing scan data, " + "possibly caused by incorrect `scanLines` parameter", maybeScanLines);
5504 }
5505 }
5506
5507 throw new EOIMarkerError("Found EOI marker (0xFFD9) while parsing scan data");
5508 }
5509
5510 throw new JpegError(`unexpected marker ${(bitsData << 8 | nextByte).toString(16)}`);
5511 }
5512 }
5513
5514 bitsCount = 7;
5515 return bitsData >>> 7;
5516 }
5517
5518 function decodeHuffman(tree) {
5519 let node = tree;
5520
5521 while (true) {
5522 node = node[readBit()];
5523
5524 switch (typeof node) {
5525 case "number":
5526 return node;
5527
5528 case "object":
5529 continue;
5530 }
5531
5532 throw new JpegError("invalid huffman sequence");
5533 }
5534 }
5535
5536 function receive(length) {
5537 let n = 0;
5538
5539 while (length > 0) {
5540 n = n << 1 | readBit();
5541 length--;
5542 }
5543
5544 return n;
5545 }
5546
5547 function receiveAndExtend(length) {
5548 if (length === 1) {
5549 return readBit() === 1 ? 1 : -1;
5550 }
5551
5552 const n = receive(length);
5553
5554 if (n >= 1 << length - 1) {
5555 return n;
5556 }
5557
5558 return n + (-1 << length) + 1;
5559 }
5560
5561 function decodeBaseline(component, blockOffset) {
5562 const t = decodeHuffman(component.huffmanTableDC);
5563 const diff = t === 0 ? 0 : receiveAndExtend(t);
5564 component.blockData[blockOffset] = component.pred += diff;
5565 let k = 1;
5566
5567 while (k < 64) {
5568 const rs = decodeHuffman(component.huffmanTableAC);
5569 const s = rs & 15,
5570 r = rs >> 4;
5571
5572 if (s === 0) {
5573 if (r < 15) {
5574 break;
5575 }
5576
5577 k += 16;
5578 continue;
5579 }
5580
5581 k += r;
5582 const z = dctZigZag[k];
5583 component.blockData[blockOffset + z] = receiveAndExtend(s);
5584 k++;
5585 }
5586 }
5587
5588 function decodeDCFirst(component, blockOffset) {
5589 const t = decodeHuffman(component.huffmanTableDC);
5590 const diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
5591 component.blockData[blockOffset] = component.pred += diff;
5592 }
5593
5594 function decodeDCSuccessive(component, blockOffset) {
5595 component.blockData[blockOffset] |= readBit() << successive;
5596 }
5597
5598 let eobrun = 0;
5599
5600 function decodeACFirst(component, blockOffset) {
5601 if (eobrun > 0) {
5602 eobrun--;
5603 return;
5604 }
5605
5606 let k = spectralStart;
5607 const e = spectralEnd;
5608
5609 while (k <= e) {
5610 const rs = decodeHuffman(component.huffmanTableAC);
5611 const s = rs & 15,
5612 r = rs >> 4;
5613
5614 if (s === 0) {
5615 if (r < 15) {
5616 eobrun = receive(r) + (1 << r) - 1;
5617 break;
5618 }
5619
5620 k += 16;
5621 continue;
5622 }
5623
5624 k += r;
5625 const z = dctZigZag[k];
5626 component.blockData[blockOffset + z] = receiveAndExtend(s) * (1 << successive);
5627 k++;
5628 }
5629 }
5630
5631 let successiveACState = 0,
5632 successiveACNextValue;
5633
5634 function decodeACSuccessive(component, blockOffset) {
5635 let k = spectralStart;
5636 const e = spectralEnd;
5637 let r = 0;
5638 let s;
5639 let rs;
5640
5641 while (k <= e) {
5642 const offsetZ = blockOffset + dctZigZag[k];
5643 const sign = component.blockData[offsetZ] < 0 ? -1 : 1;
5644
5645 switch (successiveACState) {
5646 case 0:
5647 rs = decodeHuffman(component.huffmanTableAC);
5648 s = rs & 15;
5649 r = rs >> 4;
5650
5651 if (s === 0) {
5652 if (r < 15) {
5653 eobrun = receive(r) + (1 << r);
5654 successiveACState = 4;
5655 } else {
5656 r = 16;
5657 successiveACState = 1;
5658 }
5659 } else {
5660 if (s !== 1) {
5661 throw new JpegError("invalid ACn encoding");
5662 }
5663
5664 successiveACNextValue = receiveAndExtend(s);
5665 successiveACState = r ? 2 : 3;
5666 }
5667
5668 continue;
5669
5670 case 1:
5671 case 2:
5672 if (component.blockData[offsetZ]) {
5673 component.blockData[offsetZ] += sign * (readBit() << successive);
5674 } else {
5675 r--;
5676
5677 if (r === 0) {
5678 successiveACState = successiveACState === 2 ? 3 : 0;
5679 }
5680 }
5681
5682 break;
5683
5684 case 3:
5685 if (component.blockData[offsetZ]) {
5686 component.blockData[offsetZ] += sign * (readBit() << successive);
5687 } else {
5688 component.blockData[offsetZ] = successiveACNextValue << successive;
5689 successiveACState = 0;
5690 }
5691
5692 break;
5693
5694 case 4:
5695 if (component.blockData[offsetZ]) {
5696 component.blockData[offsetZ] += sign * (readBit() << successive);
5697 }
5698
5699 break;
5700 }
5701
5702 k++;
5703 }
5704
5705 if (successiveACState === 4) {
5706 eobrun--;
5707
5708 if (eobrun === 0) {
5709 successiveACState = 0;
5710 }
5711 }
5712 }
5713
5714 let blockRow = 0;
5715
5716 function decodeMcu(component, decode, mcu, row, col) {
5717 const mcuRow = mcu / mcusPerLine | 0;
5718 const mcuCol = mcu % mcusPerLine;
5719 blockRow = mcuRow * component.v + row;
5720 const blockCol = mcuCol * component.h + col;
5721 const blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
5722 decode(component, blockOffset);
5723 }
5724
5725 function decodeBlock(component, decode, mcu) {
5726 blockRow = mcu / component.blocksPerLine | 0;
5727 const blockCol = mcu % component.blocksPerLine;
5728 const blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
5729 decode(component, blockOffset);
5730 }
5731
5732 const componentsLength = components.length;
5733 let component, i, j, k, n;
5734 let decodeFn;
5735
5736 if (progressive) {
5737 if (spectralStart === 0) {
5738 decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
5739 } else {
5740 decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
5741 }
5742 } else {
5743 decodeFn = decodeBaseline;
5744 }
5745
5746 let mcu = 0,
5747 fileMarker;
5748 let mcuExpected;
5749
5750 if (componentsLength === 1) {
5751 mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
5752 } else {
5753 mcuExpected = mcusPerLine * frame.mcusPerColumn;
5754 }
5755
5756 let h, v;
5757
5758 while (mcu <= mcuExpected) {
5759 const mcuToRead = resetInterval ? Math.min(mcuExpected - mcu, resetInterval) : mcuExpected;
5760
5761 if (mcuToRead > 0) {
5762 for (i = 0; i < componentsLength; i++) {
5763 components[i].pred = 0;
5764 }
5765
5766 eobrun = 0;
5767
5768 if (componentsLength === 1) {
5769 component = components[0];
5770
5771 for (n = 0; n < mcuToRead; n++) {
5772 decodeBlock(component, decodeFn, mcu);
5773 mcu++;
5774 }
5775 } else {
5776 for (n = 0; n < mcuToRead; n++) {
5777 for (i = 0; i < componentsLength; i++) {
5778 component = components[i];
5779 h = component.h;
5780 v = component.v;
5781
5782 for (j = 0; j < v; j++) {
5783 for (k = 0; k < h; k++) {
5784 decodeMcu(component, decodeFn, mcu, j, k);
5785 }
5786 }
5787 }
5788
5789 mcu++;
5790 }
5791 }
5792 }
5793
5794 bitsCount = 0;
5795 fileMarker = findNextFileMarker(data, offset);
5796
5797 if (!fileMarker) {
5798 break;
5799 }
5800
5801 if (fileMarker.invalid) {
5802 const partialMsg = mcuToRead > 0 ? "unexpected" : "excessive";
5803 (0, _util.warn)(`decodeScan - ${partialMsg} MCU data, current marker is: ${fileMarker.invalid}`);
5804 offset = fileMarker.offset;
5805 }
5806
5807 if (fileMarker.marker >= 0xffd0 && fileMarker.marker <= 0xffd7) {
5808 offset += 2;
5809 } else {
5810 break;
5811 }
5812 }
5813
5814 return offset - startOffset;
5815}
5816
5817function quantizeAndInverse(component, blockBufferOffset, p) {
5818 const qt = component.quantizationTable,
5819 blockData = component.blockData;
5820 let v0, v1, v2, v3, v4, v5, v6, v7;
5821 let p0, p1, p2, p3, p4, p5, p6, p7;
5822 let t;
5823
5824 if (!qt) {
5825 throw new JpegError("missing required Quantization Table.");
5826 }
5827
5828 for (let row = 0; row < 64; row += 8) {
5829 p0 = blockData[blockBufferOffset + row];
5830 p1 = blockData[blockBufferOffset + row + 1];
5831 p2 = blockData[blockBufferOffset + row + 2];
5832 p3 = blockData[blockBufferOffset + row + 3];
5833 p4 = blockData[blockBufferOffset + row + 4];
5834 p5 = blockData[blockBufferOffset + row + 5];
5835 p6 = blockData[blockBufferOffset + row + 6];
5836 p7 = blockData[blockBufferOffset + row + 7];
5837 p0 *= qt[row];
5838
5839 if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
5840 t = dctSqrt2 * p0 + 512 >> 10;
5841 p[row] = t;
5842 p[row + 1] = t;
5843 p[row + 2] = t;
5844 p[row + 3] = t;
5845 p[row + 4] = t;
5846 p[row + 5] = t;
5847 p[row + 6] = t;
5848 p[row + 7] = t;
5849 continue;
5850 }
5851
5852 p1 *= qt[row + 1];
5853 p2 *= qt[row + 2];
5854 p3 *= qt[row + 3];
5855 p4 *= qt[row + 4];
5856 p5 *= qt[row + 5];
5857 p6 *= qt[row + 6];
5858 p7 *= qt[row + 7];
5859 v0 = dctSqrt2 * p0 + 128 >> 8;
5860 v1 = dctSqrt2 * p4 + 128 >> 8;
5861 v2 = p2;
5862 v3 = p6;
5863 v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8;
5864 v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8;
5865 v5 = p3 << 4;
5866 v6 = p5 << 4;
5867 v0 = v0 + v1 + 1 >> 1;
5868 v1 = v0 - v1;
5869 t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
5870 v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
5871 v3 = t;
5872 v4 = v4 + v6 + 1 >> 1;
5873 v6 = v4 - v6;
5874 v7 = v7 + v5 + 1 >> 1;
5875 v5 = v7 - v5;
5876 v0 = v0 + v3 + 1 >> 1;
5877 v3 = v0 - v3;
5878 v1 = v1 + v2 + 1 >> 1;
5879 v2 = v1 - v2;
5880 t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
5881 v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
5882 v7 = t;
5883 t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
5884 v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
5885 v6 = t;
5886 p[row] = v0 + v7;
5887 p[row + 7] = v0 - v7;
5888 p[row + 1] = v1 + v6;
5889 p[row + 6] = v1 - v6;
5890 p[row + 2] = v2 + v5;
5891 p[row + 5] = v2 - v5;
5892 p[row + 3] = v3 + v4;
5893 p[row + 4] = v3 - v4;
5894 }
5895
5896 for (let col = 0; col < 8; ++col) {
5897 p0 = p[col];
5898 p1 = p[col + 8];
5899 p2 = p[col + 16];
5900 p3 = p[col + 24];
5901 p4 = p[col + 32];
5902 p5 = p[col + 40];
5903 p6 = p[col + 48];
5904 p7 = p[col + 56];
5905
5906 if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
5907 t = dctSqrt2 * p0 + 8192 >> 14;
5908
5909 if (t < -2040) {
5910 t = 0;
5911 } else if (t >= 2024) {
5912 t = 255;
5913 } else {
5914 t = t + 2056 >> 4;
5915 }
5916
5917 blockData[blockBufferOffset + col] = t;
5918 blockData[blockBufferOffset + col + 8] = t;
5919 blockData[blockBufferOffset + col + 16] = t;
5920 blockData[blockBufferOffset + col + 24] = t;
5921 blockData[blockBufferOffset + col + 32] = t;
5922 blockData[blockBufferOffset + col + 40] = t;
5923 blockData[blockBufferOffset + col + 48] = t;
5924 blockData[blockBufferOffset + col + 56] = t;
5925 continue;
5926 }
5927
5928 v0 = dctSqrt2 * p0 + 2048 >> 12;
5929 v1 = dctSqrt2 * p4 + 2048 >> 12;
5930 v2 = p2;
5931 v3 = p6;
5932 v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12;
5933 v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12;
5934 v5 = p3;
5935 v6 = p5;
5936 v0 = (v0 + v1 + 1 >> 1) + 4112;
5937 v1 = v0 - v1;
5938 t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
5939 v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
5940 v3 = t;
5941 v4 = v4 + v6 + 1 >> 1;
5942 v6 = v4 - v6;
5943 v7 = v7 + v5 + 1 >> 1;
5944 v5 = v7 - v5;
5945 v0 = v0 + v3 + 1 >> 1;
5946 v3 = v0 - v3;
5947 v1 = v1 + v2 + 1 >> 1;
5948 v2 = v1 - v2;
5949 t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
5950 v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
5951 v7 = t;
5952 t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
5953 v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
5954 v6 = t;
5955 p0 = v0 + v7;
5956 p7 = v0 - v7;
5957 p1 = v1 + v6;
5958 p6 = v1 - v6;
5959 p2 = v2 + v5;
5960 p5 = v2 - v5;
5961 p3 = v3 + v4;
5962 p4 = v3 - v4;
5963
5964 if (p0 < 16) {
5965 p0 = 0;
5966 } else if (p0 >= 4080) {
5967 p0 = 255;
5968 } else {
5969 p0 >>= 4;
5970 }
5971
5972 if (p1 < 16) {
5973 p1 = 0;
5974 } else if (p1 >= 4080) {
5975 p1 = 255;
5976 } else {
5977 p1 >>= 4;
5978 }
5979
5980 if (p2 < 16) {
5981 p2 = 0;
5982 } else if (p2 >= 4080) {
5983 p2 = 255;
5984 } else {
5985 p2 >>= 4;
5986 }
5987
5988 if (p3 < 16) {
5989 p3 = 0;
5990 } else if (p3 >= 4080) {
5991 p3 = 255;
5992 } else {
5993 p3 >>= 4;
5994 }
5995
5996 if (p4 < 16) {
5997 p4 = 0;
5998 } else if (p4 >= 4080) {
5999 p4 = 255;
6000 } else {
6001 p4 >>= 4;
6002 }
6003
6004 if (p5 < 16) {
6005 p5 = 0;
6006 } else if (p5 >= 4080) {
6007 p5 = 255;
6008 } else {
6009 p5 >>= 4;
6010 }
6011
6012 if (p6 < 16) {
6013 p6 = 0;
6014 } else if (p6 >= 4080) {
6015 p6 = 255;
6016 } else {
6017 p6 >>= 4;
6018 }
6019
6020 if (p7 < 16) {
6021 p7 = 0;
6022 } else if (p7 >= 4080) {
6023 p7 = 255;
6024 } else {
6025 p7 >>= 4;
6026 }
6027
6028 blockData[blockBufferOffset + col] = p0;
6029 blockData[blockBufferOffset + col + 8] = p1;
6030 blockData[blockBufferOffset + col + 16] = p2;
6031 blockData[blockBufferOffset + col + 24] = p3;
6032 blockData[blockBufferOffset + col + 32] = p4;
6033 blockData[blockBufferOffset + col + 40] = p5;
6034 blockData[blockBufferOffset + col + 48] = p6;
6035 blockData[blockBufferOffset + col + 56] = p7;
6036 }
6037}
6038
6039function buildComponentData(frame, component) {
6040 const blocksPerLine = component.blocksPerLine;
6041 const blocksPerColumn = component.blocksPerColumn;
6042 const computationBuffer = new Int16Array(64);
6043
6044 for (let blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
6045 for (let blockCol = 0; blockCol < blocksPerLine; blockCol++) {
6046 const offset = getBlockBufferOffset(component, blockRow, blockCol);
6047 quantizeAndInverse(component, offset, computationBuffer);
6048 }
6049 }
6050
6051 return component.blockData;
6052}
6053
6054function findNextFileMarker(data, currentPos, startPos = currentPos) {
6055 const maxPos = data.length - 1;
6056 let newPos = startPos < currentPos ? startPos : currentPos;
6057
6058 if (currentPos >= maxPos) {
6059 return null;
6060 }
6061
6062 const currentMarker = (0, _core_utils.readUint16)(data, currentPos);
6063
6064 if (currentMarker >= 0xffc0 && currentMarker <= 0xfffe) {
6065 return {
6066 invalid: null,
6067 marker: currentMarker,
6068 offset: currentPos
6069 };
6070 }
6071
6072 let newMarker = (0, _core_utils.readUint16)(data, newPos);
6073
6074 while (!(newMarker >= 0xffc0 && newMarker <= 0xfffe)) {
6075 if (++newPos >= maxPos) {
6076 return null;
6077 }
6078
6079 newMarker = (0, _core_utils.readUint16)(data, newPos);
6080 }
6081
6082 return {
6083 invalid: currentMarker.toString(16),
6084 marker: newMarker,
6085 offset: newPos
6086 };
6087}
6088
6089class JpegImage {
6090 constructor({
6091 decodeTransform = null,
6092 colorTransform = -1
6093 } = {}) {
6094 this._decodeTransform = decodeTransform;
6095 this._colorTransform = colorTransform;
6096 }
6097
6098 parse(data, {
6099 dnlScanLines = null
6100 } = {}) {
6101 function readDataBlock() {
6102 const length = (0, _core_utils.readUint16)(data, offset);
6103 offset += 2;
6104 let endOffset = offset + length - 2;
6105 const fileMarker = findNextFileMarker(data, endOffset, offset);
6106
6107 if (fileMarker && fileMarker.invalid) {
6108 (0, _util.warn)("readDataBlock - incorrect length, current marker is: " + fileMarker.invalid);
6109 endOffset = fileMarker.offset;
6110 }
6111
6112 const array = data.subarray(offset, endOffset);
6113 offset += array.length;
6114 return array;
6115 }
6116
6117 function prepareComponents(frame) {
6118 const mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
6119 const mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
6120
6121 for (let i = 0, ii = frame.components.length; i < ii; i++) {
6122 const component = frame.components[i];
6123 const blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH);
6124 const blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV);
6125 const blocksPerLineForMcu = mcusPerLine * component.h;
6126 const blocksPerColumnForMcu = mcusPerColumn * component.v;
6127 const blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
6128 component.blockData = new Int16Array(blocksBufferSize);
6129 component.blocksPerLine = blocksPerLine;
6130 component.blocksPerColumn = blocksPerColumn;
6131 }
6132
6133 frame.mcusPerLine = mcusPerLine;
6134 frame.mcusPerColumn = mcusPerColumn;
6135 }
6136
6137 let offset = 0;
6138 let jfif = null;
6139 let adobe = null;
6140 let frame, resetInterval;
6141 let numSOSMarkers = 0;
6142 const quantizationTables = [];
6143 const huffmanTablesAC = [],
6144 huffmanTablesDC = [];
6145 let fileMarker = (0, _core_utils.readUint16)(data, offset);
6146 offset += 2;
6147
6148 if (fileMarker !== 0xffd8) {
6149 throw new JpegError("SOI not found");
6150 }
6151
6152 fileMarker = (0, _core_utils.readUint16)(data, offset);
6153 offset += 2;
6154
6155 markerLoop: while (fileMarker !== 0xffd9) {
6156 let i, j, l;
6157
6158 switch (fileMarker) {
6159 case 0xffe0:
6160 case 0xffe1:
6161 case 0xffe2:
6162 case 0xffe3:
6163 case 0xffe4:
6164 case 0xffe5:
6165 case 0xffe6:
6166 case 0xffe7:
6167 case 0xffe8:
6168 case 0xffe9:
6169 case 0xffea:
6170 case 0xffeb:
6171 case 0xffec:
6172 case 0xffed:
6173 case 0xffee:
6174 case 0xffef:
6175 case 0xfffe:
6176 const appData = readDataBlock();
6177
6178 if (fileMarker === 0xffe0) {
6179 if (appData[0] === 0x4a && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) {
6180 jfif = {
6181 version: {
6182 major: appData[5],
6183 minor: appData[6]
6184 },
6185 densityUnits: appData[7],
6186 xDensity: appData[8] << 8 | appData[9],
6187 yDensity: appData[10] << 8 | appData[11],
6188 thumbWidth: appData[12],
6189 thumbHeight: appData[13],
6190 thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
6191 };
6192 }
6193 }
6194
6195 if (fileMarker === 0xffee) {
6196 if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6f && appData[3] === 0x62 && appData[4] === 0x65) {
6197 adobe = {
6198 version: appData[5] << 8 | appData[6],
6199 flags0: appData[7] << 8 | appData[8],
6200 flags1: appData[9] << 8 | appData[10],
6201 transformCode: appData[11]
6202 };
6203 }
6204 }
6205
6206 break;
6207
6208 case 0xffdb:
6209 const quantizationTablesLength = (0, _core_utils.readUint16)(data, offset);
6210 offset += 2;
6211 const quantizationTablesEnd = quantizationTablesLength + offset - 2;
6212 let z;
6213
6214 while (offset < quantizationTablesEnd) {
6215 const quantizationTableSpec = data[offset++];
6216 const tableData = new Uint16Array(64);
6217
6218 if (quantizationTableSpec >> 4 === 0) {
6219 for (j = 0; j < 64; j++) {
6220 z = dctZigZag[j];
6221 tableData[z] = data[offset++];
6222 }
6223 } else if (quantizationTableSpec >> 4 === 1) {
6224 for (j = 0; j < 64; j++) {
6225 z = dctZigZag[j];
6226 tableData[z] = (0, _core_utils.readUint16)(data, offset);
6227 offset += 2;
6228 }
6229 } else {
6230 throw new JpegError("DQT - invalid table spec");
6231 }
6232
6233 quantizationTables[quantizationTableSpec & 15] = tableData;
6234 }
6235
6236 break;
6237
6238 case 0xffc0:
6239 case 0xffc1:
6240 case 0xffc2:
6241 if (frame) {
6242 throw new JpegError("Only single frame JPEGs supported");
6243 }
6244
6245 offset += 2;
6246 frame = {};
6247 frame.extended = fileMarker === 0xffc1;
6248 frame.progressive = fileMarker === 0xffc2;
6249 frame.precision = data[offset++];
6250 const sofScanLines = (0, _core_utils.readUint16)(data, offset);
6251 offset += 2;
6252 frame.scanLines = dnlScanLines || sofScanLines;
6253 frame.samplesPerLine = (0, _core_utils.readUint16)(data, offset);
6254 offset += 2;
6255 frame.components = [];
6256 frame.componentIds = {};
6257 const componentsCount = data[offset++];
6258 let maxH = 0,
6259 maxV = 0;
6260
6261 for (i = 0; i < componentsCount; i++) {
6262 const componentId = data[offset];
6263 const h = data[offset + 1] >> 4;
6264 const v = data[offset + 1] & 15;
6265
6266 if (maxH < h) {
6267 maxH = h;
6268 }
6269
6270 if (maxV < v) {
6271 maxV = v;
6272 }
6273
6274 const qId = data[offset + 2];
6275 l = frame.components.push({
6276 h,
6277 v,
6278 quantizationId: qId,
6279 quantizationTable: null
6280 });
6281 frame.componentIds[componentId] = l - 1;
6282 offset += 3;
6283 }
6284
6285 frame.maxH = maxH;
6286 frame.maxV = maxV;
6287 prepareComponents(frame);
6288 break;
6289
6290 case 0xffc4:
6291 const huffmanLength = (0, _core_utils.readUint16)(data, offset);
6292 offset += 2;
6293
6294 for (i = 2; i < huffmanLength;) {
6295 const huffmanTableSpec = data[offset++];
6296 const codeLengths = new Uint8Array(16);
6297 let codeLengthSum = 0;
6298
6299 for (j = 0; j < 16; j++, offset++) {
6300 codeLengthSum += codeLengths[j] = data[offset];
6301 }
6302
6303 const huffmanValues = new Uint8Array(codeLengthSum);
6304
6305 for (j = 0; j < codeLengthSum; j++, offset++) {
6306 huffmanValues[j] = data[offset];
6307 }
6308
6309 i += 17 + codeLengthSum;
6310 (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
6311 }
6312
6313 break;
6314
6315 case 0xffdd:
6316 offset += 2;
6317 resetInterval = (0, _core_utils.readUint16)(data, offset);
6318 offset += 2;
6319 break;
6320
6321 case 0xffda:
6322 const parseDNLMarker = ++numSOSMarkers === 1 && !dnlScanLines;
6323 offset += 2;
6324 const selectorsCount = data[offset++],
6325 components = [];
6326
6327 for (i = 0; i < selectorsCount; i++) {
6328 const index = data[offset++];
6329 const componentIndex = frame.componentIds[index];
6330 const component = frame.components[componentIndex];
6331 component.index = index;
6332 const tableSpec = data[offset++];
6333 component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
6334 component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
6335 components.push(component);
6336 }
6337
6338 const spectralStart = data[offset++],
6339 spectralEnd = data[offset++],
6340 successiveApproximation = data[offset++];
6341
6342 try {
6343 const processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15, parseDNLMarker);
6344 offset += processed;
6345 } catch (ex) {
6346 if (ex instanceof DNLMarkerError) {
6347 (0, _util.warn)(`${ex.message} -- attempting to re-parse the JPEG image.`);
6348 return this.parse(data, {
6349 dnlScanLines: ex.scanLines
6350 });
6351 } else if (ex instanceof EOIMarkerError) {
6352 (0, _util.warn)(`${ex.message} -- ignoring the rest of the image data.`);
6353 break markerLoop;
6354 }
6355
6356 throw ex;
6357 }
6358
6359 break;
6360
6361 case 0xffdc:
6362 offset += 4;
6363 break;
6364
6365 case 0xffff:
6366 if (data[offset] !== 0xff) {
6367 offset--;
6368 }
6369
6370 break;
6371
6372 default:
6373 const nextFileMarker = findNextFileMarker(data, offset - 2, offset - 3);
6374
6375 if (nextFileMarker && nextFileMarker.invalid) {
6376 (0, _util.warn)("JpegImage.parse - unexpected data, current marker is: " + nextFileMarker.invalid);
6377 offset = nextFileMarker.offset;
6378 break;
6379 }
6380
6381 if (!nextFileMarker || offset >= data.length - 1) {
6382 (0, _util.warn)("JpegImage.parse - reached the end of the image data " + "without finding an EOI marker (0xFFD9).");
6383 break markerLoop;
6384 }
6385
6386 throw new JpegError("JpegImage.parse - unknown marker: " + fileMarker.toString(16));
6387 }
6388
6389 fileMarker = (0, _core_utils.readUint16)(data, offset);
6390 offset += 2;
6391 }
6392
6393 this.width = frame.samplesPerLine;
6394 this.height = frame.scanLines;
6395 this.jfif = jfif;
6396 this.adobe = adobe;
6397 this.components = [];
6398
6399 for (let i = 0, ii = frame.components.length; i < ii; i++) {
6400 const component = frame.components[i];
6401 const quantizationTable = quantizationTables[component.quantizationId];
6402
6403 if (quantizationTable) {
6404 component.quantizationTable = quantizationTable;
6405 }
6406
6407 this.components.push({
6408 index: component.index,
6409 output: buildComponentData(frame, component),
6410 scaleX: component.h / frame.maxH,
6411 scaleY: component.v / frame.maxV,
6412 blocksPerLine: component.blocksPerLine,
6413 blocksPerColumn: component.blocksPerColumn
6414 });
6415 }
6416
6417 this.numComponents = this.components.length;
6418 return undefined;
6419 }
6420
6421 _getLinearizedBlockData(width, height, isSourcePDF = false) {
6422 const scaleX = this.width / width,
6423 scaleY = this.height / height;
6424 let component, componentScaleX, componentScaleY, blocksPerScanline;
6425 let x, y, i, j, k;
6426 let index;
6427 let offset = 0;
6428 let output;
6429 const numComponents = this.components.length;
6430 const dataLength = width * height * numComponents;
6431 const data = new Uint8ClampedArray(dataLength);
6432 const xScaleBlockOffset = new Uint32Array(width);
6433 const mask3LSB = 0xfffffff8;
6434 let lastComponentScaleX;
6435
6436 for (i = 0; i < numComponents; i++) {
6437 component = this.components[i];
6438 componentScaleX = component.scaleX * scaleX;
6439 componentScaleY = component.scaleY * scaleY;
6440 offset = i;
6441 output = component.output;
6442 blocksPerScanline = component.blocksPerLine + 1 << 3;
6443
6444 if (componentScaleX !== lastComponentScaleX) {
6445 for (x = 0; x < width; x++) {
6446 j = 0 | x * componentScaleX;
6447 xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7;
6448 }
6449
6450 lastComponentScaleX = componentScaleX;
6451 }
6452
6453 for (y = 0; y < height; y++) {
6454 j = 0 | y * componentScaleY;
6455 index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3;
6456
6457 for (x = 0; x < width; x++) {
6458 data[offset] = output[index + xScaleBlockOffset[x]];
6459 offset += numComponents;
6460 }
6461 }
6462 }
6463
6464 let transform = this._decodeTransform;
6465
6466 if (!isSourcePDF && numComponents === 4 && !transform) {
6467 transform = new Int32Array([-256, 255, -256, 255, -256, 255, -256, 255]);
6468 }
6469
6470 if (transform) {
6471 for (i = 0; i < dataLength;) {
6472 for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
6473 data[i] = (data[i] * transform[k] >> 8) + transform[k + 1];
6474 }
6475 }
6476 }
6477
6478 return data;
6479 }
6480
6481 get _isColorConversionNeeded() {
6482 if (this.adobe) {
6483 return !!this.adobe.transformCode;
6484 }
6485
6486 if (this.numComponents === 3) {
6487 if (this._colorTransform === 0) {
6488 return false;
6489 } else if (this.components[0].index === 0x52 && this.components[1].index === 0x47 && this.components[2].index === 0x42) {
6490 return false;
6491 }
6492
6493 return true;
6494 }
6495
6496 if (this._colorTransform === 1) {
6497 return true;
6498 }
6499
6500 return false;
6501 }
6502
6503 _convertYccToRgb(data) {
6504 let Y, Cb, Cr;
6505
6506 for (let i = 0, length = data.length; i < length; i += 3) {
6507 Y = data[i];
6508 Cb = data[i + 1];
6509 Cr = data[i + 2];
6510 data[i] = Y - 179.456 + 1.402 * Cr;
6511 data[i + 1] = Y + 135.459 - 0.344 * Cb - 0.714 * Cr;
6512 data[i + 2] = Y - 226.816 + 1.772 * Cb;
6513 }
6514
6515 return data;
6516 }
6517
6518 _convertYcckToRgb(data) {
6519 let Y, Cb, Cr, k;
6520 let offset = 0;
6521
6522 for (let i = 0, length = data.length; i < length; i += 4) {
6523 Y = data[i];
6524 Cb = data[i + 1];
6525 Cr = data[i + 2];
6526 k = data[i + 3];
6527 data[offset++] = -122.67195406894 + Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr - 5.4080610064599e-5 * Y + 0.00048449797120281 * k - 0.154362151871126) + Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y - 0.00477271405408747 * k + 1.53380253221734) + Y * (0.000961250184130688 * Y - 0.00266257332283933 * k + 0.48357088451265) + k * (-0.000336197177618394 * k + 0.484791561490776);
6528 data[offset++] = 107.268039397724 + Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr + 0.000659397001245577 * Y + 0.000426105652938837 * k - 0.176491792462875) + Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y + 0.000770482631801132 * k - 0.151051492775562) + Y * (0.00126935368114843 * Y - 0.00265090189010898 * k + 0.25802910206845) + k * (-0.000318913117588328 * k - 0.213742400323665);
6529 data[offset++] = -20.810012546947 + Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr + 0.0020741088115012 * Y - 0.00288260236853442 * k + 0.814272968359295) + Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y + 0.000560833691242812 * k - 0.195152027534049) + Y * (0.00174418132927582 * Y - 0.00255243321439347 * k + 0.116935020465145) + k * (-0.000343531996510555 * k + 0.24165260232407);
6530 }
6531
6532 return data.subarray(0, offset);
6533 }
6534
6535 _convertYcckToCmyk(data) {
6536 let Y, Cb, Cr;
6537
6538 for (let i = 0, length = data.length; i < length; i += 4) {
6539 Y = data[i];
6540 Cb = data[i + 1];
6541 Cr = data[i + 2];
6542 data[i] = 434.456 - Y - 1.402 * Cr;
6543 data[i + 1] = 119.541 - Y + 0.344 * Cb + 0.714 * Cr;
6544 data[i + 2] = 481.816 - Y - 1.772 * Cb;
6545 }
6546
6547 return data;
6548 }
6549
6550 _convertCmykToRgb(data) {
6551 let c, m, y, k;
6552 let offset = 0;
6553
6554 for (let i = 0, length = data.length; i < length; i += 4) {
6555 c = data[i];
6556 m = data[i + 1];
6557 y = data[i + 2];
6558 k = data[i + 3];
6559 data[offset++] = 255 + c * (-0.00006747147073602441 * c + 0.0008379262121013727 * m + 0.0002894718188643294 * y + 0.003264231057537806 * k - 1.1185611867203937) + m * (0.000026374107616089405 * m - 0.00008626949158638572 * y - 0.0002748769067499491 * k - 0.02155688794978967) + y * (-0.00003878099212869363 * y - 0.0003267808279485286 * k + 0.0686742238595345) - k * (0.0003361971776183937 * k + 0.7430659151342254);
6560 data[offset++] = 255 + c * (0.00013596372813588848 * c + 0.000924537132573585 * m + 0.00010567359618683593 * y + 0.0004791864687436512 * k - 0.3109689587515875) + m * (-0.00023545346108370344 * m + 0.0002702845253534714 * y + 0.0020200308977307156 * k - 0.7488052167015494) + y * (0.00006834815998235662 * y + 0.00015168452363460973 * k - 0.09751927774728933) - k * (0.0003189131175883281 * k + 0.7364883807733168);
6561 data[offset++] = 255 + c * (0.000013598650411385307 * c + 0.00012423956175490851 * m + 0.0004751985097583589 * y - 0.0000036729317476630422 * k - 0.05562186980264034) + m * (0.00016141380598724676 * m + 0.0009692239130725186 * y + 0.0007782692450036253 * k - 0.44015232367526463) + y * (5.068882914068769e-7 * y + 0.0017778369011375071 * k - 0.7591454649749609) - k * (0.0003435319965105553 * k + 0.7063770186160144);
6562 }
6563
6564 return data.subarray(0, offset);
6565 }
6566
6567 getData({
6568 width,
6569 height,
6570 forceRGB = false,
6571 isSourcePDF = false
6572 }) {
6573 if (this.numComponents > 4) {
6574 throw new JpegError("Unsupported color mode");
6575 }
6576
6577 const data = this._getLinearizedBlockData(width, height, isSourcePDF);
6578
6579 if (this.numComponents === 1 && forceRGB) {
6580 const dataLength = data.length;
6581 const rgbData = new Uint8ClampedArray(dataLength * 3);
6582 let offset = 0;
6583
6584 for (let i = 0; i < dataLength; i++) {
6585 const grayColor = data[i];
6586 rgbData[offset++] = grayColor;
6587 rgbData[offset++] = grayColor;
6588 rgbData[offset++] = grayColor;
6589 }
6590
6591 return rgbData;
6592 } else if (this.numComponents === 3 && this._isColorConversionNeeded) {
6593 return this._convertYccToRgb(data);
6594 } else if (this.numComponents === 4) {
6595 if (this._isColorConversionNeeded) {
6596 if (forceRGB) {
6597 return this._convertYcckToRgb(data);
6598 }
6599
6600 return this._convertYcckToCmyk(data);
6601 } else if (forceRGB) {
6602 return this._convertCmykToRgb(data);
6603 }
6604 }
6605
6606 return data;
6607 }
6608
6609}
6610
6611exports.JpegImage = JpegImage;
6612
6613/***/ }),
6614/* 11 */
6615/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
6616
6617
6618
6619Object.defineProperty(exports, "__esModule", ({
6620 value: true
6621}));
6622exports.JpxImage = void 0;
6623
6624var _util = __w_pdfjs_require__(1);
6625
6626var _core_utils = __w_pdfjs_require__(5);
6627
6628var _arithmetic_decoder = __w_pdfjs_require__(8);
6629
6630class JpxError extends _util.BaseException {
6631 constructor(msg) {
6632 super(`JPX error: ${msg}`, "JpxError");
6633 }
6634
6635}
6636
6637const SubbandsGainLog2 = {
6638 LL: 0,
6639 LH: 1,
6640 HL: 1,
6641 HH: 2
6642};
6643
6644class JpxImage {
6645 constructor() {
6646 this.failOnCorruptedImage = false;
6647 }
6648
6649 parse(data) {
6650 const head = (0, _core_utils.readUint16)(data, 0);
6651
6652 if (head === 0xff4f) {
6653 this.parseCodestream(data, 0, data.length);
6654 return;
6655 }
6656
6657 const length = data.length;
6658 let position = 0;
6659
6660 while (position < length) {
6661 let headerSize = 8;
6662 let lbox = (0, _core_utils.readUint32)(data, position);
6663 const tbox = (0, _core_utils.readUint32)(data, position + 4);
6664 position += headerSize;
6665
6666 if (lbox === 1) {
6667 lbox = (0, _core_utils.readUint32)(data, position) * 4294967296 + (0, _core_utils.readUint32)(data, position + 4);
6668 position += 8;
6669 headerSize += 8;
6670 }
6671
6672 if (lbox === 0) {
6673 lbox = length - position + headerSize;
6674 }
6675
6676 if (lbox < headerSize) {
6677 throw new JpxError("Invalid box field size");
6678 }
6679
6680 const dataLength = lbox - headerSize;
6681 let jumpDataLength = true;
6682
6683 switch (tbox) {
6684 case 0x6a703268:
6685 jumpDataLength = false;
6686 break;
6687
6688 case 0x636f6c72:
6689 const method = data[position];
6690
6691 if (method === 1) {
6692 const colorspace = (0, _core_utils.readUint32)(data, position + 3);
6693
6694 switch (colorspace) {
6695 case 16:
6696 case 17:
6697 case 18:
6698 break;
6699
6700 default:
6701 (0, _util.warn)("Unknown colorspace " + colorspace);
6702 break;
6703 }
6704 } else if (method === 2) {
6705 (0, _util.info)("ICC profile not supported");
6706 }
6707
6708 break;
6709
6710 case 0x6a703263:
6711 this.parseCodestream(data, position, position + dataLength);
6712 break;
6713
6714 case 0x6a502020:
6715 if ((0, _core_utils.readUint32)(data, position) !== 0x0d0a870a) {
6716 (0, _util.warn)("Invalid JP2 signature");
6717 }
6718
6719 break;
6720
6721 case 0x6a501a1a:
6722 case 0x66747970:
6723 case 0x72726571:
6724 case 0x72657320:
6725 case 0x69686472:
6726 break;
6727
6728 default:
6729 const headerType = String.fromCharCode(tbox >> 24 & 0xff, tbox >> 16 & 0xff, tbox >> 8 & 0xff, tbox & 0xff);
6730 (0, _util.warn)(`Unsupported header type ${tbox} (${headerType}).`);
6731 break;
6732 }
6733
6734 if (jumpDataLength) {
6735 position += dataLength;
6736 }
6737 }
6738 }
6739
6740 parseImageProperties(stream) {
6741 let newByte = stream.getByte();
6742
6743 while (newByte >= 0) {
6744 const oldByte = newByte;
6745 newByte = stream.getByte();
6746 const code = oldByte << 8 | newByte;
6747
6748 if (code === 0xff51) {
6749 stream.skip(4);
6750 const Xsiz = stream.getInt32() >>> 0;
6751 const Ysiz = stream.getInt32() >>> 0;
6752 const XOsiz = stream.getInt32() >>> 0;
6753 const YOsiz = stream.getInt32() >>> 0;
6754 stream.skip(16);
6755 const Csiz = stream.getUint16();
6756 this.width = Xsiz - XOsiz;
6757 this.height = Ysiz - YOsiz;
6758 this.componentsCount = Csiz;
6759 this.bitsPerComponent = 8;
6760 return;
6761 }
6762 }
6763
6764 throw new JpxError("No size marker found in JPX stream");
6765 }
6766
6767 parseCodestream(data, start, end) {
6768 const context = {};
6769 let doNotRecover = false;
6770
6771 try {
6772 let position = start;
6773
6774 while (position + 1 < end) {
6775 const code = (0, _core_utils.readUint16)(data, position);
6776 position += 2;
6777 let length = 0,
6778 j,
6779 sqcd,
6780 spqcds,
6781 spqcdSize,
6782 scalarExpounded,
6783 tile;
6784
6785 switch (code) {
6786 case 0xff4f:
6787 context.mainHeader = true;
6788 break;
6789
6790 case 0xffd9:
6791 break;
6792
6793 case 0xff51:
6794 length = (0, _core_utils.readUint16)(data, position);
6795 const siz = {};
6796 siz.Xsiz = (0, _core_utils.readUint32)(data, position + 4);
6797 siz.Ysiz = (0, _core_utils.readUint32)(data, position + 8);
6798 siz.XOsiz = (0, _core_utils.readUint32)(data, position + 12);
6799 siz.YOsiz = (0, _core_utils.readUint32)(data, position + 16);
6800 siz.XTsiz = (0, _core_utils.readUint32)(data, position + 20);
6801 siz.YTsiz = (0, _core_utils.readUint32)(data, position + 24);
6802 siz.XTOsiz = (0, _core_utils.readUint32)(data, position + 28);
6803 siz.YTOsiz = (0, _core_utils.readUint32)(data, position + 32);
6804 const componentsCount = (0, _core_utils.readUint16)(data, position + 36);
6805 siz.Csiz = componentsCount;
6806 const components = [];
6807 j = position + 38;
6808
6809 for (let i = 0; i < componentsCount; i++) {
6810 const component = {
6811 precision: (data[j] & 0x7f) + 1,
6812 isSigned: !!(data[j] & 0x80),
6813 XRsiz: data[j + 1],
6814 YRsiz: data[j + 2]
6815 };
6816 j += 3;
6817 calculateComponentDimensions(component, siz);
6818 components.push(component);
6819 }
6820
6821 context.SIZ = siz;
6822 context.components = components;
6823 calculateTileGrids(context, components);
6824 context.QCC = [];
6825 context.COC = [];
6826 break;
6827
6828 case 0xff5c:
6829 length = (0, _core_utils.readUint16)(data, position);
6830 const qcd = {};
6831 j = position + 2;
6832 sqcd = data[j++];
6833
6834 switch (sqcd & 0x1f) {
6835 case 0:
6836 spqcdSize = 8;
6837 scalarExpounded = true;
6838 break;
6839
6840 case 1:
6841 spqcdSize = 16;
6842 scalarExpounded = false;
6843 break;
6844
6845 case 2:
6846 spqcdSize = 16;
6847 scalarExpounded = true;
6848 break;
6849
6850 default:
6851 throw new Error("Invalid SQcd value " + sqcd);
6852 }
6853
6854 qcd.noQuantization = spqcdSize === 8;
6855 qcd.scalarExpounded = scalarExpounded;
6856 qcd.guardBits = sqcd >> 5;
6857 spqcds = [];
6858
6859 while (j < length + position) {
6860 const spqcd = {};
6861
6862 if (spqcdSize === 8) {
6863 spqcd.epsilon = data[j++] >> 3;
6864 spqcd.mu = 0;
6865 } else {
6866 spqcd.epsilon = data[j] >> 3;
6867 spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
6868 j += 2;
6869 }
6870
6871 spqcds.push(spqcd);
6872 }
6873
6874 qcd.SPqcds = spqcds;
6875
6876 if (context.mainHeader) {
6877 context.QCD = qcd;
6878 } else {
6879 context.currentTile.QCD = qcd;
6880 context.currentTile.QCC = [];
6881 }
6882
6883 break;
6884
6885 case 0xff5d:
6886 length = (0, _core_utils.readUint16)(data, position);
6887 const qcc = {};
6888 j = position + 2;
6889 let cqcc;
6890
6891 if (context.SIZ.Csiz < 257) {
6892 cqcc = data[j++];
6893 } else {
6894 cqcc = (0, _core_utils.readUint16)(data, j);
6895 j += 2;
6896 }
6897
6898 sqcd = data[j++];
6899
6900 switch (sqcd & 0x1f) {
6901 case 0:
6902 spqcdSize = 8;
6903 scalarExpounded = true;
6904 break;
6905
6906 case 1:
6907 spqcdSize = 16;
6908 scalarExpounded = false;
6909 break;
6910
6911 case 2:
6912 spqcdSize = 16;
6913 scalarExpounded = true;
6914 break;
6915
6916 default:
6917 throw new Error("Invalid SQcd value " + sqcd);
6918 }
6919
6920 qcc.noQuantization = spqcdSize === 8;
6921 qcc.scalarExpounded = scalarExpounded;
6922 qcc.guardBits = sqcd >> 5;
6923 spqcds = [];
6924
6925 while (j < length + position) {
6926 const spqcd = {};
6927
6928 if (spqcdSize === 8) {
6929 spqcd.epsilon = data[j++] >> 3;
6930 spqcd.mu = 0;
6931 } else {
6932 spqcd.epsilon = data[j] >> 3;
6933 spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
6934 j += 2;
6935 }
6936
6937 spqcds.push(spqcd);
6938 }
6939
6940 qcc.SPqcds = spqcds;
6941
6942 if (context.mainHeader) {
6943 context.QCC[cqcc] = qcc;
6944 } else {
6945 context.currentTile.QCC[cqcc] = qcc;
6946 }
6947
6948 break;
6949
6950 case 0xff52:
6951 length = (0, _core_utils.readUint16)(data, position);
6952 const cod = {};
6953 j = position + 2;
6954 const scod = data[j++];
6955 cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
6956 cod.sopMarkerUsed = !!(scod & 2);
6957 cod.ephMarkerUsed = !!(scod & 4);
6958 cod.progressionOrder = data[j++];
6959 cod.layersCount = (0, _core_utils.readUint16)(data, j);
6960 j += 2;
6961 cod.multipleComponentTransform = data[j++];
6962 cod.decompositionLevelsCount = data[j++];
6963 cod.xcb = (data[j++] & 0xf) + 2;
6964 cod.ycb = (data[j++] & 0xf) + 2;
6965 const blockStyle = data[j++];
6966 cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
6967 cod.resetContextProbabilities = !!(blockStyle & 2);
6968 cod.terminationOnEachCodingPass = !!(blockStyle & 4);
6969 cod.verticallyStripe = !!(blockStyle & 8);
6970 cod.predictableTermination = !!(blockStyle & 16);
6971 cod.segmentationSymbolUsed = !!(blockStyle & 32);
6972 cod.reversibleTransformation = data[j++];
6973
6974 if (cod.entropyCoderWithCustomPrecincts) {
6975 const precinctsSizes = [];
6976
6977 while (j < length + position) {
6978 const precinctsSize = data[j++];
6979 precinctsSizes.push({
6980 PPx: precinctsSize & 0xf,
6981 PPy: precinctsSize >> 4
6982 });
6983 }
6984
6985 cod.precinctsSizes = precinctsSizes;
6986 }
6987
6988 const unsupported = [];
6989
6990 if (cod.selectiveArithmeticCodingBypass) {
6991 unsupported.push("selectiveArithmeticCodingBypass");
6992 }
6993
6994 if (cod.terminationOnEachCodingPass) {
6995 unsupported.push("terminationOnEachCodingPass");
6996 }
6997
6998 if (cod.verticallyStripe) {
6999 unsupported.push("verticallyStripe");
7000 }
7001
7002 if (cod.predictableTermination) {
7003 unsupported.push("predictableTermination");
7004 }
7005
7006 if (unsupported.length > 0) {
7007 doNotRecover = true;
7008 (0, _util.warn)(`JPX: Unsupported COD options (${unsupported.join(", ")}).`);
7009 }
7010
7011 if (context.mainHeader) {
7012 context.COD = cod;
7013 } else {
7014 context.currentTile.COD = cod;
7015 context.currentTile.COC = [];
7016 }
7017
7018 break;
7019
7020 case 0xff90:
7021 length = (0, _core_utils.readUint16)(data, position);
7022 tile = {};
7023 tile.index = (0, _core_utils.readUint16)(data, position + 2);
7024 tile.length = (0, _core_utils.readUint32)(data, position + 4);
7025 tile.dataEnd = tile.length + position - 2;
7026 tile.partIndex = data[position + 8];
7027 tile.partsCount = data[position + 9];
7028 context.mainHeader = false;
7029
7030 if (tile.partIndex === 0) {
7031 tile.COD = context.COD;
7032 tile.COC = context.COC.slice(0);
7033 tile.QCD = context.QCD;
7034 tile.QCC = context.QCC.slice(0);
7035 }
7036
7037 context.currentTile = tile;
7038 break;
7039
7040 case 0xff93:
7041 tile = context.currentTile;
7042
7043 if (tile.partIndex === 0) {
7044 initializeTile(context, tile.index);
7045 buildPackets(context);
7046 }
7047
7048 length = tile.dataEnd - position;
7049 parseTilePackets(context, data, position, length);
7050 break;
7051
7052 case 0xff53:
7053 (0, _util.warn)("JPX: Codestream code 0xFF53 (COC) is not implemented.");
7054
7055 case 0xff55:
7056 case 0xff57:
7057 case 0xff58:
7058 case 0xff64:
7059 length = (0, _core_utils.readUint16)(data, position);
7060 break;
7061
7062 default:
7063 throw new Error("Unknown codestream code: " + code.toString(16));
7064 }
7065
7066 position += length;
7067 }
7068 } catch (e) {
7069 if (doNotRecover || this.failOnCorruptedImage) {
7070 throw new JpxError(e.message);
7071 } else {
7072 (0, _util.warn)(`JPX: Trying to recover from: "${e.message}".`);
7073 }
7074 }
7075
7076 this.tiles = transformComponents(context);
7077 this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
7078 this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
7079 this.componentsCount = context.SIZ.Csiz;
7080 }
7081
7082}
7083
7084exports.JpxImage = JpxImage;
7085
7086function calculateComponentDimensions(component, siz) {
7087 component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
7088 component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
7089 component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
7090 component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
7091 component.width = component.x1 - component.x0;
7092 component.height = component.y1 - component.y0;
7093}
7094
7095function calculateTileGrids(context, components) {
7096 const siz = context.SIZ;
7097 const tiles = [];
7098 let tile;
7099 const numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
7100 const numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
7101
7102 for (let q = 0; q < numYtiles; q++) {
7103 for (let p = 0; p < numXtiles; p++) {
7104 tile = {};
7105 tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
7106 tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
7107 tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
7108 tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
7109 tile.width = tile.tx1 - tile.tx0;
7110 tile.height = tile.ty1 - tile.ty0;
7111 tile.components = [];
7112 tiles.push(tile);
7113 }
7114 }
7115
7116 context.tiles = tiles;
7117 const componentsCount = siz.Csiz;
7118
7119 for (let i = 0, ii = componentsCount; i < ii; i++) {
7120 const component = components[i];
7121
7122 for (let j = 0, jj = tiles.length; j < jj; j++) {
7123 const tileComponent = {};
7124 tile = tiles[j];
7125 tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
7126 tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
7127 tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
7128 tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
7129 tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
7130 tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
7131 tile.components[i] = tileComponent;
7132 }
7133 }
7134}
7135
7136function getBlocksDimensions(context, component, r) {
7137 const codOrCoc = component.codingStyleParameters;
7138 const result = {};
7139
7140 if (!codOrCoc.entropyCoderWithCustomPrecincts) {
7141 result.PPx = 15;
7142 result.PPy = 15;
7143 } else {
7144 result.PPx = codOrCoc.precinctsSizes[r].PPx;
7145 result.PPy = codOrCoc.precinctsSizes[r].PPy;
7146 }
7147
7148 result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
7149 result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
7150 return result;
7151}
7152
7153function buildPrecincts(context, resolution, dimensions) {
7154 const precinctWidth = 1 << dimensions.PPx;
7155 const precinctHeight = 1 << dimensions.PPy;
7156 const isZeroRes = resolution.resLevel === 0;
7157 const precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1);
7158 const precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1);
7159 const numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0;
7160 const numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0;
7161 const numprecincts = numprecinctswide * numprecinctshigh;
7162 resolution.precinctParameters = {
7163 precinctWidth,
7164 precinctHeight,
7165 numprecinctswide,
7166 numprecinctshigh,
7167 numprecincts,
7168 precinctWidthInSubband,
7169 precinctHeightInSubband
7170 };
7171}
7172
7173function buildCodeblocks(context, subband, dimensions) {
7174 const xcb_ = dimensions.xcb_;
7175 const ycb_ = dimensions.ycb_;
7176 const codeblockWidth = 1 << xcb_;
7177 const codeblockHeight = 1 << ycb_;
7178 const cbx0 = subband.tbx0 >> xcb_;
7179 const cby0 = subband.tby0 >> ycb_;
7180 const cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_;
7181 const cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_;
7182 const precinctParameters = subband.resolution.precinctParameters;
7183 const codeblocks = [];
7184 const precincts = [];
7185 let i, j, codeblock, precinctNumber;
7186
7187 for (j = cby0; j < cby1; j++) {
7188 for (i = cbx0; i < cbx1; i++) {
7189 codeblock = {
7190 cbx: i,
7191 cby: j,
7192 tbx0: codeblockWidth * i,
7193 tby0: codeblockHeight * j,
7194 tbx1: codeblockWidth * (i + 1),
7195 tby1: codeblockHeight * (j + 1)
7196 };
7197 codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
7198 codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
7199 codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
7200 codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
7201 const pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband);
7202 const pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband);
7203 precinctNumber = pi + pj * precinctParameters.numprecinctswide;
7204 codeblock.precinctNumber = precinctNumber;
7205 codeblock.subbandType = subband.type;
7206 codeblock.Lblock = 3;
7207
7208 if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
7209 continue;
7210 }
7211
7212 codeblocks.push(codeblock);
7213 let precinct = precincts[precinctNumber];
7214
7215 if (precinct !== undefined) {
7216 if (i < precinct.cbxMin) {
7217 precinct.cbxMin = i;
7218 } else if (i > precinct.cbxMax) {
7219 precinct.cbxMax = i;
7220 }
7221
7222 if (j < precinct.cbyMin) {
7223 precinct.cbxMin = j;
7224 } else if (j > precinct.cbyMax) {
7225 precinct.cbyMax = j;
7226 }
7227 } else {
7228 precincts[precinctNumber] = precinct = {
7229 cbxMin: i,
7230 cbyMin: j,
7231 cbxMax: i,
7232 cbyMax: j
7233 };
7234 }
7235
7236 codeblock.precinct = precinct;
7237 }
7238 }
7239
7240 subband.codeblockParameters = {
7241 codeblockWidth: xcb_,
7242 codeblockHeight: ycb_,
7243 numcodeblockwide: cbx1 - cbx0 + 1,
7244 numcodeblockhigh: cby1 - cby0 + 1
7245 };
7246 subband.codeblocks = codeblocks;
7247 subband.precincts = precincts;
7248}
7249
7250function createPacket(resolution, precinctNumber, layerNumber) {
7251 const precinctCodeblocks = [];
7252 const subbands = resolution.subbands;
7253
7254 for (let i = 0, ii = subbands.length; i < ii; i++) {
7255 const subband = subbands[i];
7256 const codeblocks = subband.codeblocks;
7257
7258 for (let j = 0, jj = codeblocks.length; j < jj; j++) {
7259 const codeblock = codeblocks[j];
7260
7261 if (codeblock.precinctNumber !== precinctNumber) {
7262 continue;
7263 }
7264
7265 precinctCodeblocks.push(codeblock);
7266 }
7267 }
7268
7269 return {
7270 layerNumber,
7271 codeblocks: precinctCodeblocks
7272 };
7273}
7274
7275function LayerResolutionComponentPositionIterator(context) {
7276 const siz = context.SIZ;
7277 const tileIndex = context.currentTile.index;
7278 const tile = context.tiles[tileIndex];
7279 const layersCount = tile.codingStyleDefaultParameters.layersCount;
7280 const componentsCount = siz.Csiz;
7281 let maxDecompositionLevelsCount = 0;
7282
7283 for (let q = 0; q < componentsCount; q++) {
7284 maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
7285 }
7286
7287 let l = 0,
7288 r = 0,
7289 i = 0,
7290 k = 0;
7291
7292 this.nextPacket = function JpxImage_nextPacket() {
7293 for (; l < layersCount; l++) {
7294 for (; r <= maxDecompositionLevelsCount; r++) {
7295 for (; i < componentsCount; i++) {
7296 const component = tile.components[i];
7297
7298 if (r > component.codingStyleParameters.decompositionLevelsCount) {
7299 continue;
7300 }
7301
7302 const resolution = component.resolutions[r];
7303 const numprecincts = resolution.precinctParameters.numprecincts;
7304
7305 for (; k < numprecincts;) {
7306 const packet = createPacket(resolution, k, l);
7307 k++;
7308 return packet;
7309 }
7310
7311 k = 0;
7312 }
7313
7314 i = 0;
7315 }
7316
7317 r = 0;
7318 }
7319
7320 throw new JpxError("Out of packets");
7321 };
7322}
7323
7324function ResolutionLayerComponentPositionIterator(context) {
7325 const siz = context.SIZ;
7326 const tileIndex = context.currentTile.index;
7327 const tile = context.tiles[tileIndex];
7328 const layersCount = tile.codingStyleDefaultParameters.layersCount;
7329 const componentsCount = siz.Csiz;
7330 let maxDecompositionLevelsCount = 0;
7331
7332 for (let q = 0; q < componentsCount; q++) {
7333 maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
7334 }
7335
7336 let r = 0,
7337 l = 0,
7338 i = 0,
7339 k = 0;
7340
7341 this.nextPacket = function JpxImage_nextPacket() {
7342 for (; r <= maxDecompositionLevelsCount; r++) {
7343 for (; l < layersCount; l++) {
7344 for (; i < componentsCount; i++) {
7345 const component = tile.components[i];
7346
7347 if (r > component.codingStyleParameters.decompositionLevelsCount) {
7348 continue;
7349 }
7350
7351 const resolution = component.resolutions[r];
7352 const numprecincts = resolution.precinctParameters.numprecincts;
7353
7354 for (; k < numprecincts;) {
7355 const packet = createPacket(resolution, k, l);
7356 k++;
7357 return packet;
7358 }
7359
7360 k = 0;
7361 }
7362
7363 i = 0;
7364 }
7365
7366 l = 0;
7367 }
7368
7369 throw new JpxError("Out of packets");
7370 };
7371}
7372
7373function ResolutionPositionComponentLayerIterator(context) {
7374 const siz = context.SIZ;
7375 const tileIndex = context.currentTile.index;
7376 const tile = context.tiles[tileIndex];
7377 const layersCount = tile.codingStyleDefaultParameters.layersCount;
7378 const componentsCount = siz.Csiz;
7379 let l, r, c, p;
7380 let maxDecompositionLevelsCount = 0;
7381
7382 for (c = 0; c < componentsCount; c++) {
7383 const component = tile.components[c];
7384 maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
7385 }
7386
7387 const maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
7388
7389 for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
7390 let maxNumPrecincts = 0;
7391
7392 for (c = 0; c < componentsCount; ++c) {
7393 const resolutions = tile.components[c].resolutions;
7394
7395 if (r < resolutions.length) {
7396 maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
7397 }
7398 }
7399
7400 maxNumPrecinctsInLevel[r] = maxNumPrecincts;
7401 }
7402
7403 l = 0;
7404 r = 0;
7405 c = 0;
7406 p = 0;
7407
7408 this.nextPacket = function JpxImage_nextPacket() {
7409 for (; r <= maxDecompositionLevelsCount; r++) {
7410 for (; p < maxNumPrecinctsInLevel[r]; p++) {
7411 for (; c < componentsCount; c++) {
7412 const component = tile.components[c];
7413
7414 if (r > component.codingStyleParameters.decompositionLevelsCount) {
7415 continue;
7416 }
7417
7418 const resolution = component.resolutions[r];
7419 const numprecincts = resolution.precinctParameters.numprecincts;
7420
7421 if (p >= numprecincts) {
7422 continue;
7423 }
7424
7425 for (; l < layersCount;) {
7426 const packet = createPacket(resolution, p, l);
7427 l++;
7428 return packet;
7429 }
7430
7431 l = 0;
7432 }
7433
7434 c = 0;
7435 }
7436
7437 p = 0;
7438 }
7439
7440 throw new JpxError("Out of packets");
7441 };
7442}
7443
7444function PositionComponentResolutionLayerIterator(context) {
7445 const siz = context.SIZ;
7446 const tileIndex = context.currentTile.index;
7447 const tile = context.tiles[tileIndex];
7448 const layersCount = tile.codingStyleDefaultParameters.layersCount;
7449 const componentsCount = siz.Csiz;
7450 const precinctsSizes = getPrecinctSizesInImageScale(tile);
7451 const precinctsIterationSizes = precinctsSizes;
7452 let l = 0,
7453 r = 0,
7454 c = 0,
7455 px = 0,
7456 py = 0;
7457
7458 this.nextPacket = function JpxImage_nextPacket() {
7459 for (; py < precinctsIterationSizes.maxNumHigh; py++) {
7460 for (; px < precinctsIterationSizes.maxNumWide; px++) {
7461 for (; c < componentsCount; c++) {
7462 const component = tile.components[c];
7463 const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
7464
7465 for (; r <= decompositionLevelsCount; r++) {
7466 const resolution = component.resolutions[r];
7467 const sizeInImageScale = precinctsSizes.components[c].resolutions[r];
7468 const k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
7469
7470 if (k === null) {
7471 continue;
7472 }
7473
7474 for (; l < layersCount;) {
7475 const packet = createPacket(resolution, k, l);
7476 l++;
7477 return packet;
7478 }
7479
7480 l = 0;
7481 }
7482
7483 r = 0;
7484 }
7485
7486 c = 0;
7487 }
7488
7489 px = 0;
7490 }
7491
7492 throw new JpxError("Out of packets");
7493 };
7494}
7495
7496function ComponentPositionResolutionLayerIterator(context) {
7497 const siz = context.SIZ;
7498 const tileIndex = context.currentTile.index;
7499 const tile = context.tiles[tileIndex];
7500 const layersCount = tile.codingStyleDefaultParameters.layersCount;
7501 const componentsCount = siz.Csiz;
7502 const precinctsSizes = getPrecinctSizesInImageScale(tile);
7503 let l = 0,
7504 r = 0,
7505 c = 0,
7506 px = 0,
7507 py = 0;
7508
7509 this.nextPacket = function JpxImage_nextPacket() {
7510 for (; c < componentsCount; ++c) {
7511 const component = tile.components[c];
7512 const precinctsIterationSizes = precinctsSizes.components[c];
7513 const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
7514
7515 for (; py < precinctsIterationSizes.maxNumHigh; py++) {
7516 for (; px < precinctsIterationSizes.maxNumWide; px++) {
7517 for (; r <= decompositionLevelsCount; r++) {
7518 const resolution = component.resolutions[r];
7519 const sizeInImageScale = precinctsIterationSizes.resolutions[r];
7520 const k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
7521
7522 if (k === null) {
7523 continue;
7524 }
7525
7526 for (; l < layersCount;) {
7527 const packet = createPacket(resolution, k, l);
7528 l++;
7529 return packet;
7530 }
7531
7532 l = 0;
7533 }
7534
7535 r = 0;
7536 }
7537
7538 px = 0;
7539 }
7540
7541 py = 0;
7542 }
7543
7544 throw new JpxError("Out of packets");
7545 };
7546}
7547
7548function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
7549 const posX = pxIndex * precinctIterationSizes.minWidth;
7550 const posY = pyIndex * precinctIterationSizes.minHeight;
7551
7552 if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
7553 return null;
7554 }
7555
7556 const startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
7557 return posX / sizeInImageScale.height + startPrecinctRowIndex;
7558}
7559
7560function getPrecinctSizesInImageScale(tile) {
7561 const componentsCount = tile.components.length;
7562 let minWidth = Number.MAX_VALUE;
7563 let minHeight = Number.MAX_VALUE;
7564 let maxNumWide = 0;
7565 let maxNumHigh = 0;
7566 const sizePerComponent = new Array(componentsCount);
7567
7568 for (let c = 0; c < componentsCount; c++) {
7569 const component = tile.components[c];
7570 const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
7571 const sizePerResolution = new Array(decompositionLevelsCount + 1);
7572 let minWidthCurrentComponent = Number.MAX_VALUE;
7573 let minHeightCurrentComponent = Number.MAX_VALUE;
7574 let maxNumWideCurrentComponent = 0;
7575 let maxNumHighCurrentComponent = 0;
7576 let scale = 1;
7577
7578 for (let r = decompositionLevelsCount; r >= 0; --r) {
7579 const resolution = component.resolutions[r];
7580 const widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
7581 const heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight;
7582 minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution);
7583 minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution);
7584 maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide);
7585 maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh);
7586 sizePerResolution[r] = {
7587 width: widthCurrentResolution,
7588 height: heightCurrentResolution
7589 };
7590 scale <<= 1;
7591 }
7592
7593 minWidth = Math.min(minWidth, minWidthCurrentComponent);
7594 minHeight = Math.min(minHeight, minHeightCurrentComponent);
7595 maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
7596 maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
7597 sizePerComponent[c] = {
7598 resolutions: sizePerResolution,
7599 minWidth: minWidthCurrentComponent,
7600 minHeight: minHeightCurrentComponent,
7601 maxNumWide: maxNumWideCurrentComponent,
7602 maxNumHigh: maxNumHighCurrentComponent
7603 };
7604 }
7605
7606 return {
7607 components: sizePerComponent,
7608 minWidth,
7609 minHeight,
7610 maxNumWide,
7611 maxNumHigh
7612 };
7613}
7614
7615function buildPackets(context) {
7616 const siz = context.SIZ;
7617 const tileIndex = context.currentTile.index;
7618 const tile = context.tiles[tileIndex];
7619 const componentsCount = siz.Csiz;
7620
7621 for (let c = 0; c < componentsCount; c++) {
7622 const component = tile.components[c];
7623 const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
7624 const resolutions = [];
7625 const subbands = [];
7626
7627 for (let r = 0; r <= decompositionLevelsCount; r++) {
7628 const blocksDimensions = getBlocksDimensions(context, component, r);
7629 const resolution = {};
7630 const scale = 1 << decompositionLevelsCount - r;
7631 resolution.trx0 = Math.ceil(component.tcx0 / scale);
7632 resolution.try0 = Math.ceil(component.tcy0 / scale);
7633 resolution.trx1 = Math.ceil(component.tcx1 / scale);
7634 resolution.try1 = Math.ceil(component.tcy1 / scale);
7635 resolution.resLevel = r;
7636 buildPrecincts(context, resolution, blocksDimensions);
7637 resolutions.push(resolution);
7638 let subband;
7639
7640 if (r === 0) {
7641 subband = {};
7642 subband.type = "LL";
7643 subband.tbx0 = Math.ceil(component.tcx0 / scale);
7644 subband.tby0 = Math.ceil(component.tcy0 / scale);
7645 subband.tbx1 = Math.ceil(component.tcx1 / scale);
7646 subband.tby1 = Math.ceil(component.tcy1 / scale);
7647 subband.resolution = resolution;
7648 buildCodeblocks(context, subband, blocksDimensions);
7649 subbands.push(subband);
7650 resolution.subbands = [subband];
7651 } else {
7652 const bscale = 1 << decompositionLevelsCount - r + 1;
7653 const resolutionSubbands = [];
7654 subband = {};
7655 subband.type = "HL";
7656 subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
7657 subband.tby0 = Math.ceil(component.tcy0 / bscale);
7658 subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
7659 subband.tby1 = Math.ceil(component.tcy1 / bscale);
7660 subband.resolution = resolution;
7661 buildCodeblocks(context, subband, blocksDimensions);
7662 subbands.push(subband);
7663 resolutionSubbands.push(subband);
7664 subband = {};
7665 subband.type = "LH";
7666 subband.tbx0 = Math.ceil(component.tcx0 / bscale);
7667 subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
7668 subband.tbx1 = Math.ceil(component.tcx1 / bscale);
7669 subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
7670 subband.resolution = resolution;
7671 buildCodeblocks(context, subband, blocksDimensions);
7672 subbands.push(subband);
7673 resolutionSubbands.push(subband);
7674 subband = {};
7675 subband.type = "HH";
7676 subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
7677 subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
7678 subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
7679 subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
7680 subband.resolution = resolution;
7681 buildCodeblocks(context, subband, blocksDimensions);
7682 subbands.push(subband);
7683 resolutionSubbands.push(subband);
7684 resolution.subbands = resolutionSubbands;
7685 }
7686 }
7687
7688 component.resolutions = resolutions;
7689 component.subbands = subbands;
7690 }
7691
7692 const progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
7693
7694 switch (progressionOrder) {
7695 case 0:
7696 tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
7697 break;
7698
7699 case 1:
7700 tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
7701 break;
7702
7703 case 2:
7704 tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
7705 break;
7706
7707 case 3:
7708 tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
7709 break;
7710
7711 case 4:
7712 tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
7713 break;
7714
7715 default:
7716 throw new JpxError(`Unsupported progression order ${progressionOrder}`);
7717 }
7718}
7719
7720function parseTilePackets(context, data, offset, dataLength) {
7721 let position = 0;
7722 let buffer,
7723 bufferSize = 0,
7724 skipNextBit = false;
7725
7726 function readBits(count) {
7727 while (bufferSize < count) {
7728 const b = data[offset + position];
7729 position++;
7730
7731 if (skipNextBit) {
7732 buffer = buffer << 7 | b;
7733 bufferSize += 7;
7734 skipNextBit = false;
7735 } else {
7736 buffer = buffer << 8 | b;
7737 bufferSize += 8;
7738 }
7739
7740 if (b === 0xff) {
7741 skipNextBit = true;
7742 }
7743 }
7744
7745 bufferSize -= count;
7746 return buffer >>> bufferSize & (1 << count) - 1;
7747 }
7748
7749 function skipMarkerIfEqual(value) {
7750 if (data[offset + position - 1] === 0xff && data[offset + position] === value) {
7751 skipBytes(1);
7752 return true;
7753 } else if (data[offset + position] === 0xff && data[offset + position + 1] === value) {
7754 skipBytes(2);
7755 return true;
7756 }
7757
7758 return false;
7759 }
7760
7761 function skipBytes(count) {
7762 position += count;
7763 }
7764
7765 function alignToByte() {
7766 bufferSize = 0;
7767
7768 if (skipNextBit) {
7769 position++;
7770 skipNextBit = false;
7771 }
7772 }
7773
7774 function readCodingpasses() {
7775 if (readBits(1) === 0) {
7776 return 1;
7777 }
7778
7779 if (readBits(1) === 0) {
7780 return 2;
7781 }
7782
7783 let value = readBits(2);
7784
7785 if (value < 3) {
7786 return value + 3;
7787 }
7788
7789 value = readBits(5);
7790
7791 if (value < 31) {
7792 return value + 6;
7793 }
7794
7795 value = readBits(7);
7796 return value + 37;
7797 }
7798
7799 const tileIndex = context.currentTile.index;
7800 const tile = context.tiles[tileIndex];
7801 const sopMarkerUsed = context.COD.sopMarkerUsed;
7802 const ephMarkerUsed = context.COD.ephMarkerUsed;
7803 const packetsIterator = tile.packetsIterator;
7804
7805 while (position < dataLength) {
7806 alignToByte();
7807
7808 if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
7809 skipBytes(4);
7810 }
7811
7812 const packet = packetsIterator.nextPacket();
7813
7814 if (!readBits(1)) {
7815 continue;
7816 }
7817
7818 const layerNumber = packet.layerNumber,
7819 queue = [];
7820 let codeblock;
7821
7822 for (let i = 0, ii = packet.codeblocks.length; i < ii; i++) {
7823 codeblock = packet.codeblocks[i];
7824 let precinct = codeblock.precinct;
7825 const codeblockColumn = codeblock.cbx - precinct.cbxMin;
7826 const codeblockRow = codeblock.cby - precinct.cbyMin;
7827 let codeblockIncluded = false;
7828 let firstTimeInclusion = false;
7829 let valueReady, zeroBitPlanesTree;
7830
7831 if (codeblock.included !== undefined) {
7832 codeblockIncluded = !!readBits(1);
7833 } else {
7834 precinct = codeblock.precinct;
7835 let inclusionTree;
7836
7837 if (precinct.inclusionTree !== undefined) {
7838 inclusionTree = precinct.inclusionTree;
7839 } else {
7840 const width = precinct.cbxMax - precinct.cbxMin + 1;
7841 const height = precinct.cbyMax - precinct.cbyMin + 1;
7842 inclusionTree = new InclusionTree(width, height, layerNumber);
7843 zeroBitPlanesTree = new TagTree(width, height);
7844 precinct.inclusionTree = inclusionTree;
7845 precinct.zeroBitPlanesTree = zeroBitPlanesTree;
7846
7847 for (let l = 0; l < layerNumber; l++) {
7848 if (readBits(1) !== 0) {
7849 throw new JpxError("Invalid tag tree");
7850 }
7851 }
7852 }
7853
7854 if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
7855 while (true) {
7856 if (readBits(1)) {
7857 valueReady = !inclusionTree.nextLevel();
7858
7859 if (valueReady) {
7860 codeblock.included = true;
7861 codeblockIncluded = firstTimeInclusion = true;
7862 break;
7863 }
7864 } else {
7865 inclusionTree.incrementValue(layerNumber);
7866 break;
7867 }
7868 }
7869 }
7870 }
7871
7872 if (!codeblockIncluded) {
7873 continue;
7874 }
7875
7876 if (firstTimeInclusion) {
7877 zeroBitPlanesTree = precinct.zeroBitPlanesTree;
7878 zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
7879
7880 while (true) {
7881 if (readBits(1)) {
7882 valueReady = !zeroBitPlanesTree.nextLevel();
7883
7884 if (valueReady) {
7885 break;
7886 }
7887 } else {
7888 zeroBitPlanesTree.incrementValue();
7889 }
7890 }
7891
7892 codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
7893 }
7894
7895 const codingpasses = readCodingpasses();
7896
7897 while (readBits(1)) {
7898 codeblock.Lblock++;
7899 }
7900
7901 const codingpassesLog2 = (0, _core_utils.log2)(codingpasses);
7902 const bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
7903 const codedDataLength = readBits(bits);
7904 queue.push({
7905 codeblock,
7906 codingpasses,
7907 dataLength: codedDataLength
7908 });
7909 }
7910
7911 alignToByte();
7912
7913 if (ephMarkerUsed) {
7914 skipMarkerIfEqual(0x92);
7915 }
7916
7917 while (queue.length > 0) {
7918 const packetItem = queue.shift();
7919 codeblock = packetItem.codeblock;
7920
7921 if (codeblock.data === undefined) {
7922 codeblock.data = [];
7923 }
7924
7925 codeblock.data.push({
7926 data,
7927 start: offset + position,
7928 end: offset + position + packetItem.dataLength,
7929 codingpasses: packetItem.codingpasses
7930 });
7931 position += packetItem.dataLength;
7932 }
7933 }
7934
7935 return position;
7936}
7937
7938function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed, resetContextProbabilities) {
7939 const x0 = subband.tbx0;
7940 const y0 = subband.tby0;
7941 const width = subband.tbx1 - subband.tbx0;
7942 const codeblocks = subband.codeblocks;
7943 const right = subband.type.charAt(0) === "H" ? 1 : 0;
7944 const bottom = subband.type.charAt(1) === "H" ? levelWidth : 0;
7945
7946 for (let i = 0, ii = codeblocks.length; i < ii; ++i) {
7947 const codeblock = codeblocks[i];
7948 const blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
7949 const blockHeight = codeblock.tby1_ - codeblock.tby0_;
7950
7951 if (blockWidth === 0 || blockHeight === 0) {
7952 continue;
7953 }
7954
7955 if (codeblock.data === undefined) {
7956 continue;
7957 }
7958
7959 const bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
7960 let currentCodingpassType = 2;
7961 const data = codeblock.data;
7962 let totalLength = 0,
7963 codingpasses = 0;
7964 let j, jj, dataItem;
7965
7966 for (j = 0, jj = data.length; j < jj; j++) {
7967 dataItem = data[j];
7968 totalLength += dataItem.end - dataItem.start;
7969 codingpasses += dataItem.codingpasses;
7970 }
7971
7972 const encodedData = new Uint8Array(totalLength);
7973 let position = 0;
7974
7975 for (j = 0, jj = data.length; j < jj; j++) {
7976 dataItem = data[j];
7977 const chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
7978 encodedData.set(chunk, position);
7979 position += chunk.length;
7980 }
7981
7982 const decoder = new _arithmetic_decoder.ArithmeticDecoder(encodedData, 0, totalLength);
7983 bitModel.setDecoder(decoder);
7984
7985 for (j = 0; j < codingpasses; j++) {
7986 switch (currentCodingpassType) {
7987 case 0:
7988 bitModel.runSignificancePropagationPass();
7989 break;
7990
7991 case 1:
7992 bitModel.runMagnitudeRefinementPass();
7993 break;
7994
7995 case 2:
7996 bitModel.runCleanupPass();
7997
7998 if (segmentationSymbolUsed) {
7999 bitModel.checkSegmentationSymbol();
8000 }
8001
8002 break;
8003 }
8004
8005 if (resetContextProbabilities) {
8006 bitModel.reset();
8007 }
8008
8009 currentCodingpassType = (currentCodingpassType + 1) % 3;
8010 }
8011
8012 let offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
8013 const sign = bitModel.coefficentsSign;
8014 const magnitude = bitModel.coefficentsMagnitude;
8015 const bitsDecoded = bitModel.bitsDecoded;
8016 const magnitudeCorrection = reversible ? 0 : 0.5;
8017 let k, n, nb;
8018 position = 0;
8019 const interleave = subband.type !== "LL";
8020
8021 for (j = 0; j < blockHeight; j++) {
8022 const row = offset / width | 0;
8023 const levelOffset = 2 * row * (levelWidth - width) + right + bottom;
8024
8025 for (k = 0; k < blockWidth; k++) {
8026 n = magnitude[position];
8027
8028 if (n !== 0) {
8029 n = (n + magnitudeCorrection) * delta;
8030
8031 if (sign[position] !== 0) {
8032 n = -n;
8033 }
8034
8035 nb = bitsDecoded[position];
8036 const pos = interleave ? levelOffset + (offset << 1) : offset;
8037
8038 if (reversible && nb >= mb) {
8039 coefficients[pos] = n;
8040 } else {
8041 coefficients[pos] = n * (1 << mb - nb);
8042 }
8043 }
8044
8045 offset++;
8046 position++;
8047 }
8048
8049 offset += width - blockWidth;
8050 }
8051 }
8052}
8053
8054function transformTile(context, tile, c) {
8055 const component = tile.components[c];
8056 const codingStyleParameters = component.codingStyleParameters;
8057 const quantizationParameters = component.quantizationParameters;
8058 const decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount;
8059 const spqcds = quantizationParameters.SPqcds;
8060 const scalarExpounded = quantizationParameters.scalarExpounded;
8061 const guardBits = quantizationParameters.guardBits;
8062 const segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
8063 const resetContextProbabilities = codingStyleParameters.resetContextProbabilities;
8064 const precision = context.components[c].precision;
8065 const reversible = codingStyleParameters.reversibleTransformation;
8066 const transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
8067 const subbandCoefficients = [];
8068 let b = 0;
8069
8070 for (let i = 0; i <= decompositionLevelsCount; i++) {
8071 const resolution = component.resolutions[i];
8072 const width = resolution.trx1 - resolution.trx0;
8073 const height = resolution.try1 - resolution.try0;
8074 const coefficients = new Float32Array(width * height);
8075
8076 for (let j = 0, jj = resolution.subbands.length; j < jj; j++) {
8077 let mu, epsilon;
8078
8079 if (!scalarExpounded) {
8080 mu = spqcds[0].mu;
8081 epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
8082 } else {
8083 mu = spqcds[b].mu;
8084 epsilon = spqcds[b].epsilon;
8085 b++;
8086 }
8087
8088 const subband = resolution.subbands[j];
8089 const gainLog2 = SubbandsGainLog2[subband.type];
8090 const delta = reversible ? 1 : 2 ** (precision + gainLog2 - epsilon) * (1 + mu / 2048);
8091 const mb = guardBits + epsilon - 1;
8092 copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed, resetContextProbabilities);
8093 }
8094
8095 subbandCoefficients.push({
8096 width,
8097 height,
8098 items: coefficients
8099 });
8100 }
8101
8102 const result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
8103 return {
8104 left: component.tcx0,
8105 top: component.tcy0,
8106 width: result.width,
8107 height: result.height,
8108 items: result.items
8109 };
8110}
8111
8112function transformComponents(context) {
8113 const siz = context.SIZ;
8114 const components = context.components;
8115 const componentsCount = siz.Csiz;
8116 const resultImages = [];
8117
8118 for (let i = 0, ii = context.tiles.length; i < ii; i++) {
8119 const tile = context.tiles[i];
8120 const transformedTiles = [];
8121
8122 for (let c = 0; c < componentsCount; c++) {
8123 transformedTiles[c] = transformTile(context, tile, c);
8124 }
8125
8126 const tile0 = transformedTiles[0];
8127 const out = new Uint8ClampedArray(tile0.items.length * componentsCount);
8128 const result = {
8129 left: tile0.left,
8130 top: tile0.top,
8131 width: tile0.width,
8132 height: tile0.height,
8133 items: out
8134 };
8135 let shift, offset;
8136 let pos = 0,
8137 j,
8138 jj,
8139 y0,
8140 y1,
8141 y2;
8142
8143 if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
8144 const fourComponents = componentsCount === 4;
8145 const y0items = transformedTiles[0].items;
8146 const y1items = transformedTiles[1].items;
8147 const y2items = transformedTiles[2].items;
8148 const y3items = fourComponents ? transformedTiles[3].items : null;
8149 shift = components[0].precision - 8;
8150 offset = (128 << shift) + 0.5;
8151 const component0 = tile.components[0];
8152 const alpha01 = componentsCount - 3;
8153 jj = y0items.length;
8154
8155 if (!component0.codingStyleParameters.reversibleTransformation) {
8156 for (j = 0; j < jj; j++, pos += alpha01) {
8157 y0 = y0items[j] + offset;
8158 y1 = y1items[j];
8159 y2 = y2items[j];
8160 out[pos++] = y0 + 1.402 * y2 >> shift;
8161 out[pos++] = y0 - 0.34413 * y1 - 0.71414 * y2 >> shift;
8162 out[pos++] = y0 + 1.772 * y1 >> shift;
8163 }
8164 } else {
8165 for (j = 0; j < jj; j++, pos += alpha01) {
8166 y0 = y0items[j] + offset;
8167 y1 = y1items[j];
8168 y2 = y2items[j];
8169 const g = y0 - (y2 + y1 >> 2);
8170 out[pos++] = g + y2 >> shift;
8171 out[pos++] = g >> shift;
8172 out[pos++] = g + y1 >> shift;
8173 }
8174 }
8175
8176 if (fourComponents) {
8177 for (j = 0, pos = 3; j < jj; j++, pos += 4) {
8178 out[pos] = y3items[j] + offset >> shift;
8179 }
8180 }
8181 } else {
8182 for (let c = 0; c < componentsCount; c++) {
8183 const items = transformedTiles[c].items;
8184 shift = components[c].precision - 8;
8185 offset = (128 << shift) + 0.5;
8186
8187 for (pos = c, j = 0, jj = items.length; j < jj; j++) {
8188 out[pos] = items[j] + offset >> shift;
8189 pos += componentsCount;
8190 }
8191 }
8192 }
8193
8194 resultImages.push(result);
8195 }
8196
8197 return resultImages;
8198}
8199
8200function initializeTile(context, tileIndex) {
8201 const siz = context.SIZ;
8202 const componentsCount = siz.Csiz;
8203 const tile = context.tiles[tileIndex];
8204
8205 for (let c = 0; c < componentsCount; c++) {
8206 const component = tile.components[c];
8207 const qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
8208 component.quantizationParameters = qcdOrQcc;
8209 const codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
8210 component.codingStyleParameters = codOrCoc;
8211 }
8212
8213 tile.codingStyleDefaultParameters = context.currentTile.COD;
8214}
8215
8216class TagTree {
8217 constructor(width, height) {
8218 const levelsLength = (0, _core_utils.log2)(Math.max(width, height)) + 1;
8219 this.levels = [];
8220
8221 for (let i = 0; i < levelsLength; i++) {
8222 const level = {
8223 width,
8224 height,
8225 items: []
8226 };
8227 this.levels.push(level);
8228 width = Math.ceil(width / 2);
8229 height = Math.ceil(height / 2);
8230 }
8231 }
8232
8233 reset(i, j) {
8234 let currentLevel = 0,
8235 value = 0,
8236 level;
8237
8238 while (currentLevel < this.levels.length) {
8239 level = this.levels[currentLevel];
8240 const index = i + j * level.width;
8241
8242 if (level.items[index] !== undefined) {
8243 value = level.items[index];
8244 break;
8245 }
8246
8247 level.index = index;
8248 i >>= 1;
8249 j >>= 1;
8250 currentLevel++;
8251 }
8252
8253 currentLevel--;
8254 level = this.levels[currentLevel];
8255 level.items[level.index] = value;
8256 this.currentLevel = currentLevel;
8257 delete this.value;
8258 }
8259
8260 incrementValue() {
8261 const level = this.levels[this.currentLevel];
8262 level.items[level.index]++;
8263 }
8264
8265 nextLevel() {
8266 let currentLevel = this.currentLevel;
8267 let level = this.levels[currentLevel];
8268 const value = level.items[level.index];
8269 currentLevel--;
8270
8271 if (currentLevel < 0) {
8272 this.value = value;
8273 return false;
8274 }
8275
8276 this.currentLevel = currentLevel;
8277 level = this.levels[currentLevel];
8278 level.items[level.index] = value;
8279 return true;
8280 }
8281
8282}
8283
8284class InclusionTree {
8285 constructor(width, height, defaultValue) {
8286 const levelsLength = (0, _core_utils.log2)(Math.max(width, height)) + 1;
8287 this.levels = [];
8288
8289 for (let i = 0; i < levelsLength; i++) {
8290 const items = new Uint8Array(width * height);
8291
8292 for (let j = 0, jj = items.length; j < jj; j++) {
8293 items[j] = defaultValue;
8294 }
8295
8296 const level = {
8297 width,
8298 height,
8299 items
8300 };
8301 this.levels.push(level);
8302 width = Math.ceil(width / 2);
8303 height = Math.ceil(height / 2);
8304 }
8305 }
8306
8307 reset(i, j, stopValue) {
8308 let currentLevel = 0;
8309
8310 while (currentLevel < this.levels.length) {
8311 const level = this.levels[currentLevel];
8312 const index = i + j * level.width;
8313 level.index = index;
8314 const value = level.items[index];
8315
8316 if (value === 0xff) {
8317 break;
8318 }
8319
8320 if (value > stopValue) {
8321 this.currentLevel = currentLevel;
8322 this.propagateValues();
8323 return false;
8324 }
8325
8326 i >>= 1;
8327 j >>= 1;
8328 currentLevel++;
8329 }
8330
8331 this.currentLevel = currentLevel - 1;
8332 return true;
8333 }
8334
8335 incrementValue(stopValue) {
8336 const level = this.levels[this.currentLevel];
8337 level.items[level.index] = stopValue + 1;
8338 this.propagateValues();
8339 }
8340
8341 propagateValues() {
8342 let levelIndex = this.currentLevel;
8343 let level = this.levels[levelIndex];
8344 const currentValue = level.items[level.index];
8345
8346 while (--levelIndex >= 0) {
8347 level = this.levels[levelIndex];
8348 level.items[level.index] = currentValue;
8349 }
8350 }
8351
8352 nextLevel() {
8353 let currentLevel = this.currentLevel;
8354 let level = this.levels[currentLevel];
8355 const value = level.items[level.index];
8356 level.items[level.index] = 0xff;
8357 currentLevel--;
8358
8359 if (currentLevel < 0) {
8360 return false;
8361 }
8362
8363 this.currentLevel = currentLevel;
8364 level = this.levels[currentLevel];
8365 level.items[level.index] = value;
8366 return true;
8367 }
8368
8369}
8370
8371const BitModel = function BitModelClosure() {
8372 const UNIFORM_CONTEXT = 17;
8373 const RUNLENGTH_CONTEXT = 18;
8374 const LLAndLHContextsLabel = new Uint8Array([0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8]);
8375 const HLContextLabel = new Uint8Array([0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8]);
8376 const HHContextLabel = new Uint8Array([0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8]);
8377
8378 class BitModel {
8379 constructor(width, height, subband, zeroBitPlanes, mb) {
8380 this.width = width;
8381 this.height = height;
8382 let contextLabelTable;
8383
8384 if (subband === "HH") {
8385 contextLabelTable = HHContextLabel;
8386 } else if (subband === "HL") {
8387 contextLabelTable = HLContextLabel;
8388 } else {
8389 contextLabelTable = LLAndLHContextsLabel;
8390 }
8391
8392 this.contextLabelTable = contextLabelTable;
8393 const coefficientCount = width * height;
8394 this.neighborsSignificance = new Uint8Array(coefficientCount);
8395 this.coefficentsSign = new Uint8Array(coefficientCount);
8396 let coefficentsMagnitude;
8397
8398 if (mb > 14) {
8399 coefficentsMagnitude = new Uint32Array(coefficientCount);
8400 } else if (mb > 6) {
8401 coefficentsMagnitude = new Uint16Array(coefficientCount);
8402 } else {
8403 coefficentsMagnitude = new Uint8Array(coefficientCount);
8404 }
8405
8406 this.coefficentsMagnitude = coefficentsMagnitude;
8407 this.processingFlags = new Uint8Array(coefficientCount);
8408 const bitsDecoded = new Uint8Array(coefficientCount);
8409
8410 if (zeroBitPlanes !== 0) {
8411 for (let i = 0; i < coefficientCount; i++) {
8412 bitsDecoded[i] = zeroBitPlanes;
8413 }
8414 }
8415
8416 this.bitsDecoded = bitsDecoded;
8417 this.reset();
8418 }
8419
8420 setDecoder(decoder) {
8421 this.decoder = decoder;
8422 }
8423
8424 reset() {
8425 this.contexts = new Int8Array(19);
8426 this.contexts[0] = 4 << 1 | 0;
8427 this.contexts[UNIFORM_CONTEXT] = 46 << 1 | 0;
8428 this.contexts[RUNLENGTH_CONTEXT] = 3 << 1 | 0;
8429 }
8430
8431 setNeighborsSignificance(row, column, index) {
8432 const neighborsSignificance = this.neighborsSignificance;
8433 const width = this.width,
8434 height = this.height;
8435 const left = column > 0;
8436 const right = column + 1 < width;
8437 let i;
8438
8439 if (row > 0) {
8440 i = index - width;
8441
8442 if (left) {
8443 neighborsSignificance[i - 1] += 0x10;
8444 }
8445
8446 if (right) {
8447 neighborsSignificance[i + 1] += 0x10;
8448 }
8449
8450 neighborsSignificance[i] += 0x04;
8451 }
8452
8453 if (row + 1 < height) {
8454 i = index + width;
8455
8456 if (left) {
8457 neighborsSignificance[i - 1] += 0x10;
8458 }
8459
8460 if (right) {
8461 neighborsSignificance[i + 1] += 0x10;
8462 }
8463
8464 neighborsSignificance[i] += 0x04;
8465 }
8466
8467 if (left) {
8468 neighborsSignificance[index - 1] += 0x01;
8469 }
8470
8471 if (right) {
8472 neighborsSignificance[index + 1] += 0x01;
8473 }
8474
8475 neighborsSignificance[index] |= 0x80;
8476 }
8477
8478 runSignificancePropagationPass() {
8479 const decoder = this.decoder;
8480 const width = this.width,
8481 height = this.height;
8482 const coefficentsMagnitude = this.coefficentsMagnitude;
8483 const coefficentsSign = this.coefficentsSign;
8484 const neighborsSignificance = this.neighborsSignificance;
8485 const processingFlags = this.processingFlags;
8486 const contexts = this.contexts;
8487 const labels = this.contextLabelTable;
8488 const bitsDecoded = this.bitsDecoded;
8489 const processedInverseMask = ~1;
8490 const processedMask = 1;
8491 const firstMagnitudeBitMask = 2;
8492
8493 for (let i0 = 0; i0 < height; i0 += 4) {
8494 for (let j = 0; j < width; j++) {
8495 let index = i0 * width + j;
8496
8497 for (let i1 = 0; i1 < 4; i1++, index += width) {
8498 const i = i0 + i1;
8499
8500 if (i >= height) {
8501 break;
8502 }
8503
8504 processingFlags[index] &= processedInverseMask;
8505
8506 if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
8507 continue;
8508 }
8509
8510 const contextLabel = labels[neighborsSignificance[index]];
8511 const decision = decoder.readBit(contexts, contextLabel);
8512
8513 if (decision) {
8514 const sign = this.decodeSignBit(i, j, index);
8515 coefficentsSign[index] = sign;
8516 coefficentsMagnitude[index] = 1;
8517 this.setNeighborsSignificance(i, j, index);
8518 processingFlags[index] |= firstMagnitudeBitMask;
8519 }
8520
8521 bitsDecoded[index]++;
8522 processingFlags[index] |= processedMask;
8523 }
8524 }
8525 }
8526 }
8527
8528 decodeSignBit(row, column, index) {
8529 const width = this.width,
8530 height = this.height;
8531 const coefficentsMagnitude = this.coefficentsMagnitude;
8532 const coefficentsSign = this.coefficentsSign;
8533 let contribution, sign0, sign1, significance1;
8534 let contextLabel, decoded;
8535 significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
8536
8537 if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
8538 sign1 = coefficentsSign[index + 1];
8539
8540 if (significance1) {
8541 sign0 = coefficentsSign[index - 1];
8542 contribution = 1 - sign1 - sign0;
8543 } else {
8544 contribution = 1 - sign1 - sign1;
8545 }
8546 } else if (significance1) {
8547 sign0 = coefficentsSign[index - 1];
8548 contribution = 1 - sign0 - sign0;
8549 } else {
8550 contribution = 0;
8551 }
8552
8553 const horizontalContribution = 3 * contribution;
8554 significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
8555
8556 if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
8557 sign1 = coefficentsSign[index + width];
8558
8559 if (significance1) {
8560 sign0 = coefficentsSign[index - width];
8561 contribution = 1 - sign1 - sign0 + horizontalContribution;
8562 } else {
8563 contribution = 1 - sign1 - sign1 + horizontalContribution;
8564 }
8565 } else if (significance1) {
8566 sign0 = coefficentsSign[index - width];
8567 contribution = 1 - sign0 - sign0 + horizontalContribution;
8568 } else {
8569 contribution = horizontalContribution;
8570 }
8571
8572 if (contribution >= 0) {
8573 contextLabel = 9 + contribution;
8574 decoded = this.decoder.readBit(this.contexts, contextLabel);
8575 } else {
8576 contextLabel = 9 - contribution;
8577 decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
8578 }
8579
8580 return decoded;
8581 }
8582
8583 runMagnitudeRefinementPass() {
8584 const decoder = this.decoder;
8585 const width = this.width,
8586 height = this.height;
8587 const coefficentsMagnitude = this.coefficentsMagnitude;
8588 const neighborsSignificance = this.neighborsSignificance;
8589 const contexts = this.contexts;
8590 const bitsDecoded = this.bitsDecoded;
8591 const processingFlags = this.processingFlags;
8592 const processedMask = 1;
8593 const firstMagnitudeBitMask = 2;
8594 const length = width * height;
8595 const width4 = width * 4;
8596
8597 for (let index0 = 0, indexNext; index0 < length; index0 = indexNext) {
8598 indexNext = Math.min(length, index0 + width4);
8599
8600 for (let j = 0; j < width; j++) {
8601 for (let index = index0 + j; index < indexNext; index += width) {
8602 if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
8603 continue;
8604 }
8605
8606 let contextLabel = 16;
8607
8608 if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
8609 processingFlags[index] ^= firstMagnitudeBitMask;
8610 const significance = neighborsSignificance[index] & 127;
8611 contextLabel = significance === 0 ? 15 : 14;
8612 }
8613
8614 const bit = decoder.readBit(contexts, contextLabel);
8615 coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
8616 bitsDecoded[index]++;
8617 processingFlags[index] |= processedMask;
8618 }
8619 }
8620 }
8621 }
8622
8623 runCleanupPass() {
8624 const decoder = this.decoder;
8625 const width = this.width,
8626 height = this.height;
8627 const neighborsSignificance = this.neighborsSignificance;
8628 const coefficentsMagnitude = this.coefficentsMagnitude;
8629 const coefficentsSign = this.coefficentsSign;
8630 const contexts = this.contexts;
8631 const labels = this.contextLabelTable;
8632 const bitsDecoded = this.bitsDecoded;
8633 const processingFlags = this.processingFlags;
8634 const processedMask = 1;
8635 const firstMagnitudeBitMask = 2;
8636 const oneRowDown = width;
8637 const twoRowsDown = width * 2;
8638 const threeRowsDown = width * 3;
8639 let iNext;
8640
8641 for (let i0 = 0; i0 < height; i0 = iNext) {
8642 iNext = Math.min(i0 + 4, height);
8643 const indexBase = i0 * width;
8644 const checkAllEmpty = i0 + 3 < height;
8645
8646 for (let j = 0; j < width; j++) {
8647 const index0 = indexBase + j;
8648 const allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && processingFlags[index0 + twoRowsDown] === 0 && processingFlags[index0 + threeRowsDown] === 0 && neighborsSignificance[index0] === 0 && neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0;
8649 let i1 = 0,
8650 index = index0;
8651 let i = i0,
8652 sign;
8653
8654 if (allEmpty) {
8655 const hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT);
8656
8657 if (!hasSignificantCoefficent) {
8658 bitsDecoded[index0]++;
8659 bitsDecoded[index0 + oneRowDown]++;
8660 bitsDecoded[index0 + twoRowsDown]++;
8661 bitsDecoded[index0 + threeRowsDown]++;
8662 continue;
8663 }
8664
8665 i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
8666
8667 if (i1 !== 0) {
8668 i = i0 + i1;
8669 index += i1 * width;
8670 }
8671
8672 sign = this.decodeSignBit(i, j, index);
8673 coefficentsSign[index] = sign;
8674 coefficentsMagnitude[index] = 1;
8675 this.setNeighborsSignificance(i, j, index);
8676 processingFlags[index] |= firstMagnitudeBitMask;
8677 index = index0;
8678
8679 for (let i2 = i0; i2 <= i; i2++, index += width) {
8680 bitsDecoded[index]++;
8681 }
8682
8683 i1++;
8684 }
8685
8686 for (i = i0 + i1; i < iNext; i++, index += width) {
8687 if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
8688 continue;
8689 }
8690
8691 const contextLabel = labels[neighborsSignificance[index]];
8692 const decision = decoder.readBit(contexts, contextLabel);
8693
8694 if (decision === 1) {
8695 sign = this.decodeSignBit(i, j, index);
8696 coefficentsSign[index] = sign;
8697 coefficentsMagnitude[index] = 1;
8698 this.setNeighborsSignificance(i, j, index);
8699 processingFlags[index] |= firstMagnitudeBitMask;
8700 }
8701
8702 bitsDecoded[index]++;
8703 }
8704 }
8705 }
8706 }
8707
8708 checkSegmentationSymbol() {
8709 const decoder = this.decoder;
8710 const contexts = this.contexts;
8711 const symbol = decoder.readBit(contexts, UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
8712
8713 if (symbol !== 0xa) {
8714 throw new JpxError("Invalid segmentation symbol");
8715 }
8716 }
8717
8718 }
8719
8720 return BitModel;
8721}();
8722
8723class Transform {
8724 constructor() {
8725 if (this.constructor === Transform) {
8726 (0, _util.unreachable)("Cannot initialize Transform.");
8727 }
8728 }
8729
8730 calculate(subbands, u0, v0) {
8731 let ll = subbands[0];
8732
8733 for (let i = 1, ii = subbands.length; i < ii; i++) {
8734 ll = this.iterate(ll, subbands[i], u0, v0);
8735 }
8736
8737 return ll;
8738 }
8739
8740 extend(buffer, offset, size) {
8741 let i1 = offset - 1,
8742 j1 = offset + 1;
8743 let i2 = offset + size - 2,
8744 j2 = offset + size;
8745 buffer[i1--] = buffer[j1++];
8746 buffer[j2++] = buffer[i2--];
8747 buffer[i1--] = buffer[j1++];
8748 buffer[j2++] = buffer[i2--];
8749 buffer[i1--] = buffer[j1++];
8750 buffer[j2++] = buffer[i2--];
8751 buffer[i1] = buffer[j1];
8752 buffer[j2] = buffer[i2];
8753 }
8754
8755 filter(x, offset, length) {
8756 (0, _util.unreachable)("Abstract method `filter` called");
8757 }
8758
8759 iterate(ll, hl_lh_hh, u0, v0) {
8760 const llWidth = ll.width,
8761 llHeight = ll.height;
8762 let llItems = ll.items;
8763 const width = hl_lh_hh.width;
8764 const height = hl_lh_hh.height;
8765 const items = hl_lh_hh.items;
8766 let i, j, k, l, u, v;
8767
8768 for (k = 0, i = 0; i < llHeight; i++) {
8769 l = i * 2 * width;
8770
8771 for (j = 0; j < llWidth; j++, k++, l += 2) {
8772 items[l] = llItems[k];
8773 }
8774 }
8775
8776 llItems = ll.items = null;
8777 const bufferPadding = 4;
8778 const rowBuffer = new Float32Array(width + 2 * bufferPadding);
8779
8780 if (width === 1) {
8781 if ((u0 & 1) !== 0) {
8782 for (v = 0, k = 0; v < height; v++, k += width) {
8783 items[k] *= 0.5;
8784 }
8785 }
8786 } else {
8787 for (v = 0, k = 0; v < height; v++, k += width) {
8788 rowBuffer.set(items.subarray(k, k + width), bufferPadding);
8789 this.extend(rowBuffer, bufferPadding, width);
8790 this.filter(rowBuffer, bufferPadding, width);
8791 items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
8792 }
8793 }
8794
8795 let numBuffers = 16;
8796 const colBuffers = [];
8797
8798 for (i = 0; i < numBuffers; i++) {
8799 colBuffers.push(new Float32Array(height + 2 * bufferPadding));
8800 }
8801
8802 let b,
8803 currentBuffer = 0;
8804 ll = bufferPadding + height;
8805
8806 if (height === 1) {
8807 if ((v0 & 1) !== 0) {
8808 for (u = 0; u < width; u++) {
8809 items[u] *= 0.5;
8810 }
8811 }
8812 } else {
8813 for (u = 0; u < width; u++) {
8814 if (currentBuffer === 0) {
8815 numBuffers = Math.min(width - u, numBuffers);
8816
8817 for (k = u, l = bufferPadding; l < ll; k += width, l++) {
8818 for (b = 0; b < numBuffers; b++) {
8819 colBuffers[b][l] = items[k + b];
8820 }
8821 }
8822
8823 currentBuffer = numBuffers;
8824 }
8825
8826 currentBuffer--;
8827 const buffer = colBuffers[currentBuffer];
8828 this.extend(buffer, bufferPadding, height);
8829 this.filter(buffer, bufferPadding, height);
8830
8831 if (currentBuffer === 0) {
8832 k = u - numBuffers + 1;
8833
8834 for (l = bufferPadding; l < ll; k += width, l++) {
8835 for (b = 0; b < numBuffers; b++) {
8836 items[k + b] = colBuffers[b][l];
8837 }
8838 }
8839 }
8840 }
8841 }
8842
8843 return {
8844 width,
8845 height,
8846 items
8847 };
8848 }
8849
8850}
8851
8852class IrreversibleTransform extends Transform {
8853 filter(x, offset, length) {
8854 const len = length >> 1;
8855 offset |= 0;
8856 let j, n, current, next;
8857 const alpha = -1.586134342059924;
8858 const beta = -0.052980118572961;
8859 const gamma = 0.882911075530934;
8860 const delta = 0.443506852043971;
8861 const K = 1.230174104914001;
8862 const K_ = 1 / K;
8863 j = offset - 3;
8864
8865 for (n = len + 4; n--; j += 2) {
8866 x[j] *= K_;
8867 }
8868
8869 j = offset - 2;
8870 current = delta * x[j - 1];
8871
8872 for (n = len + 3; n--; j += 2) {
8873 next = delta * x[j + 1];
8874 x[j] = K * x[j] - current - next;
8875
8876 if (n--) {
8877 j += 2;
8878 current = delta * x[j + 1];
8879 x[j] = K * x[j] - current - next;
8880 } else {
8881 break;
8882 }
8883 }
8884
8885 j = offset - 1;
8886 current = gamma * x[j - 1];
8887
8888 for (n = len + 2; n--; j += 2) {
8889 next = gamma * x[j + 1];
8890 x[j] -= current + next;
8891
8892 if (n--) {
8893 j += 2;
8894 current = gamma * x[j + 1];
8895 x[j] -= current + next;
8896 } else {
8897 break;
8898 }
8899 }
8900
8901 j = offset;
8902 current = beta * x[j - 1];
8903
8904 for (n = len + 1; n--; j += 2) {
8905 next = beta * x[j + 1];
8906 x[j] -= current + next;
8907
8908 if (n--) {
8909 j += 2;
8910 current = beta * x[j + 1];
8911 x[j] -= current + next;
8912 } else {
8913 break;
8914 }
8915 }
8916
8917 if (len !== 0) {
8918 j = offset + 1;
8919 current = alpha * x[j - 1];
8920
8921 for (n = len; n--; j += 2) {
8922 next = alpha * x[j + 1];
8923 x[j] -= current + next;
8924
8925 if (n--) {
8926 j += 2;
8927 current = alpha * x[j + 1];
8928 x[j] -= current + next;
8929 } else {
8930 break;
8931 }
8932 }
8933 }
8934 }
8935
8936}
8937
8938class ReversibleTransform extends Transform {
8939 filter(x, offset, length) {
8940 const len = length >> 1;
8941 offset |= 0;
8942 let j, n;
8943
8944 for (j = offset, n = len + 1; n--; j += 2) {
8945 x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
8946 }
8947
8948 for (j = offset + 1, n = len; n--; j += 2) {
8949 x[j] += x[j - 1] + x[j + 1] >> 1;
8950 }
8951 }
8952
8953}
8954
8955/***/ })
8956/******/ ]);
8957/************************************************************************/
8958/******/ // The module cache
8959/******/ var __webpack_module_cache__ = {};
8960/******/
8961/******/ // The require function
8962/******/ function __w_pdfjs_require__(moduleId) {
8963/******/ // Check if module is in cache
8964/******/ var cachedModule = __webpack_module_cache__[moduleId];
8965/******/ if (cachedModule !== undefined) {
8966/******/ return cachedModule.exports;
8967/******/ }
8968/******/ // Create a new module (and put it into the cache)
8969/******/ var module = __webpack_module_cache__[moduleId] = {
8970/******/ // no module.id needed
8971/******/ // no module.loaded needed
8972/******/ exports: {}
8973/******/ };
8974/******/
8975/******/ // Execute the module function
8976/******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
8977/******/
8978/******/ // Return the exports of the module
8979/******/ return module.exports;
8980/******/ }
8981/******/
8982/************************************************************************/
8983var __webpack_exports__ = {};
8984// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
8985(() => {
8986var exports = __webpack_exports__;
8987
8988
8989Object.defineProperty(exports, "__esModule", ({
8990 value: true
8991}));
8992Object.defineProperty(exports, "Jbig2Image", ({
8993 enumerable: true,
8994 get: function () {
8995 return _jbig.Jbig2Image;
8996 }
8997}));
8998Object.defineProperty(exports, "JpegImage", ({
8999 enumerable: true,
9000 get: function () {
9001 return _jpg.JpegImage;
9002 }
9003}));
9004Object.defineProperty(exports, "JpxImage", ({
9005 enumerable: true,
9006 get: function () {
9007 return _jpx.JpxImage;
9008 }
9009}));
9010Object.defineProperty(exports, "getVerbosityLevel", ({
9011 enumerable: true,
9012 get: function () {
9013 return _util.getVerbosityLevel;
9014 }
9015}));
9016Object.defineProperty(exports, "setVerbosityLevel", ({
9017 enumerable: true,
9018 get: function () {
9019 return _util.setVerbosityLevel;
9020 }
9021}));
9022
9023var _util = __w_pdfjs_require__(1);
9024
9025var _jbig = __w_pdfjs_require__(4);
9026
9027var _jpg = __w_pdfjs_require__(10);
9028
9029var _jpx = __w_pdfjs_require__(11);
9030
9031const pdfjsVersion = '2.15.349';
9032const pdfjsBuild = 'b8aa9c622';
9033})();
9034
9035/******/ return __webpack_exports__;
9036/******/ })()
9037;
9038});
9039//# sourceMappingURL=pdf.image_decoders.js.map
\No newline at end of file