]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/image-sun.c
Merge changes from CUPS 1.5.1-r9875.
[thirdparty/cups.git] / filter / image-sun.c
index f49fac157a3a333bd4ce5c0d9c5467b9cf44294d..8e6c1d3d90835524e4257631c32974d572e41987 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: image-sun.c 4741 2005-10-02 04:25:52Z mike $"
+ * "$Id: image-sun.c 7223 2008-01-16 23:41:19Z mike $"
  *
- *   Sun Raster image file routines for the Common UNIX Printing System (CUPS).
+ *   Sun Raster image file routines for CUPS.
  *
- *   Copyright 1993-2005 by Easy Software Products.
+ *   Copyright 2007-2011 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.
  *
@@ -127,7 +118,7 @@ _cupsImageReadSunRaster(
       img->ysize == 0 || img->ysize > CUPS_IMAGE_MAX_HEIGHT ||
       ras_depth == 0 || ras_depth > 32)
   {
-    fputs("ERROR: Raster image cannot be loaded!\n", stderr);
+    fputs("DEBUG: Raster image cannot be loaded!\n", stderr);
     return (1);
   }
 
@@ -161,9 +152,32 @@ _cupsImageReadSunRaster(
     in = malloc(img->xsize * 3 + 1);
   }
 
-  bpp       = cupsImageGetDepth(img);
-  out       = malloc(img->xsize * bpp);
-  scanline  = malloc(scanwidth);
+  if (!in)
+  {
+    fputs("DEBUG: Unable to allocate memory!\n", stderr);
+    fclose(fp);
+    return (1);
+  }
+
+  bpp = cupsImageGetDepth(img);
+
+  if ((out = malloc(img->xsize * bpp)) == NULL)
+  {
+    fputs("DEBUG: Unable to allocate memory!\n", stderr);
+    fclose(fp);
+    free(in);
+    return (1);
+  }
+
+  if ((scanline = malloc(scanwidth)) == NULL)
+  {
+    fputs("DEBUG: Unable to allocate memory!\n", stderr);
+    fclose(fp);
+    free(in);
+    free(out);
+    return (1);
+  }
+
   run_count = 0;
   run_value = 0;
 
@@ -171,7 +185,7 @@ _cupsImageReadSunRaster(
 
   for (y = 0; y < img->ysize; y ++)
   {
-    if (ras_depth != 8 || ras_maplength > 0)
+    if ((ras_depth != 8 && ras_depth != 24) || ras_maplength > 0)
       p = scanline;
     else
       p = in;
@@ -221,12 +235,12 @@ _cupsImageReadSunRaster(
           *p = 0;
 
        if (bit > 1)
+          bit >>= 1;
+       else
        {
           bit = 128;
           scanptr ++;
        }
-       else
-          bit >>= 1;
       }
     }
     else if (ras_depth == 1)
@@ -253,12 +267,12 @@ _cupsImageReadSunRaster(
        }
 
        if (bit > 1)
+          bit >>= 1;
+       else
        {
           bit = 128;
           scanptr ++;
        }
-       else
-          bit >>= 1;
       }
     }
     else if (ras_depth == 8 && ras_maplength > 0)
@@ -330,45 +344,32 @@ _cupsImageReadSunRaster(
     }
     else
     {
-      if (img->colorspace == CUPS_IMAGE_RGB)
-      {
-       if (saturation != 100 || hue != 0)
-         cupsImageRGBAdjust(in, img->xsize, saturation, hue);
+      if ((saturation != 100 || hue != 0) && bpp > 1)
+       cupsImageRGBAdjust(in, img->xsize, saturation, hue);
 
-        if (lut)
-         cupsImageLut(in, img->xsize * 3, lut);
-
-        _cupsImagePutRow(img, 0, y, img->xsize, in);
-      }
-      else
+      switch (img->colorspace)
       {
-       if ((saturation != 100 || hue != 0) && bpp > 1)
-         cupsImageRGBAdjust(in, img->xsize, saturation, hue);
-
-       switch (img->colorspace)
-       {
-         default :
-             break;
-
-         case CUPS_IMAGE_WHITE :
-             cupsImageRGBToWhite(in, out, img->xsize);
-             break;
-         case CUPS_IMAGE_BLACK :
-             cupsImageRGBToBlack(in, out, img->xsize);
-             break;
-         case CUPS_IMAGE_CMY :
-             cupsImageRGBToCMY(in, out, img->xsize);
-             break;
-         case CUPS_IMAGE_CMYK :
-             cupsImageRGBToCMYK(in, out, img->xsize);
-             break;
-       }
+       default :
+           break;
+
+       case CUPS_IMAGE_WHITE :
+           cupsImageRGBToWhite(in, out, img->xsize);
+           break;
+       case CUPS_IMAGE_BLACK :
+           cupsImageRGBToBlack(in, out, img->xsize);
+           break;
+       case CUPS_IMAGE_CMY :
+           cupsImageRGBToCMY(in, out, img->xsize);
+           break;
+       case CUPS_IMAGE_CMYK :
+           cupsImageRGBToCMYK(in, out, img->xsize);
+           break;
+      }
 
-        if (lut)
-         cupsImageLut(out, img->xsize * bpp, lut);
+      if (lut)
+       cupsImageLut(out, img->xsize * bpp, lut);
 
-        _cupsImagePutRow(img, 0, y, img->xsize, out);
-      }
+      _cupsImagePutRow(img, 0, y, img->xsize, out);
     }
   }
 
@@ -402,5 +403,5 @@ read_unsigned(FILE *fp)                     /* I - File to read from */
 
 
 /*
- * End of "$Id: image-sun.c 4741 2005-10-02 04:25:52Z mike $".
+ * End of "$Id: image-sun.c 7223 2008-01-16 23:41:19Z mike $".
  */