]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/image-photocd.c
2 * "$Id: image-photocd.c 5508 2006-05-11 11:41:16Z 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 1993-2006 by Easy Software Products.
12 * These coded instructions, statements, and computer programs are the
13 * property of Easy Software Products and are protected by Federal
14 * copyright law. Distribution and use rights are outlined in the file
15 * "LICENSE.txt" which should have been included with this file. If this
16 * file is missing or damaged please contact Easy Software Products
19 * Attn: CUPS Licensing Information
20 * Easy Software Products
21 * 44141 Airport View Drive, Suite 204
22 * Hollywood, Maryland 20636 USA
24 * Voice: (301) 373-9600
25 * EMail: cups-info@cups.org
26 * WWW: http://www.cups.org
28 * This file is subject to the Apple OS-Developed Software exception.
32 * _cupsImageReadPhotoCD() - Read a PhotoCD image file.
36 * Include necessary headers...
39 #include "image-private.h"
43 * '_cupsImageReadPhotoCD()' - Read a PhotoCD image file.
46 int /* O - Read status */
47 _cupsImageReadPhotoCD(
48 cups_image_t
*img
, /* IO - cupsImage */
49 FILE *fp
, /* I - cupsImage file */
50 cups_icspace_t primary
, /* I - Primary choice for colorspace */
51 cups_icspace_t secondary
, /* I - Secondary choice for colorspace */
52 int saturation
, /* I - Color saturation (%) */
53 int hue
, /* I - Color hue (degrees) */
54 const cups_ib_t
*lut
) /* I - Lookup table for gamma/brightness */
56 int x
, y
; /* Looping vars */
57 int xdir
, /* X direction */
58 xstart
; /* X starting point */
59 int bpp
; /* Bytes per pixel */
60 int pass
; /* Pass number */
61 int rotation
; /* 0 for 768x512, 1 for 512x768 */
62 int temp
, /* Adjusted luminance */
63 temp2
, /* Red, green, and blue values */
64 cb
, cr
; /* Adjusted chroma values */
65 cups_ib_t
*in
, /* Input (YCC) pixels */
67 *icb
, /* Blue chroma */
68 *icr
, /* Red chroma */
70 *rgbptr
, /* Pointer into RGB data */
71 *out
; /* Output pixels */
77 * Get the image orientation...
80 fseek(fp
, 72, SEEK_SET
);
81 rotation
= (getc(fp
) & 63) != 8;
84 * Seek to the start of the base image...
87 fseek(fp
, 0x30000, SEEK_SET
);
90 * Allocate and initialize...
93 img
->colorspace
= (primary
== CUPS_IMAGE_RGB_CMYK
) ? CUPS_IMAGE_RGB
: primary
;
108 cupsImageSetMaxTiles(img
, 0);
110 bpp
= cupsImageGetDepth(img
);
111 in
= malloc(768 * 3);
112 out
= malloc(768 * bpp
);
115 rgb
= malloc(768 * 3);
131 * Read the image file...
134 for (y
= 0; y
< 512; y
+= 2)
137 * Grab the next two scanlines:
144 if (fread(in
, 1, 768 * 3, fp
) < (768 * 3))
147 * Couldn't read a row of data - return an error!
157 * Process the two scanlines...
160 for (pass
= 0, iy
= in
; pass
< 2; pass
++)
165 * Just extract the luminance channel from the line and put it
169 if (primary
== CUPS_IMAGE_BLACK
)
173 for (rgbptr
= out
+ xstart
, x
= 0; x
< 768; x
++)
174 *rgbptr
-- = 255 - *iy
++;
177 cupsImageLut(out
, 768, lut
);
179 _cupsImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
183 cupsImageWhiteToBlack(iy
, out
, 768);
186 cupsImageLut(out
, 768, lut
);
188 _cupsImagePutRow(img
, 0, y
+ pass
, 768, out
);
194 for (rgbptr
= out
+ xstart
, x
= 0; x
< 768; x
++)
195 *rgbptr
-- = 255 - *iy
++;
198 cupsImageLut(out
, 768, lut
);
200 _cupsImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
205 cupsImageLut(iy
, 768, lut
);
207 _cupsImagePutRow(img
, 0, y
+ pass
, 768, iy
);
214 * Convert YCbCr to RGB... While every pixel gets a luminance
215 * value, adjacent pixels share chroma information.
220 for (x
= 0, rgbptr
= rgb
+ xstart
, icb
= in
+ 1536, icr
= in
+ 1920;
222 x
++, iy
++, rgbptr
+= xdir
)
226 cb
= (float)(*icb
- 156);
227 cr
= (float)(*icr
- 137);
230 temp
= 92241 * (*iy
);
232 temp2
= (temp
+ 86706 * cr
) / 65536;
235 else if (temp2
> 255)
240 temp2
= (temp
- 25914 * cb
- 44166 * cr
) / 65536;
243 else if (temp2
> 255)
248 temp2
= (temp
+ 133434 * cb
) / 65536;
251 else if (temp2
> 255)
264 * Adjust the hue and saturation if needed...
267 if (saturation
!= 100 || hue
!= 0)
268 cupsImageRGBAdjust(rgb
, 768, saturation
, hue
);
271 * Then convert the RGB data to the appropriate colorspace and
272 * put it in the image...
275 switch (img
->colorspace
)
280 case CUPS_IMAGE_RGB
:
281 cupsImageRGBToRGB(rgb
, out
, 768);
283 case CUPS_IMAGE_CMY
:
284 cupsImageRGBToCMY(rgb
, out
, 768);
286 case CUPS_IMAGE_CMYK
:
287 cupsImageRGBToCMYK(rgb
, out
, 768);
292 cupsImageLut(out
, 768 * bpp
, lut
);
295 _cupsImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
297 _cupsImagePutRow(img
, 0, y
+ pass
, 768, out
);
303 * Free memory and return...
316 * End of "$Id: image-photocd.c 5508 2006-05-11 11:41:16Z mike $".