: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if (line.prefixLength > 0) {
this.rootNode.buildTree(line, line.prefixLength - 1);
return this.rootNode.decodeNode(reader);
assignPrefixCodes(lines) {
const linesLength = lines.length;
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]++;
while (currentLength <= prefixLengthMax) {
firstCode = firstCode + histogram[currentLength - 1] << 1;
while (currentTemp < linesLength) {
line = lines[currentTemp];
if (line.prefixLength === currentLength) {
line.prefixCode = currentCode;
function decodeTablesSegment(data, start, end) {
const flags = data[start];
const lowestValue = readUint32(data, start + 1) & 0xffffffff;
const highestValue = 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;
currentRangeLow = lowestValue;
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]));
prefixLength = reader.readBits(prefixSizeBits);
lines.push(new HuffmanLine([prefixLength, 0]));
return new HuffmanTable(lines, false);
const standardTablesCache = {};
function getStandardTable(number) {
let table = standardTablesCache[number];
lines = [[0, 1, 4, 0x0], [16, 2, 8, 0x2], [272, 3, 16, 0x6], [65808, 3, 32, 0x7]];
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]];
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]];
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]];
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]];
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]];
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]];
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]];
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]];
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]];
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]];
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]];
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]];
lines = [[-2, 3, 0, 0x4], [-1, 3, 0, 0x5], [0, 1, 0, 0x0], [1, 3, 0, 0x6], [2, 3, 0, 0x7]];
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]];
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;
constructor(data, start, end) {
if (this.position >= this.end) {
throw new Jbig2Error("end of data while reading bit");
this.currentByte = this.data[this.position++];
const bit = this.currentByte >> this.shift & 1;
for (i = numBits - 1; i >= 0; i--) {
result |= this.readBit() << i;
if (this.position >= this.end) {
return this.data[this.position++];
function getCustomHuffmanTable(index, referredTo, customTables) {
for (let i = 0, ii = referredTo.length; i < ii; i++) {
const table = customTables[referredTo[i]];
if (index === currentIndex) {
throw new Jbig2Error("can't find custom Huffman table");
function getTextRegionHuffmanTables(textRegion, referredTo, customTables, numberOfSymbols, reader) {
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);
for (let i = 0; i < numberOfSymbols;) {
const codeLength = runCodesTable.decode(reader);
let repeatedLength, numberOfRepeats, j;
throw new Jbig2Error("no previous value in symbol ID table");
numberOfRepeats = reader.readBits(2) + 3;
repeatedLength = codes[i - 1].prefixLength;
numberOfRepeats = reader.readBits(3) + 3;
numberOfRepeats = reader.readBits(7) + 11;
throw new Jbig2Error("invalid code length in symbol ID table");
for (j = 0; j < numberOfRepeats; j++) {
codes.push(new HuffmanLine([i, repeatedLength, 0, 0]));
codes.push(new HuffmanLine([i, codeLength, 0, 0]));
const symbolIDTable = new HuffmanTable(codes, false);
switch (textRegion.huffmanFS) {
tableFirstS = getStandardTable(textRegion.huffmanFS + 6);
tableFirstS = getCustomHuffmanTable(customIndex, referredTo, customTables);
throw new Jbig2Error("invalid Huffman FS selector");
switch (textRegion.huffmanDS) {
tableDeltaS = getStandardTable(textRegion.huffmanDS + 8);
tableDeltaS = getCustomHuffmanTable(customIndex, referredTo, customTables);
throw new Jbig2Error("invalid Huffman DS selector");
switch (textRegion.huffmanDT) {
tableDeltaT = getStandardTable(textRegion.huffmanDT + 11);
tableDeltaT = getCustomHuffmanTable(customIndex, referredTo, customTables);
throw new Jbig2Error("invalid Huffman DT selector");
if (textRegion.refinement) {
throw new Jbig2Error("refinement with Huffman is not supported");
function getSymbolDictionaryHuffmanTables(dictionary, referredTo, customTables) {
switch (dictionary.huffmanDHSelector) {
tableDeltaHeight = getStandardTable(dictionary.huffmanDHSelector + 4);
tableDeltaHeight = getCustomHuffmanTable(customIndex, referredTo, customTables);
throw new Jbig2Error("invalid Huffman DH selector");
switch (dictionary.huffmanDWSelector) {
tableDeltaWidth = getStandardTable(dictionary.huffmanDWSelector + 2);
tableDeltaWidth = getCustomHuffmanTable(customIndex, referredTo, customTables);
throw new Jbig2Error("invalid Huffman DW selector");
let tableBitmapSize, tableAggregateInstances;
if (dictionary.bitmapSizeSelector) {
tableBitmapSize = getCustomHuffmanTable(customIndex, referredTo, customTables);
tableBitmapSize = getStandardTable(1);
if (dictionary.aggregationInstancesSelector) {
tableAggregateInstances = getCustomHuffmanTable(customIndex, referredTo, customTables);
tableAggregateInstances = getStandardTable(1);
function readUncompressedBitmap(reader, width, height) {
for (let y = 0; y < height; y++) {
const row = new Uint8Array(width);
for (let x = 0; x < width; x++) {
row[x] = reader.readBit();
function decodeMMRBitmap(input, width, height, endOfBlock) {
const decoder = new CCITTFaxDecoder(input, params);
for (let y = 0; y < height; y++) {
const row = new Uint8Array(width);
for (let x = 0; x < width; x++) {
currentByte = decoder.readNextChar();
if (currentByte === -1) {
row[x] = currentByte >> shift & 1;
if (endOfBlock && !eof) {
const lookForEOFLimit = 5;
for (let i = 0; i < lookForEOFLimit; i++) {
if (decoder.readNextChar() === -1) {
return parseJbig2Chunks(chunks);
throw new Error("Not implemented: Jbig2Image.parse");
;// CONCATENATED MODULE: ./src/core/jbig2_stream.js
class Jbig2Stream extends DecodeStream {
constructor(stream, maybeLength, params) {
this.maybeLength = maybeLength;
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
ensureBuffer(requested) {}
const jbig2Image = new Jbig2Image();
if (this.params instanceof Dict) {
const globalsStream = this.params.get("JBIG2Globals");
if (globalsStream instanceof BaseStream) {
const globals = globalsStream.getBytes();
const data = jbig2Image.parseChunks(chunks);
const dataLength = data.length;
for (let i = 0; i < dataLength; i++) {
this.bufferLength = dataLength;
;// CONCATENATED MODULE: ./src/shared/image_utils.js
function convertToRGBA(params) {
case ImageKind.GRAYSCALE_1BPP:
return convertBlackAndWhiteToRGBA(params);
case ImageKind.RGB_24BPP:
return convertRGBToRGBA(params);
function convertBlackAndWhiteToRGBA({
nonBlackColor = 0xffffffff,
const black = FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor];
const widthInSource = width >> 3;
const widthRemainder = width & 7;
const srcLength = src.length;
dest = new Uint32Array(dest.buffer);
for (let i = 0; i < height; i++) {
for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
const elem = srcPos < srcLength ? src[srcPos] : 255;
dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping;
dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping;
dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping;
dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping;
dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping;
dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping;
dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping;
dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping;
if (widthRemainder === 0) {
const elem = srcPos < srcLength ? src[srcPos++] : 255;
for (let j = 0; j < widthRemainder; j++) {
dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
function convertRGBToRGBA({