: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
const numComps = this.numComps;
const scaled = new Float32Array(numComps);
const tinted = new Float32Array(baseNumComps);
for (i = 0; i < count; i++) {
for (j = 0; j < numComps; j++) {
scaled[j] = src[srcOffset++] * scale;
tintFn(scaled, 0, tinted, 0);
if (usesZeroToOneRange) {
for (j = 0; j < baseNumComps; j++) {
baseBuf[pos++] = tinted[j] * 255;
base.getRgbItem(tinted, 0, baseBuf, pos);
base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
getOutputLength(inputLength, alpha01) {
return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
class PatternCS extends ColorSpace {
isDefaultDecode(decodeMap, bpc) {
unreachable("Should not call PatternCS.isDefaultDecode");
class IndexedCS extends ColorSpace {
constructor(base, highVal, lookup) {
const length = base.numComps * highVal;
this.lookup = new Uint8Array(length);
if (lookup instanceof BaseStream) {
const bytes = lookup.getBytes(length);
} else if (typeof lookup === "string") {
for (let i = 0; i < length; ++i) {
this.lookup[i] = lookup.charCodeAt(i) & 0xff;
throw new FormatError(`IndexedCS - unrecognized lookup table: ${lookup}`);
getRgbItem(src, srcOffset, dest, destOffset) {
const numComps = this.base.numComps;
const start = src[srcOffset] * numComps;
this.base.getRgbBuffer(this.lookup, start, 1, dest, destOffset, 8, 0);
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
const numComps = base.numComps;
const outputDelta = base.getOutputLength(numComps, alpha01);
const lookup = this.lookup;
for (let i = 0; i < count; ++i) {
const lookupPos = src[srcOffset++] * numComps;
base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
destOffset += outputDelta;
getOutputLength(inputLength, alpha01) {
return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
isDefaultDecode(decodeMap, bpc) {
if (!Array.isArray(decodeMap)) {
if (decodeMap.length !== 2) {
warn("Decode map length is not correct");
if (!Number.isInteger(bpc) || bpc < 1) {
warn("Bits per component is not correct");
return decodeMap[0] === 0 && decodeMap[1] === (1 << bpc) - 1;
class DeviceGrayCS extends ColorSpace {
getRgbItem(src, srcOffset, dest, destOffset) {
const c = src[srcOffset] * 255;
dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
const scale = 255 / ((1 << bits) - 1);
for (let i = 0; i < count; ++i) {
const c = scale * src[j++];
getOutputLength(inputLength, alpha01) {
return inputLength * (3 + alpha01);
class DeviceRgbCS extends ColorSpace {
getRgbItem(src, srcOffset, dest, destOffset) {
dest[destOffset] = src[srcOffset] * 255;
dest[destOffset + 1] = src[srcOffset + 1] * 255;
dest[destOffset + 2] = src[srcOffset + 2] * 255;
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
if (bits === 8 && alpha01 === 0) {
dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
const scale = 255 / ((1 << bits) - 1);
for (let i = 0; i < count; ++i) {
dest[q++] = scale * src[j++];
dest[q++] = scale * src[j++];
dest[q++] = scale * src[j++];
getOutputLength(inputLength, alpha01) {
return inputLength * (3 + alpha01) / 3 | 0;
class DeviceCmykCS extends ColorSpace {
#toRgb(src, srcOffset, srcScale, dest, destOffset) {
const c = src[srcOffset] * srcScale;
const m = src[srcOffset + 1] * srcScale;
const y = src[srcOffset + 2] * srcScale;
const k = src[srcOffset + 3] * srcScale;
dest[destOffset] = 255 + c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k + -285.2331026137004) + m * (1.7149763477362134 * m - 5.6096736904047315 * y + -17.873870861415444 * k - 5.497006427196366) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) + k * (-21.86122147463605 * k - 189.48180835922747);
dest[destOffset + 1] = 255 + c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k + -79.2970844816548) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) + y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + k * (-20.737325471181034 * k - 187.80453709719578);
dest[destOffset + 2] = 255 + c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k + -14.183576799673286) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) + y * (0.03296041114873217 * y + 115.60384449646641 * k + -193.58209356861505) + k * (-22.33816807309886 * k - 180.12613974708367);
getRgbItem(src, srcOffset, dest, destOffset) {
this.#toRgb(src, srcOffset, 1, dest, destOffset);
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
const scale = 1 / ((1 << bits) - 1);
for (let i = 0; i < count; i++) {
this.#toRgb(src, srcOffset, scale, dest, destOffset);
destOffset += 3 + alpha01;
getOutputLength(inputLength, alpha01) {
return inputLength / 4 * (3 + alpha01) | 0;
class CalGrayCS extends ColorSpace {
constructor(whitePoint, blackPoint, gamma) {
throw new FormatError("WhitePoint missing - required for color space CalGray");
[this.XW, this.YW, this.ZW] = whitePoint;
[this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0];
if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
throw new FormatError(`Invalid WhitePoint components for ${this.name}, no fallback available`);
if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
info(`Invalid BlackPoint for ${this.name}, falling back to default.`);
this.XB = this.YB = this.ZB = 0;
if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
warn(`${this.name}, BlackPoint: XB: ${this.XB}, YB: ${this.YB}, ` + `ZB: ${this.ZB}, only default values are supported.`);
info(`Invalid Gamma: ${this.G} for ${this.name}, falling back to default.`);
#toRgb(src, srcOffset, dest, destOffset, scale) {
const A = src[srcOffset] * scale;
const val = Math.max(295.8 * L ** 0.3333333333333333 - 40.8, 0);
dest[destOffset + 1] = val;
dest[destOffset + 2] = val;
getRgbItem(src, srcOffset, dest, destOffset) {
this.#toRgb(src, srcOffset, dest, destOffset, 1);
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
const scale = 1 / ((1 << bits) - 1);
for (let i = 0; i < count; ++i) {
this.#toRgb(src, srcOffset, dest, destOffset, scale);
destOffset += 3 + alpha01;
getOutputLength(inputLength, alpha01) {
return inputLength * (3 + alpha01);
class CalRGBCS extends ColorSpace {
static #BRADFORD_SCALE_MATRIX = new Float32Array([0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296]);
static #BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([0.9869929, -0.1470543, 0.1599627, 0.4323053, 0.5183603, 0.0492912, -0.0085287, 0.0400428, 0.9684867]);
static #SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([3.2404542, -1.5371385, -0.4985314, -0.9692660, 1.8760108, 0.0415560, 0.0556434, -0.2040259, 1.0572252]);
static #FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
static #tempNormalizeMatrix = new Float32Array(3);
static #tempConvertMatrix1 = new Float32Array(3);
static #tempConvertMatrix2 = new Float32Array(3);
static #DECODE_L_CONSTANT = ((8 + 16) / 116) ** 3 / 8.0;
constructor(whitePoint, blackPoint, gamma, matrix) {
throw new FormatError("WhitePoint missing - required for color space CalRGB");
const [XW, YW, ZW] = this.whitePoint = whitePoint;
const [XB, YB, ZB] = this.blackPoint = blackPoint || new Float32Array(3);
[this.GR, this.GG, this.GB] = gamma || new Float32Array([1, 1, 1]);
[this.MXA, this.MYA, this.MZA, this.MXB, this.MYB, this.MZB, this.MXC, this.MYC, this.MZC] = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
if (XW < 0 || ZW < 0 || YW !== 1) {
throw new FormatError(`Invalid WhitePoint components for ${this.name}, no fallback available`);
if (XB < 0 || YB < 0 || ZB < 0) {
info(`Invalid BlackPoint for ${this.name} [${XB}, ${YB}, ${ZB}], ` + "falling back to default.");
this.blackPoint = new Float32Array(3);
if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
info(`Invalid Gamma [${this.GR}, ${this.GG}, ${this.GB}] for ` + `${this.name}, falling back to default.`);
this.GR = this.GG = this.GB = 1;
#matrixProduct(a, b, result) {
result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
#toFlat(sourceWhitePoint, LMS, result) {
result[0] = LMS[0] * 1 / sourceWhitePoint[0];
result[1] = LMS[1] * 1 / sourceWhitePoint[1];
result[2] = LMS[2] * 1 / sourceWhitePoint[2];
#toD65(sourceWhitePoint, LMS, result) {
result[0] = LMS[0] * D65X / sourceWhitePoint[0];
result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
#sRGBTransferFunction(color) {
if (color <= 0.0031308) {
return this.#adjustToRange(0, 1, 12.92 * color);
if (color >= 0.99554525) {
return this.#adjustToRange(0, 1, (1 + 0.055) * color ** (1 / 2.4) - 0.055);
#adjustToRange(min, max, value) {
return Math.max(min, Math.min(max, value));
return -this.#decodeL(-L);
return ((L + 16) / 116) ** 3;
return L * CalRGBCS.#DECODE_L_CONSTANT;
#compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
const zeroDecodeL = this.#decodeL(0);
const X_DST = zeroDecodeL;
const X_SRC = this.#decodeL(sourceBlackPoint[0]);
const Y_DST = zeroDecodeL;
const Y_SRC = this.#decodeL(sourceBlackPoint[1]);
const Z_DST = zeroDecodeL;
const Z_SRC = this.#decodeL(sourceBlackPoint[2]);
const X_Scale = (1 - X_DST) / (1 - X_SRC);
const X_Offset = 1 - X_Scale;
const Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
const Y_Offset = 1 - Y_Scale;
const Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
const Z_Offset = 1 - Z_Scale;
result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
#normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
const LMS_Flat = CalRGBCS.#tempNormalizeMatrix;
this.#toFlat(sourceWhitePoint, LMS, LMS_Flat);
this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
#normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
const LMS_D65 = CalRGBCS.#tempNormalizeMatrix;
this.#toD65(sourceWhitePoint, LMS, LMS_D65);
this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
#toRgb(src, srcOffset, dest, destOffset, scale) {
const A = this.#adjustToRange(0, 1, src[srcOffset] * scale);
const B = this.#adjustToRange(0, 1, src[srcOffset + 1] * scale);
const C = this.#adjustToRange(0, 1, src[srcOffset + 2] * scale);
const AGR = A === 1 ? 1 : A ** this.GR;
const BGG = B === 1 ? 1 : B ** this.GG;
const CGB = C === 1 ? 1 : C ** this.GB;
const X = this.MXA * AGR + this.MXB * BGG + this.MXC * CGB;
const Y = this.MYA * AGR + this.MYB * BGG + this.MYC * CGB;
const Z = this.MZA * AGR + this.MZB * BGG + this.MZC * CGB;
const XYZ = CalRGBCS.#tempConvertMatrix1;
const XYZ_Flat = CalRGBCS.#tempConvertMatrix2;
this.#normalizeWhitePointToFlat(this.whitePoint, XYZ, XYZ_Flat);
const XYZ_Black = CalRGBCS.#tempConvertMatrix1;
this.#compensateBlackPoint(this.blackPoint, XYZ_Flat, XYZ_Black);
const XYZ_D65 = CalRGBCS.#tempConvertMatrix2;
this.#normalizeWhitePointToD65(CalRGBCS.#FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
const SRGB = CalRGBCS.#tempConvertMatrix1;
this.#matrixProduct(CalRGBCS.#SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
dest[destOffset] = this.#sRGBTransferFunction(SRGB[0]) * 255;
dest[destOffset + 1] = this.#sRGBTransferFunction(SRGB[1]) * 255;
dest[destOffset + 2] = this.#sRGBTransferFunction(SRGB[2]) * 255;
getRgbItem(src, srcOffset, dest, destOffset) {
this.#toRgb(src, srcOffset, dest, destOffset, 1);
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
const scale = 1 / ((1 << bits) - 1);
for (let i = 0; i < count; ++i) {
this.#toRgb(src, srcOffset, dest, destOffset, scale);
destOffset += 3 + alpha01;
getOutputLength(inputLength, alpha01) {
return inputLength * (3 + alpha01) / 3 | 0;
class LabCS extends ColorSpace {
constructor(whitePoint, blackPoint, range) {
throw new FormatError("WhitePoint missing - required for color space Lab");
[this.XW, this.YW, this.ZW] = whitePoint;
[this.amin, this.amax, this.bmin, this.bmax] = range || [-100, 100, -100, 100];
[this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0];
if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
throw new FormatError("Invalid WhitePoint components, no fallback available");
if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
info("Invalid BlackPoint, falling back to default");
this.XB = this.YB = this.ZB = 0;
if (this.amin > this.amax || this.bmin > this.bmax) {
info("Invalid Range, falling back to defaults");
return x >= 6 / 29 ? x ** 3 : 108 / 841 * (x - 4 / 29);
#decode(value, high1, low2, high2) {
return low2 + value * (high2 - low2) / high1;
#toRgb(src, srcOffset, maxVal, dest, destOffset) {
let as = src[srcOffset + 1];
let bs = src[srcOffset + 2];
Ls = this.#decode(Ls, maxVal, 0, 100);
as = this.#decode(as, maxVal, this.amin, this.amax);
bs = this.#decode(bs, maxVal, this.bmin, this.bmax);
} else if (as < this.amin) {
} else if (bs < this.bmin) {
const M = (Ls + 16) / 116;
const X = this.XW * this.#fn_g(L);
const Y = this.YW * this.#fn_g(M);
const Z = this.ZW * this.#fn_g(N);
r = X * 3.1339 + Y * -1.617 + Z * -0.4906;
g = X * -0.9785 + Y * 1.916 + Z * 0.0333;
b = X * 0.072 + Y * -0.229 + Z * 1.4057;
r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
b = X * 0.0557 + Y * -0.204 + Z * 1.057;
dest[destOffset] = Math.sqrt(r) * 255;
dest[destOffset + 1] = Math.sqrt(g) * 255;
dest[destOffset + 2] = Math.sqrt(b) * 255;
getRgbItem(src, srcOffset, dest, destOffset) {
this.#toRgb(src, srcOffset, false, dest, destOffset);
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
const maxVal = (1 << bits) - 1;
for (let i = 0; i < count; i++) {
this.#toRgb(src, srcOffset, maxVal, dest, destOffset);
destOffset += 3 + alpha01;
getOutputLength(inputLength, alpha01) {
return inputLength * (3 + alpha01) / 3 | 0;
isDefaultDecode(decodeMap, bpc) {
get usesZeroToOneRange() {
return shadow(this, "usesZeroToOneRange", false);
;// CONCATENATED MODULE: ./src/core/binary_cmap.js
function hexToInt(a, size) {
for (let i = 0; i <= size; i++) {
function hexToStr(a, size) {
return String.fromCharCode(a[0], a[1]);
return String.fromCharCode(a[0], a[1], a[2], a[3]);
return String.fromCharCode(...a.subarray(0, size + 1));
function addHex(a, b, size) {
for (let i = size; i >= 0; i--) {
function incHex(a, size) {
for (let i = size; i >= 0 && c > 0; i--) {