2 * "$Id: imagetoraster.c 6649 2007-07-11 21:46:42Z mike $"
4 * Image file to raster filter for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1993-2007 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * main() - Main entry...
20 * blank_line() - Clear a line buffer to the blank value...
21 * format_CMY() - Convert image data to CMY.
22 * format_CMYK() - Convert image data to CMYK.
23 * format_K() - Convert image data to black.
24 * format_KCMY() - Convert image data to KCMY.
25 * format_KCMYcm() - Convert image data to KCMYcm.
26 * format_RGBA() - Convert image data to RGBA/RGBW.
27 * format_W() - Convert image data to luminance.
28 * format_YMC() - Convert image data to YMC.
29 * format_YMCK() - Convert image data to YMCK.
30 * make_lut() - Make a lookup table given gamma and brightness values.
31 * raster_cb() - Validate the page header.
35 * Include necessary headers...
39 #include "image-private.h"
42 #include <cups/i18n.h>
49 int Flip
= 0, /* Flip/mirror pages */
50 XPosition
= 0, /* Horizontal position on page */
51 YPosition
= 0, /* Vertical position on page */
52 Collate
= 0, /* Collate copies? */
53 Copies
= 1; /* Number of copies */
54 int Floyd16x16
[16][16] = /* Traditional Floyd ordered dither */
56 { 0, 128, 32, 160, 8, 136, 40, 168,
57 2, 130, 34, 162, 10, 138, 42, 170 },
58 { 192, 64, 224, 96, 200, 72, 232, 104,
59 194, 66, 226, 98, 202, 74, 234, 106 },
60 { 48, 176, 16, 144, 56, 184, 24, 152,
61 50, 178, 18, 146, 58, 186, 26, 154 },
62 { 240, 112, 208, 80, 248, 120, 216, 88,
63 242, 114, 210, 82, 250, 122, 218, 90 },
64 { 12, 140, 44, 172, 4, 132, 36, 164,
65 14, 142, 46, 174, 6, 134, 38, 166 },
66 { 204, 76, 236, 108, 196, 68, 228, 100,
67 206, 78, 238, 110, 198, 70, 230, 102 },
68 { 60, 188, 28, 156, 52, 180, 20, 148,
69 62, 190, 30, 158, 54, 182, 22, 150 },
70 { 252, 124, 220, 92, 244, 116, 212, 84,
71 254, 126, 222, 94, 246, 118, 214, 86 },
72 { 3, 131, 35, 163, 11, 139, 43, 171,
73 1, 129, 33, 161, 9, 137, 41, 169 },
74 { 195, 67, 227, 99, 203, 75, 235, 107,
75 193, 65, 225, 97, 201, 73, 233, 105 },
76 { 51, 179, 19, 147, 59, 187, 27, 155,
77 49, 177, 17, 145, 57, 185, 25, 153 },
78 { 243, 115, 211, 83, 251, 123, 219, 91,
79 241, 113, 209, 81, 249, 121, 217, 89 },
80 { 15, 143, 47, 175, 7, 135, 39, 167,
81 13, 141, 45, 173, 5, 133, 37, 165 },
82 { 207, 79, 239, 111, 199, 71, 231, 103,
83 205, 77, 237, 109, 197, 69, 229, 101 },
84 { 63, 191, 31, 159, 55, 183, 23, 151,
85 61, 189, 29, 157, 53, 181, 21, 149 },
86 { 254, 127, 223, 95, 247, 119, 215, 87,
87 253, 125, 221, 93, 245, 117, 213, 85 }
91 { 0, 32, 8, 40, 2, 34, 10, 42 },
92 { 48, 16, 56, 24, 50, 18, 58, 26 },
93 { 12, 44, 4, 36, 14, 46, 6, 38 },
94 { 60, 28, 52, 20, 62, 30, 54, 22 },
95 { 3, 35, 11, 43, 1, 33, 9, 41 },
96 { 51, 19, 59, 27, 49, 17, 57, 25 },
97 { 15, 47, 7, 39, 13, 45, 5, 37 },
98 { 63, 31, 55, 23, 61, 29, 53, 21 }
108 cups_ib_t OnPixels
[256], /* On-pixel LUT */
109 OffPixels
[256]; /* Off-pixel LUT */
116 static void blank_line(cups_page_header2_t
*header
, unsigned char *row
);
117 static void format_CMY(cups_page_header2_t
*header
, unsigned char *row
, int y
, int z
, int xsize
, int ysize
, int yerr0
, int yerr1
, cups_ib_t
*r0
, cups_ib_t
*r1
);
118 static void format_CMYK(cups_page_header2_t
*header
, unsigned char *row
, int y
, int z
, int xsize
, int ysize
, int yerr0
, int yerr1
, cups_ib_t
*r0
, cups_ib_t
*r1
);
119 static void format_K(cups_page_header2_t
*header
, unsigned char *row
, int y
, int z
, int xsize
, int ysize
, int yerr0
, int yerr1
, cups_ib_t
*r0
, cups_ib_t
*r1
);
120 static void format_KCMYcm(cups_page_header2_t
*header
, unsigned char *row
, int y
, int z
, int xsize
, int ysize
, int yerr0
, int yerr1
, cups_ib_t
*r0
, cups_ib_t
*r1
);
121 static void format_KCMY(cups_page_header2_t
*header
, unsigned char *row
, int y
, int z
, int xsize
, int ysize
, int yerr0
, int yerr1
, cups_ib_t
*r0
, cups_ib_t
*r1
);
122 #define format_RGB format_CMY
123 static void format_RGBA(cups_page_header2_t
*header
, unsigned char *row
, int y
, int z
, int xsize
, int ysize
, int yerr0
, int yerr1
, cups_ib_t
*r0
, cups_ib_t
*r1
);
124 static void format_W(cups_page_header2_t
*header
, unsigned char *row
, int y
, int z
, int xsize
, int ysize
, int yerr0
, int yerr1
, cups_ib_t
*r0
, cups_ib_t
*r1
);
125 static void format_YMC(cups_page_header2_t
*header
, unsigned char *row
, int y
, int z
, int xsize
, int ysize
, int yerr0
, int yerr1
, cups_ib_t
*r0
, cups_ib_t
*r1
);
126 static void format_YMCK(cups_page_header2_t
*header
, unsigned char *row
, int y
, int z
, int xsize
, int ysize
, int yerr0
, int yerr1
, cups_ib_t
*r0
, cups_ib_t
*r1
);
127 static void make_lut(cups_ib_t
*, int, float, float);
128 static int raster_cb(cups_page_header2_t
*header
, int preferred_bits
);
132 * 'main()' - Main entry...
135 int /* O - Exit status */
136 main(int argc
, /* I - Number of command-line arguments */
137 char *argv
[]) /* I - Command-line arguments */
139 int i
; /* Looping var */
140 cups_image_t
*img
; /* Image to print */
141 float xprint
, /* Printable area */
143 xinches
, /* Total size in inches */
145 float xsize
, /* Total size in points */
149 float aspect
; /* Aspect ratio */
150 int xpages
, /* # x pages */
151 ypages
, /* # y pages */
152 xpage
, /* Current x page */
153 ypage
, /* Current y page */
154 xtemp
, /* Bitmap width in pixels */
155 ytemp
, /* Bitmap height in pixels */
156 page
; /* Current page number */
157 int xc0
, yc0
, /* Corners of the page in image coords */
159 ppd_file_t
*ppd
; /* PPD file */
160 ppd_choice_t
*choice
; /* PPD option choice */
161 char *resolution
, /* Output resolution */
162 *media_type
; /* Media type */
163 ppd_profile_t
*profile
; /* Color profile */
164 ppd_profile_t userprofile
; /* User-specified profile */
165 cups_raster_t
*ras
; /* Raster stream */
166 cups_page_header2_t header
; /* Page header */
167 int num_options
; /* Number of print options */
168 cups_option_t
*options
; /* Print options */
169 const char *val
; /* Option value */
170 int slowcollate
, /* Collate copies the slow way */
171 slowcopies
; /* Make copies the "slow" way? */
172 float g
; /* Gamma correction value */
173 float b
; /* Brightness factor */
174 float zoom
; /* Zoom facter */
175 int xppi
, yppi
; /* Pixels-per-inch */
176 int hue
, sat
; /* Hue and saturation adjustment */
177 cups_izoom_t
*z
; /* Image zoom buffer */
178 cups_iztype_t zoom_type
; /* Image zoom type */
179 int primary
, /* Primary image colorspace */
180 secondary
; /* Secondary image colorspace */
181 cups_ib_t
*row
, /* Current row */
183 *r1
; /* Bottom row */
184 int y
, /* Current Y coordinate on page */
185 iy
, /* Current Y coordinate in image */
186 last_iy
, /* Previous Y coordinate in image */
187 yerr0
, /* Top Y error value */
188 yerr1
; /* Bottom Y error value */
189 cups_ib_t lut
[256]; /* Gamma/brightness LUT */
190 int plane
, /* Current color plane */
191 num_planes
; /* Number of color planes */
192 char filename
[1024]; /* Name of file to print */
196 * Make sure status messages are not buffered...
199 setbuf(stderr
, NULL
);
202 * Check command-line...
205 if (argc
< 6 || argc
> 7)
207 fprintf(stderr
, _("Usage: %s job-id user title copies options [file]\n"),
213 * See if we need to use the imagetops and pstoraster filters instead...
217 num_options
= cupsParseOptions(argv
[5], 0, &options
);
219 if (getenv("CLASSIFICATION") ||
220 cupsGetOption("page-label", num_options
, options
))
223 * Yes, fork a copy of pstoraster and then transfer control to imagetops...
226 int mypipes
[2]; /* New pipes for imagetops | pstoraster */
227 int pid
; /* PID of pstoraster */
230 cupsFreeOptions(num_options
, options
);
234 perror("ERROR: Unable to create pipes for imagetops | pstoraster");
238 if ((pid
= fork()) == 0)
241 * Child process for pstoraster... Assign new pipe input to pstoraster...
249 execlp("pstoraster", argv
[0], argv
[1], argv
[2], argv
[3], argv
[4], argv
[5],
251 perror("ERROR: Unable to exec pstoraster");
260 perror("ERROR: Unable to fork pstoraster");
265 * Update stdout so it points at the new pstoraster...
274 * Run imagetops to get the classification or page labelling that was
278 execlp("imagetops", argv
[0], argv
[1], argv
[2], argv
[3], argv
[4], argv
[5],
280 perror("ERROR: Unable to exec imagetops");
285 * Copy stdin as needed...
290 int fd
; /* File to write to */
291 char buffer
[8192]; /* Buffer to read into */
292 int bytes
; /* # of bytes to read */
295 if ((fd
= cupsTempFd(filename
, sizeof(filename
))) < 0)
297 perror("ERROR: Unable to copy image file");
301 fprintf(stderr
, "DEBUG: imagetoraster - copying to temp print file \"%s\"\n",
304 while ((bytes
= fread(buffer
, 1, sizeof(buffer
), stdin
)) > 0)
305 write(fd
, buffer
, bytes
);
310 strlcpy(filename
, argv
[6], sizeof(filename
));
313 * Process command-line options and write the prolog...
324 Copies
= atoi(argv
[4]);
326 ppd
= SetCommonOptions(num_options
, options
, 0);
328 if ((val
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
331 * This IPP attribute is unnecessarily complicated...
333 * single-document, separate-documents-collated-copies, and
334 * single-document-new-sheet all require collated copies.
336 * separate-documents-collated-copies allows for uncollated copies.
339 Collate
= strcasecmp(val
, "separate-documents-collated-copies") != 0;
342 if ((val
= cupsGetOption("Collate", num_options
, options
)) != NULL
&&
343 strcasecmp(val
, "True") == 0)
346 if ((val
= cupsGetOption("gamma", num_options
, options
)) != NULL
)
349 * Get gamma value from 1 to 10000...
352 g
= atoi(val
) * 0.001f
;
360 if ((val
= cupsGetOption("brightness", num_options
, options
)) != NULL
)
363 * Get brightness value from 10 to 1000.
366 b
= atoi(val
) * 0.01f
;
374 if ((val
= cupsGetOption("scaling", num_options
, options
)) != NULL
)
375 zoom
= atoi(val
) * 0.01;
376 else if (cupsGetOption("fitplot", num_options
, options
))
379 if ((val
= cupsGetOption("ppi", num_options
, options
)) != NULL
)
380 if (sscanf(val
, "%dx%d", &xppi
, &yppi
) < 2)
383 if ((val
= cupsGetOption("position", num_options
, options
)) != NULL
)
385 if (strcasecmp(val
, "center") == 0)
390 else if (strcasecmp(val
, "top") == 0)
395 else if (strcasecmp(val
, "left") == 0)
400 else if (strcasecmp(val
, "right") == 0)
405 else if (strcasecmp(val
, "top-left") == 0)
410 else if (strcasecmp(val
, "top-right") == 0)
415 else if (strcasecmp(val
, "bottom") == 0)
420 else if (strcasecmp(val
, "bottom-left") == 0)
425 else if (strcasecmp(val
, "bottom-right") == 0)
432 if ((val
= cupsGetOption("saturation", num_options
, options
)) != NULL
)
435 if ((val
= cupsGetOption("hue", num_options
, options
)) != NULL
)
438 if ((choice
= ppdFindMarkedChoice(ppd
, "MirrorPrint")) != NULL
)
440 val
= choice
->choice
;
444 val
= cupsGetOption("mirror", num_options
, options
);
446 if (val
&& (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
447 !strcasecmp(val
, "yes")))
451 * Set the needed options in the page header...
454 if (cupsRasterInterpretPPD(&header
, ppd
, num_options
, options
, raster_cb
))
456 fputs(_("ERROR: Bad page setup!\n"), stderr
);
457 fprintf(stderr
, "DEBUG: %s\n", cupsRasterErrorString());
462 * Get the media type and resolution that have been chosen...
465 if ((choice
= ppdFindMarkedChoice(ppd
, "MediaType")) != NULL
)
466 media_type
= choice
->choice
;
470 if ((choice
= ppdFindMarkedChoice(ppd
, "Resolution")) != NULL
)
471 resolution
= choice
->choice
;
476 * Choose the appropriate colorspace...
479 switch (header
.cupsColorSpace
)
482 if (header
.cupsBitsPerColor
>= 8)
484 primary
= CUPS_IMAGE_WHITE
;
485 secondary
= CUPS_IMAGE_WHITE
;
489 primary
= CUPS_IMAGE_BLACK
;
490 secondary
= CUPS_IMAGE_BLACK
;
495 case CUPS_CSPACE_RGB
:
496 case CUPS_CSPACE_RGBA
:
497 case CUPS_CSPACE_RGBW
:
498 if (header
.cupsBitsPerColor
>= 8)
500 primary
= CUPS_IMAGE_RGB
;
501 secondary
= CUPS_IMAGE_RGB
;
505 primary
= CUPS_IMAGE_CMY
;
506 secondary
= CUPS_IMAGE_CMY
;
511 case CUPS_CSPACE_WHITE
:
512 case CUPS_CSPACE_GOLD
:
513 case CUPS_CSPACE_SILVER
:
514 primary
= CUPS_IMAGE_BLACK
;
515 secondary
= CUPS_IMAGE_BLACK
;
518 case CUPS_CSPACE_CMYK
:
519 case CUPS_CSPACE_YMCK
:
520 case CUPS_CSPACE_KCMY
:
521 case CUPS_CSPACE_KCMYcm
:
522 case CUPS_CSPACE_GMCK
:
523 case CUPS_CSPACE_GMCS
:
524 if (header
.cupsBitsPerColor
== 1)
526 primary
= CUPS_IMAGE_CMY
;
527 secondary
= CUPS_IMAGE_CMY
;
531 primary
= CUPS_IMAGE_CMYK
;
532 secondary
= CUPS_IMAGE_CMYK
;
536 case CUPS_CSPACE_CMY
:
537 case CUPS_CSPACE_YMC
:
538 primary
= CUPS_IMAGE_CMY
;
539 secondary
= CUPS_IMAGE_CMY
;
545 * Find a color profile matching the current options...
548 if ((val
= cupsGetOption("profile", num_options
, options
)) != NULL
)
550 profile
= &userprofile
;
551 sscanf(val
, "%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",
552 &(userprofile
.density
), &(userprofile
.gamma
),
553 userprofile
.matrix
[0] + 0, userprofile
.matrix
[0] + 1,
554 userprofile
.matrix
[0] + 2,
555 userprofile
.matrix
[1] + 0, userprofile
.matrix
[1] + 1,
556 userprofile
.matrix
[1] + 2,
557 userprofile
.matrix
[2] + 0, userprofile
.matrix
[2] + 1,
558 userprofile
.matrix
[2] + 2);
560 userprofile
.density
*= 0.001f
;
561 userprofile
.gamma
*= 0.001f
;
562 userprofile
.matrix
[0][0] *= 0.001f
;
563 userprofile
.matrix
[0][1] *= 0.001f
;
564 userprofile
.matrix
[0][2] *= 0.001f
;
565 userprofile
.matrix
[1][0] *= 0.001f
;
566 userprofile
.matrix
[1][1] *= 0.001f
;
567 userprofile
.matrix
[1][2] *= 0.001f
;
568 userprofile
.matrix
[2][0] *= 0.001f
;
569 userprofile
.matrix
[2][1] *= 0.001f
;
570 userprofile
.matrix
[2][2] *= 0.001f
;
572 else if (ppd
!= NULL
)
574 fprintf(stderr
, "DEBUG: Searching for profile \"%s/%s\"...\n",
575 resolution
, media_type
);
577 for (i
= 0, profile
= ppd
->profiles
; i
< ppd
->num_profiles
; i
++, profile
++)
579 fprintf(stderr
, "DEBUG: \"%s/%s\" = ", profile
->resolution
,
580 profile
->media_type
);
582 if ((strcmp(profile
->resolution
, resolution
) == 0 ||
583 profile
->resolution
[0] == '-') &&
584 (strcmp(profile
->media_type
, media_type
) == 0 ||
585 profile
->media_type
[0] == '-'))
587 fputs("MATCH!\n", stderr
);
591 fputs("no.\n", stderr
);
595 * If we found a color profile, use it!
598 if (i
>= ppd
->num_profiles
)
605 cupsImageSetProfile(profile
->density
, profile
->gamma
, profile
->matrix
);
607 cupsImageSetRasterColorSpace(header
.cupsColorSpace
);
610 * Create a gamma/brightness LUT...
613 make_lut(lut
, primary
, g
, b
);
616 * Open the input image to print...
619 fputs(_("INFO: Loading image file...\n"), stderr
);
621 if (header
.cupsColorSpace
== CUPS_CSPACE_CIEXYZ
||
622 header
.cupsColorSpace
== CUPS_CSPACE_CIELab
||
623 header
.cupsColorSpace
>= CUPS_CSPACE_ICC1
)
624 img
= cupsImageOpen(filename
, primary
, secondary
, sat
, hue
, NULL
);
626 img
= cupsImageOpen(filename
, primary
, secondary
, sat
, hue
, lut
);
633 fputs(_("ERROR: Unable to open image file for printing!\n"), stderr
);
639 * Scale as necessary...
642 if (zoom
== 0.0 && xppi
== 0)
651 fprintf(stderr
, "DEBUG: Before scaling: xppi=%d, yppi=%d, zoom=%.2f\n",
657 * Scale the image as neccesary to match the desired pixels-per-inch.
662 xprint
= (PageTop
- PageBottom
) / 72.0;
663 yprint
= (PageRight
- PageLeft
) / 72.0;
667 xprint
= (PageRight
- PageLeft
) / 72.0;
668 yprint
= (PageTop
- PageBottom
) / 72.0;
671 fprintf(stderr
, "DEBUG: Before scaling: xprint=%.1f, yprint=%.1f\n",
674 xinches
= (float)img
->xsize
/ (float)xppi
;
675 yinches
= (float)img
->ysize
/ (float)yppi
;
677 fprintf(stderr
, "DEBUG: Image size is %.1f x %.1f inches...\n",
680 if ((val
= cupsGetOption("natural-scaling", num_options
, options
)) != NULL
)
682 xinches
= xinches
* atoi(val
) / 100;
683 yinches
= yinches
* atoi(val
) / 100;
686 if (cupsGetOption("orientation-requested", num_options
, options
) == NULL
&&
687 cupsGetOption("landscape", num_options
, options
) == NULL
)
690 * Rotate the image if it will fit landscape but not portrait...
693 fputs("DEBUG: Auto orientation...\n", stderr
);
695 if ((xinches
> xprint
|| yinches
> yprint
) &&
696 xinches
<= yprint
&& yinches
<= xprint
)
699 * Rotate the image as needed...
702 fputs("DEBUG: Using landscape orientation...\n", stderr
);
704 Orientation
= (Orientation
+ 1) & 3;
714 * Scale percentage of page size...
717 xprint
= (PageRight
- PageLeft
) / 72.0;
718 yprint
= (PageTop
- PageBottom
) / 72.0;
719 aspect
= (float)img
->yppi
/ (float)img
->xppi
;
721 fprintf(stderr
, "DEBUG: Before scaling: xprint=%.1f, yprint=%.1f\n",
724 fprintf(stderr
, "DEBUG: img->xppi = %d, img->yppi = %d, aspect = %f\n",
725 img
->xppi
, img
->yppi
, aspect
);
727 xsize
= xprint
* zoom
;
728 ysize
= xsize
* img
->ysize
/ img
->xsize
/ aspect
;
730 if (ysize
> (yprint
* zoom
))
732 ysize
= yprint
* zoom
;
733 xsize
= ysize
* img
->xsize
* aspect
/ img
->ysize
;
736 xsize2
= yprint
* zoom
;
737 ysize2
= xsize2
* img
->ysize
/ img
->xsize
/ aspect
;
739 if (ysize2
> (xprint
* zoom
))
741 ysize2
= xprint
* zoom
;
742 xsize2
= ysize2
* img
->xsize
* aspect
/ img
->ysize
;
745 fprintf(stderr
, "DEBUG: Portrait size is %.2f x %.2f inches\n", xsize
, ysize
);
746 fprintf(stderr
, "DEBUG: Landscape size is %.2f x %.2f inches\n", xsize2
, ysize2
);
748 if (cupsGetOption("orientation-requested", num_options
, options
) == NULL
&&
749 cupsGetOption("landscape", num_options
, options
) == NULL
)
752 * Choose the rotation with the largest area, but prefer
753 * portrait if they are equal...
756 fputs("DEBUG: Auto orientation...\n", stderr
);
758 if ((xsize
* ysize
) < (xsize2
* xsize2
))
761 * Do landscape orientation...
764 fputs("DEBUG: Using landscape orientation...\n", stderr
);
769 xprint
= (PageTop
- PageBottom
) / 72.0;
770 yprint
= (PageRight
- PageLeft
) / 72.0;
775 * Do portrait orientation...
778 fputs("DEBUG: Using portrait orientation...\n", stderr
);
785 else if (Orientation
& 1)
787 fputs("DEBUG: Using landscape orientation...\n", stderr
);
791 xprint
= (PageTop
- PageBottom
) / 72.0;
792 yprint
= (PageRight
- PageLeft
) / 72.0;
796 fputs("DEBUG: Using portrait orientation...\n", stderr
);
800 xprint
= (PageRight
- PageLeft
) / 72.0;
801 yprint
= (PageTop
- PageBottom
) / 72.0;
806 * Compute the number of pages to print and the size of the image on each
810 xpages
= ceil(xinches
/ xprint
);
811 ypages
= ceil(yinches
/ yprint
);
813 xprint
= xinches
/ xpages
;
814 yprint
= yinches
/ ypages
;
816 fprintf(stderr
, "DEBUG: xpages = %dx%.2fin, ypages = %dx%.2fin\n",
817 xpages
, xprint
, ypages
, yprint
);
820 * Compute the bitmap size...
823 if ((choice
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
&&
824 strcasecmp(choice
->choice
, "Custom") == 0)
826 float width
, /* New width in points */
827 length
; /* New length in points */
831 * Use the correct width and length for the current orientation...
836 width
= yprint
* 72.0;
837 length
= xprint
* 72.0;
841 width
= xprint
* 72.0;
842 length
= yprint
* 72.0;
846 * Add margins to page size...
849 width
+= ppd
->custom_margins
[0] + ppd
->custom_margins
[2];
850 length
+= ppd
->custom_margins
[1] + ppd
->custom_margins
[3];
853 * Enforce minimums...
856 if (width
< ppd
->custom_min
[0])
857 width
= ppd
->custom_min
[0];
859 if (length
< ppd
->custom_min
[1])
860 length
= ppd
->custom_min
[1];
862 fprintf(stderr
, "DEBUG: Updated custom page size to %.2f x %.2f inches...\n",
863 width
/ 72.0, length
/ 72.0);
866 * Set the new custom size...
869 strcpy(header
.cupsPageSizeName
, "Custom");
871 header
.cupsPageSize
[0] = width
+ 0.5;
872 header
.cupsPageSize
[1] = length
+ 0.5;
873 header
.PageSize
[0] = width
+ 0.5;
874 header
.PageSize
[1] = length
+ 0.5;
877 * Update page variables...
882 PageLeft
= ppd
->custom_margins
[0];
883 PageRight
= width
- ppd
->custom_margins
[2];
884 PageBottom
= ppd
->custom_margins
[1];
885 PageTop
= length
- ppd
->custom_margins
[3];
888 * Remove margins from page size...
891 width
-= ppd
->custom_margins
[0] + ppd
->custom_margins
[2];
892 length
-= ppd
->custom_margins
[1] + ppd
->custom_margins
[3];
895 * Set the bitmap size...
898 header
.cupsWidth
= width
* header
.HWResolution
[0] / 72.0;
899 header
.cupsHeight
= length
* header
.HWResolution
[1] / 72.0;
901 header
.cupsBytesPerLine
= (header
.cupsBitsPerPixel
*
902 header
.cupsWidth
+ 7) / 8;
904 if (header
.cupsColorOrder
== CUPS_ORDER_BANDED
)
905 header
.cupsBytesPerLine
*= header
.cupsNumColors
;
908 header
.Margins
[0] = PageLeft
;
909 header
.Margins
[1] = PageBottom
;
911 fprintf(stderr
, "DEBUG: PageSize = [%d %d]\n", header
.PageSize
[0],
920 header
.cupsImagingBBox
[0] = PageLeft
;
921 header
.cupsImagingBBox
[2] = PageLeft
+ xprint
* 72;
924 header
.cupsImagingBBox
[0] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
925 header
.cupsImagingBBox
[2] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
928 header
.cupsImagingBBox
[0] = PageRight
- xprint
* 72;
929 header
.cupsImagingBBox
[2] = PageRight
;
936 header
.cupsImagingBBox
[1] = PageBottom
;
937 header
.cupsImagingBBox
[3] = PageBottom
+ yprint
* 72;
940 header
.cupsImagingBBox
[1] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
941 header
.cupsImagingBBox
[3] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
944 header
.cupsImagingBBox
[1] = PageTop
- yprint
* 72;
945 header
.cupsImagingBBox
[3] = PageTop
;
954 header
.cupsImagingBBox
[0] = PageBottom
;
955 header
.cupsImagingBBox
[2] = PageBottom
+ yprint
* 72;
958 header
.cupsImagingBBox
[0] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
959 header
.cupsImagingBBox
[2] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
962 header
.cupsImagingBBox
[0] = PageTop
- yprint
* 72;
963 header
.cupsImagingBBox
[2] = PageTop
;
970 header
.cupsImagingBBox
[1] = PageLeft
;
971 header
.cupsImagingBBox
[3] = PageLeft
+ xprint
* 72;
974 header
.cupsImagingBBox
[1] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
975 header
.cupsImagingBBox
[3] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
978 header
.cupsImagingBBox
[1] = PageRight
- xprint
* 72;
979 header
.cupsImagingBBox
[3] = PageRight
;
988 header
.cupsImagingBBox
[0] = PageLeft
;
989 header
.cupsImagingBBox
[2] = PageLeft
+ xprint
* 72;
992 header
.cupsImagingBBox
[0] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
993 header
.cupsImagingBBox
[2] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
996 header
.cupsImagingBBox
[0] = PageRight
- xprint
* 72;
997 header
.cupsImagingBBox
[2] = PageRight
;
1004 header
.cupsImagingBBox
[1] = PageBottom
;
1005 header
.cupsImagingBBox
[3] = PageBottom
+ yprint
* 72;
1008 header
.cupsImagingBBox
[1] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
1009 header
.cupsImagingBBox
[3] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
1012 header
.cupsImagingBBox
[1] = PageTop
- yprint
* 72;
1013 header
.cupsImagingBBox
[3] = PageTop
;
1022 header
.cupsImagingBBox
[0] = PageBottom
;
1023 header
.cupsImagingBBox
[2] = PageBottom
+ yprint
* 72;
1026 header
.cupsImagingBBox
[0] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
1027 header
.cupsImagingBBox
[2] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
1030 header
.cupsImagingBBox
[0] = PageTop
- yprint
* 72;
1031 header
.cupsImagingBBox
[2] = PageTop
;
1038 header
.cupsImagingBBox
[1] = PageLeft
;
1039 header
.cupsImagingBBox
[3] = PageLeft
+ xprint
* 72;
1042 header
.cupsImagingBBox
[1] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
1043 header
.cupsImagingBBox
[3] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
1046 header
.cupsImagingBBox
[1] = PageRight
- xprint
* 72;
1047 header
.cupsImagingBBox
[3] = PageRight
;
1053 header
.ImagingBoundingBox
[0] = header
.cupsImagingBBox
[0];
1054 header
.ImagingBoundingBox
[1] = header
.cupsImagingBBox
[1];
1055 header
.ImagingBoundingBox
[2] = header
.cupsImagingBBox
[2];
1056 header
.ImagingBoundingBox
[3] = header
.cupsImagingBBox
[3];
1058 if (header
.cupsColorOrder
== CUPS_ORDER_PLANAR
)
1059 num_planes
= header
.cupsNumColors
;
1063 if (header
.cupsBitsPerColor
>= 8)
1064 zoom_type
= CUPS_IZOOM_NORMAL
;
1066 zoom_type
= CUPS_IZOOM_FAST
;
1069 * See if we need to collate, and if so how we need to do it...
1072 if (xpages
== 1 && ypages
== 1)
1075 slowcollate
= Collate
&& ppdFindOption(ppd
, "Collate") == NULL
;
1077 slowcopies
= ppd
->manual_copies
;
1081 if (Copies
> 1 && !slowcollate
&& !slowcopies
)
1083 header
.Collate
= (cups_bool_t
)Collate
;
1084 header
.NumCopies
= Copies
;
1089 header
.NumCopies
= 1;
1092 * Create the dithering lookup tables...
1096 OnPixels
[255] = 0xff;
1097 OffPixels
[0] = 0x00;
1098 OffPixels
[255] = 0xff;
1100 switch (header
.cupsBitsPerColor
)
1103 for (i
= 1; i
< 255; i
++)
1105 OnPixels
[i
] = 0x55 * (i
/ 85 + 1);
1106 OffPixels
[i
] = 0x55 * (i
/ 64);
1110 for (i
= 1; i
< 255; i
++)
1112 OnPixels
[i
] = 17 * (i
/ 17 + 1);
1113 OffPixels
[i
] = 17 * (i
/ 16);
1119 * Output the pages...
1122 fprintf(stderr
, "DEBUG: cupsWidth = %d\n", header
.cupsWidth
);
1123 fprintf(stderr
, "DEBUG: cupsHeight = %d\n", header
.cupsHeight
);
1124 fprintf(stderr
, "DEBUG: cupsBitsPerColor = %d\n", header
.cupsBitsPerColor
);
1125 fprintf(stderr
, "DEBUG: cupsBitsPerPixel = %d\n", header
.cupsBitsPerPixel
);
1126 fprintf(stderr
, "DEBUG: cupsBytesPerLine = %d\n", header
.cupsBytesPerLine
);
1127 fprintf(stderr
, "DEBUG: cupsColorOrder = %d\n", header
.cupsColorOrder
);
1128 fprintf(stderr
, "DEBUG: cupsColorSpace = %d\n", header
.cupsColorSpace
);
1129 fprintf(stderr
, "DEBUG: img->colorspace = %d\n", img
->colorspace
);
1131 row
= malloc(2 * header
.cupsBytesPerLine
);
1132 ras
= cupsRasterOpen(1, CUPS_RASTER_WRITE
);
1134 for (i
= 0, page
= 1; i
< Copies
; i
++)
1135 for (xpage
= 0; xpage
< xpages
; xpage
++)
1136 for (ypage
= 0; ypage
< ypages
; ypage
++, page
++)
1138 fprintf(stderr
, _("INFO: Formatting page %d...\n"), page
);
1140 if (Orientation
& 1)
1142 xc0
= img
->xsize
* ypage
/ ypages
;
1143 xc1
= img
->xsize
* (ypage
+ 1) / ypages
- 1;
1144 yc0
= img
->ysize
* xpage
/ xpages
;
1145 yc1
= img
->ysize
* (xpage
+ 1) / xpages
- 1;
1147 xtemp
= header
.HWResolution
[0] * yprint
;
1148 ytemp
= header
.HWResolution
[1] * xprint
;
1152 xc0
= img
->xsize
* xpage
/ xpages
;
1153 xc1
= img
->xsize
* (xpage
+ 1) / xpages
- 1;
1154 yc0
= img
->ysize
* ypage
/ ypages
;
1155 yc1
= img
->ysize
* (ypage
+ 1) / ypages
- 1;
1157 xtemp
= header
.HWResolution
[0] * xprint
;
1158 ytemp
= header
.HWResolution
[1] * yprint
;
1161 cupsRasterWriteHeader2(ras
, &header
);
1163 for (plane
= 0; plane
< num_planes
; plane
++)
1166 * Initialize the image "zoom" engine...
1170 z
= _cupsImageZoomNew(img
, xc0
, yc0
, xc1
, yc1
, -xtemp
, ytemp
,
1171 Orientation
& 1, zoom_type
);
1173 z
= _cupsImageZoomNew(img
, xc0
, yc0
, xc1
, yc1
, xtemp
, ytemp
,
1174 Orientation
& 1, zoom_type
);
1177 * Write leading blank space as needed...
1180 if (header
.cupsHeight
> z
->ysize
&& YPosition
<= 0)
1182 blank_line(&header
, row
);
1184 y
= header
.cupsHeight
- z
->ysize
;
1188 fprintf(stderr
, "DEBUG: Writing %d leading blank lines...\n", y
);
1192 if (cupsRasterWritePixels(ras
, row
, header
.cupsBytesPerLine
) <
1193 header
.cupsBytesPerLine
)
1195 fputs(_("ERROR: Unable to write raster data to driver!\n"),
1197 cupsImageClose(img
);
1204 * Then write image data...
1207 for (y
= z
->ysize
, yerr0
= 0, yerr1
= z
->ysize
, iy
= 0, last_iy
= -2;
1213 if (zoom_type
!= CUPS_IZOOM_FAST
&& (iy
- last_iy
) > 1)
1214 _cupsImageZoomFill(z
, iy
);
1216 _cupsImageZoomFill(z
, iy
+ z
->yincr
);
1222 * Format this line of raster data for the printer...
1225 blank_line(&header
, row
);
1227 r0
= z
->rows
[z
->row
];
1228 r1
= z
->rows
[1 - z
->row
];
1230 switch (header
.cupsColorSpace
)
1232 case CUPS_CSPACE_W
:
1233 format_W(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1234 yerr0
, yerr1
, r0
, r1
);
1237 case CUPS_CSPACE_RGB
:
1238 format_RGB(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1239 yerr0
, yerr1
, r0
, r1
);
1241 case CUPS_CSPACE_RGBA
:
1242 case CUPS_CSPACE_RGBW
:
1243 format_RGBA(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1244 yerr0
, yerr1
, r0
, r1
);
1246 case CUPS_CSPACE_K
:
1247 case CUPS_CSPACE_WHITE
:
1248 case CUPS_CSPACE_GOLD
:
1249 case CUPS_CSPACE_SILVER
:
1250 format_K(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1251 yerr0
, yerr1
, r0
, r1
);
1253 case CUPS_CSPACE_CMY
:
1254 format_CMY(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1255 yerr0
, yerr1
, r0
, r1
);
1257 case CUPS_CSPACE_YMC
:
1258 format_YMC(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1259 yerr0
, yerr1
, r0
, r1
);
1261 case CUPS_CSPACE_CMYK
:
1262 format_CMYK(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1263 yerr0
, yerr1
, r0
, r1
);
1265 case CUPS_CSPACE_YMCK
:
1266 case CUPS_CSPACE_GMCK
:
1267 case CUPS_CSPACE_GMCS
:
1268 format_YMCK(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1269 yerr0
, yerr1
, r0
, r1
);
1271 case CUPS_CSPACE_KCMYcm
:
1272 if (header
.cupsBitsPerColor
== 1)
1274 format_KCMYcm(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1275 yerr0
, yerr1
, r0
, r1
);
1278 case CUPS_CSPACE_KCMY
:
1279 format_KCMY(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1280 yerr0
, yerr1
, r0
, r1
);
1285 * Write the raster data to the driver...
1288 if (cupsRasterWritePixels(ras
, row
, header
.cupsBytesPerLine
) <
1289 header
.cupsBytesPerLine
)
1291 fputs(_("ERROR: Unable to write raster data to driver!\n"),
1293 cupsImageClose(img
);
1298 * Compute the next scanline in the image...
1313 * Write trailing blank space as needed...
1316 if (header
.cupsHeight
> z
->ysize
&& YPosition
>= 0)
1318 blank_line(&header
, row
);
1320 y
= header
.cupsHeight
- z
->ysize
;
1324 fprintf(stderr
, "DEBUG: Writing %d trailing blank lines...\n", y
);
1328 if (cupsRasterWritePixels(ras
, row
, header
.cupsBytesPerLine
) <
1329 header
.cupsBytesPerLine
)
1331 fputs(_("ERROR: Unable to write raster data to driver!\n"),
1333 cupsImageClose(img
);
1340 * Free memory used for the "zoom" engine...
1343 _cupsImageZoomDelete(z
);
1352 cupsRasterClose(ras
);
1353 cupsImageClose(img
);
1361 * 'blank_line()' - Clear a line buffer to the blank value...
1365 blank_line(cups_page_header2_t
*header
, /* I - Page header */
1366 unsigned char *row
) /* I - Row buffer */
1368 int count
; /* Remaining bytes */
1371 count
= header
->cupsBytesPerLine
;
1373 switch (header
->cupsColorSpace
)
1375 case CUPS_CSPACE_CIEXYZ
:
1385 case CUPS_CSPACE_CIELab
:
1386 case CUPS_CSPACE_ICC1
:
1387 case CUPS_CSPACE_ICC2
:
1388 case CUPS_CSPACE_ICC3
:
1389 case CUPS_CSPACE_ICC4
:
1390 case CUPS_CSPACE_ICC5
:
1391 case CUPS_CSPACE_ICC6
:
1392 case CUPS_CSPACE_ICC7
:
1393 case CUPS_CSPACE_ICC8
:
1394 case CUPS_CSPACE_ICC9
:
1395 case CUPS_CSPACE_ICCA
:
1396 case CUPS_CSPACE_ICCB
:
1397 case CUPS_CSPACE_ICCC
:
1398 case CUPS_CSPACE_ICCD
:
1399 case CUPS_CSPACE_ICCE
:
1400 case CUPS_CSPACE_ICCF
:
1410 case CUPS_CSPACE_K
:
1411 case CUPS_CSPACE_CMY
:
1412 case CUPS_CSPACE_CMYK
:
1413 case CUPS_CSPACE_YMC
:
1414 case CUPS_CSPACE_YMCK
:
1415 case CUPS_CSPACE_KCMY
:
1416 case CUPS_CSPACE_KCMYcm
:
1417 case CUPS_CSPACE_GMCK
:
1418 case CUPS_CSPACE_GMCS
:
1419 case CUPS_CSPACE_WHITE
:
1420 case CUPS_CSPACE_GOLD
:
1421 case CUPS_CSPACE_SILVER
:
1422 memset(row
, 0, count
);
1426 memset(row
, 255, count
);
1433 * 'format_CMY()' - Convert image data to CMY.
1437 format_CMY(cups_page_header2_t
*header
, /* I - Page header */
1438 unsigned char *row
, /* IO - Bitmap data for device */
1439 int y
, /* I - Current row */
1440 int z
, /* I - Current plane */
1441 int xsize
, /* I - Width of image data */
1442 int ysize
, /* I - Height of image data */
1443 int yerr0
, /* I - Top Y error */
1444 int yerr1
, /* I - Bottom Y error */
1445 cups_ib_t
*r0
, /* I - Primary image data */
1446 cups_ib_t
*r1
) /* I - Image data for interpolation */
1448 cups_ib_t
*ptr
, /* Pointer into row */
1449 *cptr
, /* Pointer into cyan */
1450 *mptr
, /* Pointer into magenta */
1451 *yptr
, /* Pointer into yellow */
1452 bitmask
; /* Current mask for pixel */
1453 int bitoffset
; /* Current offset in line */
1454 int bandwidth
; /* Width of a color band */
1455 int x
, /* Current X coordinate on page */
1456 *dither
; /* Pointer into dither array */
1465 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
1468 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
1472 ptr
= row
+ bitoffset
/ 8;
1473 bandwidth
= header
->cupsBytesPerLine
/ 3;
1475 switch (header
->cupsColorOrder
)
1477 case CUPS_ORDER_CHUNKED
:
1478 switch (header
->cupsBitsPerColor
)
1481 bitmask
= 64 >> (bitoffset
& 7);
1482 dither
= Floyd16x16
[y
& 15];
1484 for (x
= xsize
; x
> 0; x
--)
1486 if (*r0
++ > dither
[x
& 15])
1490 if (*r0
++ > dither
[x
& 15])
1494 if (*r0
++ > dither
[x
& 15])
1508 dither
= Floyd8x8
[y
& 7];
1510 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1512 if ((r0
[0] & 63) > dither
[x
& 7])
1513 *ptr
^= (0x30 & OnPixels
[r0
[0]]);
1515 *ptr
^= (0x30 & OffPixels
[r0
[0]]);
1517 if ((r0
[1] & 63) > dither
[x
& 7])
1518 *ptr
^= (0x0c & OnPixels
[r0
[1]]);
1520 *ptr
^= (0x0c & OffPixels
[r0
[1]]);
1522 if ((r0
[2] & 63) > dither
[x
& 7])
1523 *ptr
++ ^= (0x03 & OnPixels
[r0
[2]]);
1525 *ptr
++ ^= (0x03 & OffPixels
[r0
[2]]);
1530 dither
= Floyd4x4
[y
& 3];
1532 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1534 if ((r0
[0] & 15) > dither
[x
& 3])
1535 *ptr
++ ^= (0x0f & OnPixels
[r0
[0]]);
1537 *ptr
++ ^= (0x0f & OffPixels
[r0
[0]]);
1539 if ((r0
[1] & 15) > dither
[x
& 3])
1540 *ptr
^= (0xf0 & OnPixels
[r0
[1]]);
1542 *ptr
^= (0xf0 & OffPixels
[r0
[1]]);
1544 if ((r0
[2] & 15) > dither
[x
& 3])
1545 *ptr
++ ^= (0x0f & OnPixels
[r0
[2]]);
1547 *ptr
++ ^= (0x0f & OffPixels
[r0
[2]]);
1552 for (x
= xsize
* 3; x
> 0; x
--, r0
++, r1
++)
1556 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
1561 case CUPS_ORDER_BANDED
:
1563 mptr
= ptr
+ bandwidth
;
1564 yptr
= ptr
+ 2 * bandwidth
;
1566 switch (header
->cupsBitsPerColor
)
1569 bitmask
= 0x80 >> (bitoffset
& 7);
1570 dither
= Floyd16x16
[y
& 15];
1572 for (x
= xsize
; x
> 0; x
--)
1574 if (*r0
++ > dither
[x
& 15])
1576 if (*r0
++ > dither
[x
& 15])
1578 if (*r0
++ > dither
[x
& 15])
1594 bitmask
= 0xc0 >> (bitoffset
& 7);
1595 dither
= Floyd8x8
[y
& 7];
1597 for (x
= xsize
; x
> 0; x
--)
1599 if ((*r0
& 63) > dither
[x
& 7])
1600 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
1602 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
1604 if ((*r0
& 63) > dither
[x
& 7])
1605 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
1607 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
1609 if ((*r0
& 63) > dither
[x
& 7])
1610 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
1612 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
1628 bitmask
= 0xf0 >> (bitoffset
& 7);
1629 dither
= Floyd4x4
[y
& 3];
1631 for (x
= xsize
; x
> 0; x
--)
1633 if ((*r0
& 15) > dither
[x
& 3])
1634 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
1636 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
1638 if ((*r0
& 15) > dither
[x
& 3])
1639 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
1641 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
1643 if ((*r0
& 15) > dither
[x
& 3])
1644 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
1646 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
1648 if (bitmask
== 0xf0)
1662 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
1667 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
1672 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
1677 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
1683 case CUPS_ORDER_PLANAR
:
1684 switch (header
->cupsBitsPerColor
)
1687 bitmask
= 0x80 >> (bitoffset
& 7);
1688 dither
= Floyd16x16
[y
& 15];
1693 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1695 if (r0
[0] > dither
[x
& 15])
1709 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1711 if (r0
[1] > dither
[x
& 15])
1725 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1727 if (r0
[2] > dither
[x
& 15])
1743 bitmask
= 0xc0 >> (bitoffset
& 7);
1744 dither
= Floyd8x8
[y
& 7];
1747 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1749 if ((*r0
& 63) > dither
[x
& 7])
1750 *ptr
^= (bitmask
& OnPixels
[*r0
]);
1752 *ptr
^= (bitmask
& OffPixels
[*r0
]);
1766 bitmask
= 0xf0 >> (bitoffset
& 7);
1767 dither
= Floyd4x4
[y
& 3];
1770 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1772 if ((*r0
& 15) > dither
[x
& 3])
1773 *ptr
^= (bitmask
& OnPixels
[*r0
]);
1775 *ptr
^= (bitmask
& OffPixels
[*r0
]);
1777 if (bitmask
== 0xf0)
1792 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
1797 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
1807 * 'format_CMYK()' - Convert image data to CMYK.
1811 format_CMYK(cups_page_header2_t
*header
,/* I - Page header */
1812 unsigned char *row
, /* IO - Bitmap data for device */
1813 int y
, /* I - Current row */
1814 int z
, /* I - Current plane */
1815 int xsize
, /* I - Width of image data */
1816 int ysize
, /* I - Height of image data */
1817 int yerr0
, /* I - Top Y error */
1818 int yerr1
, /* I - Bottom Y error */
1819 cups_ib_t
*r0
, /* I - Primary image data */
1820 cups_ib_t
*r1
) /* I - Image data for interpolation */
1822 cups_ib_t
*ptr
, /* Pointer into row */
1823 *cptr
, /* Pointer into cyan */
1824 *mptr
, /* Pointer into magenta */
1825 *yptr
, /* Pointer into yellow */
1826 *kptr
, /* Pointer into black */
1827 bitmask
; /* Current mask for pixel */
1828 int bitoffset
; /* Current offset in line */
1829 int bandwidth
; /* Width of a color band */
1830 int x
, /* Current X coordinate on page */
1831 *dither
; /* Pointer into dither array */
1832 int pc
, pm
, py
; /* CMY pixels */
1841 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
1844 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
1848 ptr
= row
+ bitoffset
/ 8;
1849 bandwidth
= header
->cupsBytesPerLine
/ 4;
1851 switch (header
->cupsColorOrder
)
1853 case CUPS_ORDER_CHUNKED
:
1854 switch (header
->cupsBitsPerColor
)
1857 bitmask
= 128 >> (bitoffset
& 7);
1858 dither
= Floyd16x16
[y
& 15];
1860 for (x
= xsize
; x
> 0; x
--)
1862 pc
= *r0
++ > dither
[x
& 15];
1863 pm
= *r0
++ > dither
[x
& 15];
1864 py
= *r0
++ > dither
[x
& 15];
1897 dither
= Floyd8x8
[y
& 7];
1899 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
1901 if ((r0
[0] & 63) > dither
[x
& 7])
1902 *ptr
^= (0xc0 & OnPixels
[r0
[0]]);
1904 *ptr
^= (0xc0 & OffPixels
[r0
[0]]);
1906 if ((r0
[1] & 63) > dither
[x
& 7])
1907 *ptr
^= (0x30 & OnPixels
[r0
[1]]);
1909 *ptr
^= (0x30 & OffPixels
[r0
[1]]);
1911 if ((r0
[2] & 63) > dither
[x
& 7])
1912 *ptr
^= (0x0c & OnPixels
[r0
[2]]);
1914 *ptr
^= (0x0c & OffPixels
[r0
[2]]);
1916 if ((r0
[3] & 63) > dither
[x
& 7])
1917 *ptr
++ ^= (0x03 & OnPixels
[r0
[3]]);
1919 *ptr
++ ^= (0x03 & OffPixels
[r0
[3]]);
1924 dither
= Floyd4x4
[y
& 3];
1926 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
1928 if ((r0
[0] & 15) > dither
[x
& 3])
1929 *ptr
^= (0xf0 & OnPixels
[r0
[0]]);
1931 *ptr
^= (0xf0 & OffPixels
[r0
[0]]);
1933 if ((r0
[1] & 15) > dither
[x
& 3])
1934 *ptr
++ ^= (0x0f & OnPixels
[r0
[1]]);
1936 *ptr
++ ^= (0x0f & OffPixels
[r0
[1]]);
1938 if ((r0
[2] & 15) > dither
[x
& 3])
1939 *ptr
^= (0xf0 & OnPixels
[r0
[2]]);
1941 *ptr
^= (0xf0 & OffPixels
[r0
[2]]);
1943 if ((r0
[3] & 15) > dither
[x
& 3])
1944 *ptr
++ ^= (0x0f & OnPixels
[r0
[3]]);
1946 *ptr
++ ^= (0x0f & OffPixels
[r0
[3]]);
1951 for (x
= xsize
* 4; x
> 0; x
--, r0
++, r1
++)
1955 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
1960 case CUPS_ORDER_BANDED
:
1962 mptr
= ptr
+ bandwidth
;
1963 yptr
= ptr
+ 2 * bandwidth
;
1964 kptr
= ptr
+ 3 * bandwidth
;
1966 switch (header
->cupsBitsPerColor
)
1969 bitmask
= 0x80 >> (bitoffset
& 7);
1970 dither
= Floyd16x16
[y
& 15];
1972 for (x
= xsize
; x
> 0; x
--)
1974 pc
= *r0
++ > dither
[x
& 15];
1975 pm
= *r0
++ > dither
[x
& 15];
1976 py
= *r0
++ > dither
[x
& 15];
2004 bitmask
= 0xc0 >> (bitoffset
& 7);
2005 dither
= Floyd8x8
[y
& 7];
2007 for (x
= xsize
; x
> 0; x
--)
2009 if ((*r0
& 63) > dither
[x
& 7])
2010 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2012 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2014 if ((*r0
& 63) > dither
[x
& 7])
2015 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2017 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2019 if ((*r0
& 63) > dither
[x
& 7])
2020 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2022 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2024 if ((*r0
& 63) > dither
[x
& 7])
2025 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2027 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2044 bitmask
= 0xf0 >> (bitoffset
& 7);
2045 dither
= Floyd4x4
[y
& 3];
2047 for (x
= xsize
; x
> 0; x
--)
2049 if ((*r0
& 15) > dither
[x
& 3])
2050 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2052 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2054 if ((*r0
& 15) > dither
[x
& 3])
2055 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2057 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2059 if ((*r0
& 15) > dither
[x
& 3])
2060 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2062 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2064 if ((*r0
& 15) > dither
[x
& 3])
2065 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2067 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2069 if (bitmask
== 0xf0)
2084 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2089 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
2094 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
2099 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
2104 *kptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
2110 case CUPS_ORDER_PLANAR
:
2111 switch (header
->cupsBitsPerColor
)
2114 bitmask
= 0x80 >> (bitoffset
& 7);
2115 dither
= Floyd16x16
[y
& 15];
2117 for (x
= xsize
; x
> 0; x
--)
2119 pc
= *r0
++ > dither
[x
& 15];
2120 pm
= *r0
++ > dither
[x
& 15];
2121 py
= *r0
++ > dither
[x
& 15];
2123 if ((pc
&& pm
&& py
&& z
== 3) ||
2124 (pc
&& z
== 0) || (pm
&& z
== 1) || (py
&& z
== 2))
2138 bitmask
= 0xc0 >> (bitoffset
& 7);
2139 dither
= Floyd8x8
[y
& 7];
2142 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2144 if ((*r0
& 63) > dither
[x
& 7])
2145 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2147 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2161 bitmask
= 0xf0 >> (bitoffset
& 7);
2162 dither
= Floyd4x4
[y
& 3];
2165 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2167 if ((*r0
& 15) > dither
[x
& 3])
2168 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2170 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2172 if (bitmask
== 0xf0)
2187 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2192 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
2202 * 'format_K()' - Convert image data to black.
2206 format_K(cups_page_header2_t
*header
, /* I - Page header */
2207 unsigned char *row
, /* IO - Bitmap data for device */
2208 int y
, /* I - Current row */
2209 int z
, /* I - Current plane */
2210 int xsize
, /* I - Width of image data */
2211 int ysize
, /* I - Height of image data */
2212 int yerr0
, /* I - Top Y error */
2213 int yerr1
, /* I - Bottom Y error */
2214 cups_ib_t
*r0
, /* I - Primary image data */
2215 cups_ib_t
*r1
) /* I - Image data for interpolation */
2217 cups_ib_t
*ptr
, /* Pointer into row */
2218 bitmask
; /* Current mask for pixel */
2219 int bitoffset
; /* Current offset in line */
2220 int x
, /* Current X coordinate on page */
2221 *dither
; /* Pointer into dither array */
2232 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2235 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2239 ptr
= row
+ bitoffset
/ 8;
2241 switch (header
->cupsBitsPerColor
)
2244 bitmask
= 0x80 >> (bitoffset
& 7);
2245 dither
= Floyd16x16
[y
& 15];
2247 for (x
= xsize
; x
> 0; x
--)
2249 if (*r0
++ > dither
[x
& 15])
2263 bitmask
= 0xc0 >> (bitoffset
& 7);
2264 dither
= Floyd8x8
[y
& 7];
2266 for (x
= xsize
; x
> 0; x
--)
2268 if ((*r0
& 63) > dither
[x
& 7])
2269 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
2271 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
2285 bitmask
= 0xf0 >> (bitoffset
& 7);
2286 dither
= Floyd4x4
[y
& 3];
2288 for (x
= xsize
; x
> 0; x
--)
2290 if ((*r0
& 15) > dither
[x
& 3])
2291 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
2293 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
2295 if (bitmask
== 0xf0)
2307 for (x
= xsize
; x
> 0; x
--, r0
++, r1
++)
2312 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
2320 * 'format_KCMY()' - Convert image data to KCMY.
2324 format_KCMY(cups_page_header2_t
*header
,/* I - Page header */
2325 unsigned char *row
, /* IO - Bitmap data for device */
2326 int y
, /* I - Current row */
2327 int z
, /* I - Current plane */
2328 int xsize
, /* I - Width of image data */
2329 int ysize
, /* I - Height of image data */
2330 int yerr0
, /* I - Top Y error */
2331 int yerr1
, /* I - Bottom Y error */
2332 cups_ib_t
*r0
, /* I - Primary image data */
2333 cups_ib_t
*r1
) /* I - Image data for interpolation */
2335 cups_ib_t
*ptr
, /* Pointer into row */
2336 *cptr
, /* Pointer into cyan */
2337 *mptr
, /* Pointer into magenta */
2338 *yptr
, /* Pointer into yellow */
2339 *kptr
, /* Pointer into black */
2340 bitmask
; /* Current mask for pixel */
2341 int bitoffset
; /* Current offset in line */
2342 int bandwidth
; /* Width of a color band */
2343 int x
, /* Current X coordinate on page */
2344 *dither
; /* Pointer into dither array */
2345 int pc
, pm
, py
; /* CMY pixels */
2354 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2357 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2361 ptr
= row
+ bitoffset
/ 8;
2362 bandwidth
= header
->cupsBytesPerLine
/ 4;
2364 switch (header
->cupsColorOrder
)
2366 case CUPS_ORDER_CHUNKED
:
2367 switch (header
->cupsBitsPerColor
)
2370 bitmask
= 128 >> (bitoffset
& 7);
2371 dither
= Floyd16x16
[y
& 15];
2373 for (x
= xsize
; x
> 0; x
--)
2375 pc
= *r0
++ > dither
[x
& 15];
2376 pm
= *r0
++ > dither
[x
& 15];
2377 py
= *r0
++ > dither
[x
& 15];
2410 dither
= Floyd8x8
[y
& 7];
2412 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2414 if ((r0
[3] & 63) > dither
[x
& 7])
2415 *ptr
^= (0xc0 & OnPixels
[r0
[3]]);
2417 *ptr
^= (0xc0 & OffPixels
[r0
[3]]);
2419 if ((r0
[0] & 63) > dither
[x
& 7])
2420 *ptr
^= (0x30 & OnPixels
[r0
[0]]);
2422 *ptr
^= (0x30 & OffPixels
[r0
[0]]);
2424 if ((r0
[1] & 63) > dither
[x
& 7])
2425 *ptr
^= (0x0c & OnPixels
[r0
[1]]);
2427 *ptr
^= (0x0c & OffPixels
[r0
[1]]);
2429 if ((r0
[2] & 63) > dither
[x
& 7])
2430 *ptr
++ ^= (0x03 & OnPixels
[r0
[2]]);
2432 *ptr
++ ^= (0x03 & OffPixels
[r0
[2]]);
2437 dither
= Floyd4x4
[y
& 3];
2439 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2441 if ((r0
[3] & 15) > dither
[x
& 3])
2442 *ptr
^= (0xf0 & OnPixels
[r0
[3]]);
2444 *ptr
^= (0xf0 & OffPixels
[r0
[3]]);
2446 if ((r0
[0] & 15) > dither
[x
& 3])
2447 *ptr
++ ^= (0x0f & OnPixels
[r0
[0]]);
2449 *ptr
++ ^= (0x0f & OffPixels
[r0
[0]]);
2451 if ((r0
[1] & 15) > dither
[x
& 3])
2452 *ptr
^= (0xf0 & OnPixels
[r0
[1]]);
2454 *ptr
^= (0xf0 & OffPixels
[r0
[1]]);
2456 if ((r0
[2] & 15) > dither
[x
& 3])
2457 *ptr
++ ^= (0x0f & OnPixels
[r0
[2]]);
2459 *ptr
++ ^= (0x0f & OffPixels
[r0
[2]]);
2464 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2469 *ptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
2474 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
2479 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
2484 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
2490 case CUPS_ORDER_BANDED
:
2492 cptr
= ptr
+ bandwidth
;
2493 mptr
= ptr
+ 2 * bandwidth
;
2494 yptr
= ptr
+ 3 * bandwidth
;
2496 switch (header
->cupsBitsPerColor
)
2499 bitmask
= 0x80 >> (bitoffset
& 7);
2500 dither
= Floyd16x16
[y
& 15];
2502 for (x
= xsize
; x
> 0; x
--)
2504 pc
= *r0
++ > dither
[x
& 15];
2505 pm
= *r0
++ > dither
[x
& 15];
2506 py
= *r0
++ > dither
[x
& 15];
2534 bitmask
= 0xc0 >> (bitoffset
& 7);
2535 dither
= Floyd8x8
[y
& 7];
2537 for (x
= xsize
; x
> 0; x
--)
2539 if ((*r0
& 63) > dither
[x
& 7])
2540 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2542 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2544 if ((*r0
& 63) > dither
[x
& 7])
2545 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2547 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2549 if ((*r0
& 63) > dither
[x
& 7])
2550 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2552 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2554 if ((*r0
& 63) > dither
[x
& 7])
2555 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2557 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2574 bitmask
= 0xf0 >> (bitoffset
& 7);
2575 dither
= Floyd4x4
[y
& 3];
2577 for (x
= xsize
; x
> 0; x
--)
2579 if ((*r0
& 15) > dither
[x
& 3])
2580 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2582 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2584 if ((*r0
& 15) > dither
[x
& 3])
2585 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2587 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2589 if ((*r0
& 15) > dither
[x
& 3])
2590 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2592 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2594 if ((*r0
& 15) > dither
[x
& 3])
2595 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2597 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2599 if (bitmask
== 0xf0)
2614 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2619 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
2624 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
2629 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
2634 *kptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
2640 case CUPS_ORDER_PLANAR
:
2641 switch (header
->cupsBitsPerColor
)
2644 bitmask
= 0x80 >> (bitoffset
& 7);
2645 dither
= Floyd16x16
[y
& 15];
2647 for (x
= xsize
; x
> 0; x
--)
2649 pc
= *r0
++ > dither
[x
& 15];
2650 pm
= *r0
++ > dither
[x
& 15];
2651 py
= *r0
++ > dither
[x
& 15];
2653 if ((pc
&& pm
&& py
&& z
== 0) ||
2654 (pc
&& z
== 1) || (pm
&& z
== 2) || (py
&& z
== 3))
2668 bitmask
= 0xc0 >> (bitoffset
& 7);
2669 dither
= Floyd8x8
[y
& 7];
2675 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2677 if ((*r0
& 63) > dither
[x
& 7])
2678 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2680 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2694 bitmask
= 0xf0 >> (bitoffset
& 7);
2695 dither
= Floyd4x4
[y
& 3];
2701 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2703 if ((*r0
& 15) > dither
[x
& 3])
2704 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2706 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2708 if (bitmask
== 0xf0)
2731 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2736 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
2746 * 'format_KCMYcm()' - Convert image data to KCMYcm.
2751 cups_page_header2_t
*header
, /* I - Page header */
2752 unsigned char *row
, /* IO - Bitmap data for device */
2753 int y
, /* I - Current row */
2754 int z
, /* I - Current plane */
2755 int xsize
, /* I - Width of image data */
2756 int ysize
, /* I - Height of image data */
2757 int yerr0
, /* I - Top Y error */
2758 int yerr1
, /* I - Bottom Y error */
2759 cups_ib_t
*r0
, /* I - Primary image data */
2760 cups_ib_t
*r1
) /* I - Image data for interpolation */
2762 int pc
, pm
, py
, pk
; /* Cyan, magenta, yellow, and black values */
2763 cups_ib_t
*ptr
, /* Pointer into row */
2764 *cptr
, /* Pointer into cyan */
2765 *mptr
, /* Pointer into magenta */
2766 *yptr
, /* Pointer into yellow */
2767 *kptr
, /* Pointer into black */
2768 *lcptr
, /* Pointer into light cyan */
2769 *lmptr
, /* Pointer into light magenta */
2770 bitmask
; /* Current mask for pixel */
2771 int bitoffset
; /* Current offset in line */
2772 int bandwidth
; /* Width of a color band */
2773 int x
, /* Current X coordinate on page */
2774 *dither
; /* Pointer into dither array */
2783 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2786 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2790 ptr
= row
+ bitoffset
/ 8;
2791 bandwidth
= header
->cupsBytesPerLine
/ 6;
2793 switch (header
->cupsColorOrder
)
2795 case CUPS_ORDER_CHUNKED
:
2796 dither
= Floyd16x16
[y
& 15];
2798 for (x
= xsize
; x
> 0; x
--)
2800 pc
= *r0
++ > dither
[x
& 15];
2801 pm
= *r0
++ > dither
[x
& 15];
2802 py
= *r0
++ > dither
[x
& 15];
2803 pk
= pc
&& pm
&& py
;
2806 *ptr
++ ^= 32; /* Black */
2808 *ptr
++ ^= 17; /* Blue (cyan + light magenta) */
2810 *ptr
++ ^= 6; /* Green (light cyan + yellow) */
2812 *ptr
++ ^= 12; /* Red (magenta + yellow) */
2824 case CUPS_ORDER_BANDED
:
2826 cptr
= ptr
+ bandwidth
;
2827 mptr
= ptr
+ 2 * bandwidth
;
2828 yptr
= ptr
+ 3 * bandwidth
;
2829 lcptr
= ptr
+ 4 * bandwidth
;
2830 lmptr
= ptr
+ 5 * bandwidth
;
2832 bitmask
= 0x80 >> (bitoffset
& 7);
2833 dither
= Floyd16x16
[y
& 15];
2835 for (x
= xsize
; x
> 0; x
--)
2837 pc
= *r0
++ > dither
[x
& 15];
2838 pm
= *r0
++ > dither
[x
& 15];
2839 py
= *r0
++ > dither
[x
& 15];
2840 pk
= pc
&& pm
&& py
;
2843 *kptr
^= bitmask
; /* Black */
2846 *cptr
^= bitmask
; /* Blue (cyan + light magenta) */
2851 *lcptr
^= bitmask
; /* Green (light cyan + yellow) */
2856 *mptr
^= bitmask
; /* Red (magenta + yellow) */
2881 case CUPS_ORDER_PLANAR
:
2882 bitmask
= 0x80 >> (bitoffset
& 7);
2883 dither
= Floyd16x16
[y
& 15];
2885 for (x
= xsize
; x
> 0; x
--)
2887 pc
= *r0
++ > dither
[x
& 15];
2888 pm
= *r0
++ > dither
[x
& 15];
2889 py
= *r0
++ > dither
[x
& 15];
2890 pk
= pc
&& pm
&& py
;
2894 else if (pc
&& pm
&& (z
== 1 || z
== 5))
2895 *ptr
^= bitmask
; /* Blue (cyan + light magenta) */
2896 else if (pc
&& py
&& (z
== 3 || z
== 4))
2897 *ptr
^= bitmask
; /* Green (light cyan + yellow) */
2898 else if (pm
&& py
&& (z
== 2 || z
== 3))
2899 *ptr
^= bitmask
; /* Red (magenta + yellow) */
2900 else if (pc
&& z
== 1)
2902 else if (pm
&& z
== 2)
2904 else if (py
&& z
== 3)
2921 * 'format_RGBA()' - Convert image data to RGBA/RGBW.
2925 format_RGBA(cups_page_header2_t
*header
,/* I - Page header */
2926 unsigned char *row
, /* IO - Bitmap data for device */
2927 int y
, /* I - Current row */
2928 int z
, /* I - Current plane */
2929 int xsize
, /* I - Width of image data */
2930 int ysize
, /* I - Height of image data */
2931 int yerr0
, /* I - Top Y error */
2932 int yerr1
, /* I - Bottom Y error */
2933 cups_ib_t
*r0
, /* I - Primary image data */
2934 cups_ib_t
*r1
) /* I - Image data for interpolation */
2936 cups_ib_t
*ptr
, /* Pointer into row */
2937 *cptr
, /* Pointer into cyan */
2938 *mptr
, /* Pointer into magenta */
2939 *yptr
, /* Pointer into yellow */
2940 bitmask
; /* Current mask for pixel */
2941 int bitoffset
; /* Current offset in line */
2942 int bandwidth
; /* Width of a color band */
2943 int x
, /* Current X coordinate on page */
2944 *dither
; /* Pointer into dither array */
2953 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2956 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2960 ptr
= row
+ bitoffset
/ 8;
2961 bandwidth
= header
->cupsBytesPerLine
/ 4;
2963 switch (header
->cupsColorOrder
)
2965 case CUPS_ORDER_CHUNKED
:
2966 switch (header
->cupsBitsPerColor
)
2969 bitmask
= 128 >> (bitoffset
& 7);
2970 dither
= Floyd16x16
[y
& 15];
2972 for (x
= xsize
; x
> 0; x
--)
2974 if (*r0
++ > dither
[x
& 15])
2978 if (*r0
++ > dither
[x
& 15])
2982 if (*r0
++ > dither
[x
& 15])
2996 dither
= Floyd8x8
[y
& 7];
2998 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3000 if ((r0
[0] & 63) > dither
[x
& 7])
3001 *ptr
^= (0xc0 & OnPixels
[r0
[0]]);
3003 *ptr
^= (0xc0 & OffPixels
[r0
[0]]);
3005 if ((r0
[1] & 63) > dither
[x
& 7])
3006 *ptr
^= (0x30 & OnPixels
[r0
[1]]);
3008 *ptr
^= (0x30 & OffPixels
[r0
[1]]);
3010 if ((r0
[2] & 63) > dither
[x
& 7])
3011 *ptr
^= (0x0c & OnPixels
[r0
[2]]);
3013 *ptr
^= (0x0c & OffPixels
[r0
[2]]);
3020 dither
= Floyd4x4
[y
& 3];
3022 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3024 if ((r0
[0] & 15) > dither
[x
& 3])
3025 *ptr
^= (0xf0 & OnPixels
[r0
[0]]);
3027 *ptr
^= (0xf0 & OffPixels
[r0
[0]]);
3029 if ((r0
[1] & 15) > dither
[x
& 3])
3030 *ptr
++ ^= (0x0f & OnPixels
[r0
[1]]);
3032 *ptr
++ ^= (0x0f & OffPixels
[r0
[1]]);
3034 if ((r0
[2] & 15) > dither
[x
& 3])
3035 *ptr
^= (0xf0 & OnPixels
[r0
[2]]);
3037 *ptr
^= (0xf0 & OffPixels
[r0
[2]]);
3044 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3049 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3054 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3059 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3067 case CUPS_ORDER_BANDED
:
3069 mptr
= ptr
+ bandwidth
;
3070 yptr
= ptr
+ 2 * bandwidth
;
3072 memset(ptr
+ 3 * bandwidth
, 255, bandwidth
);
3074 switch (header
->cupsBitsPerColor
)
3077 bitmask
= 0x80 >> (bitoffset
& 7);
3078 dither
= Floyd16x16
[y
& 15];
3080 for (x
= xsize
; x
> 0; x
--)
3082 if (*r0
++ > dither
[x
& 15])
3084 if (*r0
++ > dither
[x
& 15])
3086 if (*r0
++ > dither
[x
& 15])
3102 bitmask
= 0xc0 >> (bitoffset
& 7);
3103 dither
= Floyd8x8
[y
& 7];
3105 for (x
= xsize
; x
> 0; x
--)
3107 if ((*r0
& 63) > dither
[x
& 7])
3108 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3110 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3112 if ((*r0
& 63) > dither
[x
& 7])
3113 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3115 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3117 if ((*r0
& 63) > dither
[x
& 7])
3118 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3120 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3136 bitmask
= 0xf0 >> (bitoffset
& 7);
3137 dither
= Floyd4x4
[y
& 3];
3139 for (x
= xsize
; x
> 0; x
--)
3141 if ((*r0
& 15) > dither
[x
& 3])
3142 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3144 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3146 if ((*r0
& 15) > dither
[x
& 3])
3147 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3149 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3151 if ((*r0
& 15) > dither
[x
& 3])
3152 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3154 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3156 if (bitmask
== 0xf0)
3170 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3175 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3180 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3185 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3191 case CUPS_ORDER_PLANAR
:
3194 memset(row
, 255, header
->cupsBytesPerLine
);
3198 switch (header
->cupsBitsPerColor
)
3201 bitmask
= 0x80 >> (bitoffset
& 7);
3202 dither
= Floyd16x16
[y
& 15];
3207 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3209 if (r0
[0] > dither
[x
& 15])
3223 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3225 if (r0
[1] > dither
[x
& 15])
3239 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3241 if (r0
[2] > dither
[x
& 15])
3257 bitmask
= 0xc0 >> (bitoffset
& 7);
3258 dither
= Floyd8x8
[y
& 7];
3261 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3263 if ((*r0
& 63) > dither
[x
& 7])
3264 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3266 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3280 bitmask
= 0xf0 >> (bitoffset
& 7);
3281 dither
= Floyd4x4
[y
& 3];
3284 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3286 if ((*r0
& 15) > dither
[x
& 3])
3287 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3289 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3291 if (bitmask
== 0xf0)
3306 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3311 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
3321 * 'format_W()' - Convert image data to luminance.
3325 format_W(cups_page_header2_t
*header
, /* I - Page header */
3326 unsigned char *row
, /* IO - Bitmap data for device */
3327 int y
, /* I - Current row */
3328 int z
, /* I - Current plane */
3329 int xsize
, /* I - Width of image data */
3330 int ysize
, /* I - Height of image data */
3331 int yerr0
, /* I - Top Y error */
3332 int yerr1
, /* I - Bottom Y error */
3333 cups_ib_t
*r0
, /* I - Primary image data */
3334 cups_ib_t
*r1
) /* I - Image data for interpolation */
3336 cups_ib_t
*ptr
, /* Pointer into row */
3337 bitmask
; /* Current mask for pixel */
3338 int bitoffset
; /* Current offset in line */
3339 int x
, /* Current X coordinate on page */
3340 *dither
; /* Pointer into dither array */
3351 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
3354 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
3358 ptr
= row
+ bitoffset
/ 8;
3360 switch (header
->cupsBitsPerColor
)
3363 bitmask
= 0x80 >> (bitoffset
& 7);
3364 dither
= Floyd16x16
[y
& 15];
3366 for (x
= xsize
; x
> 0; x
--)
3368 if (*r0
++ > dither
[x
& 15])
3382 bitmask
= 0xc0 >> (bitoffset
& 7);
3383 dither
= Floyd8x8
[y
& 7];
3385 for (x
= xsize
; x
> 0; x
--)
3387 if ((*r0
& 63) > dither
[x
& 7])
3388 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
3390 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
3404 bitmask
= 0xf0 >> (bitoffset
& 7);
3405 dither
= Floyd4x4
[y
& 3];
3407 for (x
= xsize
; x
> 0; x
--)
3409 if ((*r0
& 15) > dither
[x
& 3])
3410 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
3412 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
3414 if (bitmask
== 0xf0)
3426 for (x
= xsize
; x
> 0; x
--, r0
++, r1
++)
3431 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
3439 * 'format_YMC()' - Convert image data to YMC.
3443 format_YMC(cups_page_header2_t
*header
, /* I - Page header */
3444 unsigned char *row
, /* IO - Bitmap data for device */
3445 int y
, /* I - Current row */
3446 int z
, /* I - Current plane */
3447 int xsize
, /* I - Width of image data */
3448 int ysize
, /* I - Height of image data */
3449 int yerr0
, /* I - Top Y error */
3450 int yerr1
, /* I - Bottom Y error */
3451 cups_ib_t
*r0
, /* I - Primary image data */
3452 cups_ib_t
*r1
) /* I - Image data for interpolation */
3454 cups_ib_t
*ptr
, /* Pointer into row */
3455 *cptr
, /* Pointer into cyan */
3456 *mptr
, /* Pointer into magenta */
3457 *yptr
, /* Pointer into yellow */
3458 bitmask
; /* Current mask for pixel */
3459 int bitoffset
; /* Current offset in line */
3460 int bandwidth
; /* Width of a color band */
3461 int x
, /* Current X coordinate on page */
3462 *dither
; /* Pointer into dither array */
3471 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
3474 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
3478 ptr
= row
+ bitoffset
/ 8;
3479 bandwidth
= header
->cupsBytesPerLine
/ 3;
3481 switch (header
->cupsColorOrder
)
3483 case CUPS_ORDER_CHUNKED
:
3484 switch (header
->cupsBitsPerColor
)
3487 bitmask
= 64 >> (bitoffset
& 7);
3488 dither
= Floyd16x16
[y
& 15];
3490 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3492 if (r0
[2] > dither
[x
& 15])
3496 if (r0
[1] > dither
[x
& 15])
3500 if (r0
[0] > dither
[x
& 15])
3514 dither
= Floyd8x8
[y
& 7];
3516 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3518 if ((r0
[2] & 63) > dither
[x
& 7])
3519 *ptr
^= (0x30 & OnPixels
[r0
[2]]);
3521 *ptr
^= (0x30 & OffPixels
[r0
[2]]);
3523 if ((r0
[1] & 63) > dither
[x
& 7])
3524 *ptr
^= (0x0c & OnPixels
[r0
[1]]);
3526 *ptr
^= (0x0c & OffPixels
[r0
[1]]);
3528 if ((r0
[0] & 63) > dither
[x
& 7])
3529 *ptr
++ ^= (0x03 & OnPixels
[r0
[0]]);
3531 *ptr
++ ^= (0x03 & OffPixels
[r0
[0]]);
3536 dither
= Floyd4x4
[y
& 3];
3538 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3540 if ((r0
[2] & 15) > dither
[x
& 3])
3541 *ptr
++ ^= (0x0f & OnPixels
[r0
[2]]);
3543 *ptr
++ ^= (0x0f & OffPixels
[r0
[2]]);
3545 if ((r0
[1] & 15) > dither
[x
& 3])
3546 *ptr
^= (0xf0 & OnPixels
[r0
[1]]);
3548 *ptr
^= (0xf0 & OffPixels
[r0
[1]]);
3550 if ((r0
[0] & 15) > dither
[x
& 3])
3551 *ptr
++ ^= (0x0f & OnPixels
[r0
[0]]);
3553 *ptr
++ ^= (0x0f & OffPixels
[r0
[0]]);
3558 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3563 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3568 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3573 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3579 case CUPS_ORDER_BANDED
:
3581 mptr
= ptr
+ bandwidth
;
3582 cptr
= ptr
+ 2 * bandwidth
;
3584 switch (header
->cupsBitsPerColor
)
3587 bitmask
= 0x80 >> (bitoffset
& 7);
3588 dither
= Floyd16x16
[y
& 15];
3590 for (x
= xsize
; x
> 0; x
--)
3592 if (*r0
++ > dither
[x
& 15])
3594 if (*r0
++ > dither
[x
& 15])
3596 if (*r0
++ > dither
[x
& 15])
3612 bitmask
= 0xc0 >> (bitoffset
& 7);
3613 dither
= Floyd8x8
[y
& 7];
3615 for (x
= xsize
; x
> 0; x
--)
3617 if ((*r0
& 63) > dither
[x
& 7])
3618 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3620 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3622 if ((*r0
& 63) > dither
[x
& 7])
3623 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3625 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3627 if ((*r0
& 63) > dither
[x
& 7])
3628 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3630 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3646 bitmask
= 0xf0 >> (bitoffset
& 7);
3647 dither
= Floyd4x4
[y
& 3];
3649 for (x
= xsize
; x
> 0; x
--)
3651 if ((*r0
& 15) > dither
[x
& 3])
3652 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3654 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3656 if ((*r0
& 15) > dither
[x
& 3])
3657 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3659 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3661 if ((*r0
& 15) > dither
[x
& 3])
3662 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3664 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3666 if (bitmask
== 0xf0)
3680 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3685 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3690 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3695 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3701 case CUPS_ORDER_PLANAR
:
3702 switch (header
->cupsBitsPerColor
)
3705 bitmask
= 0x80 >> (bitoffset
& 7);
3706 dither
= Floyd16x16
[y
& 15];
3711 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3713 if (r0
[0] > dither
[x
& 15])
3727 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3729 if (r0
[1] > dither
[x
& 15])
3743 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3745 if (r0
[2] > dither
[x
& 15])
3761 bitmask
= 0xc0 >> (bitoffset
& 7);
3762 dither
= Floyd8x8
[y
& 7];
3766 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3768 if ((*r0
& 63) > dither
[x
& 7])
3769 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3771 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3785 bitmask
= 0xf0 >> (bitoffset
& 7);
3786 dither
= Floyd4x4
[y
& 3];
3790 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3792 if ((*r0
& 15) > dither
[x
& 3])
3793 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3795 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3797 if (bitmask
== 0xf0)
3813 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3818 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
3828 * 'format_YMCK()' - Convert image data to YMCK.
3832 format_YMCK(cups_page_header2_t
*header
,/* I - Page header */
3833 unsigned char *row
, /* IO - Bitmap data for device */
3834 int y
, /* I - Current row */
3835 int z
, /* I - Current plane */
3836 int xsize
, /* I - Width of image data */
3837 int ysize
, /* I - Height of image data */
3838 int yerr0
, /* I - Top Y error */
3839 int yerr1
, /* I - Bottom Y error */
3840 cups_ib_t
*r0
, /* I - Primary image data */
3841 cups_ib_t
*r1
) /* I - Image data for interpolation */
3843 cups_ib_t
*ptr
, /* Pointer into row */
3844 *cptr
, /* Pointer into cyan */
3845 *mptr
, /* Pointer into magenta */
3846 *yptr
, /* Pointer into yellow */
3847 *kptr
, /* Pointer into black */
3848 bitmask
; /* Current mask for pixel */
3849 int bitoffset
; /* Current offset in line */
3850 int bandwidth
; /* Width of a color band */
3851 int x
, /* Current X coordinate on page */
3852 *dither
; /* Pointer into dither array */
3853 int pc
, pm
, py
; /* CMY pixels */
3862 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
3865 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
3869 ptr
= row
+ bitoffset
/ 8;
3870 bandwidth
= header
->cupsBytesPerLine
/ 4;
3872 switch (header
->cupsColorOrder
)
3874 case CUPS_ORDER_CHUNKED
:
3875 switch (header
->cupsBitsPerColor
)
3878 bitmask
= 128 >> (bitoffset
& 7);
3879 dither
= Floyd16x16
[y
& 15];
3881 for (x
= xsize
; x
> 0; x
--)
3883 pc
= *r0
++ > dither
[x
& 15];
3884 pm
= *r0
++ > dither
[x
& 15];
3885 py
= *r0
++ > dither
[x
& 15];
3919 dither
= Floyd8x8
[y
& 7];
3921 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
3923 if ((r0
[2] & 63) > dither
[x
& 7])
3924 *ptr
^= (0xc0 & OnPixels
[r0
[2]]);
3926 *ptr
^= (0xc0 & OffPixels
[r0
[2]]);
3928 if ((r0
[1] & 63) > dither
[x
& 7])
3929 *ptr
^= (0x30 & OnPixels
[r0
[1]]);
3931 *ptr
^= (0x30 & OffPixels
[r0
[1]]);
3933 if ((r0
[0] & 63) > dither
[x
& 7])
3934 *ptr
^= (0x0c & OnPixels
[r0
[0]]);
3936 *ptr
^= (0x0c & OffPixels
[r0
[0]]);
3938 if ((r0
[3] & 63) > dither
[x
& 7])
3939 *ptr
++ ^= (0x03 & OnPixels
[r0
[3]]);
3941 *ptr
++ ^= (0x03 & OffPixels
[r0
[3]]);
3946 dither
= Floyd4x4
[y
& 3];
3948 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
3950 if ((r0
[2] & 15) > dither
[x
& 3])
3951 *ptr
^= (0xf0 & OnPixels
[r0
[2]]);
3953 *ptr
^= (0xf0 & OffPixels
[r0
[2]]);
3955 if ((r0
[1] & 15) > dither
[x
& 3])
3956 *ptr
++ ^= (0x0f & OnPixels
[r0
[1]]);
3958 *ptr
++ ^= (0x0f & OffPixels
[r0
[1]]);
3960 if ((r0
[0] & 15) > dither
[x
& 3])
3961 *ptr
^= (0xf0 & OnPixels
[r0
[0]]);
3963 *ptr
^= (0xf0 & OffPixels
[r0
[0]]);
3965 if ((r0
[3] & 15) > dither
[x
& 3])
3966 *ptr
++ ^= (0x0f & OnPixels
[r0
[3]]);
3968 *ptr
++ ^= (0x0f & OffPixels
[r0
[3]]);
3973 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
3978 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3983 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3988 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3993 *ptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
3999 case CUPS_ORDER_BANDED
:
4001 mptr
= ptr
+ bandwidth
;
4002 cptr
= ptr
+ 2 * bandwidth
;
4003 kptr
= ptr
+ 3 * bandwidth
;
4005 switch (header
->cupsBitsPerColor
)
4008 bitmask
= 0x80 >> (bitoffset
& 7);
4009 dither
= Floyd16x16
[y
& 15];
4011 for (x
= xsize
; x
> 0; x
--)
4013 pc
= *r0
++ > dither
[x
& 15];
4014 pm
= *r0
++ > dither
[x
& 15];
4015 py
= *r0
++ > dither
[x
& 15];
4044 bitmask
= 0xc0 >> (bitoffset
& 7);
4045 dither
= Floyd8x8
[y
& 7];
4047 for (x
= xsize
; x
> 0; x
--)
4049 if ((*r0
& 63) > dither
[x
& 7])
4050 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
4052 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
4054 if ((*r0
& 63) > dither
[x
& 7])
4055 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
4057 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
4059 if ((*r0
& 63) > dither
[x
& 7])
4060 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
4062 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
4064 if ((*r0
& 63) > dither
[x
& 7])
4065 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
4067 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
4084 bitmask
= 0xf0 >> (bitoffset
& 7);
4085 dither
= Floyd4x4
[y
& 3];
4087 for (x
= xsize
; x
> 0; x
--)
4089 if ((*r0
& 15) > dither
[x
& 3])
4090 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
4092 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
4094 if ((*r0
& 15) > dither
[x
& 3])
4095 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
4097 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
4099 if ((*r0
& 15) > dither
[x
& 3])
4100 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
4102 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
4104 if ((*r0
& 15) > dither
[x
& 3])
4105 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
4107 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
4109 if (bitmask
== 0xf0)
4124 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
4129 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
4134 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
4139 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
4144 *kptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
4150 case CUPS_ORDER_PLANAR
:
4151 switch (header
->cupsBitsPerColor
)
4154 bitmask
= 0x80 >> (bitoffset
& 7);
4155 dither
= Floyd16x16
[y
& 15];
4157 for (x
= xsize
; x
> 0; x
--)
4159 pc
= *r0
++ > dither
[x
& 15];
4160 pm
= *r0
++ > dither
[x
& 15];
4161 py
= *r0
++ > dither
[x
& 15];
4163 if ((pc
&& pm
&& py
&& z
== 3) ||
4164 (pc
&& z
== 2) || (pm
&& z
== 1) || (py
&& z
== 0))
4178 bitmask
= 0xc0 >> (bitoffset
& 7);
4179 dither
= Floyd8x8
[y
& 7];
4185 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
4187 if ((*r0
& 63) > dither
[x
& 7])
4188 *ptr
^= (bitmask
& OnPixels
[*r0
]);
4190 *ptr
^= (bitmask
& OffPixels
[*r0
]);
4204 bitmask
= 0xf0 >> (bitoffset
& 7);
4205 dither
= Floyd4x4
[y
& 3];
4211 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
4213 if ((*r0
& 15) > dither
[x
& 3])
4214 *ptr
^= (bitmask
& OnPixels
[*r0
]);
4216 *ptr
^= (bitmask
& OffPixels
[*r0
]);
4218 if (bitmask
== 0xf0)
4241 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
4246 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
4256 * 'make_lut()' - Make a lookup table given gamma and brightness values.
4260 make_lut(cups_ib_t
*lut
, /* I - Lookup table */
4261 int colorspace
, /* I - Colorspace */
4262 float g
, /* I - Image gamma */
4263 float b
) /* I - Image brightness */
4265 int i
; /* Looping var */
4266 int v
; /* Current value */
4272 for (i
= 0; i
< 256; i
++)
4275 v
= 255.0 * b
* (1.0 - pow(1.0 - (float)i
/ 255.0, g
)) + 0.5;
4277 v
= 255.0 * (1.0 - b
* (1.0 - pow((float)i
/ 255.0, g
))) + 0.5;
4290 * 'raster_cb()' - Validate the page header.
4293 static int /* O - 0 if OK, -1 if not */
4295 cups_page_header2_t
*header
, /* IO - Raster header */
4296 int preferred_bits
) /* I - Preferred bits per color */
4299 * Ensure that colorimetric colorspaces use at least 8 bits per
4303 if ((header
->cupsColorSpace
== CUPS_CSPACE_CIEXYZ
||
4304 header
->cupsColorSpace
== CUPS_CSPACE_CIELab
||
4305 header
->cupsColorSpace
>= CUPS_CSPACE_ICC1
) &&
4306 header
->cupsBitsPerColor
< 8)
4307 header
->cupsBitsPerColor
= 8;
4314 * End of "$Id: imagetoraster.c 6649 2007-07-11 21:46:42Z mike $".