[Image-SIG] problem about color about some jpeg

Alexey Borzenkov snaury at gmail.com
Wed Apr 18 07:02:23 CEST 2007


Just in case, attaching Kevin's patch as unified diff:

Index: JpegImagePlugin.py
===================================================================
--- JpegImagePlugin.py	(revision 207)
+++ JpegImagePlugin.py	(revision 208)
@@ -32,7 +32,7 @@
 __version__ = "0.5"

 import array, string
-import Image, ImageFile
+import Image, ImageFile, ImageChops

 def i16(c,o=0):
     return ord(c[o+1]) + (ord(c[o])<<8)
@@ -270,8 +270,11 @@
                     handler(self, i)
                 if i == 0xFFDA: # start of scan
                     rawmode = self.mode
-                    if self.mode == "CMYK":
-                        rawmode = "CMYK;I"
+                    # patch by Kevin Cazabon to comment this out -
nobody should be using Photoshop 2.5 any more (and it breaks newer
versions)
+                    # CMYK images are still inverted, we'll fix that
just before returning.
+                    #if self.mode == "CMYK" and self.info.has_key("adobe"):
+                    #    rawmode = "CMYK;I" # Photoshop 2.5 is broken!
+
                     self.tile = [("jpeg", (0,0) + self.size, 0, (rawmode, ""))]
                     # self.__offset = self.fp.tell()
                     break
@@ -282,6 +285,10 @@
             else:
                 raise SyntaxError("no marker found")

+        # patch by Kevin Cazabon to re-invert CMYK JPEG files
+        if self.mode == "CMYK":
+            self.im = ImageChops.invert(self).im
+
     def draft(self, mode, size):

         if len(self.tile) != 1:
@@ -378,7 +385,7 @@
     "RGB": "RGB",
     "RGBA": "RGB",
     "RGBX": "RGB",
-    "CMYK": "CMYK;I",
+    "CMYK": "CMYK",
     "YCbCr": "YCbCr",
 }

@@ -406,6 +413,10 @@
         dpi[0], dpi[1]
         )

+    if im.mode == "CMYK":
+        # invert it so it's handled correctly in Photoshop/etc. -
Kevin Cazabon.
+        im = ImageChops.invert(im)
+
     ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])

 def _save_cjpeg(im, fp, filename):

Best regards,
Alexey.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: JpegImagePlugin-kevin-cmyk.patch
Type: application/octet-stream
Size: 1927 bytes
Desc: not available
Url : http://mail.python.org/pipermail/image-sig/attachments/20070418/e567bd08/attachment.obj 


More information about the Image-SIG mailing list