]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/image-pix.c
e72fdff14871ba78bf35356e14ccf37b371a8932
2 * "$Id: image-pix.c 6649 2007-07-11 21:46:42Z mike $"
4 * Alias PIX image routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 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 in
= malloc(img
->xsize
* (depth
/ 8));
99 bpp
= cupsImageGetDepth(img
);
100 out
= malloc(img
->xsize
* bpp
);
103 * Read the image data...
108 for (count
= 0, y
= 0, g
= 0; y
< img
->ysize
; y
++)
110 if (img
->colorspace
== CUPS_IMAGE_WHITE
)
115 for (x
= img
->xsize
; x
> 0; x
--, count
--)
126 if (img
->colorspace
!= CUPS_IMAGE_WHITE
)
127 switch (img
->colorspace
)
130 cupsImageWhiteToRGB(in
, out
, img
->xsize
);
132 case CUPS_IMAGE_BLACK
:
133 cupsImageWhiteToBlack(in
, out
, img
->xsize
);
135 case CUPS_IMAGE_CMY
:
136 cupsImageWhiteToCMY(in
, out
, img
->xsize
);
138 case CUPS_IMAGE_CMYK
:
139 cupsImageWhiteToCMYK(in
, out
, img
->xsize
);
144 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
146 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
151 for (count
= 0, y
= 0, r
= 0, g
= 0, b
= 0; y
< img
->ysize
; y
++)
155 for (x
= img
->xsize
; x
> 0; x
--, count
--)
170 if (saturation
!= 100 || hue
!= 0)
171 cupsImageRGBAdjust(in
, img
->xsize
, saturation
, hue
);
173 switch (img
->colorspace
)
178 case CUPS_IMAGE_WHITE
:
179 cupsImageRGBToWhite(in
, out
, img
->xsize
);
181 case CUPS_IMAGE_RGB
:
182 cupsImageRGBToWhite(in
, out
, img
->xsize
);
184 case CUPS_IMAGE_BLACK
:
185 cupsImageRGBToBlack(in
, out
, img
->xsize
);
187 case CUPS_IMAGE_CMY
:
188 cupsImageRGBToCMY(in
, out
, img
->xsize
);
190 case CUPS_IMAGE_CMYK
:
191 cupsImageRGBToCMYK(in
, out
, img
->xsize
);
196 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
198 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
211 * 'read_short()' - Read a 16-bit integer.
214 static short /* O - Value from file */
215 read_short(FILE *fp
) /* I - File to read from */
217 int ch
; /* Character from file */
221 return ((ch
<< 8) | getc(fp
));
226 * End of "$Id: image-pix.c 6649 2007-07-11 21:46:42Z mike $".