]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/image-pix.c
2 * "$Id: image-pix.c 4741 2005-10-02 04:25:52Z mike $"
4 * Alias PIX image routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2005 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * _cupsImageReadPIX() - Read a PIX image file.
29 * read_short() - Read a 16-bit integer.
33 * Include necessary headers...
36 #include "image-private.h"
43 static short read_short(FILE *fp
);
47 * '_cupsImageReadPIX()' - Read a PIX image file.
50 int /* O - Read status */
52 cups_image_t
*img
, /* IO - cupsImage */
53 FILE *fp
, /* I - cupsImage file */
54 cups_icspace_t primary
, /* I - Primary choice for colorspace */
55 cups_icspace_t secondary
, /* I - Secondary choice for colorspace */
56 int saturation
, /* I - Color saturation (%) */
57 int hue
, /* I - Color hue (degrees) */
58 const cups_ib_t
*lut
) /* I - Lookup table for gamma/brightness */
60 short width
, /* Width of image */
61 height
, /* Height of image */
62 depth
; /* Depth of image (bits) */
63 int count
, /* Repetition count */
64 bpp
, /* Bytes per pixel */
65 x
, y
; /* Looping vars */
66 cups_ib_t r
, g
, b
; /* Red, green/gray, blue values */
67 cups_ib_t
*in
, /* Input pixels */
68 *out
, /* Output pixels */
69 *ptr
; /* Pointer into pixels */
73 * Get the image dimensions and setup the image...
76 width
= read_short(fp
);
77 height
= read_short(fp
);
80 depth
= read_short(fp
);
83 * Check the dimensions of the image. Since the short values used for the
84 * width and height cannot exceed CUPS_IMAGE_MAX_WIDTH or
85 * CUPS_IMAGE_MAX_HEIGHT, we just need to verify they are positive integers.
88 if (width
<= 0 || height
<= 0 ||
89 (depth
!= 8 && depth
!= 24))
91 fprintf(stderr
, "ERROR: Bad PIX image dimensions %dx%dx%d\n",
92 width
, height
, depth
);
98 img
->colorspace
= secondary
;
100 img
->colorspace
= (primary
== CUPS_IMAGE_RGB_CMYK
) ? CUPS_IMAGE_RGB
: primary
;
105 cupsImageSetMaxTiles(img
, 0);
107 in
= malloc(img
->xsize
* (depth
/ 8));
108 bpp
= cupsImageGetDepth(img
);
109 out
= malloc(img
->xsize
* bpp
);
112 * Read the image data...
117 for (count
= 0, y
= 0, g
= 0; y
< img
->ysize
; y
++)
119 if (img
->colorspace
== CUPS_IMAGE_WHITE
)
124 for (x
= img
->xsize
; x
> 0; x
--, count
--)
135 if (img
->colorspace
!= CUPS_IMAGE_WHITE
)
136 switch (img
->colorspace
)
139 cupsImageWhiteToRGB(in
, out
, img
->xsize
);
141 case CUPS_IMAGE_BLACK
:
142 cupsImageWhiteToBlack(in
, out
, img
->xsize
);
144 case CUPS_IMAGE_CMY
:
145 cupsImageWhiteToCMY(in
, out
, img
->xsize
);
147 case CUPS_IMAGE_CMYK
:
148 cupsImageWhiteToCMYK(in
, out
, img
->xsize
);
153 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
155 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
160 for (count
= 0, y
= 0, r
= 0, g
= 0, b
= 0; y
< img
->ysize
; y
++)
162 if (img
->colorspace
== CUPS_IMAGE_RGB
)
167 for (x
= img
->xsize
; x
> 0; x
--, count
--)
182 if (img
->colorspace
== CUPS_IMAGE_RGB
)
184 if (saturation
!= 100 || hue
!= 0)
185 cupsImageRGBAdjust(out
, img
->xsize
, saturation
, hue
);
189 if (saturation
!= 100 || hue
!= 0)
190 cupsImageRGBAdjust(in
, img
->xsize
, saturation
, hue
);
192 switch (img
->colorspace
)
197 case CUPS_IMAGE_WHITE
:
198 cupsImageRGBToWhite(in
, out
, img
->xsize
);
200 case CUPS_IMAGE_BLACK
:
201 cupsImageRGBToBlack(in
, out
, img
->xsize
);
203 case CUPS_IMAGE_CMY
:
204 cupsImageRGBToCMY(in
, out
, img
->xsize
);
206 case CUPS_IMAGE_CMYK
:
207 cupsImageRGBToCMYK(in
, out
, img
->xsize
);
213 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
215 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
228 * 'read_short()' - Read a 16-bit integer.
231 static short /* O - Value from file */
232 read_short(FILE *fp
) /* I - File to read from */
234 int ch
; /* Character from file */
238 return ((ch
<< 8) | getc(fp
));
243 * End of "$Id: image-pix.c 4741 2005-10-02 04:25:52Z mike $".