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