]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/image-tiff.c
4 * TIFF file routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2006 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 USA
20 * Voice: (301) 373-9600
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 * _cupsImageReadTIFF() - Read a TIFF image file.
32 * Include necessary headers...
35 #include "image-private.h"
38 # include <tiff.h> /* TIFF image definitions */
44 * '_cupsImageReadTIFF()' - Read a TIFF image file.
47 int /* O - Read status */
49 cups_image_t
*img
, /* IO - cupsImage */
50 FILE *fp
, /* I - cupsImage file */
51 cups_icspace_t primary
, /* I - Primary choice for colorspace */
52 cups_icspace_t secondary
, /* I - Secondary choice for colorspace */
53 int saturation
, /* I - Color saturation (%) */
54 int hue
, /* I - Color hue (degrees) */
55 const cups_ib_t
*lut
) /* I - Lookup table for gamma/brightness */
57 TIFF
*tif
; /* TIFF file */
58 uint32 width
, height
; /* Size of image */
59 uint16 photometric
, /* Colorspace */
60 compression
, /* Type of compression */
61 orientation
, /* Orientation */
62 resunit
, /* Units for resolution */
63 samples
, /* Number of samples/pixel */
64 bits
, /* Number of bits/pixel */
65 inkset
, /* Ink set for color separations */
66 numinks
; /* Number of inks in set */
67 float xres
, /* Horizontal resolution */
68 yres
; /* Vertical resolution */
69 uint16
*redcmap
, /* Red colormap information */
70 *greencmap
, /* Green colormap information */
71 *bluecmap
; /* Blue colormap information */
72 int c
, /* Color index */
73 num_colors
, /* Number of colors */
74 bpp
, /* Bytes per pixel */
75 x
, y
, /* Current x & y */
76 row
, /* Current row in image */
77 xstart
, ystart
, /* Starting x & y */
78 xdir
, ydir
, /* X & y direction */
79 xcount
, ycount
, /* X & Y counters */
80 pstep
, /* Pixel step (= bpp or -2 * bpp) */
81 scanwidth
, /* Width of scanline */
82 r
, g
, b
, k
, /* Red, green, blue, and black values */
83 alpha
; /* cupsImage includes alpha? */
84 cups_ib_t
*in
, /* Input buffer */
85 *out
, /* Output buffer */
86 *p
, /* Pointer into buffer */
87 *scanline
, /* Scanline buffer */
88 *scanptr
, /* Pointer into scanline buffer */
89 bit
, /* Current bit */
90 pixel
, /* Current pixel */
91 zero
, /* Zero value (bitmaps) */
92 one
; /* One value (bitmaps) */
96 * Open the TIFF file and get the required parameters...
99 lseek(fileno(fp
), 0, SEEK_SET
); /* Work around "feature" in some stdio's */
101 if ((tif
= TIFFFdOpen(fileno(fp
), "", "r")) == NULL
)
103 fputs("ERROR: TIFFFdOpen() failed!\n", stderr
);
108 if (!TIFFGetField(tif
, TIFFTAG_IMAGEWIDTH
, &width
))
110 fputs("ERROR: No image width tag in the file!\n", stderr
);
116 if (!TIFFGetField(tif
, TIFFTAG_IMAGELENGTH
, &height
))
118 fputs("ERROR: No image height tag in the file!\n", stderr
);
124 if (!TIFFGetField(tif
, TIFFTAG_PHOTOMETRIC
, &photometric
))
126 fputs("ERROR: No photometric tag in the file!\n", stderr
);
132 if (!TIFFGetField(tif
, TIFFTAG_COMPRESSION
, &compression
))
134 fputs("ERROR: No compression tag in the file!\n", stderr
);
140 if (!TIFFGetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, &samples
))
143 if (!TIFFGetField(tif
, TIFFTAG_BITSPERSAMPLE
, &bits
))
147 * Get the image orientation...
150 if (!TIFFGetField(tif
, TIFFTAG_ORIENTATION
, &orientation
))
154 * Get the image resolution...
157 if (TIFFGetField(tif
, TIFFTAG_XRESOLUTION
, &xres
) &&
158 TIFFGetField(tif
, TIFFTAG_YRESOLUTION
, &yres
) &&
159 TIFFGetField(tif
, TIFFTAG_RESOLUTIONUNIT
, &resunit
))
161 if (resunit
== RESUNIT_INCH
)
166 else if (resunit
== RESUNIT_CENTIMETER
)
168 img
->xppi
= xres
* 2.54;
169 img
->yppi
= yres
* 2.54;
177 if (img
->xppi
== 0 || img
->yppi
== 0)
179 fputs("ERROR: Bad TIFF resolution.\n", stderr
);
180 img
->xppi
= img
->yppi
= 128;
183 fprintf(stderr
, "DEBUG: TIFF resolution = %fx%f, units=%d\n",
184 xres
, yres
, resunit
);
185 fprintf(stderr
, "DEBUG: Stored resolution = %dx%d PPI\n",
186 img
->xppi
, img
->yppi
);
190 * See if the image has an alpha channel...
193 if (samples
== 2 || (samples
== 4 && photometric
== PHOTOMETRIC_RGB
))
199 * Check the size of the image...
202 if (width
== 0 || width
> CUPS_IMAGE_MAX_WIDTH
||
203 height
== 0 || height
> CUPS_IMAGE_MAX_HEIGHT
||
204 (bits
!= 1 && bits
!= 2 && bits
!= 4 && bits
!= 8) ||
205 samples
< 1 || samples
> 4)
207 fprintf(stderr
, "ERROR: Bad TIFF dimensions %ux%ux%ux%u!\n",
208 (unsigned)width
, (unsigned)height
, (unsigned)bits
,
216 * Setup the image size and colorspace...
221 if (photometric
== PHOTOMETRIC_MINISBLACK
||
222 photometric
== PHOTOMETRIC_MINISWHITE
)
223 img
->colorspace
= secondary
;
224 else if (photometric
== PHOTOMETRIC_SEPARATED
&& primary
== CUPS_IMAGE_RGB_CMYK
)
225 img
->colorspace
= CUPS_IMAGE_CMYK
;
226 else if (primary
== CUPS_IMAGE_RGB_CMYK
)
227 img
->colorspace
= CUPS_IMAGE_RGB
;
229 img
->colorspace
= primary
;
231 fprintf(stderr
, "DEBUG: img->colorspace = %d\n", img
->colorspace
);
233 bpp
= cupsImageGetDepth(img
);
235 cupsImageSetMaxTiles(img
, 0);
238 * Set the X & Y start and direction according to the image orientation...
243 case ORIENTATION_TOPRIGHT
:
244 fputs("DEBUG: orientation = top-right\n", stderr
);
246 case ORIENTATION_RIGHTTOP
:
247 fputs("DEBUG: orientation = right-top\n", stderr
);
250 case ORIENTATION_TOPLEFT
:
251 fputs("DEBUG: orientation = top-left\n", stderr
);
253 case ORIENTATION_LEFTTOP
:
254 fputs("DEBUG: orientation = left-top\n", stderr
);
256 case ORIENTATION_BOTLEFT
:
257 fputs("DEBUG: orientation = bottom-left\n", stderr
);
259 case ORIENTATION_LEFTBOT
:
260 fputs("DEBUG: orientation = left-bottom\n", stderr
);
262 case ORIENTATION_BOTRIGHT
:
263 fputs("DEBUG: orientation = bottom-right\n", stderr
);
265 case ORIENTATION_RIGHTBOT
:
266 fputs("DEBUG: orientation = right-bottom\n", stderr
);
272 case ORIENTATION_TOPRIGHT
:
273 case ORIENTATION_RIGHTTOP
:
274 xstart
= img
->xsize
- 1;
280 case ORIENTATION_TOPLEFT
:
281 case ORIENTATION_LEFTTOP
:
287 case ORIENTATION_BOTLEFT
:
288 case ORIENTATION_LEFTBOT
:
291 ystart
= img
->ysize
- 1;
294 case ORIENTATION_BOTRIGHT
:
295 case ORIENTATION_RIGHTBOT
:
296 xstart
= img
->xsize
- 1;
298 ystart
= img
->ysize
- 1;
304 * Allocate a scanline buffer...
307 scanwidth
= TIFFScanlineSize(tif
);
308 scanline
= _TIFFmalloc(scanwidth
);
311 * Allocate input and output buffers...
314 if (orientation
< ORIENTATION_LEFTTOP
)
316 if (samples
> 1 || photometric
== PHOTOMETRIC_PALETTE
)
321 in
= malloc(img
->xsize
* 3 + 3);
322 out
= malloc(img
->xsize
* bpp
);
326 if (samples
> 1 || photometric
== PHOTOMETRIC_PALETTE
)
331 in
= malloc(img
->ysize
* 3 + 3);
332 out
= malloc(img
->ysize
* bpp
);
336 * Read the image. This is greatly complicated by the fact that TIFF
337 * supports literally hundreds of different colorspaces and orientations,
338 * each which must be handled separately...
341 fprintf(stderr
, "DEBUG: photometric = %d\n", photometric
);
342 fprintf(stderr
, "DEBUG: compression = %d\n", compression
);
346 case PHOTOMETRIC_MINISWHITE
:
347 case PHOTOMETRIC_MINISBLACK
:
348 if (photometric
== PHOTOMETRIC_MINISWHITE
)
359 if (orientation
< ORIENTATION_LEFTTOP
)
365 for (y
= ystart
, ycount
= img
->ysize
, row
= 0;
367 ycount
--, y
+= ydir
, row
++)
371 TIFFReadScanline(tif
, scanline
, row
, 0);
372 for (xcount
= img
->xsize
, scanptr
= scanline
, p
= in
+ xstart
, bit
= 128;
374 xcount
--, p
+= pstep
)
392 TIFFReadScanline(tif
, scanline
, row
, 0);
393 for (xcount
= img
->xsize
, scanptr
= scanline
, p
= in
+ xstart
, bit
= 0xc0;
395 xcount
--, p
+= pstep
)
397 pixel
= *scanptr
& bit
;
400 *p
= (255 * pixel
/ 3) ^ zero
;
413 TIFFReadScanline(tif
, scanline
, row
, 0);
414 for (xcount
= img
->xsize
, scanptr
= scanline
, p
= in
+ xstart
, bit
= 0xf0;
416 xcount
--, p
+= pstep
)
420 *p
= (255 * ((*scanptr
& 0xf0) >> 4) / 15) ^ zero
;
425 *p
= (255 * (*scanptr
& 0x0f) / 15) ^ zero
;
431 else if (xdir
< 0 || zero
|| alpha
)
433 TIFFReadScanline(tif
, scanline
, row
, 0);
439 for (xcount
= img
->xsize
, p
= in
+ xstart
, scanptr
= scanline
;
441 xcount
--, p
+= pstep
, scanptr
+= 2)
442 *p
= (scanptr
[1] * (255 - scanptr
[0]) +
443 (255 - scanptr
[1]) * 255) / 255;
447 for (xcount
= img
->xsize
, p
= in
+ xstart
, scanptr
= scanline
;
449 xcount
--, p
+= pstep
, scanptr
+= 2)
450 *p
= (scanptr
[1] * scanptr
[0] +
451 (255 - scanptr
[1]) * 255) / 255;
458 for (xcount
= img
->xsize
, p
= in
+ xstart
, scanptr
= scanline
;
460 xcount
--, p
+= pstep
, scanptr
++)
465 for (xcount
= img
->xsize
, p
= in
+ xstart
, scanptr
= scanline
;
467 xcount
--, p
+= pstep
, scanptr
++)
473 TIFFReadScanline(tif
, in
, row
, 0);
475 if (img
->colorspace
== CUPS_IMAGE_WHITE
)
478 cupsImageLut(in
, img
->xsize
, lut
);
480 _cupsImagePutRow(img
, 0, y
, img
->xsize
, in
);
484 switch (img
->colorspace
)
489 case CUPS_IMAGE_RGB
:
490 cupsImageWhiteToRGB(in
, out
, img
->xsize
);
492 case CUPS_IMAGE_BLACK
:
493 cupsImageWhiteToBlack(in
, out
, img
->xsize
);
495 case CUPS_IMAGE_CMY
:
496 cupsImageWhiteToCMY(in
, out
, img
->xsize
);
498 case CUPS_IMAGE_CMYK
:
499 cupsImageWhiteToCMYK(in
, out
, img
->xsize
);
504 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
506 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
513 * Column major order...
516 for (x
= xstart
, xcount
= img
->xsize
, row
= 0;
518 xcount
--, x
+= xdir
, row
++)
522 TIFFReadScanline(tif
, scanline
, row
, 0);
523 for (ycount
= img
->ysize
, scanptr
= scanline
, p
= in
+ ystart
, bit
= 128;
525 ycount
--, p
+= ydir
)
543 TIFFReadScanline(tif
, scanline
, row
, 0);
544 for (ycount
= img
->ysize
, scanptr
= scanline
, p
= in
+ ystart
, bit
= 0xc0;
546 ycount
--, p
+= ydir
)
548 pixel
= *scanptr
& 0xc0;
552 *p
= (255 * pixel
/ 3) ^ zero
;
565 TIFFReadScanline(tif
, scanline
, row
, 0);
566 for (ycount
= img
->ysize
, scanptr
= scanline
, p
= in
+ ystart
, bit
= 0xf0;
568 ycount
--, p
+= ydir
)
572 *p
= (255 * ((*scanptr
& 0xf0) >> 4) / 15) ^ zero
;
577 *p
= (255 * (*scanptr
& 0x0f) / 15) ^ zero
;
583 else if (ydir
< 0 || zero
|| alpha
)
585 TIFFReadScanline(tif
, scanline
, row
, 0);
591 for (ycount
= img
->ysize
, p
= in
+ ystart
, scanptr
= scanline
;
593 ycount
--, p
+= ydir
, scanptr
+= 2)
594 *p
= (scanptr
[1] * (255 - scanptr
[0]) +
595 (255 - scanptr
[1]) * 255) / 255;
599 for (ycount
= img
->ysize
, p
= in
+ ystart
, scanptr
= scanline
;
601 ycount
--, p
+= ydir
, scanptr
+= 2)
602 *p
= (scanptr
[1] * scanptr
[0] +
603 (255 - scanptr
[1]) * 255) / 255;
610 for (ycount
= img
->ysize
, p
= in
+ ystart
, scanptr
= scanline
;
612 ycount
--, p
+= ydir
, scanptr
++)
617 for (ycount
= img
->ysize
, p
= in
+ ystart
, scanptr
= scanline
;
619 ycount
--, p
+= ydir
, scanptr
++)
625 TIFFReadScanline(tif
, in
, row
, 0);
627 if (img
->colorspace
== CUPS_IMAGE_WHITE
)
630 cupsImageLut(in
, img
->ysize
, lut
);
632 _cupsImagePutCol(img
, x
, 0, img
->ysize
, in
);
636 switch (img
->colorspace
)
641 case CUPS_IMAGE_RGB
:
642 cupsImageWhiteToRGB(in
, out
, img
->ysize
);
644 case CUPS_IMAGE_BLACK
:
645 cupsImageWhiteToBlack(in
, out
, img
->ysize
);
647 case CUPS_IMAGE_CMY
:
648 cupsImageWhiteToCMY(in
, out
, img
->ysize
);
650 case CUPS_IMAGE_CMYK
:
651 cupsImageWhiteToCMYK(in
, out
, img
->ysize
);
656 cupsImageLut(out
, img
->ysize
* bpp
, lut
);
658 _cupsImagePutCol(img
, x
, 0, img
->ysize
, out
);
664 case PHOTOMETRIC_PALETTE
:
665 if (!TIFFGetField(tif
, TIFFTAG_COLORMAP
, &redcmap
, &greencmap
, &bluecmap
))
667 fputs("ERROR: No colormap tag in the file!\n", stderr
);
672 num_colors
= 1 << bits
;
674 for (c
= 0; c
< num_colors
; c
++)
681 if (orientation
< ORIENTATION_LEFTTOP
)
687 for (y
= ystart
, ycount
= img
->ysize
, row
= 0;
689 ycount
--, y
+= ydir
, row
++)
693 TIFFReadScanline(tif
, scanline
, row
, 0);
694 for (xcount
= img
->xsize
, scanptr
= scanline
,
695 p
= in
+ xstart
* 3, bit
= 128;
697 xcount
--, p
+= pstep
)
723 TIFFReadScanline(tif
, scanline
, row
, 0);
724 for (xcount
= img
->xsize
, scanptr
= scanline
,
725 p
= in
+ xstart
* 3, bit
= 0xc0;
727 xcount
--, p
+= pstep
)
729 pixel
= *scanptr
& bit
;
733 p
[0] = redcmap
[pixel
];
734 p
[1] = greencmap
[pixel
];
735 p
[2] = bluecmap
[pixel
];
748 TIFFReadScanline(tif
, scanline
, row
, 0);
749 for (xcount
= img
->xsize
, scanptr
= scanline
,
750 p
= in
+ 3 * xstart
, bit
= 0xf0;
752 xcount
--, p
+= pstep
)
756 pixel
= (*scanptr
& 0xf0) >> 4;
757 p
[0] = redcmap
[pixel
];
758 p
[1] = greencmap
[pixel
];
759 p
[2] = bluecmap
[pixel
];
764 pixel
= *scanptr
++ & 0x0f;
765 p
[0] = redcmap
[pixel
];
766 p
[1] = greencmap
[pixel
];
767 p
[2] = bluecmap
[pixel
];
774 TIFFReadScanline(tif
, scanline
, row
, 0);
776 for (xcount
= img
->xsize
, p
= in
+ 3 * xstart
, scanptr
= scanline
;
778 xcount
--, p
+= pstep
)
780 p
[0] = redcmap
[*scanptr
];
781 p
[1] = greencmap
[*scanptr
];
782 p
[2] = bluecmap
[*scanptr
++];
786 switch (img
->colorspace
)
791 case CUPS_IMAGE_WHITE
:
792 cupsImageRGBToWhite(in
, out
, img
->xsize
);
794 case CUPS_IMAGE_RGB
:
795 cupsImageRGBToRGB(in
, out
, img
->xsize
);
797 case CUPS_IMAGE_BLACK
:
798 cupsImageRGBToBlack(in
, out
, img
->xsize
);
800 case CUPS_IMAGE_CMY
:
801 cupsImageRGBToCMY(in
, out
, img
->xsize
);
803 case CUPS_IMAGE_CMYK
:
804 cupsImageRGBToCMYK(in
, out
, img
->xsize
);
809 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
811 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
817 * Column major order...
820 for (x
= xstart
, xcount
= img
->xsize
, row
= 0;
822 xcount
--, x
+= xdir
, row
++)
826 TIFFReadScanline(tif
, scanline
, row
, 0);
827 for (ycount
= img
->ysize
, scanptr
= scanline
,
828 p
= in
+ 3 * ystart
, bit
= 128;
830 ycount
--, p
+= ydir
)
856 TIFFReadScanline(tif
, scanline
, row
, 0);
857 for (ycount
= img
->ysize
, scanptr
= scanline
,
858 p
= in
+ 3 * ystart
, bit
= 0xc0;
860 ycount
--, p
+= ydir
)
862 pixel
= *scanptr
& 0xc0;
866 p
[0] = redcmap
[pixel
];
867 p
[1] = greencmap
[pixel
];
868 p
[2] = bluecmap
[pixel
];
881 TIFFReadScanline(tif
, scanline
, row
, 0);
882 for (ycount
= img
->ysize
, scanptr
= scanline
,
883 p
= in
+ 3 * ystart
, bit
= 0xf0;
885 ycount
--, p
+= ydir
)
889 pixel
= (*scanptr
& 0xf0) >> 4;
890 p
[0] = redcmap
[pixel
];
891 p
[1] = greencmap
[pixel
];
892 p
[2] = bluecmap
[pixel
];
897 pixel
= *scanptr
++ & 0x0f;
898 p
[0] = redcmap
[pixel
];
899 p
[1] = greencmap
[pixel
];
900 p
[2] = bluecmap
[pixel
];
907 TIFFReadScanline(tif
, scanline
, row
, 0);
909 for (ycount
= img
->ysize
, p
= in
+ 3 * ystart
, scanptr
= scanline
;
911 ycount
--, p
+= ydir
)
913 p
[0] = redcmap
[*scanptr
];
914 p
[1] = greencmap
[*scanptr
];
915 p
[2] = bluecmap
[*scanptr
++];
919 switch (img
->colorspace
)
924 case CUPS_IMAGE_WHITE
:
925 cupsImageRGBToWhite(in
, out
, img
->ysize
);
927 case CUPS_IMAGE_RGB
:
928 cupsImageRGBToRGB(in
, out
, img
->ysize
);
930 case CUPS_IMAGE_BLACK
:
931 cupsImageRGBToBlack(in
, out
, img
->ysize
);
933 case CUPS_IMAGE_CMY
:
934 cupsImageRGBToCMY(in
, out
, img
->ysize
);
936 case CUPS_IMAGE_CMYK
:
937 cupsImageRGBToCMYK(in
, out
, img
->ysize
);
942 cupsImageLut(out
, img
->ysize
* bpp
, lut
);
944 _cupsImagePutCol(img
, x
, 0, img
->ysize
, out
);
949 case PHOTOMETRIC_RGB
:
950 if (orientation
< ORIENTATION_LEFTTOP
)
956 for (y
= ystart
, ycount
= img
->ysize
, row
= 0;
958 ycount
--, y
+= ydir
, row
++)
962 TIFFReadScanline(tif
, scanline
, row
, 0);
963 for (xcount
= img
->xsize
, scanptr
= scanline
, p
= in
+ xstart
* 3, bit
= 0xf0;
965 xcount
--, p
+= pstep
)
967 if (*scanptr
& bit
& 0x88)
972 if (*scanptr
& bit
& 0x44)
977 if (*scanptr
& bit
& 0x22)
993 TIFFReadScanline(tif
, scanline
, row
, 0);
994 for (xcount
= img
->xsize
, scanptr
= scanline
, p
= in
+ xstart
* 3;
996 xcount
--, p
+= pstep
, scanptr
++)
998 pixel
= *scanptr
>> 2;
999 p
[0] = 255 * (pixel
& 3) / 3;
1001 p
[1] = 255 * (pixel
& 3) / 3;
1003 p
[2] = 255 * (pixel
& 3) / 3;
1008 TIFFReadScanline(tif
, scanline
, row
, 0);
1009 for (xcount
= img
->xsize
, scanptr
= scanline
, p
= in
+ xstart
* 3;
1011 xcount
-= 2, p
+= 2 * pstep
, scanptr
+= 3)
1014 p
[1] = 255 * (pixel
& 15) / 15;
1016 p
[0] = 255 * (pixel
& 15) / 15;
1018 p
[2] = 255 * ((pixel
>> 4) & 15) / 15;
1022 p
[pstep
+ 0] = 255 * (pixel
& 15) / 15;
1024 p
[pstep
+ 2] = 255 * (pixel
& 15) / 15;
1026 p
[pstep
+ 1] = 255 * (pixel
& 15) / 15;
1030 else if (xdir
< 0 || alpha
)
1032 TIFFReadScanline(tif
, scanline
, row
, 0);
1036 for (xcount
= img
->xsize
, p
= in
+ xstart
* 3, scanptr
= scanline
;
1038 xcount
--, p
+= pstep
, scanptr
+= 4)
1040 p
[0] = (scanptr
[0] * scanptr
[3] + 255 * (255 - scanptr
[3])) / 255;
1041 p
[1] = (scanptr
[1] * scanptr
[3] + 255 * (255 - scanptr
[3])) / 255;
1042 p
[2] = (scanptr
[2] * scanptr
[3] + 255 * (255 - scanptr
[3])) / 255;
1047 for (xcount
= img
->xsize
, p
= in
+ xstart
* 3, scanptr
= scanline
;
1049 xcount
--, p
+= pstep
, scanptr
+= 3)
1058 TIFFReadScanline(tif
, in
, row
, 0);
1060 if ((saturation
!= 100 || hue
!= 0) && bpp
> 1)
1061 cupsImageRGBAdjust(in
, img
->xsize
, saturation
, hue
);
1063 switch (img
->colorspace
)
1068 case CUPS_IMAGE_WHITE
:
1069 cupsImageRGBToWhite(in
, out
, img
->xsize
);
1071 case CUPS_IMAGE_RGB
:
1072 cupsImageRGBToRGB(in
, out
, img
->xsize
);
1074 case CUPS_IMAGE_BLACK
:
1075 cupsImageRGBToBlack(in
, out
, img
->xsize
);
1077 case CUPS_IMAGE_CMY
:
1078 cupsImageRGBToCMY(in
, out
, img
->xsize
);
1080 case CUPS_IMAGE_CMYK
:
1081 cupsImageRGBToCMYK(in
, out
, img
->xsize
);
1086 cupsImageLut(out
, img
->xsize
* bpp
, lut
);
1088 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
1094 * Column major order...
1097 for (x
= xstart
, xcount
= img
->xsize
, row
= 0;
1099 xcount
--, x
+= xdir
, row
++)
1103 TIFFReadScanline(tif
, scanline
, row
, 0);
1104 for (ycount
= img
->ysize
, scanptr
= scanline
, p
= in
+ ystart
* 3, bit
= 0xf0;
1106 ycount
--, p
+= pstep
)
1108 if (*scanptr
& bit
& 0x88)
1113 if (*scanptr
& bit
& 0x44)
1118 if (*scanptr
& bit
& 0x22)
1134 TIFFReadScanline(tif
, scanline
, row
, 0);
1135 for (ycount
= img
->ysize
, scanptr
= scanline
, p
= in
+ ystart
* 3;
1137 ycount
--, p
+= pstep
, scanptr
++)
1139 pixel
= *scanptr
>> 2;
1140 p
[0] = 255 * (pixel
& 3) / 3;
1142 p
[1] = 255 * (pixel
& 3) / 3;
1144 p
[2] = 255 * (pixel
& 3) / 3;
1149 TIFFReadScanline(tif
, scanline
, row
, 0);
1150 for (ycount
= img
->ysize
, scanptr
= scanline
, p
= in
+ ystart
* 3;
1152 ycount
-= 2, p
+= 2 * pstep
, scanptr
+= 3)
1155 p
[1] = 255 * (pixel
& 15) / 15;
1157 p
[0] = 255 * (pixel
& 15) / 15;
1159 p
[2] = 255 * ((pixel
>> 4) & 15) / 15;
1163 p
[pstep
+ 0] = 255 * (pixel
& 15) / 15;
1165 p
[pstep
+ 2] = 255 * (pixel
& 15) / 15;
1167 p
[pstep
+ 1] = 255 * (pixel
& 15) / 15;
1171 else if (ydir
< 0 || alpha
)
1173 TIFFReadScanline(tif
, scanline
, row
, 0);
1177 for (ycount
= img
->ysize
, p
= in
+ ystart
* 3, scanptr
= scanline
;
1179 ycount
--, p
+= pstep
, scanptr
+= 4)
1181 p
[0] = (scanptr
[0] * scanptr
[3] + 255 * (255 - scanptr
[3])) / 255;
1182 p
[1] = (scanptr
[1] * scanptr
[3] + 255 * (255 - scanptr
[3])) / 255;
1183 p
[2] = (scanptr
[2] * scanptr
[3] + 255 * (255 - scanptr
[3])) / 255;
1188 for (ycount
= img
->ysize
, p
= in
+ ystart
* 3, scanptr
= scanline
;
1190 ycount
--, p
+= pstep
, scanptr
+= 3)
1199 TIFFReadScanline(tif
, in
, row
, 0);
1201 if ((saturation
!= 100 || hue
!= 0) && bpp
> 1)
1202 cupsImageRGBAdjust(in
, img
->ysize
, saturation
, hue
);
1204 switch (img
->colorspace
)
1209 case CUPS_IMAGE_WHITE
:
1210 cupsImageRGBToWhite(in
, out
, img
->ysize
);
1212 case CUPS_IMAGE_RGB
:
1213 cupsImageRGBToRGB(in
, out
, img
->ysize
);
1215 case CUPS_IMAGE_BLACK
:
1216 cupsImageRGBToBlack(in
, out
, img
->ysize
);
1218 case CUPS_IMAGE_CMY
:
1219 cupsImageRGBToCMY(in
, out
, img
->ysize
);
1221 case CUPS_IMAGE_CMYK
:
1222 cupsImageRGBToCMYK(in
, out
, img
->ysize
);
1227 cupsImageLut(out
, img
->ysize
* bpp
, lut
);
1229 _cupsImagePutCol(img
, x
, 0, img
->ysize
, out
);
1234 case PHOTOMETRIC_SEPARATED
:
1235 inkset
= INKSET_CMYK
;
1238 #ifdef TIFFTAG_NUMBEROFINKS
1239 if (!TIFFGetField(tif
, TIFFTAG_INKSET
, &inkset
) &&
1240 !TIFFGetField(tif
, TIFFTAG_NUMBEROFINKS
, &numinks
))
1242 if (!TIFFGetField(tif
, TIFFTAG_INKSET
, &inkset
))
1243 #endif /* TIFFTAG_NUMBEROFINKS */
1245 fputs("WARNING: No inkset or number-of-inks tag in the file!\n", stderr
);
1248 if (inkset
== INKSET_CMYK
|| numinks
== 4)
1250 if (orientation
< ORIENTATION_LEFTTOP
)
1253 * Row major order...
1256 for (y
= ystart
, ycount
= img
->ysize
, row
= 0;
1258 ycount
--, y
+= ydir
, row
++)
1262 TIFFReadScanline(tif
, scanline
, row
, 0);
1263 for (xcount
= img
->xsize
, scanptr
= scanline
, p
= in
+ xstart
* 3, bit
= 0xf0;
1265 xcount
--, p
+= pstep
)
1267 if (*scanptr
& bit
& 0x11)
1275 if (*scanptr
& bit
& 0x88)
1280 if (*scanptr
& bit
& 0x44)
1285 if (*scanptr
& bit
& 0x22)
1302 TIFFReadScanline(tif
, scanline
, row
, 0);
1303 for (xcount
= img
->xsize
, scanptr
= scanline
, p
= in
+ xstart
* 3;
1305 xcount
--, p
+= pstep
, scanptr
++)
1308 k
= 255 * (pixel
& 3) / 3;
1318 b
= 255 - 255 * (pixel
& 3) / 3 - k
;
1327 g
= 255 - 255 * (pixel
& 3) / 3 - k
;
1336 r
= 255 - 255 * (pixel
& 3) / 3 - k
;
1348 TIFFReadScanline(tif
, scanline
, row
, 0);
1349 for (xcount
= img
->xsize
, scanptr
= scanline
, p
= in
+ xstart
* 3;
1351 xcount
--, p
+= pstep
, scanptr
+= 2)
1354 k
= 255 * (pixel
& 15) / 15;
1364 b
= 255 - 255 * (pixel
& 15) / 15 - k
;
1373 g
= 255 - 255 * (pixel
& 15) / 15 - k
;
1382 r
= 255 - 255 * (pixel
& 15) / 15 - k
;
1392 else if (img
->colorspace
== CUPS_IMAGE_CMYK
)
1394 TIFFReadScanline(tif
, scanline
, row
, 0);
1395 _cupsImagePutRow(img
, 0, y
, img
->xsize
, scanline
);
1399 TIFFReadScanline(tif
, scanline
, row
, 0);
1401 for (xcount
= img
->xsize
, p
= in
+ xstart
* 3, scanptr
= scanline
;
1403 xcount
--, p
+= pstep
, scanptr
+= 4)
1414 r
= 255 - scanptr
[0] - k
;
1422 g
= 255 - scanptr
[1] - k
;
1430 b
= 255 - scanptr
[2] - k
;
1441 if ((saturation
!= 100 || hue
!= 0) && bpp
> 1)
1442 cupsImageRGBAdjust(in
, img
->xsize
, saturation
, hue
);
1444 switch (img
->colorspace
)
1449 case CUPS_IMAGE_WHITE
:
1450 cupsImageRGBToWhite(in
, out
, img
->xsize
);
1452 case CUPS_IMAGE_RGB
:
1453 cupsImageRGBToRGB(in
, out
, img
->xsize
);
1455 case CUPS_IMAGE_BLACK
:
1456 cupsImageRGBToBlack(in
, out
, img
->xsize
);
1458 case CUPS_IMAGE_CMY
:
1459 cupsImageRGBToCMY(in
, out
, img
->xsize
);
1461 case CUPS_IMAGE_CMYK
:
1462 cupsImageRGBToCMYK(in
, out
, img
->xsize
);
1467 cupsImageLut(out
, img
->xsize
* 3, lut
);
1469 _cupsImagePutRow(img
, 0, y
, img
->xsize
, out
);
1475 * Column major order...
1478 for (x
= xstart
, xcount
= img
->xsize
, row
= 0;
1480 xcount
--, x
+= xdir
, row
++)
1484 TIFFReadScanline(tif
, scanline
, row
, 0);
1485 for (ycount
= img
->ysize
, scanptr
= scanline
, p
= in
+ xstart
* 3, bit
= 0xf0;
1487 ycount
--, p
+= pstep
)
1489 if (*scanptr
& bit
& 0x11)
1497 if (*scanptr
& bit
& 0x88)
1502 if (*scanptr
& bit
& 0x44)
1507 if (*scanptr
& bit
& 0x22)
1524 TIFFReadScanline(tif
, scanline
, row
, 0);
1525 for (ycount
= img
->ysize
, scanptr
= scanline
, p
= in
+ xstart
* 3;
1527 ycount
--, p
+= pstep
, scanptr
++)
1530 k
= 255 * (pixel
& 3) / 3;
1540 b
= 255 - 255 * (pixel
& 3) / 3 - k
;
1549 g
= 255 - 255 * (pixel
& 3) / 3 - k
;
1558 r
= 255 - 255 * (pixel
& 3) / 3 - k
;
1570 TIFFReadScanline(tif
, scanline
, row
, 0);
1571 for (ycount
= img
->ysize
, scanptr
= scanline
, p
= in
+ xstart
* 3;
1573 ycount
--, p
+= pstep
, scanptr
+= 2)
1576 k
= 255 * (pixel
& 15) / 15;
1586 b
= 255 - 255 * (pixel
& 15) / 15 - k
;
1595 g
= 255 - 255 * (pixel
& 15) / 15 - k
;
1604 r
= 255 - 255 * (pixel
& 15) / 15 - k
;
1614 else if (img
->colorspace
== CUPS_IMAGE_CMYK
)
1616 TIFFReadScanline(tif
, scanline
, row
, 0);
1617 _cupsImagePutCol(img
, x
, 0, img
->ysize
, scanline
);
1621 TIFFReadScanline(tif
, scanline
, row
, 0);
1623 for (ycount
= img
->ysize
, p
= in
+ xstart
* 3, scanptr
= scanline
;
1625 ycount
--, p
+= pstep
, scanptr
+= 4)
1636 r
= 255 - scanptr
[0] - k
;
1644 g
= 255 - scanptr
[1] - k
;
1652 b
= 255 - scanptr
[2] - k
;
1663 if ((saturation
!= 100 || hue
!= 0) && bpp
> 1)
1664 cupsImageRGBAdjust(in
, img
->ysize
, saturation
, hue
);
1666 switch (img
->colorspace
)
1671 case CUPS_IMAGE_WHITE
:
1672 cupsImageRGBToWhite(in
, out
, img
->ysize
);
1674 case CUPS_IMAGE_RGB
:
1675 cupsImageRGBToRGB(in
, out
, img
->ysize
);
1677 case CUPS_IMAGE_BLACK
:
1678 cupsImageRGBToBlack(in
, out
, img
->ysize
);
1680 case CUPS_IMAGE_CMY
:
1681 cupsImageRGBToCMY(in
, out
, img
->ysize
);
1683 case CUPS_IMAGE_CMYK
:
1684 cupsImageRGBToCMYK(in
, out
, img
->ysize
);
1689 cupsImageLut(out
, img
->ysize
* bpp
, lut
);
1691 _cupsImagePutCol(img
, x
, 0, img
->ysize
, out
);
1699 _TIFFfree(scanline
);
1704 fputs("ERROR: Unknown TIFF photometric value!\n", stderr
);
1709 * Free temporary buffers, close the TIFF file, and return.
1712 _TIFFfree(scanline
);
1719 #endif /* HAVE_LIBTIFF */