]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/image-photocd.c
2 * "$Id: image-photocd.c,v 1.14 2002/12/17 18:59:26 swdev Exp $"
4 * PhotoCD routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2003 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-3111 USA
20 * Voice: (301) 373-9603
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 * ImageReadPhotoCD() - Read a PhotoCD image file.
32 * Include necessary headers...
39 * PhotoCD support is currently limited to the 768x512 base image, which
40 * is only YCC encoded. Support for the higher resolution images will
41 * require a lot of extra code...
45 * 'ImageReadPhotoCD()' - Read a PhotoCD image file.
48 int /* O - Read status */
49 ImageReadPhotoCD(image_t
*img
, /* IO - Image */
50 FILE *fp
, /* I - Image file */
51 int primary
, /* I - Primary choice for colorspace */
52 int secondary
, /* I - Secondary choice for colorspace */
53 int saturation
, /* I - Color saturation (%) */
54 int hue
, /* I - Color hue (degrees) */
55 const ib_t
*lut
) /* I - Lookup table for gamma/brightness */
57 int x
, y
; /* Looping vars */
58 int xdir
, /* X direction */
59 xstart
; /* X starting point */
60 int bpp
; /* Bytes per pixel */
61 int pass
; /* Pass number */
62 int rotation
; /* 0 for 768x512, 1 for 512x768 */
63 int temp
, /* Adjusted luminance */
64 temp2
, /* Red, green, and blue values */
65 cb
, cr
; /* Adjusted chroma values */
66 ib_t
*in
, /* Input (YCC) pixels */
68 *icb
, /* Blue chroma */
69 *icr
, /* Red chroma */
71 *rgbptr
, /* Pointer into RGB data */
72 *out
; /* Output pixels */
78 * Get the image orientation...
81 fseek(fp
, 72, SEEK_SET
);
82 rotation
= (getc(fp
) & 63) != 8;
85 * Seek to the start of the base image...
88 fseek(fp
, 0x30000, SEEK_SET
);
91 * Allocate and initialize...
94 img
->colorspace
= (primary
== IMAGE_RGB_CMYK
) ? IMAGE_RGB
: primary
;
109 ImageSetMaxTiles(img
, 0);
111 bpp
= ImageGetDepth(img
);
112 in
= malloc(768 * 3);
113 out
= malloc(768 * bpp
);
116 rgb
= malloc(768 * 3);
132 * Read the image file...
135 for (y
= 0; y
< 512; y
+= 2)
138 * Grab the next two scanlines:
145 if (fread(in
, 1, 768 * 3, fp
) < (768 * 3))
148 * Couldn't read a row of data - return an error!
158 * Process the two scanlines...
161 for (pass
= 0, iy
= in
; pass
< 2; pass
++)
166 * Just extract the luminance channel from the line and put it
170 if (primary
== IMAGE_BLACK
)
174 for (rgbptr
= out
+ xstart
, x
= 0; x
< 768; x
++)
175 *rgbptr
-- = 255 - *iy
++;
178 ImageLut(out
, 768, lut
);
180 ImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
184 ImageWhiteToBlack(iy
, out
, 768);
187 ImageLut(out
, 768, lut
);
189 ImagePutRow(img
, 0, y
+ pass
, 768, out
);
195 for (rgbptr
= out
+ xstart
, x
= 0; x
< 768; x
++)
196 *rgbptr
-- = 255 - *iy
++;
199 ImageLut(out
, 768, lut
);
201 ImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
206 ImageLut(iy
, 768, lut
);
208 ImagePutRow(img
, 0, y
+ pass
, 768, iy
);
215 * Convert YCbCr to RGB... While every pixel gets a luminance
216 * value, adjacent pixels share chroma information.
221 for (x
= 0, rgbptr
= rgb
+ xstart
, icb
= in
+ 1536, icr
= in
+ 1920;
223 x
++, iy
++, rgbptr
+= xdir
)
227 cb
= (float)(*icb
- 156);
228 cr
= (float)(*icr
- 137);
231 temp
= 92241 * (*iy
);
233 temp2
= (temp
+ 86706 * cr
) / 65536;
236 else if (temp2
> 255)
241 temp2
= (temp
- 25914 * cb
- 44166 * cr
) / 65536;
244 else if (temp2
> 255)
249 temp2
= (temp
+ 133434 * cb
) / 65536;
252 else if (temp2
> 255)
265 * Adjust the hue and saturation if needed...
268 if (saturation
!= 100 || hue
!= 0)
269 ImageRGBAdjust(rgb
, 768, saturation
, hue
);
272 * Then convert the RGB data to the appropriate colorspace and
273 * put it in the image...
276 if (img
->colorspace
== IMAGE_RGB
)
279 ImageLut(rgb
, 768 * 3, lut
);
282 ImagePutCol(img
, 511 - y
- pass
, 0, 768, rgb
);
284 ImagePutRow(img
, 0, y
+ pass
, 768, rgb
);
288 switch (img
->colorspace
)
291 ImageRGBToCMY(rgb
, out
, 768);
294 ImageRGBToCMYK(rgb
, out
, 768);
299 ImageLut(out
, 768 * bpp
, lut
);
302 ImagePutCol(img
, 511 - y
- pass
, 0, 768, out
);
304 ImagePutRow(img
, 0, y
+ pass
, 768, out
);
311 * Free memory and return...
324 * End of "$Id: image-photocd.c,v 1.14 2002/12/17 18:59:26 swdev Exp $".