2 * "$Id: image-pix.c 9771 2011-05-12 05:21:56Z mike $"
4 * Alias PIX image routines for CUPS.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1993-2007 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * _cupsImageReadPIX() - Read a PIX image file.
20 * read_short() - Read a 16-bit integer.
24 * Include necessary headers...
27 #include "image-private.h"
34 static short read_short(FILE *fp);
38 * '_cupsImageReadPIX()' - Read a PIX image file.
41 int /* O - Read status */
43 cups_image_t *img, /* IO - cupsImage */
44 FILE *fp, /* I - cupsImage file */
45 cups_icspace_t primary, /* I - Primary choice for colorspace */
46 cups_icspace_t secondary, /* I - Secondary choice for colorspace */
47 int saturation, /* I - Color saturation (%) */
48 int hue, /* I - Color hue (degrees) */
49 const cups_ib_t *lut) /* I - Lookup table for gamma/brightness */
51 short width, /* Width of image */
52 height, /* Height of image */
53 depth; /* Depth of image (bits) */
54 int count, /* Repetition count */
55 bpp, /* Bytes per pixel */
56 x, y; /* Looping vars */
57 cups_ib_t r, g, b; /* Red, green/gray, blue values */
58 cups_ib_t *in, /* Input pixels */
59 *out, /* Output pixels */
60 *ptr; /* Pointer into pixels */
64 * Get the image dimensions and setup the image...
67 width = read_short(fp);
68 height = read_short(fp);
71 depth = read_short(fp);
74 * Check the dimensions of the image. Since the short values used for the
75 * width and height cannot exceed CUPS_IMAGE_MAX_WIDTH or
76 * CUPS_IMAGE_MAX_HEIGHT, we just need to verify they are positive integers.
79 if (width <= 0 || height <= 0 ||
80 (depth != 8 && depth != 24))
82 fprintf(stderr, "DEBUG: Bad PIX image dimensions %dx%dx%d\n",
83 width, height, depth);
89 img->colorspace = secondary;
91 img->colorspace = (primary == CUPS_IMAGE_RGB_CMYK) ? CUPS_IMAGE_RGB : primary;
96 cupsImageSetMaxTiles(img, 0);
98 bpp = cupsImageGetDepth(img);
100 if ((in = malloc(img->xsize * (depth / 8))) == NULL)
102 fputs("DEBUG: Unable to allocate memory!\n", stderr);
107 if ((out = malloc(img->xsize * bpp)) == NULL)
109 fputs("DEBUG: Unable to allocate memory!\n", stderr);
116 * Read the image data...
121 for (count = 0, y = 0, g = 0; y < img->ysize; y ++)
123 if (img->colorspace == CUPS_IMAGE_WHITE)
128 for (x = img->xsize; x > 0; x --, count --)
139 if (img->colorspace != CUPS_IMAGE_WHITE)
140 switch (img->colorspace)
143 cupsImageWhiteToRGB(in, out, img->xsize);
145 case CUPS_IMAGE_BLACK :
146 cupsImageWhiteToBlack(in, out, img->xsize);
148 case CUPS_IMAGE_CMY :
149 cupsImageWhiteToCMY(in, out, img->xsize);
151 case CUPS_IMAGE_CMYK :
152 cupsImageWhiteToCMYK(in, out, img->xsize);
157 cupsImageLut(out, img->xsize * bpp, lut);
159 _cupsImagePutRow(img, 0, y, img->xsize, out);
164 for (count = 0, y = 0, r = 0, g = 0, b = 0; y < img->ysize; y ++)
168 for (x = img->xsize; x > 0; x --, count --)
183 if (saturation != 100 || hue != 0)
184 cupsImageRGBAdjust(in, img->xsize, saturation, hue);
186 switch (img->colorspace)
191 case CUPS_IMAGE_WHITE :
192 cupsImageRGBToWhite(in, out, img->xsize);
194 case CUPS_IMAGE_RGB :
195 cupsImageRGBToWhite(in, out, img->xsize);
197 case CUPS_IMAGE_BLACK :
198 cupsImageRGBToBlack(in, out, img->xsize);
200 case CUPS_IMAGE_CMY :
201 cupsImageRGBToCMY(in, out, img->xsize);
203 case CUPS_IMAGE_CMYK :
204 cupsImageRGBToCMYK(in, out, img->xsize);
209 cupsImageLut(out, img->xsize * bpp, lut);
211 _cupsImagePutRow(img, 0, y, img->xsize, out);
224 * 'read_short()' - Read a 16-bit integer.
227 static short /* O - Value from file */
228 read_short(FILE *fp) /* I - File to read from */
230 int ch; /* Character from file */
234 return ((ch << 8) | getc(fp));
239 * End of "$Id: image-pix.c 9771 2011-05-12 05:21:56Z mike $".