[poppler] poppler/DCTStream.cc poppler/DCTStream.h

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Tue Jul 13 01:31:29 PDT 2010


 poppler/DCTStream.cc |   30 ++++++++++++++++++++++++++++++
 poppler/DCTStream.h  |    1 +
 2 files changed, 31 insertions(+)

New commits:
commit 552ab99e60fe4068be8e4e415924e4be289e47cd
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Tue Jul 13 10:18:01 2010 +0200

    Handle ColorTransform in DCT streams when using libjpeg
    
    Fixes bug #28873.

diff --git a/poppler/DCTStream.cc b/poppler/DCTStream.cc
index 1b15619..7f578a9 100644
--- a/poppler/DCTStream.cc
+++ b/poppler/DCTStream.cc
@@ -58,6 +58,7 @@ static void str_term_source(j_decompress_ptr cinfo)
 
 DCTStream::DCTStream(Stream *strA, int colorXformA) :
   FilterStream(strA) {
+  colorXform = colorXformA;
   init();
 }
 
@@ -138,6 +139,35 @@ void DCTStream::reset() {
 
   if (!setjmp(src.setjmp_buffer)) {
     jpeg_read_header(&cinfo, TRUE);
+
+    // figure out color transform
+    if (colorXform == -1 && !cinfo.saw_Adobe_marker) {
+      if (cinfo.num_components == 3) {
+        if (cinfo.saw_JFIF_marker) {
+	  colorXform = 1;
+        } else if (cinfo.cur_comp_info[0]->component_id == 82 &&
+		   cinfo.cur_comp_info[1]->component_id == 71 &&
+		   cinfo.cur_comp_info[2]->component_id == 66) { // ASCII "RGB"
+	  colorXform = 0;
+	} else {
+	  colorXform = 1;
+	}
+      } else {
+        colorXform = 0;
+      }
+    } else if (cinfo.saw_Adobe_marker) {
+      colorXform = cinfo.Adobe_transform;
+    }
+
+    switch (cinfo.num_components) {
+    case 3:
+	    cinfo.jpeg_color_space = colorXform ? JCS_YCbCr : JCS_RGB;
+	    break;
+    case 4:
+	    cinfo.jpeg_color_space = colorXform ? JCS_YCCK : JCS_CMYK;
+	    break;
+    }
+
     jpeg_start_decompress(&cinfo);
 
     row_stride = cinfo.output_width * cinfo.output_components;
diff --git a/poppler/DCTStream.h b/poppler/DCTStream.h
index 65196ec..ec2a701 100644
--- a/poppler/DCTStream.h
+++ b/poppler/DCTStream.h
@@ -72,6 +72,7 @@ private:
   virtual GBool hasGetChars() { return true; }
   virtual int getChars(int nChars, Guchar *buffer);
 
+  int colorXform;
   JSAMPLE *current;
   JSAMPLE *limit;
   struct jpeg_decompress_struct cinfo;


More information about the poppler mailing list