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"
43 #include <cups/i18n.h>
50 int Flip
= 0, /* Flip/mirror pages */
51 XPosition
= 0, /* Horizontal position on page */
52 YPosition
= 0, /* Vertical position on page */
53 Collate
= 0, /* Collate copies? */
54 Copies
= 1; /* Number of copies */
55 int Floyd16x16
[16][16] = /* Traditional Floyd ordered dither */
57 { 0, 128, 32, 160, 8, 136, 40, 168,
58 2, 130, 34, 162, 10, 138, 42, 170 },
59 { 192, 64, 224, 96, 200, 72, 232, 104,
60 194, 66, 226, 98, 202, 74, 234, 106 },
61 { 48, 176, 16, 144, 56, 184, 24, 152,
62 50, 178, 18, 146, 58, 186, 26, 154 },
63 { 240, 112, 208, 80, 248, 120, 216, 88,
64 242, 114, 210, 82, 250, 122, 218, 90 },
65 { 12, 140, 44, 172, 4, 132, 36, 164,
66 14, 142, 46, 174, 6, 134, 38, 166 },
67 { 204, 76, 236, 108, 196, 68, 228, 100,
68 206, 78, 238, 110, 198, 70, 230, 102 },
69 { 60, 188, 28, 156, 52, 180, 20, 148,
70 62, 190, 30, 158, 54, 182, 22, 150 },
71 { 252, 124, 220, 92, 244, 116, 212, 84,
72 254, 126, 222, 94, 246, 118, 214, 86 },
73 { 3, 131, 35, 163, 11, 139, 43, 171,
74 1, 129, 33, 161, 9, 137, 41, 169 },
75 { 195, 67, 227, 99, 203, 75, 235, 107,
76 193, 65, 225, 97, 201, 73, 233, 105 },
77 { 51, 179, 19, 147, 59, 187, 27, 155,
78 49, 177, 17, 145, 57, 185, 25, 153 },
79 { 243, 115, 211, 83, 251, 123, 219, 91,
80 241, 113, 209, 81, 249, 121, 217, 89 },
81 { 15, 143, 47, 175, 7, 135, 39, 167,
82 13, 141, 45, 173, 5, 133, 37, 165 },
83 { 207, 79, 239, 111, 199, 71, 231, 103,
84 205, 77, 237, 109, 197, 69, 229, 101 },
85 { 63, 191, 31, 159, 55, 183, 23, 151,
86 61, 189, 29, 157, 53, 181, 21, 149 },
87 { 254, 127, 223, 95, 247, 119, 215, 87,
88 253, 125, 221, 93, 245, 117, 213, 85 }
92 { 0, 32, 8, 40, 2, 34, 10, 42 },
93 { 48, 16, 56, 24, 50, 18, 58, 26 },
94 { 12, 44, 4, 36, 14, 46, 6, 38 },
95 { 60, 28, 52, 20, 62, 30, 54, 22 },
96 { 3, 35, 11, 43, 1, 33, 9, 41 },
97 { 51, 19, 59, 27, 49, 17, 57, 25 },
98 { 15, 47, 7, 39, 13, 45, 5, 37 },
99 { 63, 31, 55, 23, 61, 29, 53, 21 }
109 cups_ib_t OnPixels
[256], /* On-pixel LUT */
110 OffPixels
[256]; /* Off-pixel LUT */
117 static void blank_line(cups_page_header2_t
*header
, unsigned char *row
);
118 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
);
119 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
);
120 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
);
121 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
);
122 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
);
123 #define format_RGB format_CMY
124 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
);
125 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
);
126 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
);
127 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
);
128 static void make_lut(cups_ib_t
*, int, float, float);
129 static int raster_cb(cups_page_header2_t
*header
, int preferred_bits
);
133 * 'main()' - Main entry...
136 int /* O - Exit status */
137 main(int argc
, /* I - Number of command-line arguments */
138 char *argv
[]) /* I - Command-line arguments */
140 int i
; /* Looping var */
141 cups_image_t
*img
; /* Image to print */
142 float xprint
, /* Printable area */
144 xinches
, /* Total size in inches */
146 float xsize
, /* Total size in points */
150 float aspect
; /* Aspect ratio */
151 int xpages
, /* # x pages */
152 ypages
, /* # y pages */
153 xpage
, /* Current x page */
154 ypage
, /* Current y page */
155 xtemp
, /* Bitmap width in pixels */
156 ytemp
, /* Bitmap height in pixels */
157 page
; /* Current page number */
158 int xc0
, yc0
, /* Corners of the page in image coords */
160 ppd_file_t
*ppd
; /* PPD file */
161 ppd_choice_t
*choice
; /* PPD option choice */
162 char *resolution
, /* Output resolution */
163 *media_type
; /* Media type */
164 ppd_profile_t
*profile
; /* Color profile */
165 ppd_profile_t userprofile
; /* User-specified profile */
166 cups_raster_t
*ras
; /* Raster stream */
167 cups_page_header2_t header
; /* Page header */
168 int num_options
; /* Number of print options */
169 cups_option_t
*options
; /* Print options */
170 const char *val
; /* Option value */
171 int slowcollate
, /* Collate copies the slow way */
172 slowcopies
; /* Make copies the "slow" way? */
173 float g
; /* Gamma correction value */
174 float b
; /* Brightness factor */
175 float zoom
; /* Zoom facter */
176 int xppi
, yppi
; /* Pixels-per-inch */
177 int hue
, sat
; /* Hue and saturation adjustment */
178 cups_izoom_t
*z
; /* Image zoom buffer */
179 cups_iztype_t zoom_type
; /* Image zoom type */
180 int primary
, /* Primary image colorspace */
181 secondary
; /* Secondary image colorspace */
182 cups_ib_t
*row
, /* Current row */
184 *r1
; /* Bottom row */
185 int y
, /* Current Y coordinate on page */
186 iy
, /* Current Y coordinate in image */
187 last_iy
, /* Previous Y coordinate in image */
188 yerr0
, /* Top Y error value */
189 yerr1
; /* Bottom Y error value */
190 cups_ib_t lut
[256]; /* Gamma/brightness LUT */
191 int plane
, /* Current color plane */
192 num_planes
; /* Number of color planes */
193 char filename
[1024]; /* Name of file to print */
197 * Make sure status messages are not buffered...
200 setbuf(stderr
, NULL
);
203 * Check command-line...
206 if (argc
< 6 || argc
> 7)
208 fprintf(stderr
, _("Usage: %s job-id user title copies options [file]\n"),
214 * See if we need to use the imagetops and pstoraster filters instead...
218 num_options
= cupsParseOptions(argv
[5], 0, &options
);
220 if (getenv("CLASSIFICATION") ||
221 cupsGetOption("page-label", num_options
, options
))
224 * Yes, fork a copy of pstoraster and then transfer control to imagetops...
227 int mypipes
[2]; /* New pipes for imagetops | pstoraster */
228 int pid
; /* PID of pstoraster */
231 cupsFreeOptions(num_options
, options
);
235 perror("ERROR: Unable to create pipes for imagetops | pstoraster");
239 if ((pid
= fork()) == 0)
242 * Child process for pstoraster... Assign new pipe input to pstoraster...
250 execlp("pstoraster", argv
[0], argv
[1], argv
[2], argv
[3], argv
[4], argv
[5],
252 perror("ERROR: Unable to exec pstoraster");
261 perror("ERROR: Unable to fork pstoraster");
266 * Update stdout so it points at the new pstoraster...
275 * Run imagetops to get the classification or page labelling that was
279 execlp("imagetops", argv
[0], argv
[1], argv
[2], argv
[3], argv
[4], argv
[5],
281 perror("ERROR: Unable to exec imagetops");
286 * Copy stdin as needed...
291 int fd
; /* File to write to */
292 char buffer
[8192]; /* Buffer to read into */
293 int bytes
; /* # of bytes to read */
296 if ((fd
= cupsTempFd(filename
, sizeof(filename
))) < 0)
298 perror("ERROR: Unable to copy image file");
302 fprintf(stderr
, "DEBUG: imagetoraster - copying to temp print file \"%s\"\n",
305 while ((bytes
= fread(buffer
, 1, sizeof(buffer
), stdin
)) > 0)
306 write(fd
, buffer
, bytes
);
311 strlcpy(filename
, argv
[6], sizeof(filename
));
314 * Process command-line options and write the prolog...
325 Copies
= atoi(argv
[4]);
327 ppd
= SetCommonOptions(num_options
, options
, 0);
329 if ((val
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
332 * This IPP attribute is unnecessarily complicated...
334 * single-document, separate-documents-collated-copies, and
335 * single-document-new-sheet all require collated copies.
337 * separate-documents-collated-copies allows for uncollated copies.
340 Collate
= strcasecmp(val
, "separate-documents-collated-copies") != 0;
343 if ((val
= cupsGetOption("Collate", num_options
, options
)) != NULL
&&
344 strcasecmp(val
, "True") == 0)
347 if ((val
= cupsGetOption("gamma", num_options
, options
)) != NULL
)
350 * Get gamma value from 1 to 10000...
353 g
= atoi(val
) * 0.001f
;
361 if ((val
= cupsGetOption("brightness", num_options
, options
)) != NULL
)
364 * Get brightness value from 10 to 1000.
367 b
= atoi(val
) * 0.01f
;
375 if ((val
= cupsGetOption("scaling", num_options
, options
)) != NULL
)
376 zoom
= atoi(val
) * 0.01;
377 else if (cupsGetOption("fitplot", num_options
, options
))
380 if ((val
= cupsGetOption("ppi", num_options
, options
)) != NULL
)
381 if (sscanf(val
, "%dx%d", &xppi
, &yppi
) < 2)
384 if ((val
= cupsGetOption("position", num_options
, options
)) != NULL
)
386 if (strcasecmp(val
, "center") == 0)
391 else if (strcasecmp(val
, "top") == 0)
396 else if (strcasecmp(val
, "left") == 0)
401 else if (strcasecmp(val
, "right") == 0)
406 else if (strcasecmp(val
, "top-left") == 0)
411 else if (strcasecmp(val
, "top-right") == 0)
416 else if (strcasecmp(val
, "bottom") == 0)
421 else if (strcasecmp(val
, "bottom-left") == 0)
426 else if (strcasecmp(val
, "bottom-right") == 0)
433 if ((val
= cupsGetOption("saturation", num_options
, options
)) != NULL
)
436 if ((val
= cupsGetOption("hue", num_options
, options
)) != NULL
)
439 if ((choice
= ppdFindMarkedChoice(ppd
, "MirrorPrint")) != NULL
)
441 val
= choice
->choice
;
445 val
= cupsGetOption("mirror", num_options
, options
);
447 if (val
&& (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
448 !strcasecmp(val
, "yes")))
452 * Set the needed options in the page header...
455 if (cupsRasterInterpretPPD(&header
, ppd
, num_options
, options
, raster_cb
))
457 fputs(_("ERROR: Bad page setup!\n"), stderr
);
458 fprintf(stderr
, "DEBUG: %s\n", cupsRasterErrorString());
463 * Get the media type and resolution that have been chosen...
466 if ((choice
= ppdFindMarkedChoice(ppd
, "MediaType")) != NULL
)
467 media_type
= choice
->choice
;
471 if ((choice
= ppdFindMarkedChoice(ppd
, "Resolution")) != NULL
)
472 resolution
= choice
->choice
;
477 * Choose the appropriate colorspace...
480 switch (header
.cupsColorSpace
)
483 if (header
.cupsBitsPerColor
>= 8)
485 primary
= CUPS_IMAGE_WHITE
;
486 secondary
= CUPS_IMAGE_WHITE
;
490 primary
= CUPS_IMAGE_BLACK
;
491 secondary
= CUPS_IMAGE_BLACK
;
496 case CUPS_CSPACE_RGB
:
497 case CUPS_CSPACE_RGBA
:
498 case CUPS_CSPACE_RGBW
:
499 if (header
.cupsBitsPerColor
>= 8)
501 primary
= CUPS_IMAGE_RGB
;
502 secondary
= CUPS_IMAGE_RGB
;
506 primary
= CUPS_IMAGE_CMY
;
507 secondary
= CUPS_IMAGE_CMY
;
512 case CUPS_CSPACE_WHITE
:
513 case CUPS_CSPACE_GOLD
:
514 case CUPS_CSPACE_SILVER
:
515 primary
= CUPS_IMAGE_BLACK
;
516 secondary
= CUPS_IMAGE_BLACK
;
519 case CUPS_CSPACE_CMYK
:
520 case CUPS_CSPACE_YMCK
:
521 case CUPS_CSPACE_KCMY
:
522 case CUPS_CSPACE_KCMYcm
:
523 case CUPS_CSPACE_GMCK
:
524 case CUPS_CSPACE_GMCS
:
525 if (header
.cupsBitsPerColor
== 1)
527 primary
= CUPS_IMAGE_CMY
;
528 secondary
= CUPS_IMAGE_CMY
;
532 primary
= CUPS_IMAGE_CMYK
;
533 secondary
= CUPS_IMAGE_CMYK
;
537 case CUPS_CSPACE_CMY
:
538 case CUPS_CSPACE_YMC
:
539 primary
= CUPS_IMAGE_CMY
;
540 secondary
= CUPS_IMAGE_CMY
;
546 * Find a color profile matching the current options...
549 if ((val
= cupsGetOption("profile", num_options
, options
)) != NULL
)
551 profile
= &userprofile
;
552 sscanf(val
, "%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",
553 &(userprofile
.density
), &(userprofile
.gamma
),
554 userprofile
.matrix
[0] + 0, userprofile
.matrix
[0] + 1,
555 userprofile
.matrix
[0] + 2,
556 userprofile
.matrix
[1] + 0, userprofile
.matrix
[1] + 1,
557 userprofile
.matrix
[1] + 2,
558 userprofile
.matrix
[2] + 0, userprofile
.matrix
[2] + 1,
559 userprofile
.matrix
[2] + 2);
561 userprofile
.density
*= 0.001f
;
562 userprofile
.gamma
*= 0.001f
;
563 userprofile
.matrix
[0][0] *= 0.001f
;
564 userprofile
.matrix
[0][1] *= 0.001f
;
565 userprofile
.matrix
[0][2] *= 0.001f
;
566 userprofile
.matrix
[1][0] *= 0.001f
;
567 userprofile
.matrix
[1][1] *= 0.001f
;
568 userprofile
.matrix
[1][2] *= 0.001f
;
569 userprofile
.matrix
[2][0] *= 0.001f
;
570 userprofile
.matrix
[2][1] *= 0.001f
;
571 userprofile
.matrix
[2][2] *= 0.001f
;
573 else if (ppd
!= NULL
)
575 fprintf(stderr
, "DEBUG: Searching for profile \"%s/%s\"...\n",
576 resolution
, media_type
);
578 for (i
= 0, profile
= ppd
->profiles
; i
< ppd
->num_profiles
; i
++, profile
++)
580 fprintf(stderr
, "DEBUG: \"%s/%s\" = ", profile
->resolution
,
581 profile
->media_type
);
583 if ((strcmp(profile
->resolution
, resolution
) == 0 ||
584 profile
->resolution
[0] == '-') &&
585 (strcmp(profile
->media_type
, media_type
) == 0 ||
586 profile
->media_type
[0] == '-'))
588 fputs("MATCH!\n", stderr
);
592 fputs("no.\n", stderr
);
596 * If we found a color profile, use it!
599 if (i
>= ppd
->num_profiles
)
606 cupsImageSetProfile(profile
->density
, profile
->gamma
, profile
->matrix
);
608 cupsImageSetRasterColorSpace(header
.cupsColorSpace
);
611 * Create a gamma/brightness LUT...
614 make_lut(lut
, primary
, g
, b
);
617 * Open the input image to print...
620 fputs(_("INFO: Loading image file...\n"), stderr
);
622 if (header
.cupsColorSpace
== CUPS_CSPACE_CIEXYZ
||
623 header
.cupsColorSpace
== CUPS_CSPACE_CIELab
||
624 header
.cupsColorSpace
>= CUPS_CSPACE_ICC1
)
625 img
= cupsImageOpen(filename
, primary
, secondary
, sat
, hue
, NULL
);
627 img
= cupsImageOpen(filename
, primary
, secondary
, sat
, hue
, lut
);
634 fputs(_("ERROR: Unable to open image file for printing!\n"), stderr
);
640 * Scale as necessary...
643 if (zoom
== 0.0 && xppi
== 0)
652 fprintf(stderr
, "DEBUG: Before scaling: xppi=%d, yppi=%d, zoom=%.2f\n",
658 * Scale the image as neccesary to match the desired pixels-per-inch.
663 xprint
= (PageTop
- PageBottom
) / 72.0;
664 yprint
= (PageRight
- PageLeft
) / 72.0;
668 xprint
= (PageRight
- PageLeft
) / 72.0;
669 yprint
= (PageTop
- PageBottom
) / 72.0;
672 fprintf(stderr
, "DEBUG: Before scaling: xprint=%.1f, yprint=%.1f\n",
675 xinches
= (float)img
->xsize
/ (float)xppi
;
676 yinches
= (float)img
->ysize
/ (float)yppi
;
678 fprintf(stderr
, "DEBUG: Image size is %.1f x %.1f inches...\n",
681 if ((val
= cupsGetOption("natural-scaling", num_options
, options
)) != NULL
)
683 xinches
= xinches
* atoi(val
) / 100;
684 yinches
= yinches
* atoi(val
) / 100;
687 if (cupsGetOption("orientation-requested", num_options
, options
) == NULL
&&
688 cupsGetOption("landscape", num_options
, options
) == NULL
)
691 * Rotate the image if it will fit landscape but not portrait...
694 fputs("DEBUG: Auto orientation...\n", stderr
);
696 if ((xinches
> xprint
|| yinches
> yprint
) &&
697 xinches
<= yprint
&& yinches
<= xprint
)
700 * Rotate the image as needed...
703 fputs("DEBUG: Using landscape orientation...\n", stderr
);
705 Orientation
= (Orientation
+ 1) & 3;
715 * Scale percentage of page size...
718 xprint
= (PageRight
- PageLeft
) / 72.0;
719 yprint
= (PageTop
- PageBottom
) / 72.0;
720 aspect
= (float)img
->yppi
/ (float)img
->xppi
;
722 fprintf(stderr
, "DEBUG: Before scaling: xprint=%.1f, yprint=%.1f\n",
725 fprintf(stderr
, "DEBUG: img->xppi = %d, img->yppi = %d, aspect = %f\n",
726 img
->xppi
, img
->yppi
, aspect
);
728 xsize
= xprint
* zoom
;
729 ysize
= xsize
* img
->ysize
/ img
->xsize
/ aspect
;
731 if (ysize
> (yprint
* zoom
))
733 ysize
= yprint
* zoom
;
734 xsize
= ysize
* img
->xsize
* aspect
/ img
->ysize
;
737 xsize2
= yprint
* zoom
;
738 ysize2
= xsize2
* img
->ysize
/ img
->xsize
/ aspect
;
740 if (ysize2
> (xprint
* zoom
))
742 ysize2
= xprint
* zoom
;
743 xsize2
= ysize2
* img
->xsize
* aspect
/ img
->ysize
;
746 fprintf(stderr
, "DEBUG: Portrait size is %.2f x %.2f inches\n", xsize
, ysize
);
747 fprintf(stderr
, "DEBUG: Landscape size is %.2f x %.2f inches\n", xsize2
, ysize2
);
749 if (cupsGetOption("orientation-requested", num_options
, options
) == NULL
&&
750 cupsGetOption("landscape", num_options
, options
) == NULL
)
753 * Choose the rotation with the largest area, but prefer
754 * portrait if they are equal...
757 fputs("DEBUG: Auto orientation...\n", stderr
);
759 if ((xsize
* ysize
) < (xsize2
* xsize2
))
762 * Do landscape orientation...
765 fputs("DEBUG: Using landscape orientation...\n", stderr
);
770 xprint
= (PageTop
- PageBottom
) / 72.0;
771 yprint
= (PageRight
- PageLeft
) / 72.0;
776 * Do portrait orientation...
779 fputs("DEBUG: Using portrait orientation...\n", stderr
);
786 else if (Orientation
& 1)
788 fputs("DEBUG: Using landscape orientation...\n", stderr
);
792 xprint
= (PageTop
- PageBottom
) / 72.0;
793 yprint
= (PageRight
- PageLeft
) / 72.0;
797 fputs("DEBUG: Using portrait orientation...\n", stderr
);
801 xprint
= (PageRight
- PageLeft
) / 72.0;
802 yprint
= (PageTop
- PageBottom
) / 72.0;
807 * Compute the number of pages to print and the size of the image on each
811 xpages
= ceil(xinches
/ xprint
);
812 ypages
= ceil(yinches
/ yprint
);
814 xprint
= xinches
/ xpages
;
815 yprint
= yinches
/ ypages
;
817 fprintf(stderr
, "DEBUG: xpages = %dx%.2fin, ypages = %dx%.2fin\n",
818 xpages
, xprint
, ypages
, yprint
);
821 * Compute the bitmap size...
824 if ((choice
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
&&
825 strcasecmp(choice
->choice
, "Custom") == 0)
827 float width
, /* New width in points */
828 length
; /* New length in points */
832 * Use the correct width and length for the current orientation...
837 width
= yprint
* 72.0;
838 length
= xprint
* 72.0;
842 width
= xprint
* 72.0;
843 length
= yprint
* 72.0;
847 * Add margins to page size...
850 width
+= ppd
->custom_margins
[0] + ppd
->custom_margins
[2];
851 length
+= ppd
->custom_margins
[1] + ppd
->custom_margins
[3];
854 * Enforce minimums...
857 if (width
< ppd
->custom_min
[0])
858 width
= ppd
->custom_min
[0];
860 if (length
< ppd
->custom_min
[1])
861 length
= ppd
->custom_min
[1];
863 fprintf(stderr
, "DEBUG: Updated custom page size to %.2f x %.2f inches...\n",
864 width
/ 72.0, length
/ 72.0);
867 * Set the new custom size...
870 strcpy(header
.cupsPageSizeName
, "Custom");
872 header
.cupsPageSize
[0] = width
+ 0.5;
873 header
.cupsPageSize
[1] = length
+ 0.5;
874 header
.PageSize
[0] = width
+ 0.5;
875 header
.PageSize
[1] = length
+ 0.5;
878 * Update page variables...
883 PageLeft
= ppd
->custom_margins
[0];
884 PageRight
= width
- ppd
->custom_margins
[2];
885 PageBottom
= ppd
->custom_margins
[1];
886 PageTop
= length
- ppd
->custom_margins
[3];
889 * Remove margins from page size...
892 width
-= ppd
->custom_margins
[0] + ppd
->custom_margins
[2];
893 length
-= ppd
->custom_margins
[1] + ppd
->custom_margins
[3];
896 * Set the bitmap size...
899 header
.cupsWidth
= width
* header
.HWResolution
[0] / 72.0;
900 header
.cupsHeight
= length
* header
.HWResolution
[1] / 72.0;
902 header
.cupsBytesPerLine
= (header
.cupsBitsPerPixel
*
903 header
.cupsWidth
+ 7) / 8;
905 if (header
.cupsColorOrder
== CUPS_ORDER_BANDED
)
906 header
.cupsBytesPerLine
*= header
.cupsNumColors
;
909 header
.Margins
[0] = PageLeft
;
910 header
.Margins
[1] = PageBottom
;
912 fprintf(stderr
, "DEBUG: PageSize = [%d %d]\n", header
.PageSize
[0],
921 header
.cupsImagingBBox
[0] = PageLeft
;
922 header
.cupsImagingBBox
[2] = PageLeft
+ xprint
* 72;
925 header
.cupsImagingBBox
[0] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
926 header
.cupsImagingBBox
[2] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
929 header
.cupsImagingBBox
[0] = PageRight
- xprint
* 72;
930 header
.cupsImagingBBox
[2] = PageRight
;
937 header
.cupsImagingBBox
[1] = PageBottom
;
938 header
.cupsImagingBBox
[3] = PageBottom
+ yprint
* 72;
941 header
.cupsImagingBBox
[1] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
942 header
.cupsImagingBBox
[3] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
945 header
.cupsImagingBBox
[1] = PageTop
- yprint
* 72;
946 header
.cupsImagingBBox
[3] = PageTop
;
955 header
.cupsImagingBBox
[0] = PageBottom
;
956 header
.cupsImagingBBox
[2] = PageBottom
+ yprint
* 72;
959 header
.cupsImagingBBox
[0] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
960 header
.cupsImagingBBox
[2] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
963 header
.cupsImagingBBox
[0] = PageTop
- yprint
* 72;
964 header
.cupsImagingBBox
[2] = PageTop
;
971 header
.cupsImagingBBox
[1] = PageLeft
;
972 header
.cupsImagingBBox
[3] = PageLeft
+ xprint
* 72;
975 header
.cupsImagingBBox
[1] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
976 header
.cupsImagingBBox
[3] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
979 header
.cupsImagingBBox
[1] = PageRight
- xprint
* 72;
980 header
.cupsImagingBBox
[3] = PageRight
;
989 header
.cupsImagingBBox
[0] = PageLeft
;
990 header
.cupsImagingBBox
[2] = PageLeft
+ xprint
* 72;
993 header
.cupsImagingBBox
[0] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
994 header
.cupsImagingBBox
[2] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
997 header
.cupsImagingBBox
[0] = PageRight
- xprint
* 72;
998 header
.cupsImagingBBox
[2] = PageRight
;
1005 header
.cupsImagingBBox
[1] = PageBottom
;
1006 header
.cupsImagingBBox
[3] = PageBottom
+ yprint
* 72;
1009 header
.cupsImagingBBox
[1] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
1010 header
.cupsImagingBBox
[3] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
1013 header
.cupsImagingBBox
[1] = PageTop
- yprint
* 72;
1014 header
.cupsImagingBBox
[3] = PageTop
;
1023 header
.cupsImagingBBox
[0] = PageBottom
;
1024 header
.cupsImagingBBox
[2] = PageBottom
+ yprint
* 72;
1027 header
.cupsImagingBBox
[0] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
1028 header
.cupsImagingBBox
[2] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
1031 header
.cupsImagingBBox
[0] = PageTop
- yprint
* 72;
1032 header
.cupsImagingBBox
[2] = PageTop
;
1039 header
.cupsImagingBBox
[1] = PageLeft
;
1040 header
.cupsImagingBBox
[3] = PageLeft
+ xprint
* 72;
1043 header
.cupsImagingBBox
[1] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
1044 header
.cupsImagingBBox
[3] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
1047 header
.cupsImagingBBox
[1] = PageRight
- xprint
* 72;
1048 header
.cupsImagingBBox
[3] = PageRight
;
1054 header
.ImagingBoundingBox
[0] = header
.cupsImagingBBox
[0];
1055 header
.ImagingBoundingBox
[1] = header
.cupsImagingBBox
[1];
1056 header
.ImagingBoundingBox
[2] = header
.cupsImagingBBox
[2];
1057 header
.ImagingBoundingBox
[3] = header
.cupsImagingBBox
[3];
1059 if (header
.cupsColorOrder
== CUPS_ORDER_PLANAR
)
1060 num_planes
= header
.cupsNumColors
;
1064 if (header
.cupsBitsPerColor
>= 8)
1065 zoom_type
= CUPS_IZOOM_NORMAL
;
1067 zoom_type
= CUPS_IZOOM_FAST
;
1070 * See if we need to collate, and if so how we need to do it...
1073 if (xpages
== 1 && ypages
== 1)
1076 slowcollate
= Collate
&& ppdFindOption(ppd
, "Collate") == NULL
;
1078 slowcopies
= ppd
->manual_copies
;
1082 if (Copies
> 1 && !slowcollate
&& !slowcopies
)
1084 header
.Collate
= (cups_bool_t
)Collate
;
1085 header
.NumCopies
= Copies
;
1090 header
.NumCopies
= 1;
1093 * Create the dithering lookup tables...
1097 OnPixels
[255] = 0xff;
1098 OffPixels
[0] = 0x00;
1099 OffPixels
[255] = 0xff;
1101 switch (header
.cupsBitsPerColor
)
1104 for (i
= 1; i
< 255; i
++)
1106 OnPixels
[i
] = 0x55 * (i
/ 85 + 1);
1107 OffPixels
[i
] = 0x55 * (i
/ 64);
1111 for (i
= 1; i
< 255; i
++)
1113 OnPixels
[i
] = 17 * (i
/ 17 + 1);
1114 OffPixels
[i
] = 17 * (i
/ 16);
1120 * Output the pages...
1123 fprintf(stderr
, "DEBUG: cupsWidth = %d\n", header
.cupsWidth
);
1124 fprintf(stderr
, "DEBUG: cupsHeight = %d\n", header
.cupsHeight
);
1125 fprintf(stderr
, "DEBUG: cupsBitsPerColor = %d\n", header
.cupsBitsPerColor
);
1126 fprintf(stderr
, "DEBUG: cupsBitsPerPixel = %d\n", header
.cupsBitsPerPixel
);
1127 fprintf(stderr
, "DEBUG: cupsBytesPerLine = %d\n", header
.cupsBytesPerLine
);
1128 fprintf(stderr
, "DEBUG: cupsColorOrder = %d\n", header
.cupsColorOrder
);
1129 fprintf(stderr
, "DEBUG: cupsColorSpace = %d\n", header
.cupsColorSpace
);
1130 fprintf(stderr
, "DEBUG: img->colorspace = %d\n", img
->colorspace
);
1132 row
= malloc(2 * header
.cupsBytesPerLine
);
1133 ras
= cupsRasterOpen(1, CUPS_RASTER_WRITE
);
1135 for (i
= 0, page
= 1; i
< Copies
; i
++)
1136 for (xpage
= 0; xpage
< xpages
; xpage
++)
1137 for (ypage
= 0; ypage
< ypages
; ypage
++, page
++)
1139 fprintf(stderr
, _("INFO: Formatting page %d...\n"), page
);
1141 if (Orientation
& 1)
1143 xc0
= img
->xsize
* ypage
/ ypages
;
1144 xc1
= img
->xsize
* (ypage
+ 1) / ypages
- 1;
1145 yc0
= img
->ysize
* xpage
/ xpages
;
1146 yc1
= img
->ysize
* (xpage
+ 1) / xpages
- 1;
1148 xtemp
= header
.HWResolution
[0] * yprint
;
1149 ytemp
= header
.HWResolution
[1] * xprint
;
1153 xc0
= img
->xsize
* xpage
/ xpages
;
1154 xc1
= img
->xsize
* (xpage
+ 1) / xpages
- 1;
1155 yc0
= img
->ysize
* ypage
/ ypages
;
1156 yc1
= img
->ysize
* (ypage
+ 1) / ypages
- 1;
1158 xtemp
= header
.HWResolution
[0] * xprint
;
1159 ytemp
= header
.HWResolution
[1] * yprint
;
1162 cupsRasterWriteHeader2(ras
, &header
);
1164 for (plane
= 0; plane
< num_planes
; plane
++)
1167 * Initialize the image "zoom" engine...
1171 z
= _cupsImageZoomNew(img
, xc0
, yc0
, xc1
, yc1
, -xtemp
, ytemp
,
1172 Orientation
& 1, zoom_type
);
1174 z
= _cupsImageZoomNew(img
, xc0
, yc0
, xc1
, yc1
, xtemp
, ytemp
,
1175 Orientation
& 1, zoom_type
);
1178 * Write leading blank space as needed...
1181 if (header
.cupsHeight
> z
->ysize
&& YPosition
<= 0)
1183 blank_line(&header
, row
);
1185 y
= header
.cupsHeight
- z
->ysize
;
1189 fprintf(stderr
, "DEBUG: Writing %d leading blank lines...\n", y
);
1193 if (cupsRasterWritePixels(ras
, row
, header
.cupsBytesPerLine
) <
1194 header
.cupsBytesPerLine
)
1196 fputs(_("ERROR: Unable to write raster data to driver!\n"),
1198 cupsImageClose(img
);
1205 * Then write image data...
1208 for (y
= z
->ysize
, yerr0
= 0, yerr1
= z
->ysize
, iy
= 0, last_iy
= -2;
1214 if (zoom_type
!= CUPS_IZOOM_FAST
&& (iy
- last_iy
) > 1)
1215 _cupsImageZoomFill(z
, iy
);
1217 _cupsImageZoomFill(z
, iy
+ z
->yincr
);
1223 * Format this line of raster data for the printer...
1226 blank_line(&header
, row
);
1228 r0
= z
->rows
[z
->row
];
1229 r1
= z
->rows
[1 - z
->row
];
1231 switch (header
.cupsColorSpace
)
1233 case CUPS_CSPACE_W
:
1234 format_W(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1235 yerr0
, yerr1
, r0
, r1
);
1238 case CUPS_CSPACE_RGB
:
1239 format_RGB(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1240 yerr0
, yerr1
, r0
, r1
);
1242 case CUPS_CSPACE_RGBA
:
1243 case CUPS_CSPACE_RGBW
:
1244 format_RGBA(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1245 yerr0
, yerr1
, r0
, r1
);
1247 case CUPS_CSPACE_K
:
1248 case CUPS_CSPACE_WHITE
:
1249 case CUPS_CSPACE_GOLD
:
1250 case CUPS_CSPACE_SILVER
:
1251 format_K(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1252 yerr0
, yerr1
, r0
, r1
);
1254 case CUPS_CSPACE_CMY
:
1255 format_CMY(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1256 yerr0
, yerr1
, r0
, r1
);
1258 case CUPS_CSPACE_YMC
:
1259 format_YMC(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1260 yerr0
, yerr1
, r0
, r1
);
1262 case CUPS_CSPACE_CMYK
:
1263 format_CMYK(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1264 yerr0
, yerr1
, r0
, r1
);
1266 case CUPS_CSPACE_YMCK
:
1267 case CUPS_CSPACE_GMCK
:
1268 case CUPS_CSPACE_GMCS
:
1269 format_YMCK(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1270 yerr0
, yerr1
, r0
, r1
);
1272 case CUPS_CSPACE_KCMYcm
:
1273 if (header
.cupsBitsPerColor
== 1)
1275 format_KCMYcm(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1276 yerr0
, yerr1
, r0
, r1
);
1279 case CUPS_CSPACE_KCMY
:
1280 format_KCMY(&header
, row
, y
, plane
, z
->xsize
, z
->ysize
,
1281 yerr0
, yerr1
, r0
, r1
);
1286 * Write the raster data to the driver...
1289 if (cupsRasterWritePixels(ras
, row
, header
.cupsBytesPerLine
) <
1290 header
.cupsBytesPerLine
)
1292 fputs(_("ERROR: Unable to write raster data to driver!\n"),
1294 cupsImageClose(img
);
1299 * Compute the next scanline in the image...
1314 * Write trailing blank space as needed...
1317 if (header
.cupsHeight
> z
->ysize
&& YPosition
>= 0)
1319 blank_line(&header
, row
);
1321 y
= header
.cupsHeight
- z
->ysize
;
1325 fprintf(stderr
, "DEBUG: Writing %d trailing blank lines...\n", y
);
1329 if (cupsRasterWritePixels(ras
, row
, header
.cupsBytesPerLine
) <
1330 header
.cupsBytesPerLine
)
1332 fputs(_("ERROR: Unable to write raster data to driver!\n"),
1334 cupsImageClose(img
);
1341 * Free memory used for the "zoom" engine...
1344 _cupsImageZoomDelete(z
);
1353 cupsRasterClose(ras
);
1354 cupsImageClose(img
);
1362 * 'blank_line()' - Clear a line buffer to the blank value...
1366 blank_line(cups_page_header2_t
*header
, /* I - Page header */
1367 unsigned char *row
) /* I - Row buffer */
1369 int count
; /* Remaining bytes */
1372 count
= header
->cupsBytesPerLine
;
1374 switch (header
->cupsColorSpace
)
1376 case CUPS_CSPACE_CIEXYZ
:
1386 case CUPS_CSPACE_CIELab
:
1387 case CUPS_CSPACE_ICC1
:
1388 case CUPS_CSPACE_ICC2
:
1389 case CUPS_CSPACE_ICC3
:
1390 case CUPS_CSPACE_ICC4
:
1391 case CUPS_CSPACE_ICC5
:
1392 case CUPS_CSPACE_ICC6
:
1393 case CUPS_CSPACE_ICC7
:
1394 case CUPS_CSPACE_ICC8
:
1395 case CUPS_CSPACE_ICC9
:
1396 case CUPS_CSPACE_ICCA
:
1397 case CUPS_CSPACE_ICCB
:
1398 case CUPS_CSPACE_ICCC
:
1399 case CUPS_CSPACE_ICCD
:
1400 case CUPS_CSPACE_ICCE
:
1401 case CUPS_CSPACE_ICCF
:
1411 case CUPS_CSPACE_K
:
1412 case CUPS_CSPACE_CMY
:
1413 case CUPS_CSPACE_CMYK
:
1414 case CUPS_CSPACE_YMC
:
1415 case CUPS_CSPACE_YMCK
:
1416 case CUPS_CSPACE_KCMY
:
1417 case CUPS_CSPACE_KCMYcm
:
1418 case CUPS_CSPACE_GMCK
:
1419 case CUPS_CSPACE_GMCS
:
1420 case CUPS_CSPACE_WHITE
:
1421 case CUPS_CSPACE_GOLD
:
1422 case CUPS_CSPACE_SILVER
:
1423 memset(row
, 0, count
);
1427 memset(row
, 255, count
);
1434 * 'format_CMY()' - Convert image data to CMY.
1438 format_CMY(cups_page_header2_t
*header
, /* I - Page header */
1439 unsigned char *row
, /* IO - Bitmap data for device */
1440 int y
, /* I - Current row */
1441 int z
, /* I - Current plane */
1442 int xsize
, /* I - Width of image data */
1443 int ysize
, /* I - Height of image data */
1444 int yerr0
, /* I - Top Y error */
1445 int yerr1
, /* I - Bottom Y error */
1446 cups_ib_t
*r0
, /* I - Primary image data */
1447 cups_ib_t
*r1
) /* I - Image data for interpolation */
1449 cups_ib_t
*ptr
, /* Pointer into row */
1450 *cptr
, /* Pointer into cyan */
1451 *mptr
, /* Pointer into magenta */
1452 *yptr
, /* Pointer into yellow */
1453 bitmask
; /* Current mask for pixel */
1454 int bitoffset
; /* Current offset in line */
1455 int bandwidth
; /* Width of a color band */
1456 int x
, /* Current X coordinate on page */
1457 *dither
; /* Pointer into dither array */
1466 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
1469 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
1473 ptr
= row
+ bitoffset
/ 8;
1474 bandwidth
= header
->cupsBytesPerLine
/ 3;
1476 switch (header
->cupsColorOrder
)
1478 case CUPS_ORDER_CHUNKED
:
1479 switch (header
->cupsBitsPerColor
)
1482 bitmask
= 64 >> (bitoffset
& 7);
1483 dither
= Floyd16x16
[y
& 15];
1485 for (x
= xsize
; x
> 0; x
--)
1487 if (*r0
++ > dither
[x
& 15])
1491 if (*r0
++ > dither
[x
& 15])
1495 if (*r0
++ > dither
[x
& 15])
1509 dither
= Floyd8x8
[y
& 7];
1511 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1513 if ((r0
[0] & 63) > dither
[x
& 7])
1514 *ptr
^= (0x30 & OnPixels
[r0
[0]]);
1516 *ptr
^= (0x30 & OffPixels
[r0
[0]]);
1518 if ((r0
[1] & 63) > dither
[x
& 7])
1519 *ptr
^= (0x0c & OnPixels
[r0
[1]]);
1521 *ptr
^= (0x0c & OffPixels
[r0
[1]]);
1523 if ((r0
[2] & 63) > dither
[x
& 7])
1524 *ptr
++ ^= (0x03 & OnPixels
[r0
[2]]);
1526 *ptr
++ ^= (0x03 & OffPixels
[r0
[2]]);
1531 dither
= Floyd4x4
[y
& 3];
1533 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1535 if ((r0
[0] & 15) > dither
[x
& 3])
1536 *ptr
++ ^= (0x0f & OnPixels
[r0
[0]]);
1538 *ptr
++ ^= (0x0f & OffPixels
[r0
[0]]);
1540 if ((r0
[1] & 15) > dither
[x
& 3])
1541 *ptr
^= (0xf0 & OnPixels
[r0
[1]]);
1543 *ptr
^= (0xf0 & OffPixels
[r0
[1]]);
1545 if ((r0
[2] & 15) > dither
[x
& 3])
1546 *ptr
++ ^= (0x0f & OnPixels
[r0
[2]]);
1548 *ptr
++ ^= (0x0f & OffPixels
[r0
[2]]);
1553 for (x
= xsize
* 3; x
> 0; x
--, r0
++, r1
++)
1557 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
1562 case CUPS_ORDER_BANDED
:
1564 mptr
= ptr
+ bandwidth
;
1565 yptr
= ptr
+ 2 * bandwidth
;
1567 switch (header
->cupsBitsPerColor
)
1570 bitmask
= 0x80 >> (bitoffset
& 7);
1571 dither
= Floyd16x16
[y
& 15];
1573 for (x
= xsize
; x
> 0; x
--)
1575 if (*r0
++ > dither
[x
& 15])
1577 if (*r0
++ > dither
[x
& 15])
1579 if (*r0
++ > dither
[x
& 15])
1595 bitmask
= 0xc0 >> (bitoffset
& 7);
1596 dither
= Floyd8x8
[y
& 7];
1598 for (x
= xsize
; x
> 0; x
--)
1600 if ((*r0
& 63) > dither
[x
& 7])
1601 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
1603 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
1605 if ((*r0
& 63) > dither
[x
& 7])
1606 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
1608 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
1610 if ((*r0
& 63) > dither
[x
& 7])
1611 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
1613 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
1629 bitmask
= 0xf0 >> (bitoffset
& 7);
1630 dither
= Floyd4x4
[y
& 3];
1632 for (x
= xsize
; x
> 0; x
--)
1634 if ((*r0
& 15) > dither
[x
& 3])
1635 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
1637 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
1639 if ((*r0
& 15) > dither
[x
& 3])
1640 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
1642 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
1644 if ((*r0
& 15) > dither
[x
& 3])
1645 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
1647 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
1649 if (bitmask
== 0xf0)
1663 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
1668 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
1673 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
1678 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
1684 case CUPS_ORDER_PLANAR
:
1685 switch (header
->cupsBitsPerColor
)
1688 bitmask
= 0x80 >> (bitoffset
& 7);
1689 dither
= Floyd16x16
[y
& 15];
1694 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1696 if (r0
[0] > dither
[x
& 15])
1710 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1712 if (r0
[1] > dither
[x
& 15])
1726 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1728 if (r0
[2] > dither
[x
& 15])
1744 bitmask
= 0xc0 >> (bitoffset
& 7);
1745 dither
= Floyd8x8
[y
& 7];
1748 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1750 if ((*r0
& 63) > dither
[x
& 7])
1751 *ptr
^= (bitmask
& OnPixels
[*r0
]);
1753 *ptr
^= (bitmask
& OffPixels
[*r0
]);
1767 bitmask
= 0xf0 >> (bitoffset
& 7);
1768 dither
= Floyd4x4
[y
& 3];
1771 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1773 if ((*r0
& 15) > dither
[x
& 3])
1774 *ptr
^= (bitmask
& OnPixels
[*r0
]);
1776 *ptr
^= (bitmask
& OffPixels
[*r0
]);
1778 if (bitmask
== 0xf0)
1793 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
1798 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
1808 * 'format_CMYK()' - Convert image data to CMYK.
1812 format_CMYK(cups_page_header2_t
*header
,/* I - Page header */
1813 unsigned char *row
, /* IO - Bitmap data for device */
1814 int y
, /* I - Current row */
1815 int z
, /* I - Current plane */
1816 int xsize
, /* I - Width of image data */
1817 int ysize
, /* I - Height of image data */
1818 int yerr0
, /* I - Top Y error */
1819 int yerr1
, /* I - Bottom Y error */
1820 cups_ib_t
*r0
, /* I - Primary image data */
1821 cups_ib_t
*r1
) /* I - Image data for interpolation */
1823 cups_ib_t
*ptr
, /* Pointer into row */
1824 *cptr
, /* Pointer into cyan */
1825 *mptr
, /* Pointer into magenta */
1826 *yptr
, /* Pointer into yellow */
1827 *kptr
, /* Pointer into black */
1828 bitmask
; /* Current mask for pixel */
1829 int bitoffset
; /* Current offset in line */
1830 int bandwidth
; /* Width of a color band */
1831 int x
, /* Current X coordinate on page */
1832 *dither
; /* Pointer into dither array */
1833 int pc
, pm
, py
; /* CMY pixels */
1842 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
1845 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
1849 ptr
= row
+ bitoffset
/ 8;
1850 bandwidth
= header
->cupsBytesPerLine
/ 4;
1852 switch (header
->cupsColorOrder
)
1854 case CUPS_ORDER_CHUNKED
:
1855 switch (header
->cupsBitsPerColor
)
1858 bitmask
= 128 >> (bitoffset
& 7);
1859 dither
= Floyd16x16
[y
& 15];
1861 for (x
= xsize
; x
> 0; x
--)
1863 pc
= *r0
++ > dither
[x
& 15];
1864 pm
= *r0
++ > dither
[x
& 15];
1865 py
= *r0
++ > dither
[x
& 15];
1898 dither
= Floyd8x8
[y
& 7];
1900 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
1902 if ((r0
[0] & 63) > dither
[x
& 7])
1903 *ptr
^= (0xc0 & OnPixels
[r0
[0]]);
1905 *ptr
^= (0xc0 & OffPixels
[r0
[0]]);
1907 if ((r0
[1] & 63) > dither
[x
& 7])
1908 *ptr
^= (0x30 & OnPixels
[r0
[1]]);
1910 *ptr
^= (0x30 & OffPixels
[r0
[1]]);
1912 if ((r0
[2] & 63) > dither
[x
& 7])
1913 *ptr
^= (0x0c & OnPixels
[r0
[2]]);
1915 *ptr
^= (0x0c & OffPixels
[r0
[2]]);
1917 if ((r0
[3] & 63) > dither
[x
& 7])
1918 *ptr
++ ^= (0x03 & OnPixels
[r0
[3]]);
1920 *ptr
++ ^= (0x03 & OffPixels
[r0
[3]]);
1925 dither
= Floyd4x4
[y
& 3];
1927 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
1929 if ((r0
[0] & 15) > dither
[x
& 3])
1930 *ptr
^= (0xf0 & OnPixels
[r0
[0]]);
1932 *ptr
^= (0xf0 & OffPixels
[r0
[0]]);
1934 if ((r0
[1] & 15) > dither
[x
& 3])
1935 *ptr
++ ^= (0x0f & OnPixels
[r0
[1]]);
1937 *ptr
++ ^= (0x0f & OffPixels
[r0
[1]]);
1939 if ((r0
[2] & 15) > dither
[x
& 3])
1940 *ptr
^= (0xf0 & OnPixels
[r0
[2]]);
1942 *ptr
^= (0xf0 & OffPixels
[r0
[2]]);
1944 if ((r0
[3] & 15) > dither
[x
& 3])
1945 *ptr
++ ^= (0x0f & OnPixels
[r0
[3]]);
1947 *ptr
++ ^= (0x0f & OffPixels
[r0
[3]]);
1952 for (x
= xsize
* 4; x
> 0; x
--, r0
++, r1
++)
1956 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
1961 case CUPS_ORDER_BANDED
:
1963 mptr
= ptr
+ bandwidth
;
1964 yptr
= ptr
+ 2 * bandwidth
;
1965 kptr
= ptr
+ 3 * bandwidth
;
1967 switch (header
->cupsBitsPerColor
)
1970 bitmask
= 0x80 >> (bitoffset
& 7);
1971 dither
= Floyd16x16
[y
& 15];
1973 for (x
= xsize
; x
> 0; x
--)
1975 pc
= *r0
++ > dither
[x
& 15];
1976 pm
= *r0
++ > dither
[x
& 15];
1977 py
= *r0
++ > dither
[x
& 15];
2005 bitmask
= 0xc0 >> (bitoffset
& 7);
2006 dither
= Floyd8x8
[y
& 7];
2008 for (x
= xsize
; x
> 0; x
--)
2010 if ((*r0
& 63) > dither
[x
& 7])
2011 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2013 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2015 if ((*r0
& 63) > dither
[x
& 7])
2016 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2018 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2020 if ((*r0
& 63) > dither
[x
& 7])
2021 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2023 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2025 if ((*r0
& 63) > dither
[x
& 7])
2026 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2028 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2045 bitmask
= 0xf0 >> (bitoffset
& 7);
2046 dither
= Floyd4x4
[y
& 3];
2048 for (x
= xsize
; x
> 0; x
--)
2050 if ((*r0
& 15) > dither
[x
& 3])
2051 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2053 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2055 if ((*r0
& 15) > dither
[x
& 3])
2056 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2058 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2060 if ((*r0
& 15) > dither
[x
& 3])
2061 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2063 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2065 if ((*r0
& 15) > dither
[x
& 3])
2066 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2068 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2070 if (bitmask
== 0xf0)
2085 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2090 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
2095 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
2100 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
2105 *kptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
2111 case CUPS_ORDER_PLANAR
:
2112 switch (header
->cupsBitsPerColor
)
2115 bitmask
= 0x80 >> (bitoffset
& 7);
2116 dither
= Floyd16x16
[y
& 15];
2118 for (x
= xsize
; x
> 0; x
--)
2120 pc
= *r0
++ > dither
[x
& 15];
2121 pm
= *r0
++ > dither
[x
& 15];
2122 py
= *r0
++ > dither
[x
& 15];
2124 if ((pc
&& pm
&& py
&& z
== 3) ||
2125 (pc
&& z
== 0) || (pm
&& z
== 1) || (py
&& z
== 2))
2139 bitmask
= 0xc0 >> (bitoffset
& 7);
2140 dither
= Floyd8x8
[y
& 7];
2143 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2145 if ((*r0
& 63) > dither
[x
& 7])
2146 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2148 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2162 bitmask
= 0xf0 >> (bitoffset
& 7);
2163 dither
= Floyd4x4
[y
& 3];
2166 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2168 if ((*r0
& 15) > dither
[x
& 3])
2169 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2171 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2173 if (bitmask
== 0xf0)
2188 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2193 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
2203 * 'format_K()' - Convert image data to black.
2207 format_K(cups_page_header2_t
*header
, /* I - Page header */
2208 unsigned char *row
, /* IO - Bitmap data for device */
2209 int y
, /* I - Current row */
2210 int z
, /* I - Current plane */
2211 int xsize
, /* I - Width of image data */
2212 int ysize
, /* I - Height of image data */
2213 int yerr0
, /* I - Top Y error */
2214 int yerr1
, /* I - Bottom Y error */
2215 cups_ib_t
*r0
, /* I - Primary image data */
2216 cups_ib_t
*r1
) /* I - Image data for interpolation */
2218 cups_ib_t
*ptr
, /* Pointer into row */
2219 bitmask
; /* Current mask for pixel */
2220 int bitoffset
; /* Current offset in line */
2221 int x
, /* Current X coordinate on page */
2222 *dither
; /* Pointer into dither array */
2233 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2236 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2240 ptr
= row
+ bitoffset
/ 8;
2242 switch (header
->cupsBitsPerColor
)
2245 bitmask
= 0x80 >> (bitoffset
& 7);
2246 dither
= Floyd16x16
[y
& 15];
2248 for (x
= xsize
; x
> 0; x
--)
2250 if (*r0
++ > dither
[x
& 15])
2264 bitmask
= 0xc0 >> (bitoffset
& 7);
2265 dither
= Floyd8x8
[y
& 7];
2267 for (x
= xsize
; x
> 0; x
--)
2269 if ((*r0
& 63) > dither
[x
& 7])
2270 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
2272 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
2286 bitmask
= 0xf0 >> (bitoffset
& 7);
2287 dither
= Floyd4x4
[y
& 3];
2289 for (x
= xsize
; x
> 0; x
--)
2291 if ((*r0
& 15) > dither
[x
& 3])
2292 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
2294 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
2296 if (bitmask
== 0xf0)
2308 for (x
= xsize
; x
> 0; x
--, r0
++, r1
++)
2313 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
2321 * 'format_KCMY()' - Convert image data to KCMY.
2325 format_KCMY(cups_page_header2_t
*header
,/* I - Page header */
2326 unsigned char *row
, /* IO - Bitmap data for device */
2327 int y
, /* I - Current row */
2328 int z
, /* I - Current plane */
2329 int xsize
, /* I - Width of image data */
2330 int ysize
, /* I - Height of image data */
2331 int yerr0
, /* I - Top Y error */
2332 int yerr1
, /* I - Bottom Y error */
2333 cups_ib_t
*r0
, /* I - Primary image data */
2334 cups_ib_t
*r1
) /* I - Image data for interpolation */
2336 cups_ib_t
*ptr
, /* Pointer into row */
2337 *cptr
, /* Pointer into cyan */
2338 *mptr
, /* Pointer into magenta */
2339 *yptr
, /* Pointer into yellow */
2340 *kptr
, /* Pointer into black */
2341 bitmask
; /* Current mask for pixel */
2342 int bitoffset
; /* Current offset in line */
2343 int bandwidth
; /* Width of a color band */
2344 int x
, /* Current X coordinate on page */
2345 *dither
; /* Pointer into dither array */
2346 int pc
, pm
, py
; /* CMY pixels */
2355 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2358 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2362 ptr
= row
+ bitoffset
/ 8;
2363 bandwidth
= header
->cupsBytesPerLine
/ 4;
2365 switch (header
->cupsColorOrder
)
2367 case CUPS_ORDER_CHUNKED
:
2368 switch (header
->cupsBitsPerColor
)
2371 bitmask
= 128 >> (bitoffset
& 7);
2372 dither
= Floyd16x16
[y
& 15];
2374 for (x
= xsize
; x
> 0; x
--)
2376 pc
= *r0
++ > dither
[x
& 15];
2377 pm
= *r0
++ > dither
[x
& 15];
2378 py
= *r0
++ > dither
[x
& 15];
2411 dither
= Floyd8x8
[y
& 7];
2413 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2415 if ((r0
[3] & 63) > dither
[x
& 7])
2416 *ptr
^= (0xc0 & OnPixels
[r0
[3]]);
2418 *ptr
^= (0xc0 & OffPixels
[r0
[3]]);
2420 if ((r0
[0] & 63) > dither
[x
& 7])
2421 *ptr
^= (0x30 & OnPixels
[r0
[0]]);
2423 *ptr
^= (0x30 & OffPixels
[r0
[0]]);
2425 if ((r0
[1] & 63) > dither
[x
& 7])
2426 *ptr
^= (0x0c & OnPixels
[r0
[1]]);
2428 *ptr
^= (0x0c & OffPixels
[r0
[1]]);
2430 if ((r0
[2] & 63) > dither
[x
& 7])
2431 *ptr
++ ^= (0x03 & OnPixels
[r0
[2]]);
2433 *ptr
++ ^= (0x03 & OffPixels
[r0
[2]]);
2438 dither
= Floyd4x4
[y
& 3];
2440 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2442 if ((r0
[3] & 15) > dither
[x
& 3])
2443 *ptr
^= (0xf0 & OnPixels
[r0
[3]]);
2445 *ptr
^= (0xf0 & OffPixels
[r0
[3]]);
2447 if ((r0
[0] & 15) > dither
[x
& 3])
2448 *ptr
++ ^= (0x0f & OnPixels
[r0
[0]]);
2450 *ptr
++ ^= (0x0f & OffPixels
[r0
[0]]);
2452 if ((r0
[1] & 15) > dither
[x
& 3])
2453 *ptr
^= (0xf0 & OnPixels
[r0
[1]]);
2455 *ptr
^= (0xf0 & OffPixels
[r0
[1]]);
2457 if ((r0
[2] & 15) > dither
[x
& 3])
2458 *ptr
++ ^= (0x0f & OnPixels
[r0
[2]]);
2460 *ptr
++ ^= (0x0f & OffPixels
[r0
[2]]);
2465 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2470 *ptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
2475 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
2480 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
2485 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
2491 case CUPS_ORDER_BANDED
:
2493 cptr
= ptr
+ bandwidth
;
2494 mptr
= ptr
+ 2 * bandwidth
;
2495 yptr
= ptr
+ 3 * bandwidth
;
2497 switch (header
->cupsBitsPerColor
)
2500 bitmask
= 0x80 >> (bitoffset
& 7);
2501 dither
= Floyd16x16
[y
& 15];
2503 for (x
= xsize
; x
> 0; x
--)
2505 pc
= *r0
++ > dither
[x
& 15];
2506 pm
= *r0
++ > dither
[x
& 15];
2507 py
= *r0
++ > dither
[x
& 15];
2535 bitmask
= 0xc0 >> (bitoffset
& 7);
2536 dither
= Floyd8x8
[y
& 7];
2538 for (x
= xsize
; x
> 0; x
--)
2540 if ((*r0
& 63) > dither
[x
& 7])
2541 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2543 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2545 if ((*r0
& 63) > dither
[x
& 7])
2546 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2548 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2550 if ((*r0
& 63) > dither
[x
& 7])
2551 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2553 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2555 if ((*r0
& 63) > dither
[x
& 7])
2556 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2558 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2575 bitmask
= 0xf0 >> (bitoffset
& 7);
2576 dither
= Floyd4x4
[y
& 3];
2578 for (x
= xsize
; x
> 0; x
--)
2580 if ((*r0
& 15) > dither
[x
& 3])
2581 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2583 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2585 if ((*r0
& 15) > dither
[x
& 3])
2586 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2588 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2590 if ((*r0
& 15) > dither
[x
& 3])
2591 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2593 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2595 if ((*r0
& 15) > dither
[x
& 3])
2596 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2598 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2600 if (bitmask
== 0xf0)
2615 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2620 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
2625 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
2630 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
2635 *kptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
2641 case CUPS_ORDER_PLANAR
:
2642 switch (header
->cupsBitsPerColor
)
2645 bitmask
= 0x80 >> (bitoffset
& 7);
2646 dither
= Floyd16x16
[y
& 15];
2648 for (x
= xsize
; x
> 0; x
--)
2650 pc
= *r0
++ > dither
[x
& 15];
2651 pm
= *r0
++ > dither
[x
& 15];
2652 py
= *r0
++ > dither
[x
& 15];
2654 if ((pc
&& pm
&& py
&& z
== 0) ||
2655 (pc
&& z
== 1) || (pm
&& z
== 2) || (py
&& z
== 3))
2669 bitmask
= 0xc0 >> (bitoffset
& 7);
2670 dither
= Floyd8x8
[y
& 7];
2676 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2678 if ((*r0
& 63) > dither
[x
& 7])
2679 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2681 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2695 bitmask
= 0xf0 >> (bitoffset
& 7);
2696 dither
= Floyd4x4
[y
& 3];
2702 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2704 if ((*r0
& 15) > dither
[x
& 3])
2705 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2707 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2709 if (bitmask
== 0xf0)
2732 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2737 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
2747 * 'format_KCMYcm()' - Convert image data to KCMYcm.
2752 cups_page_header2_t
*header
, /* I - Page header */
2753 unsigned char *row
, /* IO - Bitmap data for device */
2754 int y
, /* I - Current row */
2755 int z
, /* I - Current plane */
2756 int xsize
, /* I - Width of image data */
2757 int ysize
, /* I - Height of image data */
2758 int yerr0
, /* I - Top Y error */
2759 int yerr1
, /* I - Bottom Y error */
2760 cups_ib_t
*r0
, /* I - Primary image data */
2761 cups_ib_t
*r1
) /* I - Image data for interpolation */
2763 int pc
, pm
, py
, pk
; /* Cyan, magenta, yellow, and black values */
2764 cups_ib_t
*ptr
, /* Pointer into row */
2765 *cptr
, /* Pointer into cyan */
2766 *mptr
, /* Pointer into magenta */
2767 *yptr
, /* Pointer into yellow */
2768 *kptr
, /* Pointer into black */
2769 *lcptr
, /* Pointer into light cyan */
2770 *lmptr
, /* Pointer into light magenta */
2771 bitmask
; /* Current mask for pixel */
2772 int bitoffset
; /* Current offset in line */
2773 int bandwidth
; /* Width of a color band */
2774 int x
, /* Current X coordinate on page */
2775 *dither
; /* Pointer into dither array */
2784 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2787 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2791 ptr
= row
+ bitoffset
/ 8;
2792 bandwidth
= header
->cupsBytesPerLine
/ 6;
2794 switch (header
->cupsColorOrder
)
2796 case CUPS_ORDER_CHUNKED
:
2797 dither
= Floyd16x16
[y
& 15];
2799 for (x
= xsize
; x
> 0; x
--)
2801 pc
= *r0
++ > dither
[x
& 15];
2802 pm
= *r0
++ > dither
[x
& 15];
2803 py
= *r0
++ > dither
[x
& 15];
2804 pk
= pc
&& pm
&& py
;
2807 *ptr
++ ^= 32; /* Black */
2809 *ptr
++ ^= 17; /* Blue (cyan + light magenta) */
2811 *ptr
++ ^= 6; /* Green (light cyan + yellow) */
2813 *ptr
++ ^= 12; /* Red (magenta + yellow) */
2825 case CUPS_ORDER_BANDED
:
2827 cptr
= ptr
+ bandwidth
;
2828 mptr
= ptr
+ 2 * bandwidth
;
2829 yptr
= ptr
+ 3 * bandwidth
;
2830 lcptr
= ptr
+ 4 * bandwidth
;
2831 lmptr
= ptr
+ 5 * bandwidth
;
2833 bitmask
= 0x80 >> (bitoffset
& 7);
2834 dither
= Floyd16x16
[y
& 15];
2836 for (x
= xsize
; x
> 0; x
--)
2838 pc
= *r0
++ > dither
[x
& 15];
2839 pm
= *r0
++ > dither
[x
& 15];
2840 py
= *r0
++ > dither
[x
& 15];
2841 pk
= pc
&& pm
&& py
;
2844 *kptr
^= bitmask
; /* Black */
2847 *cptr
^= bitmask
; /* Blue (cyan + light magenta) */
2852 *lcptr
^= bitmask
; /* Green (light cyan + yellow) */
2857 *mptr
^= bitmask
; /* Red (magenta + yellow) */
2882 case CUPS_ORDER_PLANAR
:
2883 bitmask
= 0x80 >> (bitoffset
& 7);
2884 dither
= Floyd16x16
[y
& 15];
2886 for (x
= xsize
; x
> 0; x
--)
2888 pc
= *r0
++ > dither
[x
& 15];
2889 pm
= *r0
++ > dither
[x
& 15];
2890 py
= *r0
++ > dither
[x
& 15];
2891 pk
= pc
&& pm
&& py
;
2895 else if (pc
&& pm
&& (z
== 1 || z
== 5))
2896 *ptr
^= bitmask
; /* Blue (cyan + light magenta) */
2897 else if (pc
&& py
&& (z
== 3 || z
== 4))
2898 *ptr
^= bitmask
; /* Green (light cyan + yellow) */
2899 else if (pm
&& py
&& (z
== 2 || z
== 3))
2900 *ptr
^= bitmask
; /* Red (magenta + yellow) */
2901 else if (pc
&& z
== 1)
2903 else if (pm
&& z
== 2)
2905 else if (py
&& z
== 3)
2922 * 'format_RGBA()' - Convert image data to RGBA/RGBW.
2926 format_RGBA(cups_page_header2_t
*header
,/* I - Page header */
2927 unsigned char *row
, /* IO - Bitmap data for device */
2928 int y
, /* I - Current row */
2929 int z
, /* I - Current plane */
2930 int xsize
, /* I - Width of image data */
2931 int ysize
, /* I - Height of image data */
2932 int yerr0
, /* I - Top Y error */
2933 int yerr1
, /* I - Bottom Y error */
2934 cups_ib_t
*r0
, /* I - Primary image data */
2935 cups_ib_t
*r1
) /* I - Image data for interpolation */
2937 cups_ib_t
*ptr
, /* Pointer into row */
2938 *cptr
, /* Pointer into cyan */
2939 *mptr
, /* Pointer into magenta */
2940 *yptr
, /* Pointer into yellow */
2941 bitmask
; /* Current mask for pixel */
2942 int bitoffset
; /* Current offset in line */
2943 int bandwidth
; /* Width of a color band */
2944 int x
, /* Current X coordinate on page */
2945 *dither
; /* Pointer into dither array */
2954 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2957 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2961 ptr
= row
+ bitoffset
/ 8;
2962 bandwidth
= header
->cupsBytesPerLine
/ 4;
2964 switch (header
->cupsColorOrder
)
2966 case CUPS_ORDER_CHUNKED
:
2967 switch (header
->cupsBitsPerColor
)
2970 bitmask
= 128 >> (bitoffset
& 7);
2971 dither
= Floyd16x16
[y
& 15];
2973 for (x
= xsize
; x
> 0; x
--)
2975 if (*r0
++ > dither
[x
& 15])
2979 if (*r0
++ > dither
[x
& 15])
2983 if (*r0
++ > dither
[x
& 15])
2997 dither
= Floyd8x8
[y
& 7];
2999 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3001 if ((r0
[0] & 63) > dither
[x
& 7])
3002 *ptr
^= (0xc0 & OnPixels
[r0
[0]]);
3004 *ptr
^= (0xc0 & OffPixels
[r0
[0]]);
3006 if ((r0
[1] & 63) > dither
[x
& 7])
3007 *ptr
^= (0x30 & OnPixels
[r0
[1]]);
3009 *ptr
^= (0x30 & OffPixels
[r0
[1]]);
3011 if ((r0
[2] & 63) > dither
[x
& 7])
3012 *ptr
^= (0x0c & OnPixels
[r0
[2]]);
3014 *ptr
^= (0x0c & OffPixels
[r0
[2]]);
3021 dither
= Floyd4x4
[y
& 3];
3023 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3025 if ((r0
[0] & 15) > dither
[x
& 3])
3026 *ptr
^= (0xf0 & OnPixels
[r0
[0]]);
3028 *ptr
^= (0xf0 & OffPixels
[r0
[0]]);
3030 if ((r0
[1] & 15) > dither
[x
& 3])
3031 *ptr
++ ^= (0x0f & OnPixels
[r0
[1]]);
3033 *ptr
++ ^= (0x0f & OffPixels
[r0
[1]]);
3035 if ((r0
[2] & 15) > dither
[x
& 3])
3036 *ptr
^= (0xf0 & OnPixels
[r0
[2]]);
3038 *ptr
^= (0xf0 & OffPixels
[r0
[2]]);
3045 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3050 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3055 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3060 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3068 case CUPS_ORDER_BANDED
:
3070 mptr
= ptr
+ bandwidth
;
3071 yptr
= ptr
+ 2 * bandwidth
;
3073 memset(ptr
+ 3 * bandwidth
, 255, bandwidth
);
3075 switch (header
->cupsBitsPerColor
)
3078 bitmask
= 0x80 >> (bitoffset
& 7);
3079 dither
= Floyd16x16
[y
& 15];
3081 for (x
= xsize
; x
> 0; x
--)
3083 if (*r0
++ > dither
[x
& 15])
3085 if (*r0
++ > dither
[x
& 15])
3087 if (*r0
++ > dither
[x
& 15])
3103 bitmask
= 0xc0 >> (bitoffset
& 7);
3104 dither
= Floyd8x8
[y
& 7];
3106 for (x
= xsize
; x
> 0; x
--)
3108 if ((*r0
& 63) > dither
[x
& 7])
3109 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3111 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3113 if ((*r0
& 63) > dither
[x
& 7])
3114 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3116 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3118 if ((*r0
& 63) > dither
[x
& 7])
3119 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3121 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3137 bitmask
= 0xf0 >> (bitoffset
& 7);
3138 dither
= Floyd4x4
[y
& 3];
3140 for (x
= xsize
; x
> 0; x
--)
3142 if ((*r0
& 15) > dither
[x
& 3])
3143 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3145 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3147 if ((*r0
& 15) > dither
[x
& 3])
3148 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3150 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3152 if ((*r0
& 15) > dither
[x
& 3])
3153 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3155 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3157 if (bitmask
== 0xf0)
3171 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3176 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3181 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3186 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3192 case CUPS_ORDER_PLANAR
:
3195 memset(row
, 255, header
->cupsBytesPerLine
);
3199 switch (header
->cupsBitsPerColor
)
3202 bitmask
= 0x80 >> (bitoffset
& 7);
3203 dither
= Floyd16x16
[y
& 15];
3208 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3210 if (r0
[0] > dither
[x
& 15])
3224 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3226 if (r0
[1] > dither
[x
& 15])
3240 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3242 if (r0
[2] > dither
[x
& 15])
3258 bitmask
= 0xc0 >> (bitoffset
& 7);
3259 dither
= Floyd8x8
[y
& 7];
3262 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3264 if ((*r0
& 63) > dither
[x
& 7])
3265 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3267 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3281 bitmask
= 0xf0 >> (bitoffset
& 7);
3282 dither
= Floyd4x4
[y
& 3];
3285 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3287 if ((*r0
& 15) > dither
[x
& 3])
3288 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3290 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3292 if (bitmask
== 0xf0)
3307 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3312 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
3322 * 'format_W()' - Convert image data to luminance.
3326 format_W(cups_page_header2_t
*header
, /* I - Page header */
3327 unsigned char *row
, /* IO - Bitmap data for device */
3328 int y
, /* I - Current row */
3329 int z
, /* I - Current plane */
3330 int xsize
, /* I - Width of image data */
3331 int ysize
, /* I - Height of image data */
3332 int yerr0
, /* I - Top Y error */
3333 int yerr1
, /* I - Bottom Y error */
3334 cups_ib_t
*r0
, /* I - Primary image data */
3335 cups_ib_t
*r1
) /* I - Image data for interpolation */
3337 cups_ib_t
*ptr
, /* Pointer into row */
3338 bitmask
; /* Current mask for pixel */
3339 int bitoffset
; /* Current offset in line */
3340 int x
, /* Current X coordinate on page */
3341 *dither
; /* Pointer into dither array */
3352 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
3355 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
3359 ptr
= row
+ bitoffset
/ 8;
3361 switch (header
->cupsBitsPerColor
)
3364 bitmask
= 0x80 >> (bitoffset
& 7);
3365 dither
= Floyd16x16
[y
& 15];
3367 for (x
= xsize
; x
> 0; x
--)
3369 if (*r0
++ > dither
[x
& 15])
3383 bitmask
= 0xc0 >> (bitoffset
& 7);
3384 dither
= Floyd8x8
[y
& 7];
3386 for (x
= xsize
; x
> 0; x
--)
3388 if ((*r0
& 63) > dither
[x
& 7])
3389 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
3391 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
3405 bitmask
= 0xf0 >> (bitoffset
& 7);
3406 dither
= Floyd4x4
[y
& 3];
3408 for (x
= xsize
; x
> 0; x
--)
3410 if ((*r0
& 15) > dither
[x
& 3])
3411 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
3413 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
3415 if (bitmask
== 0xf0)
3427 for (x
= xsize
; x
> 0; x
--, r0
++, r1
++)
3432 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
3440 * 'format_YMC()' - Convert image data to YMC.
3444 format_YMC(cups_page_header2_t
*header
, /* I - Page header */
3445 unsigned char *row
, /* IO - Bitmap data for device */
3446 int y
, /* I - Current row */
3447 int z
, /* I - Current plane */
3448 int xsize
, /* I - Width of image data */
3449 int ysize
, /* I - Height of image data */
3450 int yerr0
, /* I - Top Y error */
3451 int yerr1
, /* I - Bottom Y error */
3452 cups_ib_t
*r0
, /* I - Primary image data */
3453 cups_ib_t
*r1
) /* I - Image data for interpolation */
3455 cups_ib_t
*ptr
, /* Pointer into row */
3456 *cptr
, /* Pointer into cyan */
3457 *mptr
, /* Pointer into magenta */
3458 *yptr
, /* Pointer into yellow */
3459 bitmask
; /* Current mask for pixel */
3460 int bitoffset
; /* Current offset in line */
3461 int bandwidth
; /* Width of a color band */
3462 int x
, /* Current X coordinate on page */
3463 *dither
; /* Pointer into dither array */
3472 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
3475 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
3479 ptr
= row
+ bitoffset
/ 8;
3480 bandwidth
= header
->cupsBytesPerLine
/ 3;
3482 switch (header
->cupsColorOrder
)
3484 case CUPS_ORDER_CHUNKED
:
3485 switch (header
->cupsBitsPerColor
)
3488 bitmask
= 64 >> (bitoffset
& 7);
3489 dither
= Floyd16x16
[y
& 15];
3491 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3493 if (r0
[2] > dither
[x
& 15])
3497 if (r0
[1] > dither
[x
& 15])
3501 if (r0
[0] > dither
[x
& 15])
3515 dither
= Floyd8x8
[y
& 7];
3517 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3519 if ((r0
[2] & 63) > dither
[x
& 7])
3520 *ptr
^= (0x30 & OnPixels
[r0
[2]]);
3522 *ptr
^= (0x30 & OffPixels
[r0
[2]]);
3524 if ((r0
[1] & 63) > dither
[x
& 7])
3525 *ptr
^= (0x0c & OnPixels
[r0
[1]]);
3527 *ptr
^= (0x0c & OffPixels
[r0
[1]]);
3529 if ((r0
[0] & 63) > dither
[x
& 7])
3530 *ptr
++ ^= (0x03 & OnPixels
[r0
[0]]);
3532 *ptr
++ ^= (0x03 & OffPixels
[r0
[0]]);
3537 dither
= Floyd4x4
[y
& 3];
3539 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3541 if ((r0
[2] & 15) > dither
[x
& 3])
3542 *ptr
++ ^= (0x0f & OnPixels
[r0
[2]]);
3544 *ptr
++ ^= (0x0f & OffPixels
[r0
[2]]);
3546 if ((r0
[1] & 15) > dither
[x
& 3])
3547 *ptr
^= (0xf0 & OnPixels
[r0
[1]]);
3549 *ptr
^= (0xf0 & OffPixels
[r0
[1]]);
3551 if ((r0
[0] & 15) > dither
[x
& 3])
3552 *ptr
++ ^= (0x0f & OnPixels
[r0
[0]]);
3554 *ptr
++ ^= (0x0f & OffPixels
[r0
[0]]);
3559 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3564 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3569 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3574 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3580 case CUPS_ORDER_BANDED
:
3582 mptr
= ptr
+ bandwidth
;
3583 cptr
= ptr
+ 2 * bandwidth
;
3585 switch (header
->cupsBitsPerColor
)
3588 bitmask
= 0x80 >> (bitoffset
& 7);
3589 dither
= Floyd16x16
[y
& 15];
3591 for (x
= xsize
; x
> 0; x
--)
3593 if (*r0
++ > dither
[x
& 15])
3595 if (*r0
++ > dither
[x
& 15])
3597 if (*r0
++ > dither
[x
& 15])
3613 bitmask
= 0xc0 >> (bitoffset
& 7);
3614 dither
= Floyd8x8
[y
& 7];
3616 for (x
= xsize
; x
> 0; x
--)
3618 if ((*r0
& 63) > dither
[x
& 7])
3619 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3621 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3623 if ((*r0
& 63) > dither
[x
& 7])
3624 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3626 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3628 if ((*r0
& 63) > dither
[x
& 7])
3629 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3631 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3647 bitmask
= 0xf0 >> (bitoffset
& 7);
3648 dither
= Floyd4x4
[y
& 3];
3650 for (x
= xsize
; x
> 0; x
--)
3652 if ((*r0
& 15) > dither
[x
& 3])
3653 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3655 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3657 if ((*r0
& 15) > dither
[x
& 3])
3658 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3660 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3662 if ((*r0
& 15) > dither
[x
& 3])
3663 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3665 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3667 if (bitmask
== 0xf0)
3681 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3686 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3691 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3696 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3702 case CUPS_ORDER_PLANAR
:
3703 switch (header
->cupsBitsPerColor
)
3706 bitmask
= 0x80 >> (bitoffset
& 7);
3707 dither
= Floyd16x16
[y
& 15];
3712 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3714 if (r0
[0] > dither
[x
& 15])
3728 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3730 if (r0
[1] > dither
[x
& 15])
3744 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3746 if (r0
[2] > dither
[x
& 15])
3762 bitmask
= 0xc0 >> (bitoffset
& 7);
3763 dither
= Floyd8x8
[y
& 7];
3767 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3769 if ((*r0
& 63) > dither
[x
& 7])
3770 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3772 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3786 bitmask
= 0xf0 >> (bitoffset
& 7);
3787 dither
= Floyd4x4
[y
& 3];
3791 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3793 if ((*r0
& 15) > dither
[x
& 3])
3794 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3796 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3798 if (bitmask
== 0xf0)
3814 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3819 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
3829 * 'format_YMCK()' - Convert image data to YMCK.
3833 format_YMCK(cups_page_header2_t
*header
,/* I - Page header */
3834 unsigned char *row
, /* IO - Bitmap data for device */
3835 int y
, /* I - Current row */
3836 int z
, /* I - Current plane */
3837 int xsize
, /* I - Width of image data */
3838 int ysize
, /* I - Height of image data */
3839 int yerr0
, /* I - Top Y error */
3840 int yerr1
, /* I - Bottom Y error */
3841 cups_ib_t
*r0
, /* I - Primary image data */
3842 cups_ib_t
*r1
) /* I - Image data for interpolation */
3844 cups_ib_t
*ptr
, /* Pointer into row */
3845 *cptr
, /* Pointer into cyan */
3846 *mptr
, /* Pointer into magenta */
3847 *yptr
, /* Pointer into yellow */
3848 *kptr
, /* Pointer into black */
3849 bitmask
; /* Current mask for pixel */
3850 int bitoffset
; /* Current offset in line */
3851 int bandwidth
; /* Width of a color band */
3852 int x
, /* Current X coordinate on page */
3853 *dither
; /* Pointer into dither array */
3854 int pc
, pm
, py
; /* CMY pixels */
3863 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
3866 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
3870 ptr
= row
+ bitoffset
/ 8;
3871 bandwidth
= header
->cupsBytesPerLine
/ 4;
3873 switch (header
->cupsColorOrder
)
3875 case CUPS_ORDER_CHUNKED
:
3876 switch (header
->cupsBitsPerColor
)
3879 bitmask
= 128 >> (bitoffset
& 7);
3880 dither
= Floyd16x16
[y
& 15];
3882 for (x
= xsize
; x
> 0; x
--)
3884 pc
= *r0
++ > dither
[x
& 15];
3885 pm
= *r0
++ > dither
[x
& 15];
3886 py
= *r0
++ > dither
[x
& 15];
3920 dither
= Floyd8x8
[y
& 7];
3922 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
3924 if ((r0
[2] & 63) > dither
[x
& 7])
3925 *ptr
^= (0xc0 & OnPixels
[r0
[2]]);
3927 *ptr
^= (0xc0 & OffPixels
[r0
[2]]);
3929 if ((r0
[1] & 63) > dither
[x
& 7])
3930 *ptr
^= (0x30 & OnPixels
[r0
[1]]);
3932 *ptr
^= (0x30 & OffPixels
[r0
[1]]);
3934 if ((r0
[0] & 63) > dither
[x
& 7])
3935 *ptr
^= (0x0c & OnPixels
[r0
[0]]);
3937 *ptr
^= (0x0c & OffPixels
[r0
[0]]);
3939 if ((r0
[3] & 63) > dither
[x
& 7])
3940 *ptr
++ ^= (0x03 & OnPixels
[r0
[3]]);
3942 *ptr
++ ^= (0x03 & OffPixels
[r0
[3]]);
3947 dither
= Floyd4x4
[y
& 3];
3949 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
3951 if ((r0
[2] & 15) > dither
[x
& 3])
3952 *ptr
^= (0xf0 & OnPixels
[r0
[2]]);
3954 *ptr
^= (0xf0 & OffPixels
[r0
[2]]);
3956 if ((r0
[1] & 15) > dither
[x
& 3])
3957 *ptr
++ ^= (0x0f & OnPixels
[r0
[1]]);
3959 *ptr
++ ^= (0x0f & OffPixels
[r0
[1]]);
3961 if ((r0
[0] & 15) > dither
[x
& 3])
3962 *ptr
^= (0xf0 & OnPixels
[r0
[0]]);
3964 *ptr
^= (0xf0 & OffPixels
[r0
[0]]);
3966 if ((r0
[3] & 15) > dither
[x
& 3])
3967 *ptr
++ ^= (0x0f & OnPixels
[r0
[3]]);
3969 *ptr
++ ^= (0x0f & OffPixels
[r0
[3]]);
3974 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
3979 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3984 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3989 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3994 *ptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
4000 case CUPS_ORDER_BANDED
:
4002 mptr
= ptr
+ bandwidth
;
4003 cptr
= ptr
+ 2 * bandwidth
;
4004 kptr
= ptr
+ 3 * bandwidth
;
4006 switch (header
->cupsBitsPerColor
)
4009 bitmask
= 0x80 >> (bitoffset
& 7);
4010 dither
= Floyd16x16
[y
& 15];
4012 for (x
= xsize
; x
> 0; x
--)
4014 pc
= *r0
++ > dither
[x
& 15];
4015 pm
= *r0
++ > dither
[x
& 15];
4016 py
= *r0
++ > dither
[x
& 15];
4045 bitmask
= 0xc0 >> (bitoffset
& 7);
4046 dither
= Floyd8x8
[y
& 7];
4048 for (x
= xsize
; x
> 0; x
--)
4050 if ((*r0
& 63) > dither
[x
& 7])
4051 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
4053 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
4055 if ((*r0
& 63) > dither
[x
& 7])
4056 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
4058 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
4060 if ((*r0
& 63) > dither
[x
& 7])
4061 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
4063 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
4065 if ((*r0
& 63) > dither
[x
& 7])
4066 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
4068 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
4085 bitmask
= 0xf0 >> (bitoffset
& 7);
4086 dither
= Floyd4x4
[y
& 3];
4088 for (x
= xsize
; x
> 0; x
--)
4090 if ((*r0
& 15) > dither
[x
& 3])
4091 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
4093 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
4095 if ((*r0
& 15) > dither
[x
& 3])
4096 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
4098 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
4100 if ((*r0
& 15) > dither
[x
& 3])
4101 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
4103 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
4105 if ((*r0
& 15) > dither
[x
& 3])
4106 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
4108 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
4110 if (bitmask
== 0xf0)
4125 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
4130 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
4135 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
4140 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
4145 *kptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
4151 case CUPS_ORDER_PLANAR
:
4152 switch (header
->cupsBitsPerColor
)
4155 bitmask
= 0x80 >> (bitoffset
& 7);
4156 dither
= Floyd16x16
[y
& 15];
4158 for (x
= xsize
; x
> 0; x
--)
4160 pc
= *r0
++ > dither
[x
& 15];
4161 pm
= *r0
++ > dither
[x
& 15];
4162 py
= *r0
++ > dither
[x
& 15];
4164 if ((pc
&& pm
&& py
&& z
== 3) ||
4165 (pc
&& z
== 2) || (pm
&& z
== 1) || (py
&& z
== 0))
4179 bitmask
= 0xc0 >> (bitoffset
& 7);
4180 dither
= Floyd8x8
[y
& 7];
4186 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
4188 if ((*r0
& 63) > dither
[x
& 7])
4189 *ptr
^= (bitmask
& OnPixels
[*r0
]);
4191 *ptr
^= (bitmask
& OffPixels
[*r0
]);
4205 bitmask
= 0xf0 >> (bitoffset
& 7);
4206 dither
= Floyd4x4
[y
& 3];
4212 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
4214 if ((*r0
& 15) > dither
[x
& 3])
4215 *ptr
^= (bitmask
& OnPixels
[*r0
]);
4217 *ptr
^= (bitmask
& OffPixels
[*r0
]);
4219 if (bitmask
== 0xf0)
4242 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
4247 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
4257 * 'make_lut()' - Make a lookup table given gamma and brightness values.
4261 make_lut(cups_ib_t
*lut
, /* I - Lookup table */
4262 int colorspace
, /* I - Colorspace */
4263 float g
, /* I - Image gamma */
4264 float b
) /* I - Image brightness */
4266 int i
; /* Looping var */
4267 int v
; /* Current value */
4273 for (i
= 0; i
< 256; i
++)
4276 v
= 255.0 * b
* (1.0 - pow(1.0 - (float)i
/ 255.0, g
)) + 0.5;
4278 v
= 255.0 * (1.0 - b
* (1.0 - pow((float)i
/ 255.0, g
))) + 0.5;
4291 * 'raster_cb()' - Validate the page header.
4294 static int /* O - 0 if OK, -1 if not */
4296 cups_page_header2_t
*header
, /* IO - Raster header */
4297 int preferred_bits
) /* I - Preferred bits per color */
4300 * Ensure that colorimetric colorspaces use at least 8 bits per
4304 if ((header
->cupsColorSpace
== CUPS_CSPACE_CIEXYZ
||
4305 header
->cupsColorSpace
== CUPS_CSPACE_CIELab
||
4306 header
->cupsColorSpace
>= CUPS_CSPACE_ICC1
) &&
4307 header
->cupsBitsPerColor
< 8)
4308 header
->cupsBitsPerColor
= 8;
4315 * End of "$Id: imagetoraster.c 6649 2007-07-11 21:46:42Z mike $".