]> git.parisson.com Git - pdf.js.git/commitdiff
Add another way to detect cmyk images.
authorBrendan Dahl <brendan.dahl@gmail.com>
Tue, 8 Nov 2011 21:53:56 +0000 (13:53 -0800)
committerBrendan Dahl <brendan.dahl@gmail.com>
Tue, 8 Nov 2011 21:53:56 +0000 (13:53 -0800)
src/parser.js
src/stream.js
src/worker_loader.js

index a740615eddc50e06e0b3d64d43ebc1a3446715c3..93a3f21b52a74755bce05a1020fbb39c9bf79124 100644 (file)
@@ -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') {
index d8a681a88b7ada121d0e3f6edf877f2180d62448..7634e50bb930e95b1d61b349faeb00af667e97cd 100644 (file)
@@ -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;
   };
index cb0a910717283a798445d0fe42227a12cf22eab8..7141fa3e39d7f02b463ab7cda7f0a80bde395241 100644 (file)
@@ -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.