]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/image-sgi.c
2 * "$Id: image-sgi.c 6649 2007-07-11 21:46:42Z mike $"
4 * SGI image file routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 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
);
85 img
->colorspace
= secondary
;
87 img
->colorspace
= (primary
== CUPS_IMAGE_RGB_CMYK
) ? CUPS_IMAGE_RGB
: primary
;
89 img
->xsize
= sgip
->xsize
;
90 img
->ysize
= sgip
->ysize
;
92 cupsImageSetMaxTiles(img
, 0);
94 bpp
= cupsImageGetDepth(img
);
95 in
= malloc(img
->xsize
* sgip
->zsize
);
96 out
= malloc(img
->xsize
* bpp
);
98 rows
[0] = calloc(img
->xsize
* sgip
->zsize
, sizeof(unsigned short));
99 for (i
= 1; i
< sgip
->zsize
; i
++)
100 rows
[i
] = rows
[0] + i
* img
->xsize
;
103 * Read the SGI image file...
106 for (y
= 0; y
< img
->ysize
; y
++)
108 for (i
= 0; i
< sgip
->zsize
; i
++)
109 sgiGetRow(sgip
, rows
[i
], img
->ysize
- 1 - y
, i
);
115 for (i
= img
->xsize
- 1, gray
= rows
[0], inptr
= in
;
122 for (i
= img
->xsize
- 1, gray
= rows
[0], inptr
= in
;
126 *inptr
++ = (*gray
++) / 256 + 128;
131 for (i
= img
->xsize
- 1, gray
= rows
[0], alpha
= rows
[1], inptr
= in
;
135 *inptr
++ = (*gray
++) * (*alpha
++) / 255;
138 for (i
= img
->xsize
- 1, gray
= rows
[0], alpha
= rows
[1], inptr
= in
;
142 *inptr
++ = ((*gray
++) / 256 + 128) * (*alpha
++) / 32767;
147 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
148 blue
= rows
[2], inptr
= in
;
157 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
158 blue
= rows
[2], inptr
= in
;
162 *inptr
++ = (*red
++) / 256 + 128;
163 *inptr
++ = (*green
++) / 256 + 128;
164 *inptr
++ = (*blue
++) / 256 + 128;
169 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
170 blue
= rows
[2], alpha
= rows
[3], inptr
= in
;
174 *inptr
++ = (*red
++) * (*alpha
) / 255;
175 *inptr
++ = (*green
++) * (*alpha
) / 255;
176 *inptr
++ = (*blue
++) * (*alpha
++) / 255;
179 for (i
= img
->xsize
- 1, red
= rows
[0], green
= rows
[1],
180 blue
= rows
[2], alpha
= rows
[3], inptr
= in
;
184 *inptr
++ = ((*red
++) / 256 + 128) * (*alpha
) / 32767;
185 *inptr
++ = ((*green
++) / 256 + 128) * (*alpha
) / 32767;
186 *inptr
++ = ((*blue
++) / 256 + 128) * (*alpha
++) / 32767;
193 if (img
->colorspace
== CUPS_IMAGE_WHITE
)
196 cupsImageLut(in
, img
->xsize
, lut
);
198 _cupsImagePutRow(img
, 0, y
, img
->xsize
, in
);
202 switch (img
->colorspace
)
207 case CUPS_IMAGE_RGB
:
208 case CUPS_IMAGE_RGB_CMYK
:
209 cupsImageWhiteToRGB(in
, out
, img
->xsize
);
211 case CUPS_IMAGE_BLACK
:
212 cupsImageWhiteToBlack(in
, out
, img
->xsize
);
214 case CUPS_IMAGE_CMY
:
215 cupsImageWhiteToCMY(in
, out
, img
->xsize
);
217 case CUPS_IMAGE_CMYK
:
218 cupsImageWhiteToCMYK(in
, out
, img
->xsize
);
223 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
225 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
230 if ((saturation
!= 100 || hue
!= 0) && bpp
> 1)
231 cupsImageRGBAdjust(in
, img
->xsize
, saturation
, hue
);
233 switch (img
->colorspace
)
238 case CUPS_IMAGE_WHITE
:
239 cupsImageRGBToWhite(in
, out
, img
->xsize
);
241 case CUPS_IMAGE_RGB
:
242 cupsImageRGBToRGB(in
, out
, img
->xsize
);
244 case CUPS_IMAGE_BLACK
:
245 cupsImageRGBToBlack(in
, out
, img
->xsize
);
247 case CUPS_IMAGE_CMY
:
248 cupsImageRGBToCMY(in
, out
, img
->xsize
);
250 case CUPS_IMAGE_CMYK
:
251 cupsImageRGBToCMYK(in
, out
, img
->xsize
);
256 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
258 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
273 * End of "$Id: image-sgi.c 6649 2007-07-11 21:46:42Z mike $".