1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Decode more jpegs using the browser if possible.

This commit is contained in:
Brendan Dahl 2012-01-03 14:26:19 -08:00
parent c0cf081ec0
commit 3c2a0f11b1
3 changed files with 36 additions and 22 deletions

View file

@ -803,35 +803,23 @@ var JpegStream = (function JpegStreamClosure() {
// need to be removed
this.dict = dict;
// Flag indicating wether the image can be natively loaded.
this.isNative = true;
this.colorTransform = -1;
this.colorTransform = dict.get('ColorTransform') || -1;
this.isAdobeImage = false;
if (isAdobeImage(bytes)) {
// when bug 674619 land, let's check if browser can do
// normal cmyk and then we won't have to the following
var cs = xref.fetchIfRef(dict.get('ColorSpace'));
// DeviceRGB and DeviceGray are the only Adobe images that work natively
if (isName(cs) && (cs.name === 'DeviceRGB' || cs.name === 'DeviceGray')) {
bytes = fixAdobeImage(bytes);
this.src = bytesToString(bytes);
} else {
this.colorTransform = dict.get('ColorTransform');
this.isNative = false;
this.bytes = bytes;
}
} else {
this.src = bytesToString(bytes);
this.isAdobeImage = true;
bytes = fixAdobeImage(bytes);
}
this.bytes = bytes;
DecodeStream.call(this);
}
JpegStream.prototype = Object.create(DecodeStream.prototype);
JpegStream.prototype.ensureBuffer = function jpegStreamEnsureBuffer(req) {
// todo make sure this isn't called on natively supported jpegs
if (this.bufferLength)
return;
var jpegImage = new JpegImage();
@ -844,11 +832,36 @@ var JpegStream = (function JpegStreamClosure() {
this.bufferLength = data.length;
};
JpegStream.prototype.getIR = function jpegStreamGetIR() {
return this.src;
return bytesToString(this.bytes);
};
JpegStream.prototype.getChar = function jpegStreamGetChar() {
error('internal error: getChar is not valid on JpegStream');
};
/**
* Checks if the image can be decoded and displayed by the browser without any
* further processing such as color space conversions.
*/
JpegStream.prototype.isNativelySupported = function isNativelySupported(xref,
res) {
var cs = ColorSpace.parse(this.dict.get('ColorSpace'), xref, res);
if (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB')
return true;
if (cs.name === 'DeviceCMYK' && !this.isAdobeImage &&
this.colorTransform < 1)
return true;
return false;
};
/**
* Checks if the image can be decoded by the browser.
*/
JpegStream.prototype.isNativelyDecodable = function isNativelyDecodable(xref,
res) {
var cs = ColorSpace.parse(this.dict.get('ColorSpace'), xref, res);
if (cs.numComps == 1 || cs.numComps == 3)
return true;
return false;
};
return JpegStream;
})();