]> git.ipfire.org Git - thirdparty/cups.git/blob - filter/image-pix.c
Copyright update...
[thirdparty/cups.git] / filter / image-pix.c
1 /*
2 * "$Id: image-pix.c,v 1.4 2002/01/02 17:58:58 mike Exp $"
3 *
4 * Alias PIX image routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1993-2002 by Easy Software Products.
7 *
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
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
26 * ImageReadPIX() - Read a PIX image file.
27 * read_short() - Read a 16-bit integer.
28 */
29
30 /*
31 * Include necessary headers...
32 */
33
34 #include "image.h"
35
36
37 /*
38 * Local functions...
39 */
40
41 static short read_short(FILE *fp);
42
43
44 /*
45 * 'ImageReadPIX()' - Read a PIX image file.
46 */
47
48 int /* O - Read status */
49 ImageReadPIX(image_t *img, /* IO - Image */
50 FILE *fp, /* I - Image file */
51 int primary, /* I - Primary choice for colorspace */
52 int secondary, /* I - Secondary choice for colorspace */
53 int saturation, /* I - Color saturation (%) */
54 int hue, /* I - Color hue (degrees) */
55 const ib_t *lut) /* I - Lookup table for gamma/brightness */
56 {
57 short width, /* Width of image */
58 height, /* Height of image */
59 depth; /* Depth of image (bits) */
60 int count, /* Repetition count */
61 bpp, /* Bytes per pixel */
62 x, y; /* Looping vars */
63 ib_t r, g, b; /* Red, green/gray, blue values */
64 ib_t *in, /* Input pixels */
65 *out, /* Output pixels */
66 *ptr; /* Pointer into pixels */
67
68
69 /*
70 * Get the image dimensions and setup the image...
71 */
72
73 width = read_short(fp);
74 height = read_short(fp);
75 read_short(fp);
76 read_short(fp);
77 depth = read_short(fp);
78
79 if (depth == 8)
80 img->colorspace = secondary;
81 else
82 img->colorspace = primary;
83
84 img->xsize = width;
85 img->ysize = height;
86
87 ImageSetMaxTiles(img, 0);
88
89 in = malloc(img->xsize * (depth / 8));
90 bpp = ImageGetDepth(img);
91 out = malloc(img->xsize * bpp);
92
93 /*
94 * Read the image data...
95 */
96
97 if (depth == 8)
98 {
99 for (count = 0, y = 0, g = 0; y < img->ysize; y ++)
100 {
101 if (img->colorspace == IMAGE_WHITE)
102 ptr = out;
103 else
104 ptr = in;
105
106 for (x = img->xsize; x > 0; x --, count --)
107 {
108 if (count == 0)
109 {
110 count = getc(fp);
111 g = getc(fp);
112 }
113
114 *ptr++ = g;
115 }
116
117 if (img->colorspace != IMAGE_WHITE)
118 switch (img->colorspace)
119 {
120 case IMAGE_RGB :
121 ImageWhiteToRGB(in, out, img->xsize);
122 break;
123 case IMAGE_BLACK :
124 ImageWhiteToBlack(in, out, img->xsize);
125 break;
126 case IMAGE_CMY :
127 ImageWhiteToCMY(in, out, img->xsize);
128 break;
129 case IMAGE_CMYK :
130 ImageWhiteToCMYK(in, out, img->xsize);
131 break;
132 }
133
134 if (lut)
135 ImageLut(out, img->xsize * bpp, lut);
136
137 ImagePutRow(img, 0, y, img->xsize, out);
138 }
139 }
140 else
141 {
142 for (count = 0, y = 0, r = 0, g = 0, b = 0; y < img->ysize; y ++)
143 {
144 if (img->colorspace == IMAGE_RGB)
145 ptr = out;
146 else
147 ptr = in;
148
149 for (x = img->xsize; x > 0; x --, count --)
150 {
151 if (count == 0)
152 {
153 count = getc(fp);
154 b = getc(fp);
155 g = getc(fp);
156 r = getc(fp);
157 }
158
159 *ptr++ = r;
160 *ptr++ = g;
161 *ptr++ = b;
162 }
163
164 if (img->colorspace == IMAGE_RGB)
165 {
166 if (saturation != 100 || hue != 0)
167 ImageRGBAdjust(out, img->xsize, saturation, hue);
168 }
169 else
170 {
171 if (saturation != 100 || hue != 0)
172 ImageRGBAdjust(in, img->xsize, saturation, hue);
173
174 switch (img->colorspace)
175 {
176 case IMAGE_WHITE :
177 ImageRGBToWhite(in, out, img->xsize);
178 break;
179 case IMAGE_BLACK :
180 ImageRGBToBlack(in, out, img->xsize);
181 break;
182 case IMAGE_CMY :
183 ImageRGBToCMY(in, out, img->xsize);
184 break;
185 case IMAGE_CMYK :
186 ImageRGBToCMYK(in, out, img->xsize);
187 break;
188 }
189 }
190
191 if (lut)
192 ImageLut(out, img->xsize * bpp, lut);
193
194 ImagePutRow(img, 0, y, img->xsize, out);
195 }
196 }
197
198 fclose(fp);
199 free(in);
200 free(out);
201
202 return (0);
203 }
204
205
206 /*
207 * 'read_short()' - Read a 16-bit integer.
208 */
209
210 static short /* O - Value from file */
211 read_short(FILE *fp) /* I - File to read from */
212 {
213 int ch; /* Character from file */
214
215
216 ch = getc(fp);
217 return ((ch << 8) | getc(fp));
218 }
219
220
221 /*
222 * End of "$Id: image-pix.c,v 1.4 2002/01/02 17:58:58 mike Exp $".
223 */