1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158 |
- /**
- * @licstart The following is the entire license notice for the
- * JavaScript code in this page
- *
- * Copyright 2022 Mozilla Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * @licend The above is the entire license notice for the
- * JavaScript code in this page
- */
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.Jbig2Image = void 0;
- var _util = require("../shared/util.js");
- var _core_utils = require("./core_utils.js");
- var _arithmetic_decoder = require("./arithmetic_decoder.js");
- var _ccitt = require("./ccitt.js");
- class Jbig2Error extends _util.BaseException {
- constructor(msg) {
- super(`JBIG2 error: ${msg}`, "Jbig2Error");
- }
- }
- class ContextCache {
- getContexts(id) {
- if (id in this) {
- return this[id];
- }
- return this[id] = new Int8Array(1 << 16);
- }
- }
- class DecodingContext {
- constructor(data, start, end) {
- this.data = data;
- this.start = start;
- this.end = end;
- }
- get decoder() {
- const decoder = new _arithmetic_decoder.ArithmeticDecoder(this.data, this.start, this.end);
- return (0, _util.shadow)(this, "decoder", decoder);
- }
- get contextCache() {
- const cache = new ContextCache();
- return (0, _util.shadow)(this, "contextCache", cache);
- }
- }
- function decodeInteger(contextCache, procedure, decoder) {
- const contexts = contextCache.getContexts(procedure);
- let prev = 1;
- function readBits(length) {
- let v = 0;
- for (let i = 0; i < length; i++) {
- const bit = decoder.readBit(contexts, prev);
- prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
- v = v << 1 | bit;
- }
- return v >>> 0;
- }
- const sign = readBits(1);
- const value = readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(32) + 4436 : readBits(12) + 340 : readBits(8) + 84 : readBits(6) + 20 : readBits(4) + 4 : readBits(2);
- if (sign === 0) {
- return value;
- } else if (value > 0) {
- return -value;
- }
- return null;
- }
- function decodeIAID(contextCache, decoder, codeLength) {
- const contexts = contextCache.getContexts("IAID");
- let prev = 1;
- for (let i = 0; i < codeLength; i++) {
- const bit = decoder.readBit(contexts, prev);
- prev = prev << 1 | bit;
- }
- if (codeLength < 31) {
- return prev & (1 << codeLength) - 1;
- }
- return prev & 0x7fffffff;
- }
- const 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"];
- const CodingTemplates = [[{
- x: -1,
- y: -2
- }, {
- x: 0,
- y: -2
- }, {
- x: 1,
- y: -2
- }, {
- x: -2,
- y: -1
- }, {
- x: -1,
- y: -1
- }, {
- x: 0,
- y: -1
- }, {
- x: 1,
- y: -1
- }, {
- x: 2,
- y: -1
- }, {
- x: -4,
- y: 0
- }, {
- x: -3,
- y: 0
- }, {
- x: -2,
- y: 0
- }, {
- x: -1,
- y: 0
- }], [{
- x: -1,
- y: -2
- }, {
- x: 0,
- y: -2
- }, {
- x: 1,
- y: -2
- }, {
- x: 2,
- y: -2
- }, {
- x: -2,
- y: -1
- }, {
- x: -1,
- y: -1
- }, {
- x: 0,
- y: -1
- }, {
- x: 1,
- y: -1
- }, {
- x: 2,
- y: -1
- }, {
- x: -3,
- y: 0
- }, {
- x: -2,
- y: 0
- }, {
- x: -1,
- y: 0
- }], [{
- x: -1,
- y: -2
- }, {
- x: 0,
- y: -2
- }, {
- x: 1,
- y: -2
- }, {
- x: -2,
- y: -1
- }, {
- x: -1,
- y: -1
- }, {
- x: 0,
- y: -1
- }, {
- x: 1,
- y: -1
- }, {
- x: -2,
- y: 0
- }, {
- x: -1,
- y: 0
- }], [{
- x: -3,
- y: -1
- }, {
- x: -2,
- y: -1
- }, {
- x: -1,
- y: -1
- }, {
- x: 0,
- y: -1
- }, {
- x: 1,
- y: -1
- }, {
- x: -4,
- y: 0
- }, {
- x: -3,
- y: 0
- }, {
- x: -2,
- y: 0
- }, {
- x: -1,
- y: 0
- }]];
- const RefinementTemplates = [{
- coding: [{
- x: 0,
- y: -1
- }, {
- x: 1,
- y: -1
- }, {
- x: -1,
- y: 0
- }],
- reference: [{
- x: 0,
- y: -1
- }, {
- x: 1,
- y: -1
- }, {
- x: -1,
- y: 0
- }, {
- x: 0,
- y: 0
- }, {
- x: 1,
- y: 0
- }, {
- x: -1,
- y: 1
- }, {
- x: 0,
- y: 1
- }, {
- x: 1,
- y: 1
- }]
- }, {
- coding: [{
- x: -1,
- y: -1
- }, {
- x: 0,
- y: -1
- }, {
- x: 1,
- y: -1
- }, {
- x: -1,
- y: 0
- }],
- reference: [{
- x: 0,
- y: -1
- }, {
- x: -1,
- y: 0
- }, {
- x: 0,
- y: 0
- }, {
- x: 1,
- y: 0
- }, {
- x: 0,
- y: 1
- }, {
- x: 1,
- y: 1
- }]
- }];
- const ReusedContexts = [0x9b25, 0x0795, 0x00e5, 0x0195];
- const RefinementReusedContexts = [0x0020, 0x0008];
- function decodeBitmapTemplate0(width, height, decodingContext) {
- const decoder = decodingContext.decoder;
- const contexts = decodingContext.contextCache.getContexts("GB");
- const bitmap = [];
- let contextLabel, i, j, pixel, row, row1, row2;
- const OLD_PIXEL_MASK = 0x7bf7;
- for (i = 0; i < height; i++) {
- row = bitmap[i] = new Uint8Array(width);
- row1 = i < 1 ? row : bitmap[i - 1];
- row2 = i < 2 ? row : bitmap[i - 2];
- contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
- for (j = 0; j < width; j++) {
- row[j] = pixel = decoder.readBit(contexts, contextLabel);
- contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
- }
- }
- return bitmap;
- }
- function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
- if (mmr) {
- const input = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
- return decodeMMRBitmap(input, width, height, false);
- }
- 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) {
- return decodeBitmapTemplate0(width, height, decodingContext);
- }
- const useskip = !!skip;
- const template = CodingTemplates[templateIndex].concat(at);
- template.sort(function (a, b) {
- return a.y - b.y || a.x - b.x;
- });
- const templateLength = template.length;
- const templateX = new Int8Array(templateLength);
- const templateY = new Int8Array(templateLength);
- const changingTemplateEntries = [];
- let reuseMask = 0,
- minX = 0,
- maxX = 0,
- minY = 0;
- let c, k;
- for (k = 0; k < templateLength; k++) {
- templateX[k] = template[k].x;
- templateY[k] = template[k].y;
- minX = Math.min(minX, template[k].x);
- maxX = Math.max(maxX, template[k].x);
- minY = Math.min(minY, template[k].y);
- if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
- reuseMask |= 1 << templateLength - 1 - k;
- } else {
- changingTemplateEntries.push(k);
- }
- }
- const changingEntriesLength = changingTemplateEntries.length;
- const changingTemplateX = new Int8Array(changingEntriesLength);
- const changingTemplateY = new Int8Array(changingEntriesLength);
- const changingTemplateBit = new Uint16Array(changingEntriesLength);
- for (c = 0; c < changingEntriesLength; c++) {
- k = changingTemplateEntries[c];
- changingTemplateX[c] = template[k].x;
- changingTemplateY[c] = template[k].y;
- changingTemplateBit[c] = 1 << templateLength - 1 - k;
- }
- const sbb_left = -minX;
- const sbb_top = -minY;
- const sbb_right = width - maxX;
- const pseudoPixelContext = ReusedContexts[templateIndex];
- let row = new Uint8Array(width);
- const bitmap = [];
- const decoder = decodingContext.decoder;
- const contexts = decodingContext.contextCache.getContexts("GB");
- let ltp = 0,
- j,
- i0,
- j0,
- contextLabel = 0,
- bit,
- shift;
- for (let i = 0; i < height; i++) {
- if (prediction) {
- const sltp = decoder.readBit(contexts, pseudoPixelContext);
- ltp ^= sltp;
- if (ltp) {
- bitmap.push(row);
- continue;
- }
- }
- row = new Uint8Array(row);
- bitmap.push(row);
- for (j = 0; j < width; j++) {
- if (useskip && skip[i][j]) {
- row[j] = 0;
- continue;
- }
- if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
- contextLabel = contextLabel << 1 & reuseMask;
- for (k = 0; k < changingEntriesLength; k++) {
- i0 = i + changingTemplateY[k];
- j0 = j + changingTemplateX[k];
- bit = bitmap[i0][j0];
- if (bit) {
- bit = changingTemplateBit[k];
- contextLabel |= bit;
- }
- }
- } else {
- contextLabel = 0;
- shift = templateLength - 1;
- for (k = 0; k < templateLength; k++, shift--) {
- j0 = j + templateX[k];
- if (j0 >= 0 && j0 < width) {
- i0 = i + templateY[k];
- if (i0 >= 0) {
- bit = bitmap[i0][j0];
- if (bit) {
- contextLabel |= bit << shift;
- }
- }
- }
- }
- }
- const pixel = decoder.readBit(contexts, contextLabel);
- row[j] = pixel;
- }
- }
- return bitmap;
- }
- function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
- let codingTemplate = RefinementTemplates[templateIndex].coding;
- if (templateIndex === 0) {
- codingTemplate = codingTemplate.concat([at[0]]);
- }
- const codingTemplateLength = codingTemplate.length;
- const codingTemplateX = new Int32Array(codingTemplateLength);
- const codingTemplateY = new Int32Array(codingTemplateLength);
- let k;
- for (k = 0; k < codingTemplateLength; k++) {
- codingTemplateX[k] = codingTemplate[k].x;
- codingTemplateY[k] = codingTemplate[k].y;
- }
- let referenceTemplate = RefinementTemplates[templateIndex].reference;
- if (templateIndex === 0) {
- referenceTemplate = referenceTemplate.concat([at[1]]);
- }
- const referenceTemplateLength = referenceTemplate.length;
- const referenceTemplateX = new Int32Array(referenceTemplateLength);
- const referenceTemplateY = new Int32Array(referenceTemplateLength);
- for (k = 0; k < referenceTemplateLength; k++) {
- referenceTemplateX[k] = referenceTemplate[k].x;
- referenceTemplateY[k] = referenceTemplate[k].y;
- }
- const referenceWidth = referenceBitmap[0].length;
- const referenceHeight = referenceBitmap.length;
- const pseudoPixelContext = RefinementReusedContexts[templateIndex];
- const bitmap = [];
- const decoder = decodingContext.decoder;
- const contexts = decodingContext.contextCache.getContexts("GR");
- let ltp = 0;
- for (let i = 0; i < height; i++) {
- if (prediction) {
- const sltp = decoder.readBit(contexts, pseudoPixelContext);
- ltp ^= sltp;
- if (ltp) {
- throw new Jbig2Error("prediction is not supported");
- }
- }
- const row = new Uint8Array(width);
- bitmap.push(row);
- for (let j = 0; j < width; j++) {
- let i0, j0;
- let contextLabel = 0;
- for (k = 0; k < codingTemplateLength; k++) {
- i0 = i + codingTemplateY[k];
- j0 = j + codingTemplateX[k];
- if (i0 < 0 || j0 < 0 || j0 >= width) {
- contextLabel <<= 1;
- } else {
- contextLabel = contextLabel << 1 | bitmap[i0][j0];
- }
- }
- for (k = 0; k < referenceTemplateLength; k++) {
- i0 = i + referenceTemplateY[k] - offsetY;
- j0 = j + referenceTemplateX[k] - offsetX;
- if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
- contextLabel <<= 1;
- } else {
- contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
- }
- }
- const pixel = decoder.readBit(contexts, contextLabel);
- row[j] = pixel;
- }
- }
- return bitmap;
- }
- function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext, huffmanInput) {
- if (huffman && refinement) {
- throw new Jbig2Error("symbol refinement with Huffman is not supported");
- }
- const newSymbols = [];
- let currentHeight = 0;
- let symbolCodeLength = (0, _core_utils.log2)(symbols.length + numberOfNewSymbols);
- const decoder = decodingContext.decoder;
- const contextCache = decodingContext.contextCache;
- let tableB1, symbolWidths;
- if (huffman) {
- tableB1 = getStandardTable(1);
- symbolWidths = [];
- symbolCodeLength = Math.max(symbolCodeLength, 1);
- }
- while (newSymbols.length < numberOfNewSymbols) {
- const deltaHeight = huffman ? huffmanTables.tableDeltaHeight.decode(huffmanInput) : decodeInteger(contextCache, "IADH", decoder);
- currentHeight += deltaHeight;
- let currentWidth = 0,
- totalWidth = 0;
- const firstSymbol = huffman ? symbolWidths.length : 0;
- while (true) {
- const deltaWidth = huffman ? huffmanTables.tableDeltaWidth.decode(huffmanInput) : decodeInteger(contextCache, "IADW", decoder);
- if (deltaWidth === null) {
- break;
- }
- currentWidth += deltaWidth;
- totalWidth += currentWidth;
- let bitmap;
- if (refinement) {
- const numberOfInstances = decodeInteger(contextCache, "IAAI", decoder);
- if (numberOfInstances > 1) {
- bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, symbols.concat(newSymbols), symbolCodeLength, 0, 0, 1, 0, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, 0, huffmanInput);
- } else {
- const symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
- const rdx = decodeInteger(contextCache, "IARDX", decoder);
- const rdy = decodeInteger(contextCache, "IARDY", decoder);
- const symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
- bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
- }
- newSymbols.push(bitmap);
- } else if (huffman) {
- symbolWidths.push(currentWidth);
- } else {
- bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
- newSymbols.push(bitmap);
- }
- }
- if (huffman && !refinement) {
- const bitmapSize = huffmanTables.tableBitmapSize.decode(huffmanInput);
- huffmanInput.byteAlign();
- let collectiveBitmap;
- if (bitmapSize === 0) {
- collectiveBitmap = readUncompressedBitmap(huffmanInput, totalWidth, currentHeight);
- } else {
- const originalEnd = huffmanInput.end;
- const bitmapEnd = huffmanInput.position + bitmapSize;
- huffmanInput.end = bitmapEnd;
- collectiveBitmap = decodeMMRBitmap(huffmanInput, totalWidth, currentHeight, false);
- huffmanInput.end = originalEnd;
- huffmanInput.position = bitmapEnd;
- }
- const numberOfSymbolsDecoded = symbolWidths.length;
- if (firstSymbol === numberOfSymbolsDecoded - 1) {
- newSymbols.push(collectiveBitmap);
- } else {
- let i,
- y,
- xMin = 0,
- xMax,
- bitmapWidth,
- symbolBitmap;
- for (i = firstSymbol; i < numberOfSymbolsDecoded; i++) {
- bitmapWidth = symbolWidths[i];
- xMax = xMin + bitmapWidth;
- symbolBitmap = [];
- for (y = 0; y < currentHeight; y++) {
- symbolBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
- }
- newSymbols.push(symbolBitmap);
- xMin = xMax;
- }
- }
- }
- }
- const exportedSymbols = [],
- flags = [];
- let currentFlag = false,
- i,
- ii;
- const totalSymbolsLength = symbols.length + numberOfNewSymbols;
- while (flags.length < totalSymbolsLength) {
- let runLength = huffman ? tableB1.decode(huffmanInput) : decodeInteger(contextCache, "IAEX", decoder);
- while (runLength--) {
- flags.push(currentFlag);
- }
- currentFlag = !currentFlag;
- }
- for (i = 0, ii = symbols.length; i < ii; i++) {
- if (flags[i]) {
- exportedSymbols.push(symbols[i]);
- }
- }
- for (let j = 0; j < numberOfNewSymbols; i++, j++) {
- if (flags[i]) {
- exportedSymbols.push(newSymbols[j]);
- }
- }
- return exportedSymbols;
- }
- function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, logStripSize, huffmanInput) {
- if (huffman && refinement) {
- throw new Jbig2Error("refinement with Huffman is not supported");
- }
- const bitmap = [];
- let i, row;
- for (i = 0; i < height; i++) {
- row = new Uint8Array(width);
- if (defaultPixelValue) {
- for (let j = 0; j < width; j++) {
- row[j] = defaultPixelValue;
- }
- }
- bitmap.push(row);
- }
- const decoder = decodingContext.decoder;
- const contextCache = decodingContext.contextCache;
- let stripT = huffman ? -huffmanTables.tableDeltaT.decode(huffmanInput) : -decodeInteger(contextCache, "IADT", decoder);
- let firstS = 0;
- i = 0;
- while (i < numberOfSymbolInstances) {
- const deltaT = huffman ? huffmanTables.tableDeltaT.decode(huffmanInput) : decodeInteger(contextCache, "IADT", decoder);
- stripT += deltaT;
- const deltaFirstS = huffman ? huffmanTables.tableFirstS.decode(huffmanInput) : decodeInteger(contextCache, "IAFS", decoder);
- firstS += deltaFirstS;
- let currentS = firstS;
- do {
- let currentT = 0;
- if (stripSize > 1) {
- currentT = huffman ? huffmanInput.readBits(logStripSize) : decodeInteger(contextCache, "IAIT", decoder);
- }
- const t = stripSize * stripT + currentT;
- const symbolId = huffman ? huffmanTables.symbolIDTable.decode(huffmanInput) : decodeIAID(contextCache, decoder, symbolCodeLength);
- const applyRefinement = refinement && (huffman ? huffmanInput.readBit() : decodeInteger(contextCache, "IARI", decoder));
- let symbolBitmap = inputSymbols[symbolId];
- let symbolWidth = symbolBitmap[0].length;
- let symbolHeight = symbolBitmap.length;
- if (applyRefinement) {
- const rdw = decodeInteger(contextCache, "IARDW", decoder);
- const rdh = decodeInteger(contextCache, "IARDH", decoder);
- const rdx = decodeInteger(contextCache, "IARDX", decoder);
- const rdy = decodeInteger(contextCache, "IARDY", decoder);
- symbolWidth += rdw;
- symbolHeight += rdh;
- symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
- }
- const offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight - 1);
- const offsetS = currentS - (referenceCorner & 2 ? symbolWidth - 1 : 0);
- let s2, t2, symbolRow;
- if (transposed) {
- for (s2 = 0; s2 < symbolHeight; s2++) {
- row = bitmap[offsetS + s2];
- if (!row) {
- continue;
- }
- symbolRow = symbolBitmap[s2];
- const maxWidth = Math.min(width - offsetT, symbolWidth);
- switch (combinationOperator) {
- case 0:
- for (t2 = 0; t2 < maxWidth; t2++) {
- row[offsetT + t2] |= symbolRow[t2];
- }
- break;
- case 2:
- for (t2 = 0; t2 < maxWidth; t2++) {
- row[offsetT + t2] ^= symbolRow[t2];
- }
- break;
- default:
- throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
- }
- }
- currentS += symbolHeight - 1;
- } else {
- for (t2 = 0; t2 < symbolHeight; t2++) {
- row = bitmap[offsetT + t2];
- if (!row) {
- continue;
- }
- symbolRow = symbolBitmap[t2];
- switch (combinationOperator) {
- case 0:
- for (s2 = 0; s2 < symbolWidth; s2++) {
- row[offsetS + s2] |= symbolRow[s2];
- }
- break;
- case 2:
- for (s2 = 0; s2 < symbolWidth; s2++) {
- row[offsetS + s2] ^= symbolRow[s2];
- }
- break;
- default:
- throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
- }
- }
- currentS += symbolWidth - 1;
- }
- i++;
- const deltaS = huffman ? huffmanTables.tableDeltaS.decode(huffmanInput) : decodeInteger(contextCache, "IADS", decoder);
- if (deltaS === null) {
- break;
- }
- currentS += deltaS + dsOffset;
- } while (true);
- }
- return bitmap;
- }
- function decodePatternDictionary(mmr, patternWidth, patternHeight, maxPatternIndex, template, decodingContext) {
- const at = [];
- if (!mmr) {
- at.push({
- x: -patternWidth,
- y: 0
- });
- if (template === 0) {
- at.push({
- x: -3,
- y: -1
- }, {
- x: 2,
- y: -2
- }, {
- x: -2,
- y: -2
- });
- }
- }
- const collectiveWidth = (maxPatternIndex + 1) * patternWidth;
- const collectiveBitmap = decodeBitmap(mmr, collectiveWidth, patternHeight, template, false, null, at, decodingContext);
- const patterns = [];
- for (let i = 0; i <= maxPatternIndex; i++) {
- const patternBitmap = [];
- const xMin = patternWidth * i;
- const xMax = xMin + patternWidth;
- for (let y = 0; y < patternHeight; y++) {
- patternBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
- }
- patterns.push(patternBitmap);
- }
- return patterns;
- }
- function decodeHalftoneRegion(mmr, patterns, template, regionWidth, regionHeight, defaultPixelValue, enableSkip, combinationOperator, gridWidth, gridHeight, gridOffsetX, gridOffsetY, gridVectorX, gridVectorY, decodingContext) {
- const skip = null;
- if (enableSkip) {
- throw new Jbig2Error("skip is not supported");
- }
- if (combinationOperator !== 0) {
- throw new Jbig2Error(`operator "${combinationOperator}" is not supported in halftone region`);
- }
- const regionBitmap = [];
- let i, j, row;
- for (i = 0; i < regionHeight; i++) {
- row = new Uint8Array(regionWidth);
- if (defaultPixelValue) {
- for (j = 0; j < regionWidth; j++) {
- row[j] = defaultPixelValue;
- }
- }
- regionBitmap.push(row);
- }
- const numberOfPatterns = patterns.length;
- const pattern0 = patterns[0];
- const patternWidth = pattern0[0].length,
- patternHeight = pattern0.length;
- const bitsPerValue = (0, _core_utils.log2)(numberOfPatterns);
- const at = [];
- if (!mmr) {
- at.push({
- x: template <= 1 ? 3 : 2,
- y: -1
- });
- if (template === 0) {
- at.push({
- x: -3,
- y: -1
- }, {
- x: 2,
- y: -2
- }, {
- x: -2,
- y: -2
- });
- }
- }
- const grayScaleBitPlanes = [];
- let mmrInput, bitmap;
- if (mmr) {
- mmrInput = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
- }
- for (i = bitsPerValue - 1; i >= 0; i--) {
- if (mmr) {
- bitmap = decodeMMRBitmap(mmrInput, gridWidth, gridHeight, true);
- } else {
- bitmap = decodeBitmap(false, gridWidth, gridHeight, template, false, skip, at, decodingContext);
- }
- grayScaleBitPlanes[i] = bitmap;
- }
- let mg, ng, bit, patternIndex, patternBitmap, x, y, patternRow, regionRow;
- for (mg = 0; mg < gridHeight; mg++) {
- for (ng = 0; ng < gridWidth; ng++) {
- bit = 0;
- patternIndex = 0;
- for (j = bitsPerValue - 1; j >= 0; j--) {
- bit ^= grayScaleBitPlanes[j][mg][ng];
- patternIndex |= bit << j;
- }
- patternBitmap = patterns[patternIndex];
- x = gridOffsetX + mg * gridVectorY + ng * gridVectorX >> 8;
- y = gridOffsetY + mg * gridVectorX - ng * gridVectorY >> 8;
- if (x >= 0 && x + patternWidth <= regionWidth && y >= 0 && y + patternHeight <= regionHeight) {
- for (i = 0; i < patternHeight; i++) {
- regionRow = regionBitmap[y + i];
- patternRow = patternBitmap[i];
- for (j = 0; j < patternWidth; j++) {
- regionRow[x + j] |= patternRow[j];
- }
- }
- } else {
- let regionX, regionY;
- for (i = 0; i < patternHeight; i++) {
- regionY = y + i;
- if (regionY < 0 || regionY >= regionHeight) {
- continue;
- }
- regionRow = regionBitmap[regionY];
- patternRow = patternBitmap[i];
- for (j = 0; j < patternWidth; j++) {
- regionX = x + j;
- if (regionX >= 0 && regionX < regionWidth) {
- regionRow[regionX] |= patternRow[j];
- }
- }
- }
- }
- }
- }
- return regionBitmap;
- }
- function readSegmentHeader(data, start) {
- const segmentHeader = {};
- segmentHeader.number = (0, _core_utils.readUint32)(data, start);
- const flags = data[start + 4];
- const segmentType = flags & 0x3f;
- if (!SegmentTypes[segmentType]) {
- throw new Jbig2Error("invalid segment type: " + segmentType);
- }
- segmentHeader.type = segmentType;
- segmentHeader.typeName = SegmentTypes[segmentType];
- segmentHeader.deferredNonRetain = !!(flags & 0x80);
- const pageAssociationFieldSize = !!(flags & 0x40);
- const referredFlags = data[start + 5];
- let referredToCount = referredFlags >> 5 & 7;
- const retainBits = [referredFlags & 31];
- let position = start + 6;
- if (referredFlags === 7) {
- referredToCount = (0, _core_utils.readUint32)(data, position - 1) & 0x1fffffff;
- position += 3;
- let bytes = referredToCount + 7 >> 3;
- retainBits[0] = data[position++];
- while (--bytes > 0) {
- retainBits.push(data[position++]);
- }
- } else if (referredFlags === 5 || referredFlags === 6) {
- throw new Jbig2Error("invalid referred-to flags");
- }
- segmentHeader.retainBits = retainBits;
- let referredToSegmentNumberSize = 4;
- if (segmentHeader.number <= 256) {
- referredToSegmentNumberSize = 1;
- } else if (segmentHeader.number <= 65536) {
- referredToSegmentNumberSize = 2;
- }
- const referredTo = [];
- let i, ii;
- for (i = 0; i < referredToCount; i++) {
- let number;
- if (referredToSegmentNumberSize === 1) {
- number = data[position];
- } else if (referredToSegmentNumberSize === 2) {
- number = (0, _core_utils.readUint16)(data, position);
- } else {
- number = (0, _core_utils.readUint32)(data, position);
- }
- referredTo.push(number);
- position += referredToSegmentNumberSize;
- }
- segmentHeader.referredTo = referredTo;
- if (!pageAssociationFieldSize) {
- segmentHeader.pageAssociation = data[position++];
- } else {
- segmentHeader.pageAssociation = (0, _core_utils.readUint32)(data, position);
- position += 4;
- }
- segmentHeader.length = (0, _core_utils.readUint32)(data, position);
- position += 4;
- if (segmentHeader.length === 0xffffffff) {
- if (segmentType === 38) {
- const genericRegionInfo = readRegionSegmentInformation(data, position);
- const genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
- const genericRegionMmr = !!(genericRegionSegmentFlags & 1);
- const searchPatternLength = 6;
- const searchPattern = new Uint8Array(searchPatternLength);
- if (!genericRegionMmr) {
- searchPattern[0] = 0xff;
- searchPattern[1] = 0xac;
- }
- searchPattern[2] = genericRegionInfo.height >>> 24 & 0xff;
- searchPattern[3] = genericRegionInfo.height >> 16 & 0xff;
- searchPattern[4] = genericRegionInfo.height >> 8 & 0xff;
- searchPattern[5] = genericRegionInfo.height & 0xff;
- for (i = position, ii = data.length; i < ii; i++) {
- let j = 0;
- while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
- j++;
- }
- if (j === searchPatternLength) {
- segmentHeader.length = i + searchPatternLength;
- break;
- }
- }
- if (segmentHeader.length === 0xffffffff) {
- throw new Jbig2Error("segment end was not found");
- }
- } else {
- throw new Jbig2Error("invalid unknown segment length");
- }
- }
- segmentHeader.headerEnd = position;
- return segmentHeader;
- }
- function readSegments(header, data, start, end) {
- const segments = [];
- let position = start;
- while (position < end) {
- const segmentHeader = readSegmentHeader(data, position);
- position = segmentHeader.headerEnd;
- const segment = {
- header: segmentHeader,
- data
- };
- if (!header.randomAccess) {
- segment.start = position;
- position += segmentHeader.length;
- segment.end = position;
- }
- segments.push(segment);
- if (segmentHeader.type === 51) {
- break;
- }
- }
- if (header.randomAccess) {
- for (let i = 0, ii = segments.length; i < ii; i++) {
- segments[i].start = position;
- position += segments[i].header.length;
- segments[i].end = position;
- }
- }
- return segments;
- }
- function readRegionSegmentInformation(data, start) {
- return {
- width: (0, _core_utils.readUint32)(data, start),
- height: (0, _core_utils.readUint32)(data, start + 4),
- x: (0, _core_utils.readUint32)(data, start + 8),
- y: (0, _core_utils.readUint32)(data, start + 12),
- combinationOperator: data[start + 16] & 7
- };
- }
- const RegionSegmentInformationFieldLength = 17;
- function processSegment(segment, visitor) {
- const header = segment.header;
- const data = segment.data,
- end = segment.end;
- let position = segment.start;
- let args, at, i, atLength;
- switch (header.type) {
- case 0:
- const dictionary = {};
- const dictionaryFlags = (0, _core_utils.readUint16)(data, position);
- dictionary.huffman = !!(dictionaryFlags & 1);
- dictionary.refinement = !!(dictionaryFlags & 2);
- dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
- dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
- dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
- dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
- dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
- dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
- dictionary.template = dictionaryFlags >> 10 & 3;
- dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
- position += 2;
- if (!dictionary.huffman) {
- atLength = dictionary.template === 0 ? 4 : 1;
- at = [];
- for (i = 0; i < atLength; i++) {
- at.push({
- x: (0, _core_utils.readInt8)(data, position),
- y: (0, _core_utils.readInt8)(data, position + 1)
- });
- position += 2;
- }
- dictionary.at = at;
- }
- if (dictionary.refinement && !dictionary.refinementTemplate) {
- at = [];
- for (i = 0; i < 2; i++) {
- at.push({
- x: (0, _core_utils.readInt8)(data, position),
- y: (0, _core_utils.readInt8)(data, position + 1)
- });
- position += 2;
- }
- dictionary.refinementAt = at;
- }
- dictionary.numberOfExportedSymbols = (0, _core_utils.readUint32)(data, position);
- position += 4;
- dictionary.numberOfNewSymbols = (0, _core_utils.readUint32)(data, position);
- position += 4;
- args = [dictionary, header.number, header.referredTo, data, position, end];
- break;
- case 6:
- case 7:
- const textRegion = {};
- textRegion.info = readRegionSegmentInformation(data, position);
- position += RegionSegmentInformationFieldLength;
- const textRegionSegmentFlags = (0, _core_utils.readUint16)(data, position);
- position += 2;
- textRegion.huffman = !!(textRegionSegmentFlags & 1);
- textRegion.refinement = !!(textRegionSegmentFlags & 2);
- textRegion.logStripSize = textRegionSegmentFlags >> 2 & 3;
- textRegion.stripSize = 1 << textRegion.logStripSize;
- textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
- textRegion.transposed = !!(textRegionSegmentFlags & 64);
- textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
- textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
- textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
- textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
- if (textRegion.huffman) {
- const textRegionHuffmanFlags = (0, _core_utils.readUint16)(data, position);
- position += 2;
- textRegion.huffmanFS = textRegionHuffmanFlags & 3;
- textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
- textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
- textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
- textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
- textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
- textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
- textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 0x4000);
- }
- if (textRegion.refinement && !textRegion.refinementTemplate) {
- at = [];
- for (i = 0; i < 2; i++) {
- at.push({
- x: (0, _core_utils.readInt8)(data, position),
- y: (0, _core_utils.readInt8)(data, position + 1)
- });
- position += 2;
- }
- textRegion.refinementAt = at;
- }
- textRegion.numberOfSymbolInstances = (0, _core_utils.readUint32)(data, position);
- position += 4;
- args = [textRegion, header.referredTo, data, position, end];
- break;
- case 16:
- const patternDictionary = {};
- const patternDictionaryFlags = data[position++];
- patternDictionary.mmr = !!(patternDictionaryFlags & 1);
- patternDictionary.template = patternDictionaryFlags >> 1 & 3;
- patternDictionary.patternWidth = data[position++];
- patternDictionary.patternHeight = data[position++];
- patternDictionary.maxPatternIndex = (0, _core_utils.readUint32)(data, position);
- position += 4;
- args = [patternDictionary, header.number, data, position, end];
- break;
- case 22:
- case 23:
- const halftoneRegion = {};
- halftoneRegion.info = readRegionSegmentInformation(data, position);
- position += RegionSegmentInformationFieldLength;
- const halftoneRegionFlags = data[position++];
- halftoneRegion.mmr = !!(halftoneRegionFlags & 1);
- halftoneRegion.template = halftoneRegionFlags >> 1 & 3;
- halftoneRegion.enableSkip = !!(halftoneRegionFlags & 8);
- halftoneRegion.combinationOperator = halftoneRegionFlags >> 4 & 7;
- halftoneRegion.defaultPixelValue = halftoneRegionFlags >> 7 & 1;
- halftoneRegion.gridWidth = (0, _core_utils.readUint32)(data, position);
- position += 4;
- halftoneRegion.gridHeight = (0, _core_utils.readUint32)(data, position);
- position += 4;
- halftoneRegion.gridOffsetX = (0, _core_utils.readUint32)(data, position) & 0xffffffff;
- position += 4;
- halftoneRegion.gridOffsetY = (0, _core_utils.readUint32)(data, position) & 0xffffffff;
- position += 4;
- halftoneRegion.gridVectorX = (0, _core_utils.readUint16)(data, position);
- position += 2;
- halftoneRegion.gridVectorY = (0, _core_utils.readUint16)(data, position);
- position += 2;
- args = [halftoneRegion, header.referredTo, data, position, end];
- break;
- case 38:
- case 39:
- const genericRegion = {};
- genericRegion.info = readRegionSegmentInformation(data, position);
- position += RegionSegmentInformationFieldLength;
- const genericRegionSegmentFlags = data[position++];
- genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
- genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
- genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
- if (!genericRegion.mmr) {
- atLength = genericRegion.template === 0 ? 4 : 1;
- at = [];
- for (i = 0; i < atLength; i++) {
- at.push({
- x: (0, _core_utils.readInt8)(data, position),
- y: (0, _core_utils.readInt8)(data, position + 1)
- });
- position += 2;
- }
- genericRegion.at = at;
- }
- args = [genericRegion, data, position, end];
- break;
- case 48:
- const pageInfo = {
- width: (0, _core_utils.readUint32)(data, position),
- height: (0, _core_utils.readUint32)(data, position + 4),
- resolutionX: (0, _core_utils.readUint32)(data, position + 8),
- resolutionY: (0, _core_utils.readUint32)(data, position + 12)
- };
- if (pageInfo.height === 0xffffffff) {
- delete pageInfo.height;
- }
- const pageSegmentFlags = data[position + 16];
- (0, _core_utils.readUint16)(data, position + 17);
- pageInfo.lossless = !!(pageSegmentFlags & 1);
- pageInfo.refinement = !!(pageSegmentFlags & 2);
- pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
- pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
- pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
- pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
- args = [pageInfo];
- break;
- case 49:
- break;
- case 50:
- break;
- case 51:
- break;
- case 53:
- args = [header.number, data, position, end];
- break;
- case 62:
- break;
- default:
- throw new Jbig2Error(`segment type ${header.typeName}(${header.type}) is not implemented`);
- }
- const callbackName = "on" + header.typeName;
- if (callbackName in visitor) {
- visitor[callbackName].apply(visitor, args);
- }
- }
- function processSegments(segments, visitor) {
- for (let i = 0, ii = segments.length; i < ii; i++) {
- processSegment(segments[i], visitor);
- }
- }
- function parseJbig2Chunks(chunks) {
- const visitor = new SimpleSegmentVisitor();
- for (let i = 0, ii = chunks.length; i < ii; i++) {
- const chunk = chunks[i];
- const segments = readSegments({}, chunk.data, chunk.start, chunk.end);
- processSegments(segments, visitor);
- }
- return visitor.buffer;
- }
- function parseJbig2(data) {
- throw new Error("Not implemented: parseJbig2");
- }
- class SimpleSegmentVisitor {
- onPageInformation(info) {
- this.currentPageInfo = info;
- const rowSize = info.width + 7 >> 3;
- const buffer = new Uint8ClampedArray(rowSize * info.height);
- if (info.defaultPixelValue) {
- buffer.fill(0xff);
- }
- this.buffer = buffer;
- }
- drawBitmap(regionInfo, bitmap) {
- const pageInfo = this.currentPageInfo;
- const width = regionInfo.width,
- height = regionInfo.height;
- const rowSize = pageInfo.width + 7 >> 3;
- const combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
- const buffer = this.buffer;
- const mask0 = 128 >> (regionInfo.x & 7);
- let offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
- let i, j, mask, offset;
- switch (combinationOperator) {
- case 0:
- for (i = 0; i < height; i++) {
- mask = mask0;
- offset = offset0;
- for (j = 0; j < width; j++) {
- if (bitmap[i][j]) {
- buffer[offset] |= mask;
- }
- mask >>= 1;
- if (!mask) {
- mask = 128;
- offset++;
- }
- }
- offset0 += rowSize;
- }
- break;
- case 2:
- for (i = 0; i < height; i++) {
- mask = mask0;
- offset = offset0;
- for (j = 0; j < width; j++) {
- if (bitmap[i][j]) {
- buffer[offset] ^= mask;
- }
- mask >>= 1;
- if (!mask) {
- mask = 128;
- offset++;
- }
- }
- offset0 += rowSize;
- }
- break;
- default:
- throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
- }
- }
- onImmediateGenericRegion(region, data, start, end) {
- const regionInfo = region.info;
- const decodingContext = new DecodingContext(data, start, end);
- const bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
- this.drawBitmap(regionInfo, bitmap);
- }
- onImmediateLosslessGenericRegion() {
- this.onImmediateGenericRegion.apply(this, arguments);
- }
- onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
- let huffmanTables, huffmanInput;
- if (dictionary.huffman) {
- huffmanTables = getSymbolDictionaryHuffmanTables(dictionary, referredSegments, this.customTables);
- huffmanInput = new Reader(data, start, end);
- }
- let symbols = this.symbols;
- if (!symbols) {
- this.symbols = symbols = {};
- }
- const inputSymbols = [];
- for (const referredSegment of referredSegments) {
- const referredSymbols = symbols[referredSegment];
- if (referredSymbols) {
- inputSymbols.push(...referredSymbols);
- }
- }
- const decodingContext = new DecodingContext(data, start, end);
- symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext, huffmanInput);
- }
- onImmediateTextRegion(region, referredSegments, data, start, end) {
- const regionInfo = region.info;
- let huffmanTables, huffmanInput;
- const symbols = this.symbols;
- const inputSymbols = [];
- for (const referredSegment of referredSegments) {
- const referredSymbols = symbols[referredSegment];
- if (referredSymbols) {
- inputSymbols.push(...referredSymbols);
- }
- }
- const symbolCodeLength = (0, _core_utils.log2)(inputSymbols.length);
- if (region.huffman) {
- huffmanInput = new Reader(data, start, end);
- huffmanTables = getTextRegionHuffmanTables(region, referredSegments, this.customTables, inputSymbols.length, huffmanInput);
- }
- const decodingContext = new DecodingContext(data, start, end);
- const bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext, region.logStripSize, huffmanInput);
- this.drawBitmap(regionInfo, bitmap);
- }
- onImmediateLosslessTextRegion() {
- this.onImmediateTextRegion.apply(this, arguments);
- }
- onPatternDictionary(dictionary, currentSegment, data, start, end) {
- let patterns = this.patterns;
- if (!patterns) {
- this.patterns = patterns = {};
- }
- const decodingContext = new DecodingContext(data, start, end);
- patterns[currentSegment] = decodePatternDictionary(dictionary.mmr, dictionary.patternWidth, dictionary.patternHeight, dictionary.maxPatternIndex, dictionary.template, decodingContext);
- }
- onImmediateHalftoneRegion(region, referredSegments, data, start, end) {
- const patterns = this.patterns[referredSegments[0]];
- const regionInfo = region.info;
- const decodingContext = new DecodingContext(data, start, end);
- 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);
- this.drawBitmap(regionInfo, bitmap);
- }
- onImmediateLosslessHalftoneRegion() {
- this.onImmediateHalftoneRegion.apply(this, arguments);
- }
- onTables(currentSegment, data, start, end) {
- let customTables = this.customTables;
- if (!customTables) {
- this.customTables = customTables = {};
- }
- customTables[currentSegment] = decodeTablesSegment(data, start, end);
- }
- }
- class HuffmanLine {
- constructor(lineData) {
- if (lineData.length === 2) {
- this.isOOB = true;
- this.rangeLow = 0;
- this.prefixLength = lineData[0];
- this.rangeLength = 0;
- this.prefixCode = lineData[1];
- this.isLowerRange = false;
- } else {
- this.isOOB = false;
- this.rangeLow = lineData[0];
- this.prefixLength = lineData[1];
- this.rangeLength = lineData[2];
- this.prefixCode = lineData[3];
- this.isLowerRange = lineData[4] === "lower";
- }
- }
- }
- class HuffmanTreeNode {
- constructor(line) {
- this.children = [];
- if (line) {
- this.isLeaf = true;
- this.rangeLength = line.rangeLength;
- this.rangeLow = line.rangeLow;
- this.isLowerRange = line.isLowerRange;
- this.isOOB = line.isOOB;
- } else {
- this.isLeaf = false;
- }
- }
- buildTree(line, shift) {
- const bit = line.prefixCode >> shift & 1;
- if (shift <= 0) {
- this.children[bit] = new HuffmanTreeNode(line);
- } else {
- let node = this.children[bit];
- if (!node) {
- this.children[bit] = node = new HuffmanTreeNode(null);
- }
- node.buildTree(line, shift - 1);
- }
- }
- decodeNode(reader) {
- if (this.isLeaf) {
- if (this.isOOB) {
- return null;
- }
- const htOffset = reader.readBits(this.rangeLength);
- return this.rangeLow + (this.isLowerRange ? -htOffset : htOffset);
- }
- const node = this.children[reader.readBit()];
- if (!node) {
- throw new Jbig2Error("invalid Huffman data");
- }
- return node.decodeNode(reader);
- }
- }
- class HuffmanTable {
- constructor(lines, prefixCodesDone) {
- if (!prefixCodesDone) {
- this.assignPrefixCodes(lines);
- }
- this.rootNode = new HuffmanTreeNode(null);
- for (let i = 0, ii = lines.length; i < ii; i++) {
- const line = lines[i];
- if (line.prefixLength > 0) {
- this.rootNode.buildTree(line, line.prefixLength - 1);
- }
- }
- }
- decode(reader) {
- return this.rootNode.decodeNode(reader);
- }
- assignPrefixCodes(lines) {
- const linesLength = lines.length;
- let prefixLengthMax = 0;
- for (let i = 0; i < linesLength; i++) {
- prefixLengthMax = Math.max(prefixLengthMax, lines[i].prefixLength);
- }
- const histogram = new Uint32Array(prefixLengthMax + 1);
- for (let i = 0; i < linesLength; i++) {
- histogram[lines[i].prefixLength]++;
- }
- let currentLength = 1,
- firstCode = 0,
- currentCode,
- currentTemp,
- line;
- histogram[0] = 0;
- while (currentLength <= prefixLengthMax) {
- firstCode = firstCode + histogram[currentLength - 1] << 1;
- currentCode = firstCode;
- currentTemp = 0;
- while (currentTemp < linesLength) {
- line = lines[currentTemp];
- if (line.prefixLength === currentLength) {
- line.prefixCode = currentCode;
- currentCode++;
- }
- currentTemp++;
- }
- currentLength++;
- }
- }
- }
- function decodeTablesSegment(data, start, end) {
- const flags = data[start];
- const lowestValue = (0, _core_utils.readUint32)(data, start + 1) & 0xffffffff;
- const highestValue = (0, _core_utils.readUint32)(data, start + 5) & 0xffffffff;
- const reader = new Reader(data, start + 9, end);
- const prefixSizeBits = (flags >> 1 & 7) + 1;
- const rangeSizeBits = (flags >> 4 & 7) + 1;
- const lines = [];
- let prefixLength,
- rangeLength,
- currentRangeLow = lowestValue;
- do {
- prefixLength = reader.readBits(prefixSizeBits);
- rangeLength = reader.readBits(rangeSizeBits);
- lines.push(new HuffmanLine([currentRangeLow, prefixLength, rangeLength, 0]));
- currentRangeLow += 1 << rangeLength;
- } while (currentRangeLow < highestValue);
- prefixLength = reader.readBits(prefixSizeBits);
- lines.push(new HuffmanLine([lowestValue - 1, prefixLength, 32, 0, "lower"]));
- prefixLength = reader.readBits(prefixSizeBits);
- lines.push(new HuffmanLine([highestValue, prefixLength, 32, 0]));
- if (flags & 1) {
- prefixLength = reader.readBits(prefixSizeBits);
- lines.push(new HuffmanLine([prefixLength, 0]));
- }
- return new HuffmanTable(lines, false);
- }
- const standardTablesCache = {};
- function getStandardTable(number) {
- let table = standardTablesCache[number];
- if (table) {
- return table;
- }
- let lines;
- switch (number) {
- case 1:
- lines = [[0, 1, 4, 0x0], [16, 2, 8, 0x2], [272, 3, 16, 0x6], [65808, 3, 32, 0x7]];
- break;
- case 2:
- 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]];
- break;
- case 3:
- 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]];
- break;
- case 4:
- 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]];
- break;
- case 5:
- 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]];
- break;
- case 6:
- 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]];
- break;
- case 7:
- 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]];
- break;
- case 8:
- 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]];
- break;
- case 9:
- 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]];
- break;
- case 10:
- 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]];
- break;
- case 11:
- 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]];
- break;
- case 12:
- 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]];
- break;
- case 13:
- 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]];
- break;
- case 14:
- lines = [[-2, 3, 0, 0x4], [-1, 3, 0, 0x5], [0, 1, 0, 0x0], [1, 3, 0, 0x6], [2, 3, 0, 0x7]];
- break;
- case 15:
- 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]];
- break;
- default:
- throw new Jbig2Error(`standard table B.${number} does not exist`);
- }
- for (let i = 0, ii = lines.length; i < ii; i++) {
- lines[i] = new HuffmanLine(lines[i]);
- }
- table = new HuffmanTable(lines, true);
- standardTablesCache[number] = table;
- return table;
- }
- class Reader {
- constructor(data, start, end) {
- this.data = data;
- this.start = start;
- this.end = end;
- this.position = start;
- this.shift = -1;
- this.currentByte = 0;
- }
- readBit() {
- if (this.shift < 0) {
- if (this.position >= this.end) {
- throw new Jbig2Error("end of data while reading bit");
- }
- this.currentByte = this.data[this.position++];
- this.shift = 7;
- }
- const bit = this.currentByte >> this.shift & 1;
- this.shift--;
- return bit;
- }
- readBits(numBits) {
- let result = 0,
- i;
- for (i = numBits - 1; i >= 0; i--) {
- result |= this.readBit() << i;
- }
- return result;
- }
- byteAlign() {
- this.shift = -1;
- }
- next() {
- if (this.position >= this.end) {
- return -1;
- }
- return this.data[this.position++];
- }
- }
- function getCustomHuffmanTable(index, referredTo, customTables) {
- let currentIndex = 0;
- for (let i = 0, ii = referredTo.length; i < ii; i++) {
- const table = customTables[referredTo[i]];
- if (table) {
- if (index === currentIndex) {
- return table;
- }
- currentIndex++;
- }
- }
- throw new Jbig2Error("can't find custom Huffman table");
- }
- function getTextRegionHuffmanTables(textRegion, referredTo, customTables, numberOfSymbols, reader) {
- const codes = [];
- for (let i = 0; i <= 34; i++) {
- const codeLength = reader.readBits(4);
- codes.push(new HuffmanLine([i, codeLength, 0, 0]));
- }
- const runCodesTable = new HuffmanTable(codes, false);
- codes.length = 0;
- for (let i = 0; i < numberOfSymbols;) {
- const codeLength = runCodesTable.decode(reader);
- if (codeLength >= 32) {
- let repeatedLength, numberOfRepeats, j;
- switch (codeLength) {
- case 32:
- if (i === 0) {
- throw new Jbig2Error("no previous value in symbol ID table");
- }
- numberOfRepeats = reader.readBits(2) + 3;
- repeatedLength = codes[i - 1].prefixLength;
- break;
- case 33:
- numberOfRepeats = reader.readBits(3) + 3;
- repeatedLength = 0;
- break;
- case 34:
- numberOfRepeats = reader.readBits(7) + 11;
- repeatedLength = 0;
- break;
- default:
- throw new Jbig2Error("invalid code length in symbol ID table");
- }
- for (j = 0; j < numberOfRepeats; j++) {
- codes.push(new HuffmanLine([i, repeatedLength, 0, 0]));
- i++;
- }
- } else {
- codes.push(new HuffmanLine([i, codeLength, 0, 0]));
- i++;
- }
- }
- reader.byteAlign();
- const symbolIDTable = new HuffmanTable(codes, false);
- let customIndex = 0,
- tableFirstS,
- tableDeltaS,
- tableDeltaT;
- switch (textRegion.huffmanFS) {
- case 0:
- case 1:
- tableFirstS = getStandardTable(textRegion.huffmanFS + 6);
- break;
- case 3:
- tableFirstS = getCustomHuffmanTable(customIndex, referredTo, customTables);
- customIndex++;
- break;
- default:
- throw new Jbig2Error("invalid Huffman FS selector");
- }
- switch (textRegion.huffmanDS) {
- case 0:
- case 1:
- case 2:
- tableDeltaS = getStandardTable(textRegion.huffmanDS + 8);
- break;
- case 3:
- tableDeltaS = getCustomHuffmanTable(customIndex, referredTo, customTables);
- customIndex++;
- break;
- default:
- throw new Jbig2Error("invalid Huffman DS selector");
- }
- switch (textRegion.huffmanDT) {
- case 0:
- case 1:
- case 2:
- tableDeltaT = getStandardTable(textRegion.huffmanDT + 11);
- break;
- case 3:
- tableDeltaT = getCustomHuffmanTable(customIndex, referredTo, customTables);
- customIndex++;
- break;
- default:
- throw new Jbig2Error("invalid Huffman DT selector");
- }
- if (textRegion.refinement) {
- throw new Jbig2Error("refinement with Huffman is not supported");
- }
- return {
- symbolIDTable,
- tableFirstS,
- tableDeltaS,
- tableDeltaT
- };
- }
- function getSymbolDictionaryHuffmanTables(dictionary, referredTo, customTables) {
- let customIndex = 0,
- tableDeltaHeight,
- tableDeltaWidth;
- switch (dictionary.huffmanDHSelector) {
- case 0:
- case 1:
- tableDeltaHeight = getStandardTable(dictionary.huffmanDHSelector + 4);
- break;
- case 3:
- tableDeltaHeight = getCustomHuffmanTable(customIndex, referredTo, customTables);
- customIndex++;
- break;
- default:
- throw new Jbig2Error("invalid Huffman DH selector");
- }
- switch (dictionary.huffmanDWSelector) {
- case 0:
- case 1:
- tableDeltaWidth = getStandardTable(dictionary.huffmanDWSelector + 2);
- break;
- case 3:
- tableDeltaWidth = getCustomHuffmanTable(customIndex, referredTo, customTables);
- customIndex++;
- break;
- default:
- throw new Jbig2Error("invalid Huffman DW selector");
- }
- let tableBitmapSize, tableAggregateInstances;
- if (dictionary.bitmapSizeSelector) {
- tableBitmapSize = getCustomHuffmanTable(customIndex, referredTo, customTables);
- customIndex++;
- } else {
- tableBitmapSize = getStandardTable(1);
- }
- if (dictionary.aggregationInstancesSelector) {
- tableAggregateInstances = getCustomHuffmanTable(customIndex, referredTo, customTables);
- } else {
- tableAggregateInstances = getStandardTable(1);
- }
- return {
- tableDeltaHeight,
- tableDeltaWidth,
- tableBitmapSize,
- tableAggregateInstances
- };
- }
- function readUncompressedBitmap(reader, width, height) {
- const bitmap = [];
- for (let y = 0; y < height; y++) {
- const row = new Uint8Array(width);
- bitmap.push(row);
- for (let x = 0; x < width; x++) {
- row[x] = reader.readBit();
- }
- reader.byteAlign();
- }
- return bitmap;
- }
- function decodeMMRBitmap(input, width, height, endOfBlock) {
- const params = {
- K: -1,
- Columns: width,
- Rows: height,
- BlackIs1: true,
- EndOfBlock: endOfBlock
- };
- const decoder = new _ccitt.CCITTFaxDecoder(input, params);
- const bitmap = [];
- let currentByte,
- eof = false;
- for (let y = 0; y < height; y++) {
- const row = new Uint8Array(width);
- bitmap.push(row);
- let shift = -1;
- for (let x = 0; x < width; x++) {
- if (shift < 0) {
- currentByte = decoder.readNextChar();
- if (currentByte === -1) {
- currentByte = 0;
- eof = true;
- }
- shift = 7;
- }
- row[x] = currentByte >> shift & 1;
- shift--;
- }
- }
- if (endOfBlock && !eof) {
- const lookForEOFLimit = 5;
- for (let i = 0; i < lookForEOFLimit; i++) {
- if (decoder.readNextChar() === -1) {
- break;
- }
- }
- }
- return bitmap;
- }
- class Jbig2Image {
- parseChunks(chunks) {
- return parseJbig2Chunks(chunks);
- }
- parse(data) {
- throw new Error("Not implemented: Jbig2Image.parse");
- }
- }
- exports.Jbig2Image = Jbig2Image;
|