calgray: fix getRgbBuffer problem
This fixes issue 3903.
This commit is contained in:
parent
1de3fae840
commit
4c040dd955
@ -639,8 +639,8 @@ var DeviceCmykCS = (function DeviceCmykCSClosure() {
|
||||
var CalGrayCS = (function CalGrayCSClosure() {
|
||||
function CalGrayCS(whitePoint, blackPoint, gamma) {
|
||||
this.name = 'CalGray';
|
||||
this.numComps = 3;
|
||||
this.defaultColor = new Float32Array([0, 0, 0]);
|
||||
this.numComps = 1;
|
||||
this.defaultColor = new Float32Array([0]);
|
||||
|
||||
if (!whitePoint) {
|
||||
error('WhitePoint missing - required for color space CalGray');
|
||||
@ -682,6 +682,33 @@ var CalGrayCS = (function CalGrayCSClosure() {
|
||||
}
|
||||
}
|
||||
|
||||
function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
|
||||
// A represents a gray component of a calibrated gray space.
|
||||
// A <---> AG in the spec
|
||||
var A = src[srcOffset] * scale;
|
||||
var AG = Math.pow(A, cs.G);
|
||||
|
||||
// Computes intermediate variables M, L, N as per spec.
|
||||
// Except if other than default BlackPoint values are used.
|
||||
var M = cs.XW * AG;
|
||||
var L = cs.YW * AG;
|
||||
var N = cs.ZW * AG;
|
||||
|
||||
// Decode XYZ, as per spec.
|
||||
var X = M;
|
||||
var Y = L;
|
||||
var Z = N;
|
||||
|
||||
// http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
|
||||
// This yields values in range [0, 100].
|
||||
var Lstar = Math.max(116 * Math.pow(Y, 1 / 3) - 16, 0);
|
||||
|
||||
// Convert values to rgb range [0, 255].
|
||||
dest[destOffset] = Lstar * 255 / 100;
|
||||
dest[destOffset + 1] = Lstar * 255 / 100;
|
||||
dest[destOffset + 2] = Lstar * 255 / 100;
|
||||
}
|
||||
|
||||
CalGrayCS.prototype = {
|
||||
getRgb: function CalGrayCS_getRgb(src, srcOffset) {
|
||||
var rgb = new Uint8Array(3);
|
||||
@ -690,41 +717,16 @@ var CalGrayCS = (function CalGrayCSClosure() {
|
||||
},
|
||||
getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
|
||||
dest, destOffset) {
|
||||
// A represents a gray component of a calibrated gray space.
|
||||
// A <---> AG in the spec
|
||||
var A = src[srcOffset];
|
||||
var AG = Math.pow(A, this.G);
|
||||
|
||||
// Computes intermediate variables M, L, N as per spec.
|
||||
// Except if other than default BlackPoint values are used.
|
||||
var M = this.XW * AG;
|
||||
var L = this.YW * AG;
|
||||
var N = this.ZW * AG;
|
||||
|
||||
// Decode XYZ, as per spec.
|
||||
var X = M;
|
||||
var Y = L;
|
||||
var Z = N;
|
||||
|
||||
// http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
|
||||
// This yields values in range [0, 100].
|
||||
var Lstar = Math.max(116 * Math.pow(Y, 1 / 3) - 16, 0);
|
||||
|
||||
// Convert values to rgb range [0, 255].
|
||||
dest[destOffset] = Lstar * 255 / 100;
|
||||
dest[destOffset + 1] = Lstar * 255 / 100;
|
||||
dest[destOffset + 2] = Lstar * 255 / 100;
|
||||
convertToRgb(this, src, srcOffset, dest, destOffset, 1);
|
||||
},
|
||||
getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
|
||||
dest, destOffset, bits) {
|
||||
// TODO: This part is copied from DeviceGray. Make this utility function.
|
||||
var scale = 255 / ((1 << bits) - 1);
|
||||
var j = srcOffset, q = destOffset;
|
||||
var scale = 1 / ((1 << bits) - 1);
|
||||
|
||||
for (var i = 0; i < count; ++i) {
|
||||
var c = (scale * src[j++]) | 0;
|
||||
dest[q++] = c;
|
||||
dest[q++] = c;
|
||||
dest[q++] = c;
|
||||
convertToRgb(this, src, srcOffset, dest, destOffset, scale);
|
||||
srcOffset += 1;
|
||||
destOffset += 3;
|
||||
}
|
||||
},
|
||||
getOutputLength: function CalGrayCS_getOutputLength(inputLength) {
|
||||
|
1
test/pdfs/issue3903.pdf.link
Normal file
1
test/pdfs/issue3903.pdf.link
Normal file
@ -0,0 +1 @@
|
||||
http://www.reloadbench.com/pdf/files/1%20Inch%20Diamonds.pdf
|
@ -76,6 +76,15 @@
|
||||
"lastPage": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "issue3903",
|
||||
"file": "pdfs/issue3903.pdf",
|
||||
"md5": "c9a4a8012e15cf3b10d671982ce35a92",
|
||||
"rounds": 1,
|
||||
"link": true,
|
||||
"firstPage": 1,
|
||||
"lastPage": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "issue2391-1",
|
||||
"file": "pdfs/issue2391-1.pdf",
|
||||
"md5": "25ae9cb959612e7b343b55da63af2716",
|
||||
|
Loading…
Reference in New Issue
Block a user