Add another way to detect cmyk images.
This commit is contained in:
parent
1869888838
commit
8d52a1e92a
@ -236,7 +236,7 @@ var Parser = (function parserParser() {
|
||||
return new LZWStream(stream, earlyChange);
|
||||
} else if (name == 'DCTDecode' || name == 'DCT') {
|
||||
var bytes = stream.getBytes(length);
|
||||
return new JpegStream(bytes, stream.dict);
|
||||
return new JpegStream(bytes, stream.dict, this.xref);
|
||||
} else if (name == 'ASCII85Decode' || name == 'A85') {
|
||||
return new Ascii85Stream(stream);
|
||||
} else if (name == 'ASCIIHexDecode' || name == 'AHx') {
|
||||
|
@ -776,6 +776,25 @@ var JpegStream = (function jpegStream() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isCmykAdobe(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] == 0 &&
|
||||
bytes[i + 15] == 2 ) {
|
||||
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,
|
||||
@ -789,19 +808,20 @@ var JpegStream = (function jpegStream() {
|
||||
return newBytes;
|
||||
}
|
||||
|
||||
function constructor(bytes, dict) {
|
||||
function constructor(bytes, dict, xref) {
|
||||
// TODO: per poppler, some images may have 'junk' before that
|
||||
// need to be removed
|
||||
this.dict = dict;
|
||||
|
||||
|
||||
// Flag indicating wether the image can be natively loaded.
|
||||
this.isNative = true;
|
||||
|
||||
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 = dict.get('ColorSpace');
|
||||
var cs = xref.fetchIfRef(dict.get('ColorSpace'));
|
||||
if (isName(cs) && cs.name === 'DeviceCMYK') {
|
||||
//if (isCmykAdobe(bytes)) {
|
||||
this.isNative = false;
|
||||
this.bytes = bytes;
|
||||
} else {
|
||||
@ -826,7 +846,7 @@ var JpegStream = (function jpegStream() {
|
||||
var height = jpegImage.height;
|
||||
var dataLength = width * height * 4;
|
||||
var data = new Uint8Array(dataLength);
|
||||
jpegImage.getData(data, width, height);
|
||||
jpegImage.getData(data, width, height, true);
|
||||
this.buffer = data;
|
||||
this.bufferLength = data.length;
|
||||
};
|
||||
|
@ -40,7 +40,8 @@ function onMessageLoader(evt) {
|
||||
'parser.js',
|
||||
'pattern.js',
|
||||
'stream.js',
|
||||
'worker.js'
|
||||
'worker.js',
|
||||
'../external/jpgjs/jpg.js'
|
||||
];
|
||||
|
||||
// Load all the files.
|
||||
|
Loading…
Reference in New Issue
Block a user