CalRGB: optimize CalRGB calculations
Also fix one silly mistake.
This commit is contained in:
parent
3ad972ad45
commit
0c5525dc8a
@ -829,6 +829,8 @@ var CalRGBCS = (function CalRGBCSClosure() {
|
||||
var tempConvertMatrix1 = new Float32Array(3);
|
||||
var tempConvertMatrix2 = new Float32Array(3);
|
||||
|
||||
var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
|
||||
|
||||
function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
|
||||
this.name = 'CalRGB';
|
||||
this.numComps = 3;
|
||||
@ -937,18 +939,30 @@ var CalRGBCS = (function CalRGBCSClosure() {
|
||||
return -decodeL(-L);
|
||||
}
|
||||
|
||||
if (L > 80) {
|
||||
if (L > 8.0) {
|
||||
return Math.pow(((L + 16) / 116), 3);
|
||||
}
|
||||
|
||||
return L * Math.pow(((8 + 16) / 116), 3) / 8.0;
|
||||
return L * DECODE_L_CONSTANT;
|
||||
}
|
||||
|
||||
function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
|
||||
// For the BlackPoint calculation details, please see
|
||||
|
||||
// In case the blackPoint is already the default blackPoint then there is
|
||||
// no need to do compensation.
|
||||
if (sourceBlackPoint[0] === 0 &&
|
||||
sourceBlackPoint[1] === 0 &&
|
||||
sourceBlackPoint[2] === 0) {
|
||||
result[0] = XYZ_Flat[0];
|
||||
result[1] = XYZ_Flat[1];
|
||||
result[2] = XYZ_Flat[2];
|
||||
return;
|
||||
}
|
||||
|
||||
// For the blackPoint calculation details, please see
|
||||
// http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
|
||||
// AdobeBPC.pdf.
|
||||
// The destination BlackPoint is the default BlackPoint [0, 0, 0].
|
||||
// The destination blackPoint is the default blackPoint [0, 0, 0].
|
||||
var zeroDecodeL = decodeL(0);
|
||||
|
||||
var X_DST = zeroDecodeL;
|
||||
@ -976,6 +990,15 @@ 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) {
|
||||
result[0] = XYZ_In[0];
|
||||
result[1] = XYZ_In[1];
|
||||
result[2] = XYZ_In[2];
|
||||
return;
|
||||
}
|
||||
|
||||
var LMS = result;
|
||||
matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
|
||||
|
||||
@ -1010,15 +1033,11 @@ var CalRGBCS = (function CalRGBCSClosure() {
|
||||
var BGG = Math.pow(B, cs.GG);
|
||||
var CGB = Math.pow(C, cs.GB);
|
||||
|
||||
// Computes intermediate variables M, L, N as per spec.
|
||||
var M = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
|
||||
var L = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
|
||||
var N = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
|
||||
|
||||
// Decode XYZ, as per spec.
|
||||
var X = M;
|
||||
var Y = L;
|
||||
var Z = N;
|
||||
// Computes intermediate variables L, M, N as per spec.
|
||||
// To decode X, Y, Z values map L, M, N directly to them.
|
||||
var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
|
||||
var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
|
||||
var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
|
||||
|
||||
// The following calculations are based on this document:
|
||||
// http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
|
||||
@ -1028,6 +1047,7 @@ var CalRGBCS = (function CalRGBCSClosure() {
|
||||
XYZ[1] = Y;
|
||||
XYZ[2] = Z;
|
||||
var XYZ_Flat = tempConvertMatrix2;
|
||||
|
||||
normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
|
||||
|
||||
var XYZ_Black = tempConvertMatrix1;
|
||||
|
@ -10,8 +10,8 @@
|
||||
/Keywords (CalRGB, Color Space, Example, Test PDF) %
|
||||
/Creator (genpdf.py) %
|
||||
/Producer (genpdf.py) %
|
||||
/CreationDate (D:20140814232935+02'00') %
|
||||
/ModDate (D:20140814232935+02'00') %
|
||||
/CreationDate (D:20140816112719+02'00') %
|
||||
/ModDate (D:20140816112719+02'00') %
|
||||
/Trapped (False) %
|
||||
%
|
||||
>> %
|
||||
@ -5569,7 +5569,7 @@ endobj
|
||||
47 0 obj %
|
||||
[ /CalRGB %
|
||||
<< /WhitePoint [ 1.00000 1.00000 1.00000 ] %
|
||||
/BlackPoint [ 80.0000 80.0000 80.0000 ] %
|
||||
/BlackPoint [ 8.00000 8.00000 8.00000 ] %
|
||||
/Gamma [ 1.00000 1.00000 1.00000 ] %
|
||||
/Matrix [ 1.00000 0.00000 0.00000 0.00000 1.00000 0.00000 0.00000 0.00000 1.00000 ] %
|
||||
>> %
|
||||
@ -6071,7 +6071,7 @@ stream
|
||||
-400 530 Td %
|
||||
(WhitePoint [ 1.00000 1.00000 1.00000 ]) Tj %
|
||||
0 -15 Td %
|
||||
(BlackPoint [ 80.0000 80.0000 80.0000 ]) Tj %
|
||||
(BlackPoint [ 8.00000 8.00000 8.00000 ]) Tj %
|
||||
0 -15 Td %
|
||||
(Gamma [ 1.00000 1.00000 1.00000 ]) Tj %
|
||||
0 -15 Td %
|
||||
@ -6111,7 +6111,7 @@ endobj
|
||||
51 0 obj %
|
||||
[ /CalRGB %
|
||||
<< /WhitePoint [ 1.00000 1.00000 1.00000 ] %
|
||||
/BlackPoint [ 81.0000 81.0000 81.0000 ] %
|
||||
/BlackPoint [ 50.0000 50.0000 50.0000 ] %
|
||||
/Gamma [ 1.00000 1.00000 1.00000 ] %
|
||||
/Matrix [ 1.00000 0.00000 0.00000 0.00000 1.00000 0.00000 0.00000 0.00000 1.00000 ] %
|
||||
>> %
|
||||
@ -6613,7 +6613,7 @@ stream
|
||||
-400 530 Td %
|
||||
(WhitePoint [ 1.00000 1.00000 1.00000 ]) Tj %
|
||||
0 -15 Td %
|
||||
(BlackPoint [ 81.0000 81.0000 81.0000 ]) Tj %
|
||||
(BlackPoint [ 50.0000 50.0000 50.0000 ]) Tj %
|
||||
0 -15 Td %
|
||||
(Gamma [ 1.00000 1.00000 1.00000 ]) Tj %
|
||||
0 -15 Td %
|
||||
|
@ -1693,7 +1693,7 @@
|
||||
},
|
||||
{ "id": "calrgb",
|
||||
"file": "pdfs/calrgb.pdf",
|
||||
"md5": "5f3dfda1d3a795cd214a457244130bfa",
|
||||
"md5": "625068e9a7dd80e4f70b24ce97b3ec5c",
|
||||
"rounds": 1,
|
||||
"lastPage": 8,
|
||||
"type": "eq"
|
||||
|
Loading…
Reference in New Issue
Block a user