Commits

Fredrik Lundh committed 8fb7447

Fixed JPEG CMYK handling.

Note that the inversion should be done by the converters. We'll fix
this later (when we have proper test data).

Comments (0)

Files changed (2)

 
 *** Changes from release 1.1.6 to 1.1.7 ***
 
++ Fixed JPEG CMYK handling (from Kevin Cazabon)
+
 + Added resolution save option for PDF files (from Andreas Kostyrka).
 
 + Look for Tcl/Tk files in /usr/include/tclX.X (from Encolpe Degoute)

PIL/JpegImagePlugin.py

 #
 # The Python Imaging Library.
-# $Id: JpegImagePlugin.py 2763 2006-06-22 21:43:28Z fredrik $
+# $Id$
 #
 # JPEG (JFIF) file handling
 #
 __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)
                     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
             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:
     "RGB": "RGB",
     "RGBA": "RGB",
     "RGBX": "RGB",
-    "CMYK": "CMYK;I",
+    "CMYK": "CMYK",
     "YCbCr": "YCbCr",
 }
 
         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):