]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/image-photocd.c
2 * "$Id: image-photocd.c 6649 2007-07-11 21:46:42Z mike $"
4 * PhotoCD routines for the Common UNIX Printing System (CUPS).
6 * PhotoCD support is currently limited to the 768x512 base image, which
7 * is only YCC encoded. Support for the higher resolution images will
8 * require a lot of extra code...
10 * Copyright 2007-2008 by Apple Inc.
11 * Copyright 1993-2006 by Easy Software Products.
13 * These coded instructions, statements, and computer programs are the
14 * property of Apple Inc. and are protected by Federal copyright
15 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
16 * which should have been included with this file. If this file is
17 * file is missing or damaged, see the license at "http://www.cups.org/".
19 * This file is subject to the Apple OS-Developed Software exception.
23 * _cupsImageReadPhotoCD() - Read a PhotoCD image file.
27 * Include necessary headers...
30 #include "image-private.h"
34 * '_cupsImageReadPhotoCD()' - Read a PhotoCD image file.
37 int /* O - Read status */
38 _cupsImageReadPhotoCD(
39 cups_image_t
*img
, /* IO - cupsImage */
40 FILE *fp
, /* I - cupsImage file */
41 cups_icspace_t primary
, /* I - Primary choice for colorspace */
42 cups_icspace_t secondary
, /* I - Secondary choice for colorspace */
43 int saturation
, /* I - Color saturation (%) */
44 int hue
, /* I - Color hue (degrees) */
45 const cups_ib_t
*lut
) /* I - Lookup table for gamma/brightness */
47 int x
, y
; /* Looping vars */
48 int xdir
, /* X direction */
49 xstart
; /* X starting point */
50 int bpp
; /* Bytes per pixel */
51 int pass
; /* Pass number */
52 int rotation
; /* 0 for 768x512, 1 for 512x768 */
53 int temp
, /* Adjusted luminance */
54 temp2
, /* Red, green, and blue values */
55 cb
, cr
; /* Adjusted chroma values */
56 cups_ib_t
*in
, /* Input (YCC) pixels */
58 *icb
, /* Blue chroma */
59 *icr
, /* Red chroma */
61 *rgbptr
, /* Pointer into RGB data */
62 *out
; /* Output pixels */
68 * Get the image orientation...
71 fseek(fp
, 72, SEEK_SET
);
72 rotation
= (getc(fp
) & 63) != 8;
75 * Seek to the start of the base image...
78 fseek(fp
, 0x30000, SEEK_SET
);
81 * Allocate and initialize...
84 img
->colorspace
= (primary
== CUPS_IMAGE_RGB_CMYK
) ? CUPS_IMAGE_RGB
: primary
;
99 cupsImageSetMaxTiles(img
, 0);
101 bpp
= cupsImageGetDepth(img
);
103 if ((in
= malloc(768 * 3)) == NULL
)
105 fputs("DEBUG: Unable to allocate memory!\n", stderr
);
110 if ((out
= malloc(768 * bpp
)) == NULL
)
112 fputs("DEBUG: Unable to allocate memory!\n", stderr
);
120 if ((rgb
= malloc(768 * 3)) == NULL
)
122 fputs("DEBUG: Unable to allocate memory!\n", stderr
);
144 * Read the image file...
147 for (y
= 0; y
< 512; y
+= 2)
150 * Grab the next two scanlines:
157 if (fread(in
, 1, 768 * 3, fp
) < (768 * 3))
160 * Couldn't read a row of data - return an error!
173 * Process the two scanlines...
176 for (pass
= 0, iy
= in
; pass
< 2; pass
++)
181 * Just extract the luminance channel from the line and put it
185 if (primary
== CUPS_IMAGE_BLACK
)
189 for (rgbptr
= out
+ xstart
, x
= 0; x
< 768; x
++)
190 *rgbptr
-- = 255 - *iy
++;
193 cupsImageLut(out
, 768, lut
);
195 _cupsImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
199 cupsImageWhiteToBlack(iy
, out
, 768);
202 cupsImageLut(out
, 768, lut
);
204 _cupsImagePutRow(img
, 0, y
+ pass
, 768, out
);
210 for (rgbptr
= out
+ xstart
, x
= 0; x
< 768; x
++)
211 *rgbptr
-- = 255 - *iy
++;
214 cupsImageLut(out
, 768, lut
);
216 _cupsImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
221 cupsImageLut(iy
, 768, lut
);
223 _cupsImagePutRow(img
, 0, y
+ pass
, 768, iy
);
230 * Convert YCbCr to RGB... While every pixel gets a luminance
231 * value, adjacent pixels share chroma information.
236 for (x
= 0, rgbptr
= rgb
+ xstart
, icb
= in
+ 1536, icr
= in
+ 1920;
238 x
++, iy
++, rgbptr
+= xdir
)
242 cb
= (float)(*icb
- 156);
243 cr
= (float)(*icr
- 137);
246 temp
= 92241 * (*iy
);
248 temp2
= (temp
+ 86706 * cr
) / 65536;
251 else if (temp2
> 255)
256 temp2
= (temp
- 25914 * cb
- 44166 * cr
) / 65536;
259 else if (temp2
> 255)
264 temp2
= (temp
+ 133434 * cb
) / 65536;
267 else if (temp2
> 255)
280 * Adjust the hue and saturation if needed...
283 if (saturation
!= 100 || hue
!= 0)
284 cupsImageRGBAdjust(rgb
, 768, saturation
, hue
);
287 * Then convert the RGB data to the appropriate colorspace and
288 * put it in the image...
291 switch (img
->colorspace
)
296 case CUPS_IMAGE_RGB
:
297 cupsImageRGBToRGB(rgb
, out
, 768);
299 case CUPS_IMAGE_CMY
:
300 cupsImageRGBToCMY(rgb
, out
, 768);
302 case CUPS_IMAGE_CMYK
:
303 cupsImageRGBToCMYK(rgb
, out
, 768);
308 cupsImageLut(out
, 768 * bpp
, lut
);
311 _cupsImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
313 _cupsImagePutRow(img
, 0, y
+ pass
, 768, out
);
319 * Free memory and return...
332 * End of "$Id: image-photocd.c 6649 2007-07-11 21:46:42Z mike $".