Merge pull request #3436 from yurydelendik/jpeg-cmyk

Removes browser decoding optimization for JPEG CMYK
This commit is contained in:
Brendan Dahl 2013-07-12 17:54:12 -07:00
commit 6c6719efeb
4 changed files with 11 additions and 53 deletions

View File

@ -847,8 +847,6 @@ var JpegImage = (function jpegImage() {
}
break;
case 4:
if (!this.adobe)
throw 'Unsupported color mode (4 components)';
// The default transform for four components is false
colorTransform = false;
// The adobe transform marker overrides any previous setting

View File

@ -802,49 +802,10 @@ var PredictorStream = (function PredictorStreamClosure() {
* DecodeStreams.
*/
var JpegStream = (function JpegStreamClosure() {
function isAdobeImage(bytes) {
var maxBytesScanned = Math.max(bytes.length - 16, 1024);
// Looking for APP14, 'Adobe'
for (var i = 0; i < maxBytesScanned; ++i) {
if (bytes[i] == 0xFF && bytes[i + 1] == 0xEE &&
bytes[i + 2] === 0x00 && bytes[i + 3] == 0x0E &&
bytes[i + 4] == 0x41 && bytes[i + 5] == 0x64 &&
bytes[i + 6] == 0x6F && bytes[i + 7] == 0x62 &&
bytes[i + 8] == 0x65 && bytes[i + 9] === 0x00)
return true;
// scanning until frame tag
if (bytes[i] == 0xFF && bytes[i + 1] == 0xC0)
break;
}
return false;
}
function fixAdobeImage(bytes) {
// Inserting 'EMBED' marker after JPEG signature
var embedMarker = new Uint8Array([0xFF, 0xEC, 0, 8, 0x45, 0x4D, 0x42, 0x45,
0x44, 0]);
var newBytes = new Uint8Array(bytes.length + embedMarker.length);
newBytes.set(bytes, embedMarker.length);
// copy JPEG header
newBytes[0] = bytes[0];
newBytes[1] = bytes[1];
newBytes.set(embedMarker, 2);
return newBytes;
}
function JpegStream(bytes, dict, xref) {
// TODO: per poppler, some images may have 'junk' before that
// need to be removed
this.dict = dict;
this.isAdobeImage = false;
this.colorTransform = dict.get('ColorTransform') || -1;
if (isAdobeImage(bytes)) {
this.isAdobeImage = true;
bytes = fixAdobeImage(bytes);
}
this.bytes = bytes;
DecodeStream.call(this);
@ -880,14 +841,7 @@ var JpegStream = (function JpegStreamClosure() {
JpegStream.prototype.isNativelySupported =
function JpegStream_isNativelySupported(xref, res) {
var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
// when bug 674619 lands, let's check if browser can do
// normal cmyk and then we won't need to decode in JS
if (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB')
return true;
if (cs.name === 'DeviceCMYK' && !this.isAdobeImage &&
this.colorTransform < 1)
return true;
return false;
return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
};
/**
* Checks if the image can be decoded by the browser.
@ -896,10 +850,7 @@ var JpegStream = (function JpegStreamClosure() {
function JpegStream_isNativelyDecodable(xref, res) {
var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
var numComps = cs.numComps;
if (numComps == 1 || numComps == 3)
return true;
return false;
return numComps == 1 || numComps == 3;
};
return JpegStream;

View File

@ -0,0 +1 @@
http://www.nature.com/news/2010/100721/pdf/466432a.pdf

View File

@ -1094,6 +1094,14 @@
"rounds": 1,
"type": "eq"
},
{ "id": "bug887152",
"file": "pdfs/bug887152.pdf",
"md5": "783a3e7b1de2cf40a47ffe1f36a41d4f",
"rounds": 1,
"lastPage": 1,
"link": true,
"type": "eq"
},
{ "id": "bug816075",
"file": "pdfs/bug816075.pdf",
"md5": "7ec87c115c1f9ec41234cc7002555e82",