]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/image-sgi.c
2 * "$Id: image-sgi.c 6420 2007-03-30 20:00:59Z mike $"
4 * SGI image file routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2007 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 * _cupsImageReadSGI() - Read a SGI image file.
32 * Include necessary headers...
35 #include "image-private.h"
36 #include "image-sgi.h"
40 * '_cupsImageReadSGI()' - Read a SGI image file.
43 int /* O - Read status */
45 cups_image_t
*img
, /* IO - cupsImage */
46 FILE *fp
, /* I - cupsImage file */
47 cups_icspace_t primary
, /* I - Primary choice for colorspace */
48 cups_icspace_t secondary
, /* I - Secondary choice for colorspace */
49 int saturation
, /* I - Color saturation (%) */
50 int hue
, /* I - Color hue (degrees) */
51 const cups_ib_t
*lut
) /* I - Lookup table for gamma/brightness */
53 int i
, y
; /* Looping vars */
54 int bpp
; /* Bytes per pixel */
55 sgi_t
*sgip
; /* SGI image file */
56 cups_ib_t
*in
, /* Input pixels */
57 *inptr
, /* Current input pixel */
58 *out
; /* Output pixels */
59 unsigned short *rows
[4], /* Row pointers for image data */
68 * Setup the SGI file...
71 sgip
= sgiOpenFile(fp
, SGI_READ
, 0, 0, 0, 0, 0);
74 * Get the image dimensions and load the output image...
78 * Check the image dimensions; since xsize and ysize are unsigned shorts,
79 * just check if they are 0 since they can't exceed CUPS_IMAGE_MAX_WIDTH or
80 * CUPS_IMAGE_MAX_HEIGHT...
83 if (sgip
->xsize
== 0 || sgip
->ysize
== 0 ||
84 sgip
->zsize
== 0 || sgip
->zsize
> 4)
86 fprintf(stderr
, "DEBUG: Bad SGI image dimensions %ux%ux%u!\n",
87 sgip
->xsize
, sgip
->ysize
, sgip
->zsize
);
94 img
->colorspace
= secondary
;
96 img
->colorspace
= (primary
== CUPS_IMAGE_RGB_CMYK
) ? CUPS_IMAGE_RGB
: primary
;
98 img
->xsize
= sgip
->xsize
;
99 img
->ysize
= sgip
->ysize
;
101 cupsImageSetMaxTiles(img
, 0);
103 bpp
= cupsImageGetDepth(img
);
104 in
= malloc(img
->xsize
* sgip
->zsize
);
105 out
= malloc(img
->xsize
* bpp
);
107 rows
[0] = calloc(img
->xsize
* sgip
->zsize
, sizeof(unsigned short));
108 for (i
= 1; i
< sgip
->zsize
; i
++)
109 rows
[i
] = rows
[0] + i
* img
->xsize
;
112 * Read the SGI image file...
115 for (y
= 0; y
< img
->ysize
; y
++)
117 for (i
= 0; i
< sgip
->zsize
; i
++)
118 sgiGetRow(sgip
, rows
[i
], img
->ysize
- 1 - y
, i
);
124 for (i
= img
->xsize
- 1, gray
= rows
[0], inptr
= in
;
131 for (i
= img
->xsize
- 1, gray
= rows
[0], inptr
= in
;
135 *inptr
++ = (*gray
++) / 256 + 128;
140 for (i
= img
->xsize
- 1, gray
= rows
[0], alpha
= rows
[1], inptr
= in
;
144 *inptr
++ = (*gray
++) * (*alpha
++) / 255;
147 for (i
= img
->xsize
- 1, gray
= rows
[0], alpha
= rows
[1], inptr
= in
;
151 *inptr
++ = ((*gray
++) / 256 + 128) * (*alpha
++) / 32767;
156 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
157 blue
= rows
[2], inptr
= in
;
166 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
167 blue
= rows
[2], inptr
= in
;
171 *inptr
++ = (*red
++) / 256 + 128;
172 *inptr
++ = (*green
++) / 256 + 128;
173 *inptr
++ = (*blue
++) / 256 + 128;
178 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
179 blue
= rows
[2], alpha
= rows
[3], inptr
= in
;
183 *inptr
++ = (*red
++) * (*alpha
) / 255;
184 *inptr
++ = (*green
++) * (*alpha
) / 255;
185 *inptr
++ = (*blue
++) * (*alpha
++) / 255;
188 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
189 blue
= rows
[2], alpha
= rows
[3], inptr
= in
;
193 *inptr
++ = ((*red
++) / 256 + 128) * (*alpha
) / 32767;
194 *inptr
++ = ((*green
++) / 256 + 128) * (*alpha
) / 32767;
195 *inptr
++ = ((*blue
++) / 256 + 128) * (*alpha
++) / 32767;
202 if (img
->colorspace
== CUPS_IMAGE_WHITE
)
205 cupsImageLut(in
, img
->xsize
, lut
);
207 _cupsImagePutRow(img
, 0, y
, img
->xsize
, in
);
211 switch (img
->colorspace
)
216 case CUPS_IMAGE_RGB
:
217 case CUPS_IMAGE_RGB_CMYK
:
218 cupsImageWhiteToRGB(in
, out
, img
->xsize
);
220 case CUPS_IMAGE_BLACK
:
221 cupsImageWhiteToBlack(in
, out
, img
->xsize
);
223 case CUPS_IMAGE_CMY
:
224 cupsImageWhiteToCMY(in
, out
, img
->xsize
);
226 case CUPS_IMAGE_CMYK
:
227 cupsImageWhiteToCMYK(in
, out
, img
->xsize
);
232 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
234 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
239 if ((saturation
!= 100 || hue
!= 0) && bpp
> 1)
240 cupsImageRGBAdjust(in
, img
->xsize
, saturation
, hue
);
242 switch (img
->colorspace
)
247 case CUPS_IMAGE_WHITE
:
248 cupsImageRGBToWhite(in
, out
, img
->xsize
);
250 case CUPS_IMAGE_RGB
:
251 cupsImageRGBToRGB(in
, out
, img
->xsize
);
253 case CUPS_IMAGE_BLACK
:
254 cupsImageRGBToBlack(in
, out
, img
->xsize
);
256 case CUPS_IMAGE_CMY
:
257 cupsImageRGBToCMY(in
, out
, img
->xsize
);
259 case CUPS_IMAGE_CMYK
:
260 cupsImageRGBToCMYK(in
, out
, img
->xsize
);
265 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
267 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
282 * End of "$Id: image-sgi.c 6420 2007-03-30 20:00:59Z mike $".