]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/image-jpeg.c
Merge changes from CUPS 1.4svn-r7696.
[thirdparty/cups.git] / filter / image-jpeg.c
index 5a07a7bbd1d07f91cef9786249a4a107dd3f57e1..4710ab269bd60e2fa6304ad6bbe50aaf0bdadbb2 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: image-jpeg.c 5508 2006-05-11 11:41:16Z mike $"
+ * "$Id: image-jpeg.c 7355 2008-02-28 20:49:40Z mike $"
  *
  *   JPEG image routines for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1993-2006 by Easy Software Products.
+ *   Copyright 2007 by Apple Inc.
+ *   Copyright 1993-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  *   This file is subject to the Apple OS-Developed Software exception.
  *
@@ -56,8 +47,8 @@ _cupsImageReadJPEG(
   struct jpeg_error_mgr        jerr;           /* Error handler info */
   cups_ib_t            *in,            /* Input pixels */
                        *out;           /* Output pixels */
-  char                 header[16];     /* Photoshop JPEG header */
-  int                  psjpeg;         /* Non-zero if Photoshop JPEG */
+  jpeg_saved_marker_ptr        marker;         /* Pointer to marker data */
+  int                  psjpeg = 0;     /* Non-zero if Photoshop CMYK JPEG */
   static const char    *cspaces[] =
                        {               /* JPEG colorspaces... */
                          "JCS_UNKNOWN",
@@ -69,24 +60,31 @@ _cupsImageReadJPEG(
                        };
 
 
- /*
-  * Read the first 16 bytes to determine if this is a Photoshop JPEG file...
-  */
-
-  fread(header, sizeof(header), 1, fp);
-  rewind(fp);
-
-  psjpeg = memcmp(header + 6, "Photoshop ", 10) == 0;
-
  /*
   * Read the JPEG header...
   */
 
   cinfo.err = jpeg_std_error(&jerr);
   jpeg_create_decompress(&cinfo);
+  jpeg_save_markers(&cinfo, JPEG_APP0 + 14, 0xffff); /* Adobe JPEG */
   jpeg_stdio_src(&cinfo, fp);
   jpeg_read_header(&cinfo, 1);
 
+ /*
+  * Parse any Adobe APPE data embedded in the JPEG file.  Since Adobe doesn't
+  * bother following standards, we have to invert the CMYK JPEG data written by
+  * Adobe apps...
+  */
+
+  for (marker = cinfo.marker_list; marker; marker = marker->next)
+    if (marker->marker == (JPEG_APP0 + 14) && marker->data_length >= 12 &&
+        !memcmp(marker->data, "Adobe", 5) && marker->data[11] == 2)
+    {
+      fputs("DEBUG: Adobe CMYK JPEG detected (inverting color values)\n",
+           stderr);
+      psjpeg = 1;
+    }
+
   cinfo.quantize_colors = 0;
 
   fprintf(stderr, "DEBUG: num_components = %d\n", cinfo.num_components);
@@ -129,7 +127,7 @@ _cupsImageReadJPEG(
   if (cinfo.output_width <= 0 || cinfo.output_width > CUPS_IMAGE_MAX_WIDTH ||
       cinfo.output_height <= 0 || cinfo.output_height > CUPS_IMAGE_MAX_HEIGHT)
   {
-    fprintf(stderr, "ERROR: Bad JPEG dimensions %dx%d!\n",
+    fprintf(stderr, "DEBUG: Bad JPEG dimensions %dx%d!\n",
             cinfo.output_width, cinfo.output_height);
 
     jpeg_destroy_decompress(&cinfo);
@@ -156,7 +154,7 @@ _cupsImageReadJPEG(
 
     if (img->xppi == 0 || img->yppi == 0)
     {
-      fprintf(stderr, "ERROR: Bad JPEG image resolution %dx%d PPI.\n",
+      fprintf(stderr, "DEBUG: Bad JPEG image resolution %dx%d PPI.\n",
               img->xppi, img->yppi);
       img->xppi = img->yppi = 128;
     }
@@ -320,5 +318,5 @@ _cupsImageReadJPEG(
 
 
 /*
- * End of "$Id: image-jpeg.c 5508 2006-05-11 11:41:16Z mike $".
+ * End of "$Id: image-jpeg.c 7355 2008-02-28 20:49:40Z mike $".
  */