]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/image-bmp.c
Merge changes from CUPS 1.5.1-r9875.
[thirdparty/cups.git] / filter / image-bmp.c
index 9a20ec8c4e95c8d410d2ced2ed4601b914119575..b93c1c5002a4312537b513deb9d9b3ffe2f0bbd6 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: image-bmp.c 4741 2005-10-02 04:25:52Z mike $"
+ * "$Id: image-bmp.c 7221 2008-01-16 22:20:08Z mike $"
  *
- *   BMP image routines for the Common UNIX Printing System (CUPS).
+ *   BMP image 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.
  *
@@ -110,7 +101,7 @@ _cupsImageReadBMP(
 
   if (offset < 0)
   {
-    fprintf(stderr, "ERROR: Bad BMP offset %d\n", offset);
+    fprintf(stderr, "DEBUG: Bad BMP offset %d\n", offset);
     fclose(fp);
     return (1);
   }
@@ -135,7 +126,7 @@ _cupsImageReadBMP(
       img->ysize == 0 || img->ysize > CUPS_IMAGE_MAX_HEIGHT ||
       (depth != 1 && depth != 4 && depth != 8 && depth != 24))
   {
-    fprintf(stderr, "ERROR: Bad BMP dimensions %ux%ux%d\n",
+    fprintf(stderr, "DEBUG: Bad BMP dimensions %ux%ux%d\n",
             img->xsize, img->ysize, depth);
     fclose(fp);
     return (1);
@@ -143,14 +134,14 @@ _cupsImageReadBMP(
 
   if (colors_used < 0 || colors_used > 256)
   {
-    fprintf(stderr, "ERROR: Bad BMP colormap size %d\n", colors_used);
+    fprintf(stderr, "DEBUG: Bad BMP colormap size %d\n", colors_used);
     fclose(fp);
     return (1);
   }
 
   if (img->xppi == 0 || img->yppi == 0)
   {
-    fprintf(stderr, "ERROR: Bad BMP resolution %dx%d PPI.\n",
+    fprintf(stderr, "DEBUG: Bad BMP resolution %dx%d PPI.\n",
             img->xppi, img->yppi);
     img->xppi = img->yppi = 128;
   }
@@ -179,6 +170,8 @@ _cupsImageReadBMP(
 
   if (colors_used > 0)
     fread(colormap, colors_used, 4, fp);
+  else
+    memset(colormap, 0, sizeof(colormap));
 
  /*
   * Setup image and buffers...
@@ -188,9 +181,22 @@ _cupsImageReadBMP(
 
   cupsImageSetMaxTiles(img, 0);
 
-  in  = malloc(img->xsize * 3);
   bpp = cupsImageGetDepth(img);
-  out = malloc(img->xsize * bpp);
+
+  if ((in = malloc(img->xsize * 3)) == NULL)
+  {
+    fputs("DEBUG: Unable to allocate memory!\n", stderr);
+    fclose(fp);
+    return (1);
+  }
+
+  if ((out = malloc(img->xsize * bpp)) == NULL)
+  {
+    fputs("DEBUG: Unable to allocate memory!\n", stderr);
+    free(in);
+    fclose(fp);
+    return (1);
+  }
 
  /*
   * Read the image data...
@@ -202,10 +208,7 @@ _cupsImageReadBMP(
 
   for (y = img->ysize - 1; y >= 0; y --)
   {
-    if (img->colorspace == CUPS_IMAGE_RGB)
-      ptr = out;
-    else
-      ptr = in;
+    ptr = in;
 
     switch (depth)
     {
@@ -442,37 +445,33 @@ _cupsImageReadBMP(
           break;
     }
 
-    if (img->colorspace == CUPS_IMAGE_RGB)
-    {
-      if (saturation != 100 || hue != 0)
-       cupsImageRGBAdjust(out, img->xsize, saturation, hue);
-    }
-    else
+    if (saturation != 100 || hue != 0)
+      cupsImageRGBAdjust(in, img->xsize, saturation, hue);
+
+    switch (img->colorspace)
     {
-      if (saturation != 100 || hue != 0)
-       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_RGB :
+         cupsImageRGBToRGB(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)
@@ -542,5 +541,5 @@ read_long(FILE *fp)               /* I - File to read from */
 
 
 /*
- * End of "$Id: image-bmp.c 4741 2005-10-02 04:25:52Z mike $".
+ * End of "$Id: image-bmp.c 7221 2008-01-16 22:20:08Z mike $".
  */