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