Remove the closure from the CalGrayCS
class
Now that modern JavaScript is fully supported also in the worker-thread we no longer need to keep old closures, which slightly reduces the size of the code.
This commit is contained in:
parent
d2c8997380
commit
4d615f087f
@ -886,26 +886,7 @@ class DeviceCmykCS extends ColorSpace {
|
|||||||
*
|
*
|
||||||
* The default color is `new Float32Array([0])`.
|
* The default color is `new Float32Array([0])`.
|
||||||
*/
|
*/
|
||||||
const CalGrayCS = (function CalGrayCSClosure() {
|
class CalGrayCS extends ColorSpace {
|
||||||
function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
|
|
||||||
// A represents a gray component of a calibrated gray space.
|
|
||||||
// A <---> AG in the spec
|
|
||||||
const A = src[srcOffset] * scale;
|
|
||||||
const AG = A ** cs.G;
|
|
||||||
|
|
||||||
// Computes L as per spec. ( = cs.YW * AG )
|
|
||||||
// Except if other than default BlackPoint values are used.
|
|
||||||
const L = cs.YW * AG;
|
|
||||||
// http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
|
|
||||||
// Convert values to rgb range [0, 255].
|
|
||||||
const val = Math.max(295.8 * L ** 0.3333333333333333 - 40.8, 0);
|
|
||||||
dest[destOffset] = val;
|
|
||||||
dest[destOffset + 1] = val;
|
|
||||||
dest[destOffset + 2] = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-shadow
|
|
||||||
class CalGrayCS extends ColorSpace {
|
|
||||||
constructor(whitePoint, blackPoint, gamma) {
|
constructor(whitePoint, blackPoint, gamma) {
|
||||||
super("CalGray", 1);
|
super("CalGray", 1);
|
||||||
|
|
||||||
@ -914,25 +895,15 @@ const CalGrayCS = (function CalGrayCSClosure() {
|
|||||||
"WhitePoint missing - required for color space CalGray"
|
"WhitePoint missing - required for color space CalGray"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
blackPoint ||= [0, 0, 0];
|
|
||||||
gamma ||= 1;
|
|
||||||
|
|
||||||
// Translate arguments to spec variables.
|
// Translate arguments to spec variables.
|
||||||
this.XW = whitePoint[0];
|
[this.XW, this.YW, this.ZW] = whitePoint;
|
||||||
this.YW = whitePoint[1];
|
[this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0];
|
||||||
this.ZW = whitePoint[2];
|
this.G = gamma || 1;
|
||||||
|
|
||||||
this.XB = blackPoint[0];
|
|
||||||
this.YB = blackPoint[1];
|
|
||||||
this.ZB = blackPoint[2];
|
|
||||||
|
|
||||||
this.G = gamma;
|
|
||||||
|
|
||||||
// Validate variables as per spec.
|
// Validate variables as per spec.
|
||||||
if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
|
if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
|
||||||
throw new FormatError(
|
throw new FormatError(
|
||||||
`Invalid WhitePoint components for ${this.name}` +
|
`Invalid WhitePoint components for ${this.name}, no fallback available`
|
||||||
", no fallback available"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,13 +921,29 @@ const CalGrayCS = (function CalGrayCSClosure() {
|
|||||||
|
|
||||||
if (this.G < 1) {
|
if (this.G < 1) {
|
||||||
info(
|
info(
|
||||||
`Invalid Gamma: ${this.G} for ${this.name}, ` +
|
`Invalid Gamma: ${this.G} for ${this.name}, falling back to default.`
|
||||||
"falling back to default."
|
|
||||||
);
|
);
|
||||||
this.G = 1;
|
this.G = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#toRgb(src, srcOffset, dest, destOffset, scale) {
|
||||||
|
// A represents a gray component of a calibrated gray space.
|
||||||
|
// A <---> AG in the spec
|
||||||
|
const A = src[srcOffset] * scale;
|
||||||
|
const AG = A ** this.G;
|
||||||
|
|
||||||
|
// Computes L as per spec. ( = this.YW * AG )
|
||||||
|
// Except if other than default BlackPoint values are used.
|
||||||
|
const L = this.YW * AG;
|
||||||
|
// http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
|
||||||
|
// Convert values to rgb range [0, 255].
|
||||||
|
const val = Math.max(295.8 * L ** 0.3333333333333333 - 40.8, 0);
|
||||||
|
dest[destOffset] = val;
|
||||||
|
dest[destOffset + 1] = val;
|
||||||
|
dest[destOffset + 2] = val;
|
||||||
|
}
|
||||||
|
|
||||||
getRgbItem(src, srcOffset, dest, destOffset) {
|
getRgbItem(src, srcOffset, dest, destOffset) {
|
||||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||||
assert(
|
assert(
|
||||||
@ -964,7 +951,7 @@ const CalGrayCS = (function CalGrayCSClosure() {
|
|||||||
'CalGrayCS.getRgbItem: Unsupported "dest" type.'
|
'CalGrayCS.getRgbItem: Unsupported "dest" type.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
convertToRgb(this, src, srcOffset, dest, destOffset, 1);
|
this.#toRgb(src, srcOffset, dest, destOffset, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
||||||
@ -977,7 +964,7 @@ const CalGrayCS = (function CalGrayCSClosure() {
|
|||||||
const scale = 1 / ((1 << bits) - 1);
|
const scale = 1 / ((1 << bits) - 1);
|
||||||
|
|
||||||
for (let i = 0; i < count; ++i) {
|
for (let i = 0; i < count; ++i) {
|
||||||
convertToRgb(this, src, srcOffset, dest, destOffset, scale);
|
this.#toRgb(src, srcOffset, dest, destOffset, scale);
|
||||||
srcOffset += 1;
|
srcOffset += 1;
|
||||||
destOffset += 3 + alpha01;
|
destOffset += 3 + alpha01;
|
||||||
}
|
}
|
||||||
@ -986,9 +973,7 @@ const CalGrayCS = (function CalGrayCSClosure() {
|
|||||||
getOutputLength(inputLength, alpha01) {
|
getOutputLength(inputLength, alpha01) {
|
||||||
return inputLength * (3 + alpha01);
|
return inputLength * (3 + alpha01);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CalGrayCS;
|
|
||||||
})();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
|
* CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
|
||||||
|
Loading…
Reference in New Issue
Block a user