]> git.ipfire.org Git - thirdparty/cups.git/blame - filter/image-sgi.c
Y2k copyright changes.
[thirdparty/cups.git] / filter / image-sgi.c
CommitLineData
516ba4c9 1/*
71fe22b7 2 * "$Id: image-sgi.c,v 1.6 2000/01/04 13:45:45 mike Exp $"
516ba4c9 3 *
ed19bd98 4 * SGI image file routines for the Common UNIX Printing System (CUPS).
516ba4c9 5 *
71fe22b7 6 * Copyright 1993-2000 by Easy Software Products.
516ba4c9 7 *
ed19bd98 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:
516ba4c9 14 *
ed19bd98 15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
516ba4c9 19 *
ed19bd98 20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
68749fc8 23 *
ed19bd98 24 * Contents:
516ba4c9 25 *
6de9968b 26 * ImageReadSGI() - Read a SGI image file.
516ba4c9 27 */
28
29/*
30 * Include necessary headers...
31 */
32
33#include "image.h"
ed19bd98 34#include "image-sgi.h"
516ba4c9 35
36
6de9968b 37/*
38 * 'ImageReadSGI()' - Read a SGI image file.
39 */
40
081ab09a 41int /* O - Read status */
42ImageReadSGI(image_t *img, /* IO - Image */
43 FILE *fp, /* I - Image file */
44 int primary, /* I - Primary choice for colorspace */
45 int secondary, /* I - Secondary choice for colorspace */
46 int saturation, /* I - Color saturation (%) */
47 int hue, /* I - Color hue (degrees) */
48 const ib_t *lut) /* I - Lookup table for gamma/brightness */
516ba4c9 49{
50 int i, y; /* Looping vars */
51 int bpp; /* Bytes per pixel */
52 sgi_t *sgip; /* SGI image file */
53 ib_t *in, /* Input pixels */
54 *inptr, /* Current input pixel */
55 *out; /* Output pixels */
6de9968b 56 unsigned short *rows[4], /* Row pointers for image data */
516ba4c9 57 *red,
58 *green,
59 *blue,
60 *gray,
61 *alpha;
62
63
64 /*
65 * Setup the SGI file...
66 */
67
68 sgip = sgiOpenFile(fp, SGI_READ, 0, 0, 0, 0, 0);
69
70 /*
71 * Get the image dimensions and load the output image...
72 */
73
74 if (sgip->zsize < 3)
75 img->colorspace = secondary;
76 else
77 img->colorspace = primary;
78
79 img->xsize = sgip->xsize;
80 img->ysize = sgip->ysize;
81
82 ImageSetMaxTiles(img, 0);
83
84 bpp = ImageGetDepth(img);
85 in = malloc(img->xsize * sgip->zsize);
86 out = malloc(img->xsize * bpp);
87
6de9968b 88 rows[0] = calloc(img->xsize * sgip->zsize, sizeof(unsigned short));
516ba4c9 89 for (i = 1; i < sgip->zsize; i ++)
90 rows[i] = rows[0] + i * img->xsize;
91
92 /*
93 * Read the SGI image file...
94 */
95
96 for (y = 0; y < img->ysize; y ++)
97 {
98 for (i = 0; i < sgip->zsize; i ++)
99 sgiGetRow(sgip, rows[i], img->ysize - 1 - y, i);
100
101 switch (sgip->zsize)
102 {
103 case 1 :
104 if (sgip->bpp == 1)
105 for (i = img->xsize - 1, gray = rows[0], inptr = in;
106 i >= 0;
107 i --)
108 {
109 *inptr++ = *gray++;
110 }
111 else
112 for (i = img->xsize - 1, gray = rows[0], inptr = in;
113 i >= 0;
114 i --)
115 {
116 *inptr++ = (*gray++) / 256 + 128;
6de9968b 117 }
516ba4c9 118 break;
119 case 2 :
120 if (sgip->bpp == 1)
121 for (i = img->xsize - 1, gray = rows[0], alpha = rows[1], inptr = in;
122 i >= 0;
123 i --)
124 {
125 *inptr++ = (*gray++) * (*alpha++) / 255;
126 }
127 else
128 for (i = img->xsize - 1, gray = rows[0], alpha = rows[1], inptr = in;
129 i >= 0;
130 i --)
131 {
132 *inptr++ = ((*gray++) / 256 + 128) * (*alpha++) / 32767;
6de9968b 133 }
516ba4c9 134 break;
135 case 3 :
136 if (sgip->bpp == 1)
137 for (i = img->xsize - 1, red = rows[0], green = rows[1],
138 blue = rows[2], inptr = in;
139 i >= 0;
140 i --)
141 {
142 *inptr++ = *red++;
143 *inptr++ = *green++;
144 *inptr++ = *blue++;
145 }
146 else
147 for (i = img->xsize - 1, red = rows[0], green = rows[1],
148 blue = rows[2], inptr = in;
149 i >= 0;
150 i --)
151 {
152 *inptr++ = (*red++) / 256 + 128;
153 *inptr++ = (*green++) / 256 + 128;
154 *inptr++ = (*blue++) / 256 + 128;
6de9968b 155 }
516ba4c9 156 break;
157 case 4 :
158 if (sgip->bpp == 1)
159 for (i = img->xsize - 1, red = rows[0], green = rows[1],
160 blue = rows[2], alpha = rows[3], inptr = in;
161 i >= 0;
162 i --)
163 {
164 *inptr++ = (*red++) * (*alpha) / 255;
165 *inptr++ = (*green++) * (*alpha) / 255;
166 *inptr++ = (*blue++) * (*alpha++) / 255;
167 }
168 else
169 for (i = img->xsize - 1, red = rows[0], green = rows[1],
170 blue = rows[2], inptr = in;
171 i >= 0;
172 i --)
173 {
174 *inptr++ = ((*red++) / 256 + 128) * (*alpha) / 32767;
175 *inptr++ = ((*green++) / 256 + 128) * (*alpha) / 32767;
176 *inptr++ = ((*blue++) / 256 + 128) * (*alpha++) / 32767;
6de9968b 177 }
516ba4c9 178 break;
6de9968b 179 }
516ba4c9 180
181 if (sgip->zsize < 3)
182 {
183 if (img->colorspace == IMAGE_WHITE)
6de9968b 184 {
185 if (lut)
186 ImageLut(in, img->xsize, lut);
187
516ba4c9 188 ImagePutRow(img, 0, y, img->xsize, in);
6de9968b 189 }
516ba4c9 190 else
191 {
192 switch (img->colorspace)
193 {
194 case IMAGE_RGB :
195 ImageWhiteToRGB(in, out, img->xsize);
196 break;
197 case IMAGE_BLACK :
198 ImageWhiteToBlack(in, out, img->xsize);
199 break;
200 case IMAGE_CMY :
201 ImageWhiteToCMY(in, out, img->xsize);
202 break;
203 case IMAGE_CMYK :
204 ImageWhiteToCMYK(in, out, img->xsize);
205 break;
6de9968b 206 }
207
208 if (lut)
209 ImageLut(out, img->xsize * bpp, lut);
516ba4c9 210
211 ImagePutRow(img, 0, y, img->xsize, out);
6de9968b 212 }
516ba4c9 213 }
214 else
215 {
216 if (img->colorspace == IMAGE_RGB)
217 {
218 if (saturation != 100 || hue != 0)
219 ImageRGBAdjust(in, img->xsize, saturation, hue);
220
6de9968b 221 if (lut)
222 ImageLut(in, img->xsize * 3, lut);
223
516ba4c9 224 ImagePutRow(img, 0, y, img->xsize, in);
225 }
226 else
227 {
228 if ((saturation != 100 || hue != 0) && bpp > 1)
229 ImageRGBAdjust(in, img->xsize, saturation, hue);
230
231 switch (img->colorspace)
232 {
233 case IMAGE_WHITE :
234 ImageRGBToWhite(in, out, img->xsize);
235 break;
236 case IMAGE_BLACK :
237 ImageRGBToBlack(in, out, img->xsize);
238 break;
239 case IMAGE_CMY :
240 ImageRGBToCMY(in, out, img->xsize);
241 break;
242 case IMAGE_CMYK :
243 ImageRGBToCMYK(in, out, img->xsize);
244 break;
6de9968b 245 }
246
247 if (lut)
248 ImageLut(out, img->xsize * bpp, lut);
516ba4c9 249
250 ImagePutRow(img, 0, y, img->xsize, out);
6de9968b 251 }
252 }
253 }
516ba4c9 254
255 free(in);
256 free(out);
257 free(rows[0]);
258
259 sgiClose(sgip);
260
261 return (0);
262}
263
264
265/*
71fe22b7 266 * End of "$Id: image-sgi.c,v 1.6 2000/01/04 13:45:45 mike Exp $".
516ba4c9 267 */