]>
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 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
);
102 in
= malloc(768 * 3);
103 out
= malloc(768 * bpp
);
106 rgb
= malloc(768 * 3);
122 * Read the image file...
125 for (y
= 0; y
< 512; y
+= 2)
128 * Grab the next two scanlines:
135 if (fread(in
, 1, 768 * 3, fp
) < (768 * 3))
138 * Couldn't read a row of data - return an error!
148 * Process the two scanlines...
151 for (pass
= 0, iy
= in
; pass
< 2; pass
++)
156 * Just extract the luminance channel from the line and put it
160 if (primary
== CUPS_IMAGE_BLACK
)
164 for (rgbptr
= out
+ xstart
, x
= 0; x
< 768; x
++)
165 *rgbptr
-- = 255 - *iy
++;
168 cupsImageLut(out
, 768, lut
);
170 _cupsImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
174 cupsImageWhiteToBlack(iy
, out
, 768);
177 cupsImageLut(out
, 768, lut
);
179 _cupsImagePutRow(img
, 0, y
+ pass
, 768, out
);
185 for (rgbptr
= out
+ xstart
, x
= 0; x
< 768; x
++)
186 *rgbptr
-- = 255 - *iy
++;
189 cupsImageLut(out
, 768, lut
);
191 _cupsImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
196 cupsImageLut(iy
, 768, lut
);
198 _cupsImagePutRow(img
, 0, y
+ pass
, 768, iy
);
205 * Convert YCbCr to RGB... While every pixel gets a luminance
206 * value, adjacent pixels share chroma information.
211 for (x
= 0, rgbptr
= rgb
+ xstart
, icb
= in
+ 1536, icr
= in
+ 1920;
213 x
++, iy
++, rgbptr
+= xdir
)
217 cb
= (float)(*icb
- 156);
218 cr
= (float)(*icr
- 137);
221 temp
= 92241 * (*iy
);
223 temp2
= (temp
+ 86706 * cr
) / 65536;
226 else if (temp2
> 255)
231 temp2
= (temp
- 25914 * cb
- 44166 * cr
) / 65536;
234 else if (temp2
> 255)
239 temp2
= (temp
+ 133434 * cb
) / 65536;
242 else if (temp2
> 255)
255 * Adjust the hue and saturation if needed...
258 if (saturation
!= 100 || hue
!= 0)
259 cupsImageRGBAdjust(rgb
, 768, saturation
, hue
);
262 * Then convert the RGB data to the appropriate colorspace and
263 * put it in the image...
266 switch (img
->colorspace
)
271 case CUPS_IMAGE_RGB
:
272 cupsImageRGBToRGB(rgb
, out
, 768);
274 case CUPS_IMAGE_CMY
:
275 cupsImageRGBToCMY(rgb
, out
, 768);
277 case CUPS_IMAGE_CMYK
:
278 cupsImageRGBToCMYK(rgb
, out
, 768);
283 cupsImageLut(out
, 768 * bpp
, lut
);
286 _cupsImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
288 _cupsImagePutRow(img
, 0, y
+ pass
, 768, out
);
294 * Free memory and return...
307 * End of "$Id: image-photocd.c 6649 2007-07-11 21:46:42Z mike $".