Use shorthand method signatures in src/core/colorspace.js

This commit is contained in:
Jonas Jenwald 2018-06-11 17:25:33 +02:00
parent 32367c5968
commit d1637056b3

View File

@ -65,7 +65,7 @@ var ColorSpace = (function ColorSpaceClosure() {
* located in the src array starting from the srcOffset. Returns the array * located in the src array starting from the srcOffset. Returns the array
* of the rgb components, each value ranging from [0,255]. * of the rgb components, each value ranging from [0,255].
*/ */
getRgb: function ColorSpace_getRgb(src, srcOffset) { getRgb(src, srcOffset) {
var rgb = new Uint8Array(3); var rgb = new Uint8Array(3);
this.getRgbItem(src, srcOffset, rgb, 0); this.getRgbItem(src, srcOffset, rgb, 0);
return rgb; return rgb;
@ -74,8 +74,7 @@ var ColorSpace = (function ColorSpaceClosure() {
* Converts the color value to the RGB color, similar to the getRgb method. * Converts the color value to the RGB color, similar to the getRgb method.
* The result placed into the dest array starting from the destOffset. * The result placed into the dest array starting from the destOffset.
*/ */
getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, getRgbItem(src, srcOffset, dest, destOffset) {
dest, destOffset) {
unreachable('Should not call ColorSpace.getRgbItem'); unreachable('Should not call ColorSpace.getRgbItem');
}, },
/** /**
@ -87,9 +86,7 @@ var ColorSpace = (function ColorSpaceClosure() {
* there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
* array). * array).
*/ */
getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
dest, destOffset, bits,
alpha01) {
unreachable('Should not call ColorSpace.getRgbBuffer'); unreachable('Should not call ColorSpace.getRgbBuffer');
}, },
/** /**
@ -97,14 +94,13 @@ var ColorSpace = (function ColorSpaceClosure() {
* conversion done by the getRgbBuffer method. As in getRgbBuffer, * conversion done by the getRgbBuffer method. As in getRgbBuffer,
* |alpha01| is either 0 (RGB output) or 1 (RGBA output). * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
*/ */
getOutputLength: function ColorSpace_getOutputLength(inputLength, getOutputLength(inputLength, alpha01) {
alpha01) {
unreachable('Should not call ColorSpace.getOutputLength'); unreachable('Should not call ColorSpace.getOutputLength');
}, },
/** /**
* Returns true if source data will be equal the result/output data. * Returns true if source data will be equal the result/output data.
*/ */
isPassthrough: function ColorSpace_isPassthrough(bits) { isPassthrough(bits) {
return false; return false;
}, },
/** /**
@ -112,9 +108,8 @@ var ColorSpace = (function ColorSpaceClosure() {
* how many alpha components there are in the dest array; it will be either * how many alpha components there are in the dest array; it will be either
* 0 (RGB array) or 1 (RGBA array). * 0 (RGB array) or 1 (RGBA array).
*/ */
fillRgb: function ColorSpace_fillRgb(dest, originalWidth, fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight,
originalHeight, width, height, bpc, comps, alpha01) {
actualHeight, bpc, comps, alpha01) {
var count = originalWidth * originalHeight; var count = originalWidth * originalHeight;
var rgbBuf = null; var rgbBuf = null;
var numComponentColors = 1 << bpc; var numComponentColors = 1 << bpc;
@ -385,7 +380,7 @@ var ColorSpace = (function ColorSpaceClosure() {
* @param {Array} decode Decode map (usually from an image). * @param {Array} decode Decode map (usually from an image).
* @param {Number} n Number of components the color space has. * @param {Number} n Number of components the color space has.
*/ */
ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) { ColorSpace.isDefaultDecode = function(decode, n) {
if (!Array.isArray(decode)) { if (!Array.isArray(decode)) {
return true; return true;
} }
@ -438,15 +433,12 @@ var AlternateCS = (function AlternateCSClosure() {
AlternateCS.prototype = { AlternateCS.prototype = {
getRgb: ColorSpace.prototype.getRgb, getRgb: ColorSpace.prototype.getRgb,
getRgbItem: function AlternateCS_getRgbItem(src, srcOffset, getRgbItem(src, srcOffset, dest, destOffset) {
dest, destOffset) {
var tmpBuf = this.tmpBuf; var tmpBuf = this.tmpBuf;
this.tintFn(src, srcOffset, tmpBuf, 0); this.tintFn(src, srcOffset, tmpBuf, 0);
this.base.getRgbItem(tmpBuf, 0, dest, destOffset); this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
}, },
getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count, getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
dest, destOffset, bits,
alpha01) {
var tintFn = this.tintFn; var tintFn = this.tintFn;
var base = this.base; var base = this.base;
var scale = 1 / ((1 << bits) - 1); var scale = 1 / ((1 << bits) - 1);
@ -481,15 +473,14 @@ var AlternateCS = (function AlternateCSClosure() {
base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01); base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
} }
}, },
getOutputLength: function AlternateCS_getOutputLength(inputLength, getOutputLength(inputLength, alpha01) {
alpha01) {
return this.base.getOutputLength(inputLength * return this.base.getOutputLength(inputLength *
this.base.numComps / this.numComps, this.base.numComps / this.numComps,
alpha01); alpha01);
}, },
isPassthrough: ColorSpace.prototype.isPassthrough, isPassthrough: ColorSpace.prototype.isPassthrough,
fillRgb: ColorSpace.prototype.fillRgb, fillRgb: ColorSpace.prototype.fillRgb,
isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) { isDefaultDecode(decodeMap) {
return ColorSpace.isDefaultDecode(decodeMap, this.numComps); return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
}, },
usesZeroToOneRange: true, usesZeroToOneRange: true,
@ -537,15 +528,12 @@ var IndexedCS = (function IndexedCSClosure() {
IndexedCS.prototype = { IndexedCS.prototype = {
getRgb: ColorSpace.prototype.getRgb, getRgb: ColorSpace.prototype.getRgb,
getRgbItem: function IndexedCS_getRgbItem(src, srcOffset, getRgbItem(src, srcOffset, dest, destOffset) {
dest, destOffset) {
var numComps = this.base.numComps; var numComps = this.base.numComps;
var start = src[srcOffset] * numComps; var start = src[srcOffset] * numComps;
this.base.getRgbBuffer(this.lookup, start, 1, dest, destOffset, 8, 0); this.base.getRgbBuffer(this.lookup, start, 1, dest, destOffset, 8, 0);
}, },
getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count, getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
dest, destOffset, bits,
alpha01) {
var base = this.base; var base = this.base;
var numComps = base.numComps; var numComps = base.numComps;
var outputDelta = base.getOutputLength(numComps, alpha01); var outputDelta = base.getOutputLength(numComps, alpha01);
@ -557,13 +545,13 @@ var IndexedCS = (function IndexedCSClosure() {
destOffset += outputDelta; destOffset += outputDelta;
} }
}, },
getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) { getOutputLength(inputLength, alpha01) {
return this.base.getOutputLength(inputLength * this.base.numComps, return this.base.getOutputLength(inputLength * this.base.numComps,
alpha01); alpha01);
}, },
isPassthrough: ColorSpace.prototype.isPassthrough, isPassthrough: ColorSpace.prototype.isPassthrough,
fillRgb: ColorSpace.prototype.fillRgb, fillRgb: ColorSpace.prototype.fillRgb,
isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) { isDefaultDecode(decodeMap) {
// indexed color maps shouldn't be changed // indexed color maps shouldn't be changed
return true; return true;
}, },
@ -581,15 +569,12 @@ var DeviceGrayCS = (function DeviceGrayCSClosure() {
DeviceGrayCS.prototype = { DeviceGrayCS.prototype = {
getRgb: ColorSpace.prototype.getRgb, getRgb: ColorSpace.prototype.getRgb,
getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset, getRgbItem(src, srcOffset, dest, destOffset) {
dest, destOffset) {
var c = (src[srcOffset] * 255) | 0; var c = (src[srcOffset] * 255) | 0;
c = c < 0 ? 0 : c > 255 ? 255 : c; c = c < 0 ? 0 : c > 255 ? 255 : c;
dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c; dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
}, },
getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count, getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
dest, destOffset, bits,
alpha01) {
var scale = 255 / ((1 << bits) - 1); var scale = 255 / ((1 << bits) - 1);
var j = srcOffset, q = destOffset; var j = srcOffset, q = destOffset;
for (var i = 0; i < count; ++i) { for (var i = 0; i < count; ++i) {
@ -600,13 +585,12 @@ var DeviceGrayCS = (function DeviceGrayCSClosure() {
q += alpha01; q += alpha01;
} }
}, },
getOutputLength: function DeviceGrayCS_getOutputLength(inputLength, getOutputLength(inputLength, alpha01) {
alpha01) {
return inputLength * (3 + alpha01); return inputLength * (3 + alpha01);
}, },
isPassthrough: ColorSpace.prototype.isPassthrough, isPassthrough: ColorSpace.prototype.isPassthrough,
fillRgb: ColorSpace.prototype.fillRgb, fillRgb: ColorSpace.prototype.fillRgb,
isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) { isDefaultDecode(decodeMap) {
return ColorSpace.isDefaultDecode(decodeMap, this.numComps); return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
}, },
usesZeroToOneRange: true, usesZeroToOneRange: true,
@ -622,8 +606,7 @@ var DeviceRgbCS = (function DeviceRgbCSClosure() {
} }
DeviceRgbCS.prototype = { DeviceRgbCS.prototype = {
getRgb: ColorSpace.prototype.getRgb, getRgb: ColorSpace.prototype.getRgb,
getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset, getRgbItem(src, srcOffset, dest, destOffset) {
dest, destOffset) {
var r = (src[srcOffset] * 255) | 0; var r = (src[srcOffset] * 255) | 0;
var g = (src[srcOffset + 1] * 255) | 0; var g = (src[srcOffset + 1] * 255) | 0;
var b = (src[srcOffset + 2] * 255) | 0; var b = (src[srcOffset + 2] * 255) | 0;
@ -631,9 +614,7 @@ var DeviceRgbCS = (function DeviceRgbCSClosure() {
dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g; dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b; dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
}, },
getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count, getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
dest, destOffset, bits,
alpha01) {
if (bits === 8 && alpha01 === 0) { if (bits === 8 && alpha01 === 0) {
dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset); dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
return; return;
@ -647,15 +628,14 @@ var DeviceRgbCS = (function DeviceRgbCSClosure() {
q += alpha01; q += alpha01;
} }
}, },
getOutputLength: function DeviceRgbCS_getOutputLength(inputLength, getOutputLength(inputLength, alpha01) {
alpha01) {
return (inputLength * (3 + alpha01) / 3) | 0; return (inputLength * (3 + alpha01) / 3) | 0;
}, },
isPassthrough: function DeviceRgbCS_isPassthrough(bits) { isPassthrough(bits) {
return bits === 8; return bits === 8;
}, },
fillRgb: ColorSpace.prototype.fillRgb, fillRgb: ColorSpace.prototype.fillRgb,
isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) { isDefaultDecode(decodeMap) {
return ColorSpace.isDefaultDecode(decodeMap, this.numComps); return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
}, },
usesZeroToOneRange: true, usesZeroToOneRange: true,
@ -717,13 +697,10 @@ var DeviceCmykCS = (function DeviceCmykCSClosure() {
} }
DeviceCmykCS.prototype = { DeviceCmykCS.prototype = {
getRgb: ColorSpace.prototype.getRgb, getRgb: ColorSpace.prototype.getRgb,
getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset, getRgbItem(src, srcOffset, dest, destOffset) {
dest, destOffset) {
convertToRgb(src, srcOffset, 1, dest, destOffset); convertToRgb(src, srcOffset, 1, dest, destOffset);
}, },
getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count, getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
dest, destOffset, bits,
alpha01) {
var scale = 1 / ((1 << bits) - 1); var scale = 1 / ((1 << bits) - 1);
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
convertToRgb(src, srcOffset, scale, dest, destOffset); convertToRgb(src, srcOffset, scale, dest, destOffset);
@ -731,13 +708,12 @@ var DeviceCmykCS = (function DeviceCmykCSClosure() {
destOffset += 3 + alpha01; destOffset += 3 + alpha01;
} }
}, },
getOutputLength: function DeviceCmykCS_getOutputLength(inputLength, getOutputLength(inputLength, alpha01) {
alpha01) {
return (inputLength / 4 * (3 + alpha01)) | 0; return (inputLength / 4 * (3 + alpha01)) | 0;
}, },
isPassthrough: ColorSpace.prototype.isPassthrough, isPassthrough: ColorSpace.prototype.isPassthrough,
fillRgb: ColorSpace.prototype.fillRgb, fillRgb: ColorSpace.prototype.fillRgb,
isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) { isDefaultDecode(decodeMap) {
return ColorSpace.isDefaultDecode(decodeMap, this.numComps); return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
}, },
usesZeroToOneRange: true, usesZeroToOneRange: true,
@ -815,13 +791,10 @@ var CalGrayCS = (function CalGrayCSClosure() {
CalGrayCS.prototype = { CalGrayCS.prototype = {
getRgb: ColorSpace.prototype.getRgb, getRgb: ColorSpace.prototype.getRgb,
getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset, getRgbItem(src, srcOffset, dest, destOffset) {
dest, destOffset) {
convertToRgb(this, src, srcOffset, dest, destOffset, 1); convertToRgb(this, src, srcOffset, dest, destOffset, 1);
}, },
getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count, getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
dest, destOffset, bits,
alpha01) {
var scale = 1 / ((1 << bits) - 1); var scale = 1 / ((1 << bits) - 1);
for (var i = 0; i < count; ++i) { for (var i = 0; i < count; ++i) {
@ -830,12 +803,12 @@ var CalGrayCS = (function CalGrayCSClosure() {
destOffset += 3 + alpha01; destOffset += 3 + alpha01;
} }
}, },
getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) { getOutputLength(inputLength, alpha01) {
return inputLength * (3 + alpha01); return inputLength * (3 + alpha01);
}, },
isPassthrough: ColorSpace.prototype.isPassthrough, isPassthrough: ColorSpace.prototype.isPassthrough,
fillRgb: ColorSpace.prototype.fillRgb, fillRgb: ColorSpace.prototype.fillRgb,
isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) { isDefaultDecode(decodeMap) {
return ColorSpace.isDefaultDecode(decodeMap, this.numComps); return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
}, },
usesZeroToOneRange: true, usesZeroToOneRange: true,
@ -847,7 +820,6 @@ var CalGrayCS = (function CalGrayCSClosure() {
// CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247 // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
// //
var CalRGBCS = (function CalRGBCSClosure() { var CalRGBCS = (function CalRGBCSClosure() {
// See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
// matrices. // matrices.
var BRADFORD_SCALE_MATRIX = new Float32Array([ var BRADFORD_SCALE_MATRIX = new Float32Array([
@ -991,7 +963,6 @@ var CalRGBCS = (function CalRGBCSClosure() {
} }
function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) { function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
// In case the blackPoint is already the default blackPoint then there is // In case the blackPoint is already the default blackPoint then there is
// no need to do compensation. // no need to do compensation.
if (sourceBlackPoint[0] === 0 && if (sourceBlackPoint[0] === 0 &&
@ -1033,7 +1004,6 @@ var CalRGBCS = (function CalRGBCSClosure() {
} }
function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) { function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
// In case the whitePoint is already flat then there is no need to do // In case the whitePoint is already flat then there is no need to do
// normalization. // normalization.
if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) { if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
@ -1053,7 +1023,6 @@ var CalRGBCS = (function CalRGBCSClosure() {
} }
function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) { function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
var LMS = result; var LMS = result;
matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS); matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
@ -1115,13 +1084,10 @@ var CalRGBCS = (function CalRGBCSClosure() {
CalRGBCS.prototype = { CalRGBCS.prototype = {
getRgb: ColorSpace.prototype.getRgb, getRgb: ColorSpace.prototype.getRgb,
getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset, getRgbItem(src, srcOffset, dest, destOffset) {
dest, destOffset) {
convertToRgb(this, src, srcOffset, dest, destOffset, 1); convertToRgb(this, src, srcOffset, dest, destOffset, 1);
}, },
getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count, getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
dest, destOffset, bits,
alpha01) {
var scale = 1 / ((1 << bits) - 1); var scale = 1 / ((1 << bits) - 1);
for (var i = 0; i < count; ++i) { for (var i = 0; i < count; ++i) {
@ -1130,12 +1096,12 @@ var CalRGBCS = (function CalRGBCSClosure() {
destOffset += 3 + alpha01; destOffset += 3 + alpha01;
} }
}, },
getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) { getOutputLength(inputLength, alpha01) {
return (inputLength * (3 + alpha01) / 3) | 0; return (inputLength * (3 + alpha01) / 3) | 0;
}, },
isPassthrough: ColorSpace.prototype.isPassthrough, isPassthrough: ColorSpace.prototype.isPassthrough,
fillRgb: ColorSpace.prototype.fillRgb, fillRgb: ColorSpace.prototype.fillRgb,
isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) { isDefaultDecode(decodeMap) {
return ColorSpace.isDefaultDecode(decodeMap, this.numComps); return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
}, },
usesZeroToOneRange: true, usesZeroToOneRange: true,
@ -1261,12 +1227,10 @@ var LabCS = (function LabCSClosure() {
LabCS.prototype = { LabCS.prototype = {
getRgb: ColorSpace.prototype.getRgb, getRgb: ColorSpace.prototype.getRgb,
getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) { getRgbItem(src, srcOffset, dest, destOffset) {
convertToRgb(this, src, srcOffset, false, dest, destOffset); convertToRgb(this, src, srcOffset, false, dest, destOffset);
}, },
getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count, getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
dest, destOffset, bits,
alpha01) {
var maxVal = (1 << bits) - 1; var maxVal = (1 << bits) - 1;
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
convertToRgb(this, src, srcOffset, maxVal, dest, destOffset); convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
@ -1274,12 +1238,12 @@ var LabCS = (function LabCSClosure() {
destOffset += 3 + alpha01; destOffset += 3 + alpha01;
} }
}, },
getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) { getOutputLength(inputLength, alpha01) {
return (inputLength * (3 + alpha01) / 3) | 0; return (inputLength * (3 + alpha01) / 3) | 0;
}, },
isPassthrough: ColorSpace.prototype.isPassthrough, isPassthrough: ColorSpace.prototype.isPassthrough,
fillRgb: ColorSpace.prototype.fillRgb, fillRgb: ColorSpace.prototype.fillRgb,
isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) { isDefaultDecode(decodeMap) {
// XXX: Decoding is handled with the lab conversion because of the strange // XXX: Decoding is handled with the lab conversion because of the strange
// ranges that are used. // ranges that are used.
return true; return true;