]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/image-sgi.c
2 * "$Id: image-sgi.c 7223 2008-01-16 23:41:19Z mike $"
4 * SGI image file 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 * _cupsImageReadSGI() - Read a SGI image file.
23 * Include necessary headers...
26 #include "image-private.h"
27 #include "image-sgi.h"
31 * '_cupsImageReadSGI()' - Read a SGI image file.
34 int /* O - Read status */
36 cups_image_t
*img
, /* IO - cupsImage */
37 FILE *fp
, /* I - cupsImage file */
38 cups_icspace_t primary
, /* I - Primary choice for colorspace */
39 cups_icspace_t secondary
, /* I - Secondary choice for colorspace */
40 int saturation
, /* I - Color saturation (%) */
41 int hue
, /* I - Color hue (degrees) */
42 const cups_ib_t
*lut
) /* I - Lookup table for gamma/brightness */
44 int i
, y
; /* Looping vars */
45 int bpp
; /* Bytes per pixel */
46 sgi_t
*sgip
; /* SGI image file */
47 cups_ib_t
*in
, /* Input pixels */
48 *inptr
, /* Current input pixel */
49 *out
; /* Output pixels */
50 unsigned short *rows
[4], /* Row pointers for image data */
59 * Setup the SGI file...
62 sgip
= sgiOpenFile(fp
, SGI_READ
, 0, 0, 0, 0, 0);
65 * Get the image dimensions and load the output image...
69 * Check the image dimensions; since xsize and ysize are unsigned shorts,
70 * just check if they are 0 since they can't exceed CUPS_IMAGE_MAX_WIDTH or
71 * CUPS_IMAGE_MAX_HEIGHT...
74 if (sgip
->xsize
== 0 || sgip
->ysize
== 0 ||
75 sgip
->zsize
== 0 || sgip
->zsize
> 4)
77 fprintf(stderr
, "DEBUG: Bad SGI image dimensions %ux%ux%u!\n",
78 sgip
->xsize
, sgip
->ysize
, sgip
->zsize
);
84 img
->colorspace
= secondary
;
86 img
->colorspace
= (primary
== CUPS_IMAGE_RGB_CMYK
) ? CUPS_IMAGE_RGB
: primary
;
88 img
->xsize
= sgip
->xsize
;
89 img
->ysize
= sgip
->ysize
;
91 cupsImageSetMaxTiles(img
, 0);
93 bpp
= cupsImageGetDepth(img
);
95 if ((in
= malloc(img
->xsize
* sgip
->zsize
)) == NULL
)
97 fputs("DEBUG: Unable to allocate memory!\n", stderr
);
102 if ((out
= malloc(img
->xsize
* bpp
)) == NULL
)
104 fputs("DEBUG: Unable to allocate memory!\n", stderr
);
110 if ((rows
[0] = calloc(img
->xsize
* sgip
->zsize
,
111 sizeof(unsigned short))) == NULL
)
113 fputs("DEBUG: Unable to allocate memory!\n", stderr
);
120 for (i
= 1; i
< sgip
->zsize
; i
++)
121 rows
[i
] = rows
[0] + i
* img
->xsize
;
124 * Read the SGI image file...
127 for (y
= 0; y
< img
->ysize
; y
++)
129 for (i
= 0; i
< sgip
->zsize
; i
++)
130 sgiGetRow(sgip
, rows
[i
], img
->ysize
- 1 - y
, i
);
136 for (i
= img
->xsize
- 1, gray
= rows
[0], inptr
= in
;
143 for (i
= img
->xsize
- 1, gray
= rows
[0], inptr
= in
;
147 *inptr
++ = (*gray
++) / 256 + 128;
152 for (i
= img
->xsize
- 1, gray
= rows
[0], alpha
= rows
[1], inptr
= in
;
156 *inptr
++ = (*gray
++) * (*alpha
++) / 255;
159 for (i
= img
->xsize
- 1, gray
= rows
[0], alpha
= rows
[1], inptr
= in
;
163 *inptr
++ = ((*gray
++) / 256 + 128) * (*alpha
++) / 32767;
168 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
169 blue
= rows
[2], inptr
= in
;
178 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
179 blue
= rows
[2], inptr
= in
;
183 *inptr
++ = (*red
++) / 256 + 128;
184 *inptr
++ = (*green
++) / 256 + 128;
185 *inptr
++ = (*blue
++) / 256 + 128;
190 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
191 blue
= rows
[2], alpha
= rows
[3], inptr
= in
;
195 *inptr
++ = (*red
++) * (*alpha
) / 255;
196 *inptr
++ = (*green
++) * (*alpha
) / 255;
197 *inptr
++ = (*blue
++) * (*alpha
++) / 255;
200 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
201 blue
= rows
[2], alpha
= rows
[3], inptr
= in
;
205 *inptr
++ = ((*red
++) / 256 + 128) * (*alpha
) / 32767;
206 *inptr
++ = ((*green
++) / 256 + 128) * (*alpha
) / 32767;
207 *inptr
++ = ((*blue
++) / 256 + 128) * (*alpha
++) / 32767;
214 if (img
->colorspace
== CUPS_IMAGE_WHITE
)
217 cupsImageLut(in
, img
->xsize
, lut
);
219 _cupsImagePutRow(img
, 0, y
, img
->xsize
, in
);
223 switch (img
->colorspace
)
228 case CUPS_IMAGE_RGB
:
229 case CUPS_IMAGE_RGB_CMYK
:
230 cupsImageWhiteToRGB(in
, out
, img
->xsize
);
232 case CUPS_IMAGE_BLACK
:
233 cupsImageWhiteToBlack(in
, out
, img
->xsize
);
235 case CUPS_IMAGE_CMY
:
236 cupsImageWhiteToCMY(in
, out
, img
->xsize
);
238 case CUPS_IMAGE_CMYK
:
239 cupsImageWhiteToCMYK(in
, out
, img
->xsize
);
244 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
246 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
251 if ((saturation
!= 100 || hue
!= 0) && bpp
> 1)
252 cupsImageRGBAdjust(in
, img
->xsize
, saturation
, hue
);
254 switch (img
->colorspace
)
259 case CUPS_IMAGE_WHITE
:
260 cupsImageRGBToWhite(in
, out
, img
->xsize
);
262 case CUPS_IMAGE_RGB
:
263 cupsImageRGBToRGB(in
, out
, img
->xsize
);
265 case CUPS_IMAGE_BLACK
:
266 cupsImageRGBToBlack(in
, out
, img
->xsize
);
268 case CUPS_IMAGE_CMY
:
269 cupsImageRGBToCMY(in
, out
, img
->xsize
);
271 case CUPS_IMAGE_CMYK
:
272 cupsImageRGBToCMYK(in
, out
, img
->xsize
);
277 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
279 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
294 * End of "$Id: image-sgi.c 7223 2008-01-16 23:41:19Z mike $".