1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 09:38:06 +02:00

Merge pull request #4528 from bthorben/lessColorConversion

Less color conversion
This commit is contained in:
Yury Delendik 2014-04-28 08:28:33 -05:00
commit 58f697f977
7 changed files with 318 additions and 231 deletions

View file

@ -44,6 +44,7 @@ var PDFImage = (function PDFImageClosure() {
return Promise.resolve(image);
}
}
/**
* Decode and clamp a value. The formula is different from the spec because we
* don't decode to float range [0,1], we decode it in the [0,max] range.
@ -53,6 +54,7 @@ var PDFImage = (function PDFImageClosure() {
// Clamp the value to the range
return (value < 0 ? 0 : (value > max ? max : value));
}
function PDFImage(xref, res, image, inline, smask, mask, isMask) {
this.image = image;
var dict = image.dict;
@ -279,11 +281,13 @@ var PDFImage = (function PDFImageClosure() {
this.smask && this.smask.width || 0,
this.mask && this.mask.width || 0);
},
get drawHeight() {
return Math.max(this.height,
this.smask && this.smask.height || 0,
this.mask && this.mask.height || 0);
},
decodeBuffer: function PDFImage_decodeBuffer(buffer) {
var bpc = this.bpc;
var numComps = this.numComps;
@ -309,6 +313,7 @@ var PDFImage = (function PDFImageClosure() {
}
}
},
getComponents: function PDFImage_getComponents(buffer) {
var bpc = this.bpc;
@ -385,6 +390,7 @@ var PDFImage = (function PDFImageClosure() {
}
return output;
},
fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
actualHeight, image) {
var smask = this.smask;
@ -451,6 +457,7 @@ var PDFImage = (function PDFImageClosure() {
}
}
},
undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
var matte = this.smask && this.smask.matte;
if (!matte) {
@ -467,7 +474,7 @@ var PDFImage = (function PDFImageClosure() {
var alpha = buffer[i + 3];
if (alpha === 0) {
// according formula we have to get Infinity in all components
// making it as white (tipical paper color) should be okay
// making it white (tipical paper color) should be okay
buffer[i] = 255;
buffer[i + 1] = 255;
buffer[i + 2] = 255;
@ -479,6 +486,7 @@ var PDFImage = (function PDFImageClosure() {
buffer[i + 2] = clamp((buffer[i + 2] - matteRgb[2]) * k + matteRgb[2]);
}
},
createImageData: function PDFImage_createImageData(forceRGBA) {
var drawWidth = this.drawWidth;
var drawHeight = this.drawHeight;
@ -494,7 +502,7 @@ var PDFImage = (function PDFImageClosure() {
// Rows start at byte boundary.
var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
var imgArray = this.getImageBytes(originalHeight * rowBytes);
var imgArray;
if (!forceRGBA) {
// If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
@ -514,6 +522,7 @@ var PDFImage = (function PDFImageClosure() {
drawWidth === originalWidth && drawHeight === originalHeight) {
imgData.kind = kind;
imgArray = this.getImageBytes(originalHeight * rowBytes);
// If imgArray came from a DecodeStream, we're safe to transfer it
// (and thus neuter it) because it will constitute the entire
// DecodeStream's data. But if it came from a Stream, we need to
@ -529,7 +538,14 @@ var PDFImage = (function PDFImageClosure() {
return imgData;
}
}
if (this.image instanceof JpegStream) {
imgData.kind = ImageKind.RGB_24BPP;
imgData.data = this.getImageBytes(originalHeight * rowBytes,
drawWidth, drawHeight);
return imgData;
}
imgArray = this.getImageBytes(originalHeight * rowBytes);
// imgArray can be incomplete (e.g. after CCITT fax encoding).
var actualHeight = 0 | (imgArray.length / rowBytes *
drawHeight / originalHeight);
@ -567,6 +583,7 @@ var PDFImage = (function PDFImageClosure() {
return imgData;
},
fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
var numComps = this.numComps;
if (numComps != 1) {
@ -611,8 +628,12 @@ var PDFImage = (function PDFImageClosure() {
buffer[i] = (scale * comps[i]) | 0;
}
},
getImageBytes: function PDFImage_getImageBytes(length) {
getImageBytes: function PDFImage_getImageBytes(length,
drawWidth, drawHeight) {
this.image.reset();
this.image.drawWidth = drawWidth;
this.image.drawHeight = drawHeight;
return this.image.getBytes(length);
}
};

1039
src/core/jpg.js Normal file

File diff suppressed because it is too large Load diff

View file

@ -873,9 +873,8 @@ var JpegStream = (function JpegStreamClosure() {
jpegImage.colorTransform = this.colorTransform;
}
jpegImage.parse(this.bytes);
var width = jpegImage.width;
var height = jpegImage.height;
var data = jpegImage.getData(width, height);
var data = jpegImage.getData(this.drawWidth, this.drawHeight,
/* forceRGBoutput = */true);
this.buffer = data;
this.bufferLength = data.length;
this.eof = true;
@ -883,6 +882,12 @@ var JpegStream = (function JpegStreamClosure() {
error('JPEG error: ' + e);
}
};
JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
this.ensureBuffer();
return this.buffer;
};
JpegStream.prototype.getIR = function JpegStream_getIR() {
return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
};