2 * "$Id: imagetoraster.c 177 2006-06-21 00:20:03Z jlovell $"
4 * Image file to raster filter for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * main() - Main entry...
29 * blank_line() - Clear a line buffer to the blank value...
30 * format_CMY() - Convert image data to CMY.
31 * format_CMYK() - Convert image data to CMYK.
32 * format_K() - Convert image data to black.
33 * format_KCMY() - Convert image data to KCMY.
34 * format_KCMYcm() - Convert image data to KCMYcm.
35 * format_RGBA() - Convert image data to RGBA/RGBW.
36 * format_W() - Convert image data to luminance.
37 * format_YMC() - Convert image data to YMC.
38 * format_YMCK() - Convert image data to YMCK.
39 * make_lut() - Make a lookup table given gamma and brightness values.
40 * raster_cb() - Validate the page header.
44 * Include necessary headers...
48 #include "image-private.h"
58 int Flip
= 0, /* Flip/mirror pages */
59 XPosition
= 0, /* Horizontal position on page */
60 YPosition
= 0, /* Vertical position on page */
61 Collate
= 0, /* Collate copies? */
62 Copies
= 1; /* Number of copies */
63 int Floyd16x16
[16][16] = /* Traditional Floyd ordered dither */
65 { 0, 128, 32, 160, 8, 136, 40, 168,
66 2, 130, 34, 162, 10, 138, 42, 170 },
67 { 192, 64, 224, 96, 200, 72, 232, 104,
68 194, 66, 226, 98, 202, 74, 234, 106 },
69 { 48, 176, 16, 144, 56, 184, 24, 152,
70 50, 178, 18, 146, 58, 186, 26, 154 },
71 { 240, 112, 208, 80, 248, 120, 216, 88,
72 242, 114, 210, 82, 250, 122, 218, 90 },
73 { 12, 140, 44, 172, 4, 132, 36, 164,
74 14, 142, 46, 174, 6, 134, 38, 166 },
75 { 204, 76, 236, 108, 196, 68, 228, 100,
76 206, 78, 238, 110, 198, 70, 230, 102 },
77 { 60, 188, 28, 156, 52, 180, 20, 148,
78 62, 190, 30, 158, 54, 182, 22, 150 },
79 { 252, 124, 220, 92, 244, 116, 212, 84,
80 254, 126, 222, 94, 246, 118, 214, 86 },
81 { 3, 131, 35, 163, 11, 139, 43, 171,
82 1, 129, 33, 161, 9, 137, 41, 169 },
83 { 195, 67, 227, 99, 203, 75, 235, 107,
84 193, 65, 225, 97, 201, 73, 233, 105 },
85 { 51, 179, 19, 147, 59, 187, 27, 155,
86 49, 177, 17, 145, 57, 185, 25, 153 },
87 { 243, 115, 211, 83, 251, 123, 219, 91,
88 241, 113, 209, 81, 249, 121, 217, 89 },
89 { 15, 143, 47, 175, 7, 135, 39, 167,
90 13, 141, 45, 173, 5, 133, 37, 165 },
91 { 207, 79, 239, 111, 199, 71, 231, 103,
92 205, 77, 237, 109, 197, 69, 229, 101 },
93 { 63, 191, 31, 159, 55, 183, 23, 151,
94 61, 189, 29, 157, 53, 181, 21, 149 },
95 { 254, 127, 223, 95, 247, 119, 215, 87,
96 253, 125, 221, 93, 245, 117, 213, 85 }
100 { 0, 32, 8, 40, 2, 34, 10, 42 },
101 { 48, 16, 56, 24, 50, 18, 58, 26 },
102 { 12, 44, 4, 36, 14, 46, 6, 38 },
103 { 60, 28, 52, 20, 62, 30, 54, 22 },
104 { 3, 35, 11, 43, 1, 33, 9, 41 },
105 { 51, 19, 59, 27, 49, 17, 57, 25 },
106 { 15, 47, 7, 39, 13, 45, 5, 37 },
107 { 63, 31, 55, 23, 61, 29, 53, 21 }
117 cups_ib_t OnPixels
[256], /* On-pixel LUT */
118 OffPixels
[256]; /* Off-pixel LUT */
125 static void blank_line(cups_page_header2_t
*header
, unsigned char *row
);
126 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
);
127 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
);
128 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
);
129 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
);
130 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
);
131 #define format_RGB format_CMY
132 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
);
133 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
);
134 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
);
135 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
);
136 static void make_lut(cups_ib_t
*, int, float, float);
137 static int raster_cb(cups_page_header2_t
*header
, int preferred_bits
);
141 * 'main()' - Main entry...
144 int /* O - Exit status */
145 main(int argc
, /* I - Number of command-line arguments */
146 char *argv
[]) /* I - Command-line arguments */
148 int i
; /* Looping var */
149 cups_image_t
*img
; /* Image to print */
150 float xprint
, /* Printable area */
152 xinches
, /* Total size in inches */
154 float xsize
, /* Total size in points */
158 float aspect
; /* Aspect ratio */
159 int xpages
, /* # x pages */
160 ypages
, /* # y pages */
161 xpage
, /* Current x page */
162 ypage
, /* Current y page */
163 xtemp
, /* Bitmap width in pixels */
164 ytemp
, /* Bitmap height in pixels */
165 page
; /* Current page number */
166 int xc0
, yc0
, /* Corners of the page in image coords */
168 ppd_file_t
*ppd
; /* PPD file */
169 ppd_choice_t
*choice
; /* PPD option choice */
170 char *resolution
, /* Output resolution */
171 *media_type
; /* Media type */
172 ppd_profile_t
*profile
; /* Color profile */
173 ppd_profile_t userprofile
; /* User-specified profile */
174 cups_raster_t
*ras
; /* Raster stream */
175 cups_page_header2_t header
; /* Page header */
176 int num_options
; /* Number of print options */
177 cups_option_t
*options
; /* Print options */
178 const char *val
; /* Option value */
179 int slowcollate
, /* Collate copies the slow way */
180 slowcopies
; /* Make copies the "slow" way? */
181 float g
; /* Gamma correction value */
182 float b
; /* Brightness factor */
183 float zoom
; /* Zoom facter */
184 int xppi
, yppi
; /* Pixels-per-inch */
185 int hue
, sat
; /* Hue and saturation adjustment */
186 cups_izoom_t
*z
; /* Image zoom buffer */
187 cups_iztype_t zoom_type
; /* Image zoom type */
188 int primary
, /* Primary image colorspace */
189 secondary
; /* Secondary image colorspace */
190 cups_ib_t
*row
, /* Current row */
192 *r1
; /* Bottom row */
193 int y
, /* Current Y coordinate on page */
194 iy
, /* Current Y coordinate in image */
195 last_iy
, /* Previous Y coordinate in image */
196 yerr0
, /* Top Y error value */
197 yerr1
; /* Bottom Y error value */
198 cups_ib_t lut
[256]; /* Gamma/brightness LUT */
199 int plane
, /* Current color plane */
200 num_planes
; /* Number of color planes */
201 char filename
[1024]; /* Name of file to print */
205 * Make sure status messages are not buffered...
208 setbuf(stderr
, NULL
);
211 * Check command-line...
214 if (argc
< 6 || argc
> 7)
216 fputs("ERROR: imagetoraster job-id user title copies options [file]\n", stderr
);
220 fprintf(stderr
, "INFO: %s %s %s %s %s %s %s\n", argv
[0], argv
[1], argv
[2],
221 argv
[3], argv
[4], argv
[5], argv
[6] ? argv
[6] : "(null)");
224 * See if we need to use the imagetops and pstoraster filters instead...
228 num_options
= cupsParseOptions(argv
[5], 0, &options
);
230 if (getenv("CLASSIFICATION") ||
231 cupsGetOption("page-label", num_options
, options
))
234 * Yes, fork a copy of pstoraster and then transfer control to imagetops...
237 int mypipes
[2]; /* New pipes for imagetops | pstoraster */
238 int pid
; /* PID of pstoraster */
241 cupsFreeOptions(num_options
, options
);
245 perror("ERROR: Unable to create pipes for imagetops | pstoraster");
249 if ((pid
= fork()) == 0)
252 * Child process for pstoraster... Assign new pipe input to pstoraster...
260 execlp("pstoraster", argv
[0], argv
[1], argv
[2], argv
[3], argv
[4], argv
[5],
262 perror("ERROR: Unable to exec pstoraster");
271 perror("ERROR: Unable to fork pstoraster");
276 * Update stdout so it points at the new pstoraster...
285 * Run imagetops to get the classification or page labelling that was
289 execlp("imagetops", argv
[0], argv
[1], argv
[2], argv
[3], argv
[4], argv
[5],
291 perror("ERROR: Unable to exec imagetops");
296 * Copy stdin as needed...
301 int fd
; /* File to write to */
302 char buffer
[8192]; /* Buffer to read into */
303 int bytes
; /* # of bytes to read */
306 if ((fd
= cupsTempFd(filename
, sizeof(filename
))) < 0)
308 perror("ERROR: Unable to copy image file");
312 fprintf(stderr
, "DEBUG: imagetoraster - copying to temp print file \"%s\"\n",
315 while ((bytes
= fread(buffer
, 1, sizeof(buffer
), stdin
)) > 0)
316 write(fd
, buffer
, bytes
);
321 strlcpy(filename
, argv
[6], sizeof(filename
));
324 * Process command-line options and write the prolog...
335 Copies
= atoi(argv
[4]);
337 ppd
= SetCommonOptions(num_options
, options
, 0);
339 if ((val
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
342 * This IPP attribute is unnecessarily complicated...
344 * single-document, separate-documents-collated-copies, and
345 * single-document-new-sheet all require collated copies.
347 * separate-documents-collated-copies allows for uncollated copies.
350 Collate
= strcasecmp(val
, "separate-documents-collated-copies") != 0;
353 if ((val
= cupsGetOption("Collate", num_options
, options
)) != NULL
&&
354 strcasecmp(val
, "True") == 0)
357 if ((val
= cupsGetOption("gamma", num_options
, options
)) != NULL
)
360 * Get gamma value from 1 to 10000...
363 g
= atoi(val
) * 0.001f
;
371 if ((val
= cupsGetOption("brightness", num_options
, options
)) != NULL
)
374 * Get brightness value from 10 to 1000.
377 b
= atoi(val
) * 0.01f
;
385 if ((val
= cupsGetOption("scaling", num_options
, options
)) != NULL
)
386 zoom
= atoi(val
) * 0.01;
387 else if (cupsGetOption("fitplot", num_options
, options
))
390 if ((val
= cupsGetOption("ppi", num_options
, options
)) != NULL
)
391 if (sscanf(val
, "%dx%d", &xppi
, &yppi
) < 2)
394 if ((val
= cupsGetOption("position", num_options
, options
)) != NULL
)
396 if (strcasecmp(val
, "center") == 0)
401 else if (strcasecmp(val
, "top") == 0)
406 else if (strcasecmp(val
, "left") == 0)
411 else if (strcasecmp(val
, "right") == 0)
416 else if (strcasecmp(val
, "top-left") == 0)
421 else if (strcasecmp(val
, "top-right") == 0)
426 else if (strcasecmp(val
, "bottom") == 0)
431 else if (strcasecmp(val
, "bottom-left") == 0)
436 else if (strcasecmp(val
, "bottom-right") == 0)
443 if ((val
= cupsGetOption("saturation", num_options
, options
)) != NULL
)
446 if ((val
= cupsGetOption("hue", num_options
, options
)) != NULL
)
449 if ((val
= cupsGetOption("mirror", num_options
, options
)) != NULL
&&
450 strcasecmp(val
, "True") == 0)
454 * Set the needed options in the page header...
457 if (cupsRasterInterpretPPD(&header
, ppd
, num_options
, options
, raster_cb
))
459 fputs("ERROR: Bad page setup!\n", stderr
);
464 * Get the media type and resolution that have been chosen...
467 if ((choice
= ppdFindMarkedChoice(ppd
, "MediaType")) != NULL
)
468 media_type
= choice
->choice
;
472 if ((choice
= ppdFindMarkedChoice(ppd
, "Resolution")) != NULL
)
473 resolution
= choice
->choice
;
478 * Choose the appropriate colorspace...
481 switch (header
.cupsColorSpace
)
484 if (header
.cupsBitsPerColor
>= 8)
486 primary
= CUPS_IMAGE_WHITE
;
487 secondary
= CUPS_IMAGE_WHITE
;
491 primary
= CUPS_IMAGE_BLACK
;
492 secondary
= CUPS_IMAGE_BLACK
;
497 case CUPS_CSPACE_RGB
:
498 case CUPS_CSPACE_RGBA
:
499 case CUPS_CSPACE_RGBW
:
500 if (header
.cupsBitsPerColor
>= 8)
502 primary
= CUPS_IMAGE_RGB
;
503 secondary
= CUPS_IMAGE_RGB
;
507 primary
= CUPS_IMAGE_CMY
;
508 secondary
= CUPS_IMAGE_CMY
;
513 case CUPS_CSPACE_WHITE
:
514 case CUPS_CSPACE_GOLD
:
515 case CUPS_CSPACE_SILVER
:
516 primary
= CUPS_IMAGE_BLACK
;
517 secondary
= CUPS_IMAGE_BLACK
;
520 case CUPS_CSPACE_CMYK
:
521 case CUPS_CSPACE_YMCK
:
522 case CUPS_CSPACE_KCMY
:
523 case CUPS_CSPACE_KCMYcm
:
524 case CUPS_CSPACE_GMCK
:
525 case CUPS_CSPACE_GMCS
:
526 if (header
.cupsBitsPerColor
== 1)
528 primary
= CUPS_IMAGE_CMY
;
529 secondary
= CUPS_IMAGE_CMY
;
533 primary
= CUPS_IMAGE_CMYK
;
534 secondary
= CUPS_IMAGE_CMYK
;
538 case CUPS_CSPACE_CMY
:
539 case CUPS_CSPACE_YMC
:
540 primary
= CUPS_IMAGE_CMY
;
541 secondary
= CUPS_IMAGE_CMY
;
547 * Find a color profile matching the current options...
550 if ((val
= cupsGetOption("profile", num_options
, options
)) != NULL
)
552 profile
= &userprofile
;
553 sscanf(val
, "%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",
554 &(userprofile
.density
), &(userprofile
.gamma
),
555 userprofile
.matrix
[0] + 0, userprofile
.matrix
[0] + 1,
556 userprofile
.matrix
[0] + 2,
557 userprofile
.matrix
[1] + 0, userprofile
.matrix
[1] + 1,
558 userprofile
.matrix
[1] + 2,
559 userprofile
.matrix
[2] + 0, userprofile
.matrix
[2] + 1,
560 userprofile
.matrix
[2] + 2);
562 userprofile
.density
*= 0.001f
;
563 userprofile
.gamma
*= 0.001f
;
564 userprofile
.matrix
[0][0] *= 0.001f
;
565 userprofile
.matrix
[0][1] *= 0.001f
;
566 userprofile
.matrix
[0][2] *= 0.001f
;
567 userprofile
.matrix
[1][0] *= 0.001f
;
568 userprofile
.matrix
[1][1] *= 0.001f
;
569 userprofile
.matrix
[1][2] *= 0.001f
;
570 userprofile
.matrix
[2][0] *= 0.001f
;
571 userprofile
.matrix
[2][1] *= 0.001f
;
572 userprofile
.matrix
[2][2] *= 0.001f
;
574 else if (ppd
!= NULL
)
576 fprintf(stderr
, "DEBUG: Searching for profile \"%s/%s\"...\n",
577 resolution
, media_type
);
579 for (i
= 0, profile
= ppd
->profiles
; i
< ppd
->num_profiles
; i
++, profile
++)
581 fprintf(stderr
, "DEBUG: \"%s/%s\" = ", profile
->resolution
,
582 profile
->media_type
);
584 if ((strcmp(profile
->resolution
, resolution
) == 0 ||
585 profile
->resolution
[0] == '-') &&
586 (strcmp(profile
->media_type
, media_type
) == 0 ||
587 profile
->media_type
[0] == '-'))
589 fputs("MATCH!\n", stderr
);
593 fputs("no.\n", stderr
);
597 * If we found a color profile, use it!
600 if (i
>= ppd
->num_profiles
)
607 cupsImageSetProfile(profile
->density
, profile
->gamma
, profile
->matrix
);
609 cupsImageSetRasterColorSpace(header
.cupsColorSpace
);
612 * Create a gamma/brightness LUT...
615 make_lut(lut
, primary
, g
, b
);
618 * Open the input image to print...
621 fputs("INFO: Loading image file...\n", stderr
);
623 if (header
.cupsColorSpace
== CUPS_CSPACE_CIEXYZ
||
624 header
.cupsColorSpace
== CUPS_CSPACE_CIELab
||
625 header
.cupsColorSpace
>= CUPS_CSPACE_ICC1
)
626 img
= cupsImageOpen(filename
, primary
, secondary
, sat
, hue
, NULL
);
628 img
= cupsImageOpen(filename
, primary
, secondary
, sat
, hue
, lut
);
635 fputs("ERROR: Unable to open image file for printing!\n", stderr
);
641 * Scale as necessary...
644 if (zoom
== 0.0 && xppi
== 0)
653 fprintf(stderr
, "DEBUG: Before scaling: xppi=%d, yppi=%d, zoom=%.2f\n",
659 * Scale the image as neccesary to match the desired pixels-per-inch.
664 xprint
= (PageTop
- PageBottom
) / 72.0;
665 yprint
= (PageRight
- PageLeft
) / 72.0;
669 xprint
= (PageRight
- PageLeft
) / 72.0;
670 yprint
= (PageTop
- PageBottom
) / 72.0;
673 fprintf(stderr
, "DEBUG: Before scaling: xprint=%.1f, yprint=%.1f\n",
676 xinches
= (float)img
->xsize
/ (float)xppi
;
677 yinches
= (float)img
->ysize
/ (float)yppi
;
679 fprintf(stderr
, "DEBUG: Image size is %.1f x %.1f inches...\n",
682 if ((val
= cupsGetOption("natural-scaling", num_options
, options
)) != NULL
)
684 xinches
= xinches
* atoi(val
) / 100;
685 yinches
= yinches
* atoi(val
) / 100;
688 if (cupsGetOption("orientation-requested", num_options
, options
) == NULL
&&
689 cupsGetOption("landscape", num_options
, options
) == NULL
)
692 * Rotate the image if it will fit landscape but not portrait...
695 fputs("DEBUG: Auto orientation...\n", stderr
);
697 if ((xinches
> xprint
|| yinches
> yprint
) &&
698 xinches
<= yprint
&& yinches
<= xprint
)
701 * Rotate the image as needed...
704 fputs("DEBUG: Using landscape orientation...\n", stderr
);
706 Orientation
= (Orientation
+ 1) & 3;
716 * Scale percentage of page size...
719 xprint
= (PageRight
- PageLeft
) / 72.0;
720 yprint
= (PageTop
- PageBottom
) / 72.0;
721 aspect
= (float)img
->yppi
/ (float)img
->xppi
;
723 fprintf(stderr
, "DEBUG: Before scaling: xprint=%.1f, yprint=%.1f\n",
726 fprintf(stderr
, "DEBUG: img->xppi = %d, img->yppi = %d, aspect = %f\n",
727 img
->xppi
, img
->yppi
, aspect
);
729 xsize
= xprint
* zoom
;
730 ysize
= xsize
* img
->ysize
/ img
->xsize
/ aspect
;
732 if (ysize
> (yprint
* zoom
))
734 ysize
= yprint
* zoom
;
735 xsize
= ysize
* img
->xsize
* aspect
/ img
->ysize
;
738 xsize2
= yprint
* zoom
;
739 ysize2
= xsize2
* img
->ysize
/ img
->xsize
/ aspect
;
741 if (ysize2
> (xprint
* zoom
))
743 ysize2
= xprint
* zoom
;
744 xsize2
= ysize2
* img
->xsize
* aspect
/ img
->ysize
;
747 fprintf(stderr
, "DEBUG: Portrait size is %.2f x %.2f inches\n", xsize
, ysize
);
748 fprintf(stderr
, "DEBUG: Landscape size is %.2f x %.2f inches\n", xsize2
, ysize2
);
750 if (cupsGetOption("orientation-requested", num_options
, options
) == NULL
&&
751 cupsGetOption("landscape", num_options
, options
) == NULL
)
754 * Choose the rotation with the largest area, but prefer
755 * portrait if they are equal...
758 fputs("DEBUG: Auto orientation...\n", stderr
);
760 if ((xsize
* ysize
) < (xsize2
* xsize2
))
763 * Do landscape orientation...
766 fputs("DEBUG: Using landscape orientation...\n", stderr
);
771 xprint
= (PageTop
- PageBottom
) / 72.0;
772 yprint
= (PageRight
- PageLeft
) / 72.0;
777 * Do portrait orientation...
780 fputs("DEBUG: Using portrait orientation...\n", stderr
);
787 else if (Orientation
& 1)
789 fputs("DEBUG: Using landscape orientation...\n", stderr
);
793 xprint
= (PageTop
- PageBottom
) / 72.0;
794 yprint
= (PageRight
- PageLeft
) / 72.0;
798 fputs("DEBUG: Using portrait orientation...\n", stderr
);
802 xprint
= (PageRight
- PageLeft
) / 72.0;
803 yprint
= (PageTop
- PageBottom
) / 72.0;
808 * Compute the number of pages to print and the size of the image on each
812 xpages
= ceil(xinches
/ xprint
);
813 ypages
= ceil(yinches
/ yprint
);
815 xprint
= xinches
/ xpages
;
816 yprint
= yinches
/ ypages
;
818 fprintf(stderr
, "DEBUG: xpages = %dx%.2fin, ypages = %dx%.2fin\n",
819 xpages
, xprint
, ypages
, yprint
);
822 * Compute the bitmap size...
825 if ((choice
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
&&
826 strcasecmp(choice
->choice
, "Custom") == 0)
828 float width
, /* New width in points */
829 length
; /* New length in points */
833 * Use the correct width and length for the current orientation...
838 width
= yprint
* 72.0;
839 length
= xprint
* 72.0;
843 width
= xprint
* 72.0;
844 length
= yprint
* 72.0;
848 * Add margins to page size...
851 width
+= ppd
->custom_margins
[0] + ppd
->custom_margins
[2];
852 length
+= ppd
->custom_margins
[1] + ppd
->custom_margins
[3];
855 * Enforce minimums...
858 if (width
< ppd
->custom_min
[0])
859 width
= ppd
->custom_min
[0];
861 if (length
< ppd
->custom_min
[1])
862 length
= ppd
->custom_min
[1];
864 fprintf(stderr
, "DEBUG: Updated custom page size to %.2f x %.2f inches...\n",
865 width
/ 72.0, length
/ 72.0);
868 * Set the new custom size...
871 strcpy(header
.cupsPageSizeName
, "Custom");
873 header
.cupsPageSize
[0] = width
+ 0.5;
874 header
.cupsPageSize
[1] = length
+ 0.5;
875 header
.PageSize
[0] = width
+ 0.5;
876 header
.PageSize
[1] = length
+ 0.5;
879 * Update page variables...
884 PageLeft
= ppd
->custom_margins
[0];
885 PageRight
= width
- ppd
->custom_margins
[2];
886 PageBottom
= ppd
->custom_margins
[1];
887 PageTop
= length
- ppd
->custom_margins
[3];
890 * Remove margins from page size...
893 width
-= ppd
->custom_margins
[0] + ppd
->custom_margins
[2];
894 length
-= ppd
->custom_margins
[1] + ppd
->custom_margins
[3];
897 * Set the bitmap size...
900 header
.cupsWidth
= width
* header
.HWResolution
[0] / 72.0;
901 header
.cupsHeight
= length
* header
.HWResolution
[1] / 72.0;
903 header
.cupsBytesPerLine
= (header
.cupsBitsPerPixel
*
904 header
.cupsWidth
+ 7) / 8;
906 if (header
.cupsColorOrder
== CUPS_ORDER_BANDED
)
907 header
.cupsBytesPerLine
*= header
.cupsNumColors
;
910 header
.Margins
[0] = PageLeft
;
911 header
.Margins
[1] = PageBottom
;
913 fprintf(stderr
, "DEBUG: PageSize = [%d %d]\n", header
.PageSize
[0],
922 header
.cupsImagingBBox
[0] = PageLeft
;
923 header
.cupsImagingBBox
[2] = PageLeft
+ xprint
* 72;
926 header
.cupsImagingBBox
[0] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
927 header
.cupsImagingBBox
[2] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
930 header
.cupsImagingBBox
[0] = PageRight
- xprint
* 72;
931 header
.cupsImagingBBox
[2] = PageRight
;
938 header
.cupsImagingBBox
[1] = PageBottom
;
939 header
.cupsImagingBBox
[3] = PageBottom
+ yprint
* 72;
942 header
.cupsImagingBBox
[1] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
943 header
.cupsImagingBBox
[3] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
946 header
.cupsImagingBBox
[1] = PageTop
- yprint
* 72;
947 header
.cupsImagingBBox
[3] = PageTop
;
956 header
.cupsImagingBBox
[0] = PageBottom
;
957 header
.cupsImagingBBox
[2] = PageBottom
+ yprint
* 72;
960 header
.cupsImagingBBox
[0] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
961 header
.cupsImagingBBox
[2] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
964 header
.cupsImagingBBox
[0] = PageTop
- yprint
* 72;
965 header
.cupsImagingBBox
[2] = PageTop
;
972 header
.cupsImagingBBox
[1] = PageLeft
;
973 header
.cupsImagingBBox
[3] = PageLeft
+ xprint
* 72;
976 header
.cupsImagingBBox
[1] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
977 header
.cupsImagingBBox
[3] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
980 header
.cupsImagingBBox
[1] = PageRight
- xprint
* 72;
981 header
.cupsImagingBBox
[3] = PageRight
;
990 header
.cupsImagingBBox
[0] = PageLeft
;
991 header
.cupsImagingBBox
[2] = PageLeft
+ xprint
* 72;
994 header
.cupsImagingBBox
[0] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
995 header
.cupsImagingBBox
[2] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
998 header
.cupsImagingBBox
[0] = PageRight
- xprint
* 72;
999 header
.cupsImagingBBox
[2] = PageRight
;
1006 header
.cupsImagingBBox
[1] = PageBottom
;
1007 header
.cupsImagingBBox
[3] = PageBottom
+ yprint
* 72;
1010 header
.cupsImagingBBox
[1] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
1011 header
.cupsImagingBBox
[3] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
1014 header
.cupsImagingBBox
[1] = PageTop
- yprint
* 72;
1015 header
.cupsImagingBBox
[3] = PageTop
;
1024 header
.cupsImagingBBox
[0] = PageBottom
;
1025 header
.cupsImagingBBox
[2] = PageBottom
+ yprint
* 72;
1028 header
.cupsImagingBBox
[0] = (PageTop
+ PageBottom
- yprint
* 72) / 2;
1029 header
.cupsImagingBBox
[2] = (PageTop
+ PageBottom
+ yprint
* 72) / 2;
1032 header
.cupsImagingBBox
[0] = PageTop
- yprint
* 72;
1033 header
.cupsImagingBBox
[2] = PageTop
;
1040 header
.cupsImagingBBox
[1] = PageLeft
;
1041 header
.cupsImagingBBox
[3] = PageLeft
+ xprint
* 72;
1044 header
.cupsImagingBBox
[1] = (PageRight
+ PageLeft
- xprint
* 72) / 2;
1045 header
.cupsImagingBBox
[3] = (PageRight
+ PageLeft
+ xprint
* 72) / 2;
1048 header
.cupsImagingBBox
[1] = PageRight
- xprint
* 72;
1049 header
.cupsImagingBBox
[3] = PageRight
;
1055 header
.ImagingBoundingBox
[0] = header
.cupsImagingBBox
[0];
1056 header
.ImagingBoundingBox
[1] = header
.cupsImagingBBox
[1];
1057 header
.ImagingBoundingBox
[2] = header
.cupsImagingBBox
[2];
1058 header
.ImagingBoundingBox
[3] = header
.cupsImagingBBox
[3];
1060 if (header
.cupsColorOrder
== CUPS_ORDER_PLANAR
)
1061 num_planes
= header
.cupsNumColors
;
1065 if (header
.cupsBitsPerColor
>= 8)
1066 zoom_type
= CUPS_IZOOM_NORMAL
;
1068 zoom_type
= CUPS_IZOOM_FAST
;
1071 * See if we need to collate, and if so how we need to do it...
1074 if (xpages
== 1 && ypages
== 1)
1077 slowcollate
= Collate
&& ppdFindOption(ppd
, "Collate") == NULL
;
1079 slowcopies
= ppd
->manual_copies
;
1083 if (Copies
> 1 && !slowcollate
&& !slowcopies
)
1085 header
.Collate
= (cups_bool_t
)Collate
;
1086 header
.NumCopies
= Copies
;
1091 header
.NumCopies
= 1;
1094 * Create the dithering lookup tables...
1098 OnPixels
[255] = 0xff;
1099 OffPixels
[0] = 0x00;
1100 OffPixels
[255] = 0xff;
1102 switch (header
.cupsBitsPerColor
)
1105 for (i
= 1; i
< 255; i
++)
1107 OnPixels
[i
] = 0x55 * (i
/ 85 + 1);
1108 OffPixels
[i
] = 0x55 * (i
/ 64);
1112 for (i
= 1; i
< 255; i
++)
1114 OnPixels
[i
] = 17 * (i
/ 17 + 1);
1115 OffPixels
[i
] = 17 * (i
/ 16);
1121 * Output the pages...
1124 fprintf(stderr
, "DEBUG: cupsWidth = %d\n", header
.cupsWidth
);
1125 fprintf(stderr
, "DEBUG: cupsHeight = %d\n", header
.cupsHeight
);
1126 fprintf(stderr
, "DEBUG: cupsBitsPerColor = %d\n", header
.cupsBitsPerColor
);
1127 fprintf(stderr
, "DEBUG: cupsBitsPerPixel = %d\n", header
.cupsBitsPerPixel
);
1128 fprintf(stderr
, "DEBUG: cupsBytesPerLine = %d\n", header
.cupsBytesPerLine
);
1129 fprintf(stderr
, "DEBUG: cupsColorOrder = %d\n", header
.cupsColorOrder
);
1130 fprintf(stderr
, "DEBUG: cupsColorSpace = %d\n", header
.cupsColorSpace
);
1131 fprintf(stderr
, "DEBUG: img->colorspace = %d\n", img
->colorspace
);
1133 row
= malloc(2 * header
.cupsBytesPerLine
);
1134 ras
= cupsRasterOpen(1, CUPS_RASTER_WRITE
);
1136 for (i
= 0, page
= 1; i
< Copies
; i
++)
1137 for (xpage
= 0; xpage
< xpages
; xpage
++)
1138 for (ypage
= 0; ypage
< ypages
; ypage
++, page
++)
1140 fprintf(stderr
, "INFO: Formatting page %d...\n", page
);
1142 if (Orientation
& 1)
1144 xc0
= img
->xsize
* ypage
/ ypages
;
1145 xc1
= img
->xsize
* (ypage
+ 1) / ypages
- 1;
1146 yc0
= img
->ysize
* xpage
/ xpages
;
1147 yc1
= img
->ysize
* (xpage
+ 1) / xpages
- 1;
1149 xtemp
= header
.HWResolution
[0] * yprint
;
1150 ytemp
= header
.HWResolution
[1] * xprint
;
1154 xc0
= img
->xsize
* xpage
/ xpages
;
1155 xc1
= img
->xsize
* (xpage
+ 1) / xpages
- 1;
1156 yc0
= img
->ysize
* ypage
/ ypages
;
1157 yc1
= img
->ysize
* (ypage
+ 1) / ypages
- 1;
1159 xtemp
= header
.HWResolution
[0] * xprint
;
1160 ytemp
= header
.HWResolution
[1] * yprint
;
1163 cupsRasterWriteHeader2(ras
, &header
);
1165 for (plane
= 0; plane
< num_planes
; plane
++)
1168 * Initialize the image "zoom" engine...
1172 z
= _cupsImageZoomNew(img
, xc0
, yc0
, xc1
, yc1
, -xtemp
, ytemp
,
1173 Orientation
& 1, zoom_type
);
1175 z
= _cupsImageZoomNew(img
, xc0
, yc0
, xc1
, yc1
, xtemp
, ytemp
,
1176 Orientation
& 1, zoom_type
);
1179 * Write leading blank space as needed...
1182 if (header
.cupsHeight
> z
->ysize
&& YPosition
<= 0)
1184 blank_line(&header
, row
);
1186 y
= header
.cupsHeight
- z
->ysize
;
1190 fprintf(stderr
, "DEBUG: Writing %d leading blank lines...\n", y
);
1194 if (cupsRasterWritePixels(ras
, row
, header
.cupsBytesPerLine
) <
1195 header
.cupsBytesPerLine
)
1197 fputs("ERROR: Unable to write raster data to driver!\n", stderr
);
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", stderr
);
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", stderr
);
1332 cupsImageClose(img
);
1339 * Free memory used for the "zoom" engine...
1342 _cupsImageZoomDelete(z
);
1351 cupsRasterClose(ras
);
1352 cupsImageClose(img
);
1360 * 'blank_line()' - Clear a line buffer to the blank value...
1364 blank_line(cups_page_header2_t
*header
, /* I - Page header */
1365 unsigned char *row
) /* I - Row buffer */
1367 int count
; /* Remaining bytes */
1370 count
= header
->cupsBytesPerLine
;
1372 switch (header
->cupsColorSpace
)
1374 case CUPS_CSPACE_CIEXYZ
:
1384 case CUPS_CSPACE_CIELab
:
1385 case CUPS_CSPACE_ICC1
:
1386 case CUPS_CSPACE_ICC2
:
1387 case CUPS_CSPACE_ICC3
:
1388 case CUPS_CSPACE_ICC4
:
1389 case CUPS_CSPACE_ICC5
:
1390 case CUPS_CSPACE_ICC6
:
1391 case CUPS_CSPACE_ICC7
:
1392 case CUPS_CSPACE_ICC8
:
1393 case CUPS_CSPACE_ICC9
:
1394 case CUPS_CSPACE_ICCA
:
1395 case CUPS_CSPACE_ICCB
:
1396 case CUPS_CSPACE_ICCC
:
1397 case CUPS_CSPACE_ICCD
:
1398 case CUPS_CSPACE_ICCE
:
1399 case CUPS_CSPACE_ICCF
:
1409 case CUPS_CSPACE_K
:
1410 case CUPS_CSPACE_CMY
:
1411 case CUPS_CSPACE_CMYK
:
1412 case CUPS_CSPACE_YMC
:
1413 case CUPS_CSPACE_YMCK
:
1414 case CUPS_CSPACE_KCMY
:
1415 case CUPS_CSPACE_KCMYcm
:
1416 case CUPS_CSPACE_GMCK
:
1417 case CUPS_CSPACE_GMCS
:
1418 case CUPS_CSPACE_WHITE
:
1419 case CUPS_CSPACE_GOLD
:
1420 case CUPS_CSPACE_SILVER
:
1421 memset(row
, 0, count
);
1425 memset(row
, 255, count
);
1432 * 'format_CMY()' - Convert image data to CMY.
1436 format_CMY(cups_page_header2_t
*header
, /* I - Page header */
1437 unsigned char *row
, /* IO - Bitmap data for device */
1438 int y
, /* I - Current row */
1439 int z
, /* I - Current plane */
1440 int xsize
, /* I - Width of image data */
1441 int ysize
, /* I - Height of image data */
1442 int yerr0
, /* I - Top Y error */
1443 int yerr1
, /* I - Bottom Y error */
1444 cups_ib_t
*r0
, /* I - Primary image data */
1445 cups_ib_t
*r1
) /* I - Image data for interpolation */
1447 cups_ib_t
*ptr
, /* Pointer into row */
1448 *cptr
, /* Pointer into cyan */
1449 *mptr
, /* Pointer into magenta */
1450 *yptr
, /* Pointer into yellow */
1451 bitmask
; /* Current mask for pixel */
1452 int bitoffset
; /* Current offset in line */
1453 int bandwidth
; /* Width of a color band */
1454 int x
, /* Current X coordinate on page */
1455 *dither
; /* Pointer into dither array */
1464 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
1467 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
1471 ptr
= row
+ bitoffset
/ 8;
1472 bandwidth
= header
->cupsBytesPerLine
/ 3;
1474 switch (header
->cupsColorOrder
)
1476 case CUPS_ORDER_CHUNKED
:
1477 switch (header
->cupsBitsPerColor
)
1480 bitmask
= 64 >> (bitoffset
& 7);
1481 dither
= Floyd16x16
[y
& 15];
1483 for (x
= xsize
; x
> 0; x
--)
1485 if (*r0
++ > dither
[x
& 15])
1489 if (*r0
++ > dither
[x
& 15])
1493 if (*r0
++ > dither
[x
& 15])
1507 dither
= Floyd8x8
[y
& 7];
1509 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1511 if ((r0
[0] & 63) > dither
[x
& 7])
1512 *ptr
^= (0x30 & OnPixels
[r0
[0]]);
1514 *ptr
^= (0x30 & OffPixels
[r0
[0]]);
1516 if ((r0
[1] & 63) > dither
[x
& 7])
1517 *ptr
^= (0x0c & OnPixels
[r0
[1]]);
1519 *ptr
^= (0x0c & OffPixels
[r0
[1]]);
1521 if ((r0
[2] & 63) > dither
[x
& 7])
1522 *ptr
++ ^= (0x03 & OnPixels
[r0
[2]]);
1524 *ptr
++ ^= (0x03 & OffPixels
[r0
[2]]);
1529 dither
= Floyd4x4
[y
& 3];
1531 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1533 if ((r0
[0] & 15) > dither
[x
& 3])
1534 *ptr
++ ^= (0x0f & OnPixels
[r0
[0]]);
1536 *ptr
++ ^= (0x0f & OffPixels
[r0
[0]]);
1538 if ((r0
[1] & 15) > dither
[x
& 3])
1539 *ptr
^= (0xf0 & OnPixels
[r0
[1]]);
1541 *ptr
^= (0xf0 & OffPixels
[r0
[1]]);
1543 if ((r0
[2] & 15) > dither
[x
& 3])
1544 *ptr
++ ^= (0x0f & OnPixels
[r0
[2]]);
1546 *ptr
++ ^= (0x0f & OffPixels
[r0
[2]]);
1551 for (x
= xsize
* 3; x
> 0; x
--, r0
++, r1
++)
1555 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
1560 case CUPS_ORDER_BANDED
:
1562 mptr
= ptr
+ bandwidth
;
1563 yptr
= ptr
+ 2 * bandwidth
;
1565 switch (header
->cupsBitsPerColor
)
1568 bitmask
= 0x80 >> (bitoffset
& 7);
1569 dither
= Floyd16x16
[y
& 15];
1571 for (x
= xsize
; x
> 0; x
--)
1573 if (*r0
++ > dither
[x
& 15])
1575 if (*r0
++ > dither
[x
& 15])
1577 if (*r0
++ > dither
[x
& 15])
1593 bitmask
= 0xc0 >> (bitoffset
& 7);
1594 dither
= Floyd8x8
[y
& 7];
1596 for (x
= xsize
; x
> 0; x
--)
1598 if ((*r0
& 63) > dither
[x
& 7])
1599 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
1601 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
1603 if ((*r0
& 63) > dither
[x
& 7])
1604 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
1606 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
1608 if ((*r0
& 63) > dither
[x
& 7])
1609 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
1611 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
1627 bitmask
= 0xf0 >> (bitoffset
& 7);
1628 dither
= Floyd4x4
[y
& 3];
1630 for (x
= xsize
; x
> 0; x
--)
1632 if ((*r0
& 15) > dither
[x
& 3])
1633 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
1635 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
1637 if ((*r0
& 15) > dither
[x
& 3])
1638 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
1640 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
1642 if ((*r0
& 15) > dither
[x
& 3])
1643 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
1645 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
1647 if (bitmask
== 0xf0)
1661 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
1666 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
1671 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
1676 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
1682 case CUPS_ORDER_PLANAR
:
1683 switch (header
->cupsBitsPerColor
)
1686 bitmask
= 0x80 >> (bitoffset
& 7);
1687 dither
= Floyd16x16
[y
& 15];
1692 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1694 if (r0
[0] > dither
[x
& 15])
1708 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1710 if (r0
[1] > dither
[x
& 15])
1724 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1726 if (r0
[2] > dither
[x
& 15])
1742 bitmask
= 0xc0 >> (bitoffset
& 7);
1743 dither
= Floyd8x8
[y
& 7];
1746 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1748 if ((*r0
& 63) > dither
[x
& 7])
1749 *ptr
^= (bitmask
& OnPixels
[*r0
]);
1751 *ptr
^= (bitmask
& OffPixels
[*r0
]);
1765 bitmask
= 0xf0 >> (bitoffset
& 7);
1766 dither
= Floyd4x4
[y
& 3];
1769 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
1771 if ((*r0
& 15) > dither
[x
& 3])
1772 *ptr
^= (bitmask
& OnPixels
[*r0
]);
1774 *ptr
^= (bitmask
& OffPixels
[*r0
]);
1776 if (bitmask
== 0xf0)
1791 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
1796 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
1806 * 'format_CMYK()' - Convert image data to CMYK.
1810 format_CMYK(cups_page_header2_t
*header
,/* I - Page header */
1811 unsigned char *row
, /* IO - Bitmap data for device */
1812 int y
, /* I - Current row */
1813 int z
, /* I - Current plane */
1814 int xsize
, /* I - Width of image data */
1815 int ysize
, /* I - Height of image data */
1816 int yerr0
, /* I - Top Y error */
1817 int yerr1
, /* I - Bottom Y error */
1818 cups_ib_t
*r0
, /* I - Primary image data */
1819 cups_ib_t
*r1
) /* I - Image data for interpolation */
1821 cups_ib_t
*ptr
, /* Pointer into row */
1822 *cptr
, /* Pointer into cyan */
1823 *mptr
, /* Pointer into magenta */
1824 *yptr
, /* Pointer into yellow */
1825 *kptr
, /* Pointer into black */
1826 bitmask
; /* Current mask for pixel */
1827 int bitoffset
; /* Current offset in line */
1828 int bandwidth
; /* Width of a color band */
1829 int x
, /* Current X coordinate on page */
1830 *dither
; /* Pointer into dither array */
1831 int pc
, pm
, py
; /* CMY pixels */
1840 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
1843 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
1847 ptr
= row
+ bitoffset
/ 8;
1848 bandwidth
= header
->cupsBytesPerLine
/ 4;
1850 switch (header
->cupsColorOrder
)
1852 case CUPS_ORDER_CHUNKED
:
1853 switch (header
->cupsBitsPerColor
)
1856 bitmask
= 128 >> (bitoffset
& 7);
1857 dither
= Floyd16x16
[y
& 15];
1859 for (x
= xsize
; x
> 0; x
--)
1861 pc
= *r0
++ > dither
[x
& 15];
1862 pm
= *r0
++ > dither
[x
& 15];
1863 py
= *r0
++ > dither
[x
& 15];
1896 dither
= Floyd8x8
[y
& 7];
1898 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
1900 if ((r0
[0] & 63) > dither
[x
& 7])
1901 *ptr
^= (0xc0 & OnPixels
[r0
[0]]);
1903 *ptr
^= (0xc0 & OffPixels
[r0
[0]]);
1905 if ((r0
[1] & 63) > dither
[x
& 7])
1906 *ptr
^= (0x30 & OnPixels
[r0
[1]]);
1908 *ptr
^= (0x30 & OffPixels
[r0
[1]]);
1910 if ((r0
[2] & 63) > dither
[x
& 7])
1911 *ptr
^= (0x0c & OnPixels
[r0
[2]]);
1913 *ptr
^= (0x0c & OffPixels
[r0
[2]]);
1915 if ((r0
[3] & 63) > dither
[x
& 7])
1916 *ptr
++ ^= (0x03 & OnPixels
[r0
[3]]);
1918 *ptr
++ ^= (0x03 & OffPixels
[r0
[3]]);
1923 dither
= Floyd4x4
[y
& 3];
1925 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
1927 if ((r0
[0] & 15) > dither
[x
& 3])
1928 *ptr
^= (0xf0 & OnPixels
[r0
[0]]);
1930 *ptr
^= (0xf0 & OffPixels
[r0
[0]]);
1932 if ((r0
[1] & 15) > dither
[x
& 3])
1933 *ptr
++ ^= (0x0f & OnPixels
[r0
[1]]);
1935 *ptr
++ ^= (0x0f & OffPixels
[r0
[1]]);
1937 if ((r0
[2] & 15) > dither
[x
& 3])
1938 *ptr
^= (0xf0 & OnPixels
[r0
[2]]);
1940 *ptr
^= (0xf0 & OffPixels
[r0
[2]]);
1942 if ((r0
[3] & 15) > dither
[x
& 3])
1943 *ptr
++ ^= (0x0f & OnPixels
[r0
[3]]);
1945 *ptr
++ ^= (0x0f & OffPixels
[r0
[3]]);
1950 for (x
= xsize
* 4; x
> 0; x
--, r0
++, r1
++)
1954 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
1959 case CUPS_ORDER_BANDED
:
1961 mptr
= ptr
+ bandwidth
;
1962 yptr
= ptr
+ 2 * bandwidth
;
1963 kptr
= ptr
+ 3 * bandwidth
;
1965 switch (header
->cupsBitsPerColor
)
1968 bitmask
= 0x80 >> (bitoffset
& 7);
1969 dither
= Floyd16x16
[y
& 15];
1971 for (x
= xsize
; x
> 0; x
--)
1973 pc
= *r0
++ > dither
[x
& 15];
1974 pm
= *r0
++ > dither
[x
& 15];
1975 py
= *r0
++ > dither
[x
& 15];
2003 bitmask
= 0xc0 >> (bitoffset
& 7);
2004 dither
= Floyd8x8
[y
& 7];
2006 for (x
= xsize
; x
> 0; x
--)
2008 if ((*r0
& 63) > dither
[x
& 7])
2009 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2011 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2013 if ((*r0
& 63) > dither
[x
& 7])
2014 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2016 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2018 if ((*r0
& 63) > dither
[x
& 7])
2019 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2021 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2023 if ((*r0
& 63) > dither
[x
& 7])
2024 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2026 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2043 bitmask
= 0xf0 >> (bitoffset
& 7);
2044 dither
= Floyd4x4
[y
& 3];
2046 for (x
= xsize
; x
> 0; x
--)
2048 if ((*r0
& 15) > dither
[x
& 3])
2049 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2051 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2053 if ((*r0
& 15) > dither
[x
& 3])
2054 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2056 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2058 if ((*r0
& 15) > dither
[x
& 3])
2059 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2061 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2063 if ((*r0
& 15) > dither
[x
& 3])
2064 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2066 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2068 if (bitmask
== 0xf0)
2083 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2088 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
2093 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
2098 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
2103 *kptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
2109 case CUPS_ORDER_PLANAR
:
2110 switch (header
->cupsBitsPerColor
)
2113 bitmask
= 0x80 >> (bitoffset
& 7);
2114 dither
= Floyd16x16
[y
& 15];
2116 for (x
= xsize
; x
> 0; x
--)
2118 pc
= *r0
++ > dither
[x
& 15];
2119 pm
= *r0
++ > dither
[x
& 15];
2120 py
= *r0
++ > dither
[x
& 15];
2122 if ((pc
&& pm
&& py
&& z
== 3) ||
2123 (pc
&& z
== 0) || (pm
&& z
== 1) || (py
&& z
== 2))
2137 bitmask
= 0xc0 >> (bitoffset
& 7);
2138 dither
= Floyd8x8
[y
& 7];
2141 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2143 if ((*r0
& 63) > dither
[x
& 7])
2144 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2146 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2160 bitmask
= 0xf0 >> (bitoffset
& 7);
2161 dither
= Floyd4x4
[y
& 3];
2164 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2166 if ((*r0
& 15) > dither
[x
& 3])
2167 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2169 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2171 if (bitmask
== 0xf0)
2186 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2191 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
2201 * 'format_K()' - Convert image data to black.
2205 format_K(cups_page_header2_t
*header
, /* I - Page header */
2206 unsigned char *row
, /* IO - Bitmap data for device */
2207 int y
, /* I - Current row */
2208 int z
, /* I - Current plane */
2209 int xsize
, /* I - Width of image data */
2210 int ysize
, /* I - Height of image data */
2211 int yerr0
, /* I - Top Y error */
2212 int yerr1
, /* I - Bottom Y error */
2213 cups_ib_t
*r0
, /* I - Primary image data */
2214 cups_ib_t
*r1
) /* I - Image data for interpolation */
2216 cups_ib_t
*ptr
, /* Pointer into row */
2217 bitmask
; /* Current mask for pixel */
2218 int bitoffset
; /* Current offset in line */
2219 int x
, /* Current X coordinate on page */
2220 *dither
; /* Pointer into dither array */
2231 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2234 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2238 ptr
= row
+ bitoffset
/ 8;
2240 switch (header
->cupsBitsPerColor
)
2243 bitmask
= 0x80 >> (bitoffset
& 7);
2244 dither
= Floyd16x16
[y
& 15];
2246 for (x
= xsize
; x
> 0; x
--)
2248 if (*r0
++ > dither
[x
& 15])
2262 bitmask
= 0xc0 >> (bitoffset
& 7);
2263 dither
= Floyd8x8
[y
& 7];
2265 for (x
= xsize
; x
> 0; x
--)
2267 if ((*r0
& 63) > dither
[x
& 7])
2268 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
2270 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
2284 bitmask
= 0xf0 >> (bitoffset
& 7);
2285 dither
= Floyd4x4
[y
& 3];
2287 for (x
= xsize
; x
> 0; x
--)
2289 if ((*r0
& 15) > dither
[x
& 3])
2290 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
2292 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
2294 if (bitmask
== 0xf0)
2306 for (x
= xsize
; x
> 0; x
--, r0
++, r1
++)
2311 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
2319 * 'format_KCMY()' - Convert image data to KCMY.
2323 format_KCMY(cups_page_header2_t
*header
,/* I - Page header */
2324 unsigned char *row
, /* IO - Bitmap data for device */
2325 int y
, /* I - Current row */
2326 int z
, /* I - Current plane */
2327 int xsize
, /* I - Width of image data */
2328 int ysize
, /* I - Height of image data */
2329 int yerr0
, /* I - Top Y error */
2330 int yerr1
, /* I - Bottom Y error */
2331 cups_ib_t
*r0
, /* I - Primary image data */
2332 cups_ib_t
*r1
) /* I - Image data for interpolation */
2334 cups_ib_t
*ptr
, /* Pointer into row */
2335 *cptr
, /* Pointer into cyan */
2336 *mptr
, /* Pointer into magenta */
2337 *yptr
, /* Pointer into yellow */
2338 *kptr
, /* Pointer into black */
2339 bitmask
; /* Current mask for pixel */
2340 int bitoffset
; /* Current offset in line */
2341 int bandwidth
; /* Width of a color band */
2342 int x
, /* Current X coordinate on page */
2343 *dither
; /* Pointer into dither array */
2344 int pc
, pm
, py
; /* CMY pixels */
2353 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2356 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2360 ptr
= row
+ bitoffset
/ 8;
2361 bandwidth
= header
->cupsBytesPerLine
/ 4;
2363 switch (header
->cupsColorOrder
)
2365 case CUPS_ORDER_CHUNKED
:
2366 switch (header
->cupsBitsPerColor
)
2369 bitmask
= 128 >> (bitoffset
& 7);
2370 dither
= Floyd16x16
[y
& 15];
2372 for (x
= xsize
; x
> 0; x
--)
2374 pc
= *r0
++ > dither
[x
& 15];
2375 pm
= *r0
++ > dither
[x
& 15];
2376 py
= *r0
++ > dither
[x
& 15];
2409 dither
= Floyd8x8
[y
& 7];
2411 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2413 if ((r0
[3] & 63) > dither
[x
& 7])
2414 *ptr
^= (0xc0 & OnPixels
[r0
[3]]);
2416 *ptr
^= (0xc0 & OffPixels
[r0
[3]]);
2418 if ((r0
[0] & 63) > dither
[x
& 7])
2419 *ptr
^= (0x30 & OnPixels
[r0
[0]]);
2421 *ptr
^= (0x30 & OffPixels
[r0
[0]]);
2423 if ((r0
[1] & 63) > dither
[x
& 7])
2424 *ptr
^= (0x0c & OnPixels
[r0
[1]]);
2426 *ptr
^= (0x0c & OffPixels
[r0
[1]]);
2428 if ((r0
[2] & 63) > dither
[x
& 7])
2429 *ptr
++ ^= (0x03 & OnPixels
[r0
[2]]);
2431 *ptr
++ ^= (0x03 & OffPixels
[r0
[2]]);
2436 dither
= Floyd4x4
[y
& 3];
2438 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2440 if ((r0
[3] & 15) > dither
[x
& 3])
2441 *ptr
^= (0xf0 & OnPixels
[r0
[3]]);
2443 *ptr
^= (0xf0 & OffPixels
[r0
[3]]);
2445 if ((r0
[0] & 15) > dither
[x
& 3])
2446 *ptr
++ ^= (0x0f & OnPixels
[r0
[0]]);
2448 *ptr
++ ^= (0x0f & OffPixels
[r0
[0]]);
2450 if ((r0
[1] & 15) > dither
[x
& 3])
2451 *ptr
^= (0xf0 & OnPixels
[r0
[1]]);
2453 *ptr
^= (0xf0 & OffPixels
[r0
[1]]);
2455 if ((r0
[2] & 15) > dither
[x
& 3])
2456 *ptr
++ ^= (0x0f & OnPixels
[r0
[2]]);
2458 *ptr
++ ^= (0x0f & OffPixels
[r0
[2]]);
2463 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2468 *ptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
2473 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
2478 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
2483 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
2489 case CUPS_ORDER_BANDED
:
2491 cptr
= ptr
+ bandwidth
;
2492 mptr
= ptr
+ 2 * bandwidth
;
2493 yptr
= ptr
+ 3 * bandwidth
;
2495 switch (header
->cupsBitsPerColor
)
2498 bitmask
= 0x80 >> (bitoffset
& 7);
2499 dither
= Floyd16x16
[y
& 15];
2501 for (x
= xsize
; x
> 0; x
--)
2503 pc
= *r0
++ > dither
[x
& 15];
2504 pm
= *r0
++ > dither
[x
& 15];
2505 py
= *r0
++ > dither
[x
& 15];
2533 bitmask
= 0xc0 >> (bitoffset
& 7);
2534 dither
= Floyd8x8
[y
& 7];
2536 for (x
= xsize
; x
> 0; x
--)
2538 if ((*r0
& 63) > dither
[x
& 7])
2539 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2541 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2543 if ((*r0
& 63) > dither
[x
& 7])
2544 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2546 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2548 if ((*r0
& 63) > dither
[x
& 7])
2549 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2551 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2553 if ((*r0
& 63) > dither
[x
& 7])
2554 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2556 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2573 bitmask
= 0xf0 >> (bitoffset
& 7);
2574 dither
= Floyd4x4
[y
& 3];
2576 for (x
= xsize
; x
> 0; x
--)
2578 if ((*r0
& 15) > dither
[x
& 3])
2579 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
2581 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
2583 if ((*r0
& 15) > dither
[x
& 3])
2584 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
2586 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
2588 if ((*r0
& 15) > dither
[x
& 3])
2589 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
2591 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
2593 if ((*r0
& 15) > dither
[x
& 3])
2594 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
2596 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
2598 if (bitmask
== 0xf0)
2613 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2618 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
2623 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
2628 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
2633 *kptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
2639 case CUPS_ORDER_PLANAR
:
2640 switch (header
->cupsBitsPerColor
)
2643 bitmask
= 0x80 >> (bitoffset
& 7);
2644 dither
= Floyd16x16
[y
& 15];
2646 for (x
= xsize
; x
> 0; x
--)
2648 pc
= *r0
++ > dither
[x
& 15];
2649 pm
= *r0
++ > dither
[x
& 15];
2650 py
= *r0
++ > dither
[x
& 15];
2652 if ((pc
&& pm
&& py
&& z
== 0) ||
2653 (pc
&& z
== 1) || (pm
&& z
== 2) || (py
&& z
== 3))
2667 bitmask
= 0xc0 >> (bitoffset
& 7);
2668 dither
= Floyd8x8
[y
& 7];
2674 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2676 if ((*r0
& 63) > dither
[x
& 7])
2677 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2679 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2693 bitmask
= 0xf0 >> (bitoffset
& 7);
2694 dither
= Floyd4x4
[y
& 3];
2700 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
2702 if ((*r0
& 15) > dither
[x
& 3])
2703 *ptr
^= (bitmask
& OnPixels
[*r0
]);
2705 *ptr
^= (bitmask
& OffPixels
[*r0
]);
2707 if (bitmask
== 0xf0)
2730 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
2735 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
2745 * 'format_KCMYcm()' - Convert image data to KCMYcm.
2750 cups_page_header2_t
*header
, /* I - Page header */
2751 unsigned char *row
, /* IO - Bitmap data for device */
2752 int y
, /* I - Current row */
2753 int z
, /* I - Current plane */
2754 int xsize
, /* I - Width of image data */
2755 int ysize
, /* I - Height of image data */
2756 int yerr0
, /* I - Top Y error */
2757 int yerr1
, /* I - Bottom Y error */
2758 cups_ib_t
*r0
, /* I - Primary image data */
2759 cups_ib_t
*r1
) /* I - Image data for interpolation */
2761 int pc
, pm
, py
, pk
; /* Cyan, magenta, yellow, and black values */
2762 cups_ib_t
*ptr
, /* Pointer into row */
2763 *cptr
, /* Pointer into cyan */
2764 *mptr
, /* Pointer into magenta */
2765 *yptr
, /* Pointer into yellow */
2766 *kptr
, /* Pointer into black */
2767 *lcptr
, /* Pointer into light cyan */
2768 *lmptr
, /* Pointer into light magenta */
2769 bitmask
; /* Current mask for pixel */
2770 int bitoffset
; /* Current offset in line */
2771 int bandwidth
; /* Width of a color band */
2772 int x
, /* Current X coordinate on page */
2773 *dither
; /* Pointer into dither array */
2782 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2785 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2789 ptr
= row
+ bitoffset
/ 8;
2790 bandwidth
= header
->cupsBytesPerLine
/ 6;
2792 switch (header
->cupsColorOrder
)
2794 case CUPS_ORDER_CHUNKED
:
2795 dither
= Floyd16x16
[y
& 15];
2797 for (x
= xsize
; x
> 0; x
--)
2799 pc
= *r0
++ > dither
[x
& 15];
2800 pm
= *r0
++ > dither
[x
& 15];
2801 py
= *r0
++ > dither
[x
& 15];
2802 pk
= pc
&& pm
&& py
;
2805 *ptr
++ ^= 32; /* Black */
2807 *ptr
++ ^= 17; /* Blue (cyan + light magenta) */
2809 *ptr
++ ^= 6; /* Green (light cyan + yellow) */
2811 *ptr
++ ^= 12; /* Red (magenta + yellow) */
2823 case CUPS_ORDER_BANDED
:
2825 cptr
= ptr
+ bandwidth
;
2826 mptr
= ptr
+ 2 * bandwidth
;
2827 yptr
= ptr
+ 3 * bandwidth
;
2828 lcptr
= ptr
+ 4 * bandwidth
;
2829 lmptr
= ptr
+ 5 * bandwidth
;
2831 bitmask
= 0x80 >> (bitoffset
& 7);
2832 dither
= Floyd16x16
[y
& 15];
2834 for (x
= xsize
; x
> 0; x
--)
2836 pc
= *r0
++ > dither
[x
& 15];
2837 pm
= *r0
++ > dither
[x
& 15];
2838 py
= *r0
++ > dither
[x
& 15];
2839 pk
= pc
&& pm
&& py
;
2842 *kptr
^= bitmask
; /* Black */
2845 *cptr
^= bitmask
; /* Blue (cyan + light magenta) */
2850 *lcptr
^= bitmask
; /* Green (light cyan + yellow) */
2855 *mptr
^= bitmask
; /* Red (magenta + yellow) */
2880 case CUPS_ORDER_PLANAR
:
2881 bitmask
= 0x80 >> (bitoffset
& 7);
2882 dither
= Floyd16x16
[y
& 15];
2884 for (x
= xsize
; x
> 0; x
--)
2886 pc
= *r0
++ > dither
[x
& 15];
2887 pm
= *r0
++ > dither
[x
& 15];
2888 py
= *r0
++ > dither
[x
& 15];
2889 pk
= pc
&& pm
&& py
;
2893 else if (pc
&& pm
&& (z
== 1 || z
== 5))
2894 *ptr
^= bitmask
; /* Blue (cyan + light magenta) */
2895 else if (pc
&& py
&& (z
== 3 || z
== 4))
2896 *ptr
^= bitmask
; /* Green (light cyan + yellow) */
2897 else if (pm
&& py
&& (z
== 2 || z
== 3))
2898 *ptr
^= bitmask
; /* Red (magenta + yellow) */
2899 else if (pc
&& z
== 1)
2901 else if (pm
&& z
== 2)
2903 else if (py
&& z
== 3)
2920 * 'format_RGBA()' - Convert image data to RGBA/RGBW.
2924 format_RGBA(cups_page_header2_t
*header
,/* I - Page header */
2925 unsigned char *row
, /* IO - Bitmap data for device */
2926 int y
, /* I - Current row */
2927 int z
, /* I - Current plane */
2928 int xsize
, /* I - Width of image data */
2929 int ysize
, /* I - Height of image data */
2930 int yerr0
, /* I - Top Y error */
2931 int yerr1
, /* I - Bottom Y error */
2932 cups_ib_t
*r0
, /* I - Primary image data */
2933 cups_ib_t
*r1
) /* I - Image data for interpolation */
2935 cups_ib_t
*ptr
, /* Pointer into row */
2936 *cptr
, /* Pointer into cyan */
2937 *mptr
, /* Pointer into magenta */
2938 *yptr
, /* Pointer into yellow */
2939 bitmask
; /* Current mask for pixel */
2940 int bitoffset
; /* Current offset in line */
2941 int bandwidth
; /* Width of a color band */
2942 int x
, /* Current X coordinate on page */
2943 *dither
; /* Pointer into dither array */
2952 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
2955 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
2959 ptr
= row
+ bitoffset
/ 8;
2960 bandwidth
= header
->cupsBytesPerLine
/ 4;
2962 switch (header
->cupsColorOrder
)
2964 case CUPS_ORDER_CHUNKED
:
2965 switch (header
->cupsBitsPerColor
)
2968 bitmask
= 128 >> (bitoffset
& 7);
2969 dither
= Floyd16x16
[y
& 15];
2971 for (x
= xsize
; x
> 0; x
--)
2973 if (*r0
++ > dither
[x
& 15])
2977 if (*r0
++ > dither
[x
& 15])
2981 if (*r0
++ > dither
[x
& 15])
2995 dither
= Floyd8x8
[y
& 7];
2997 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
2999 if ((r0
[0] & 63) > dither
[x
& 7])
3000 *ptr
^= (0xc0 & OnPixels
[r0
[0]]);
3002 *ptr
^= (0xc0 & OffPixels
[r0
[0]]);
3004 if ((r0
[1] & 63) > dither
[x
& 7])
3005 *ptr
^= (0x30 & OnPixels
[r0
[1]]);
3007 *ptr
^= (0x30 & OffPixels
[r0
[1]]);
3009 if ((r0
[2] & 63) > dither
[x
& 7])
3010 *ptr
^= (0x0c & OnPixels
[r0
[2]]);
3012 *ptr
^= (0x0c & OffPixels
[r0
[2]]);
3019 dither
= Floyd4x4
[y
& 3];
3021 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3023 if ((r0
[0] & 15) > dither
[x
& 3])
3024 *ptr
^= (0xf0 & OnPixels
[r0
[0]]);
3026 *ptr
^= (0xf0 & OffPixels
[r0
[0]]);
3028 if ((r0
[1] & 15) > dither
[x
& 3])
3029 *ptr
++ ^= (0x0f & OnPixels
[r0
[1]]);
3031 *ptr
++ ^= (0x0f & OffPixels
[r0
[1]]);
3033 if ((r0
[2] & 15) > dither
[x
& 3])
3034 *ptr
^= (0xf0 & OnPixels
[r0
[2]]);
3036 *ptr
^= (0xf0 & OffPixels
[r0
[2]]);
3043 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3048 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3053 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3058 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3066 case CUPS_ORDER_BANDED
:
3068 mptr
= ptr
+ bandwidth
;
3069 yptr
= ptr
+ 2 * bandwidth
;
3071 memset(ptr
+ 3 * bandwidth
, 255, bandwidth
);
3073 switch (header
->cupsBitsPerColor
)
3076 bitmask
= 0x80 >> (bitoffset
& 7);
3077 dither
= Floyd16x16
[y
& 15];
3079 for (x
= xsize
; x
> 0; x
--)
3081 if (*r0
++ > dither
[x
& 15])
3083 if (*r0
++ > dither
[x
& 15])
3085 if (*r0
++ > dither
[x
& 15])
3101 bitmask
= 0xc0 >> (bitoffset
& 7);
3102 dither
= Floyd8x8
[y
& 7];
3104 for (x
= xsize
; x
> 0; x
--)
3106 if ((*r0
& 63) > dither
[x
& 7])
3107 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3109 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3111 if ((*r0
& 63) > dither
[x
& 7])
3112 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3114 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3116 if ((*r0
& 63) > dither
[x
& 7])
3117 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3119 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3135 bitmask
= 0xf0 >> (bitoffset
& 7);
3136 dither
= Floyd4x4
[y
& 3];
3138 for (x
= xsize
; x
> 0; x
--)
3140 if ((*r0
& 15) > dither
[x
& 3])
3141 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3143 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3145 if ((*r0
& 15) > dither
[x
& 3])
3146 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3148 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3150 if ((*r0
& 15) > dither
[x
& 3])
3151 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3153 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3155 if (bitmask
== 0xf0)
3169 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3174 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3179 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3184 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3190 case CUPS_ORDER_PLANAR
:
3193 memset(row
, 255, header
->cupsBytesPerLine
);
3197 switch (header
->cupsBitsPerColor
)
3200 bitmask
= 0x80 >> (bitoffset
& 7);
3201 dither
= Floyd16x16
[y
& 15];
3206 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3208 if (r0
[0] > dither
[x
& 15])
3222 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3224 if (r0
[1] > dither
[x
& 15])
3238 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3240 if (r0
[2] > dither
[x
& 15])
3256 bitmask
= 0xc0 >> (bitoffset
& 7);
3257 dither
= Floyd8x8
[y
& 7];
3260 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3262 if ((*r0
& 63) > dither
[x
& 7])
3263 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3265 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3279 bitmask
= 0xf0 >> (bitoffset
& 7);
3280 dither
= Floyd4x4
[y
& 3];
3283 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3285 if ((*r0
& 15) > dither
[x
& 3])
3286 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3288 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3290 if (bitmask
== 0xf0)
3305 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3310 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
3320 * 'format_W()' - Convert image data to luminance.
3324 format_W(cups_page_header2_t
*header
, /* I - Page header */
3325 unsigned char *row
, /* IO - Bitmap data for device */
3326 int y
, /* I - Current row */
3327 int z
, /* I - Current plane */
3328 int xsize
, /* I - Width of image data */
3329 int ysize
, /* I - Height of image data */
3330 int yerr0
, /* I - Top Y error */
3331 int yerr1
, /* I - Bottom Y error */
3332 cups_ib_t
*r0
, /* I - Primary image data */
3333 cups_ib_t
*r1
) /* I - Image data for interpolation */
3335 cups_ib_t
*ptr
, /* Pointer into row */
3336 bitmask
; /* Current mask for pixel */
3337 int bitoffset
; /* Current offset in line */
3338 int x
, /* Current X coordinate on page */
3339 *dither
; /* Pointer into dither array */
3350 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
3353 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
3357 ptr
= row
+ bitoffset
/ 8;
3359 switch (header
->cupsBitsPerColor
)
3362 bitmask
= 0x80 >> (bitoffset
& 7);
3363 dither
= Floyd16x16
[y
& 15];
3365 for (x
= xsize
; x
> 0; x
--)
3367 if (*r0
++ > dither
[x
& 15])
3381 bitmask
= 0xc0 >> (bitoffset
& 7);
3382 dither
= Floyd8x8
[y
& 7];
3384 for (x
= xsize
; x
> 0; x
--)
3386 if ((*r0
& 63) > dither
[x
& 7])
3387 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
3389 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
3403 bitmask
= 0xf0 >> (bitoffset
& 7);
3404 dither
= Floyd4x4
[y
& 3];
3406 for (x
= xsize
; x
> 0; x
--)
3408 if ((*r0
& 15) > dither
[x
& 3])
3409 *ptr
^= (bitmask
& OnPixels
[*r0
++]);
3411 *ptr
^= (bitmask
& OffPixels
[*r0
++]);
3413 if (bitmask
== 0xf0)
3425 for (x
= xsize
; x
> 0; x
--, r0
++, r1
++)
3430 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
3438 * 'format_YMC()' - Convert image data to YMC.
3442 format_YMC(cups_page_header2_t
*header
, /* I - Page header */
3443 unsigned char *row
, /* IO - Bitmap data for device */
3444 int y
, /* I - Current row */
3445 int z
, /* I - Current plane */
3446 int xsize
, /* I - Width of image data */
3447 int ysize
, /* I - Height of image data */
3448 int yerr0
, /* I - Top Y error */
3449 int yerr1
, /* I - Bottom Y error */
3450 cups_ib_t
*r0
, /* I - Primary image data */
3451 cups_ib_t
*r1
) /* I - Image data for interpolation */
3453 cups_ib_t
*ptr
, /* Pointer into row */
3454 *cptr
, /* Pointer into cyan */
3455 *mptr
, /* Pointer into magenta */
3456 *yptr
, /* Pointer into yellow */
3457 bitmask
; /* Current mask for pixel */
3458 int bitoffset
; /* Current offset in line */
3459 int bandwidth
; /* Width of a color band */
3460 int x
, /* Current X coordinate on page */
3461 *dither
; /* Pointer into dither array */
3470 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
3473 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
3477 ptr
= row
+ bitoffset
/ 8;
3478 bandwidth
= header
->cupsBytesPerLine
/ 3;
3480 switch (header
->cupsColorOrder
)
3482 case CUPS_ORDER_CHUNKED
:
3483 switch (header
->cupsBitsPerColor
)
3486 bitmask
= 64 >> (bitoffset
& 7);
3487 dither
= Floyd16x16
[y
& 15];
3489 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3491 if (r0
[2] > dither
[x
& 15])
3495 if (r0
[1] > dither
[x
& 15])
3499 if (r0
[0] > dither
[x
& 15])
3513 dither
= Floyd8x8
[y
& 7];
3515 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3517 if ((r0
[2] & 63) > dither
[x
& 7])
3518 *ptr
^= (0x30 & OnPixels
[r0
[2]]);
3520 *ptr
^= (0x30 & OffPixels
[r0
[2]]);
3522 if ((r0
[1] & 63) > dither
[x
& 7])
3523 *ptr
^= (0x0c & OnPixels
[r0
[1]]);
3525 *ptr
^= (0x0c & OffPixels
[r0
[1]]);
3527 if ((r0
[0] & 63) > dither
[x
& 7])
3528 *ptr
++ ^= (0x03 & OnPixels
[r0
[0]]);
3530 *ptr
++ ^= (0x03 & OffPixels
[r0
[0]]);
3535 dither
= Floyd4x4
[y
& 3];
3537 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3539 if ((r0
[2] & 15) > dither
[x
& 3])
3540 *ptr
++ ^= (0x0f & OnPixels
[r0
[2]]);
3542 *ptr
++ ^= (0x0f & OffPixels
[r0
[2]]);
3544 if ((r0
[1] & 15) > dither
[x
& 3])
3545 *ptr
^= (0xf0 & OnPixels
[r0
[1]]);
3547 *ptr
^= (0xf0 & OffPixels
[r0
[1]]);
3549 if ((r0
[0] & 15) > dither
[x
& 3])
3550 *ptr
++ ^= (0x0f & OnPixels
[r0
[0]]);
3552 *ptr
++ ^= (0x0f & OffPixels
[r0
[0]]);
3557 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3562 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3567 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3572 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3578 case CUPS_ORDER_BANDED
:
3580 mptr
= ptr
+ bandwidth
;
3581 cptr
= ptr
+ 2 * bandwidth
;
3583 switch (header
->cupsBitsPerColor
)
3586 bitmask
= 0x80 >> (bitoffset
& 7);
3587 dither
= Floyd16x16
[y
& 15];
3589 for (x
= xsize
; x
> 0; x
--)
3591 if (*r0
++ > dither
[x
& 15])
3593 if (*r0
++ > dither
[x
& 15])
3595 if (*r0
++ > dither
[x
& 15])
3611 bitmask
= 0xc0 >> (bitoffset
& 7);
3612 dither
= Floyd8x8
[y
& 7];
3614 for (x
= xsize
; x
> 0; x
--)
3616 if ((*r0
& 63) > dither
[x
& 7])
3617 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3619 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3621 if ((*r0
& 63) > dither
[x
& 7])
3622 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3624 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3626 if ((*r0
& 63) > dither
[x
& 7])
3627 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3629 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3645 bitmask
= 0xf0 >> (bitoffset
& 7);
3646 dither
= Floyd4x4
[y
& 3];
3648 for (x
= xsize
; x
> 0; x
--)
3650 if ((*r0
& 15) > dither
[x
& 3])
3651 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
3653 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
3655 if ((*r0
& 15) > dither
[x
& 3])
3656 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
3658 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
3660 if ((*r0
& 15) > dither
[x
& 3])
3661 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
3663 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
3665 if (bitmask
== 0xf0)
3679 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3684 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3689 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3694 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3700 case CUPS_ORDER_PLANAR
:
3701 switch (header
->cupsBitsPerColor
)
3704 bitmask
= 0x80 >> (bitoffset
& 7);
3705 dither
= Floyd16x16
[y
& 15];
3710 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3712 if (r0
[0] > dither
[x
& 15])
3726 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3728 if (r0
[1] > dither
[x
& 15])
3742 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3744 if (r0
[2] > dither
[x
& 15])
3760 bitmask
= 0xc0 >> (bitoffset
& 7);
3761 dither
= Floyd8x8
[y
& 7];
3765 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3767 if ((*r0
& 63) > dither
[x
& 7])
3768 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3770 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3784 bitmask
= 0xf0 >> (bitoffset
& 7);
3785 dither
= Floyd4x4
[y
& 3];
3789 for (x
= xsize
; x
> 0; x
--, r0
+= 3)
3791 if ((*r0
& 15) > dither
[x
& 3])
3792 *ptr
^= (bitmask
& OnPixels
[*r0
]);
3794 *ptr
^= (bitmask
& OffPixels
[*r0
]);
3796 if (bitmask
== 0xf0)
3812 for (x
= xsize
; x
> 0; x
--, r0
+= 3, r1
+= 3)
3817 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
3827 * 'format_YMCK()' - Convert image data to YMCK.
3831 format_YMCK(cups_page_header2_t
*header
,/* I - Page header */
3832 unsigned char *row
, /* IO - Bitmap data for device */
3833 int y
, /* I - Current row */
3834 int z
, /* I - Current plane */
3835 int xsize
, /* I - Width of image data */
3836 int ysize
, /* I - Height of image data */
3837 int yerr0
, /* I - Top Y error */
3838 int yerr1
, /* I - Bottom Y error */
3839 cups_ib_t
*r0
, /* I - Primary image data */
3840 cups_ib_t
*r1
) /* I - Image data for interpolation */
3842 cups_ib_t
*ptr
, /* Pointer into row */
3843 *cptr
, /* Pointer into cyan */
3844 *mptr
, /* Pointer into magenta */
3845 *yptr
, /* Pointer into yellow */
3846 *kptr
, /* Pointer into black */
3847 bitmask
; /* Current mask for pixel */
3848 int bitoffset
; /* Current offset in line */
3849 int bandwidth
; /* Width of a color band */
3850 int x
, /* Current X coordinate on page */
3851 *dither
; /* Pointer into dither array */
3852 int pc
, pm
, py
; /* CMY pixels */
3861 bitoffset
= header
->cupsBitsPerPixel
* ((header
->cupsWidth
- xsize
) / 2);
3864 bitoffset
= header
->cupsBitsPerPixel
* (header
->cupsWidth
- xsize
);
3868 ptr
= row
+ bitoffset
/ 8;
3869 bandwidth
= header
->cupsBytesPerLine
/ 4;
3871 switch (header
->cupsColorOrder
)
3873 case CUPS_ORDER_CHUNKED
:
3874 switch (header
->cupsBitsPerColor
)
3877 bitmask
= 128 >> (bitoffset
& 7);
3878 dither
= Floyd16x16
[y
& 15];
3880 for (x
= xsize
; x
> 0; x
--)
3882 pc
= *r0
++ > dither
[x
& 15];
3883 pm
= *r0
++ > dither
[x
& 15];
3884 py
= *r0
++ > dither
[x
& 15];
3918 dither
= Floyd8x8
[y
& 7];
3920 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
3922 if ((r0
[2] & 63) > dither
[x
& 7])
3923 *ptr
^= (0xc0 & OnPixels
[r0
[2]]);
3925 *ptr
^= (0xc0 & OffPixels
[r0
[2]]);
3927 if ((r0
[1] & 63) > dither
[x
& 7])
3928 *ptr
^= (0x30 & OnPixels
[r0
[1]]);
3930 *ptr
^= (0x30 & OffPixels
[r0
[1]]);
3932 if ((r0
[0] & 63) > dither
[x
& 7])
3933 *ptr
^= (0x0c & OnPixels
[r0
[0]]);
3935 *ptr
^= (0x0c & OffPixels
[r0
[0]]);
3937 if ((r0
[3] & 63) > dither
[x
& 7])
3938 *ptr
++ ^= (0x03 & OnPixels
[r0
[3]]);
3940 *ptr
++ ^= (0x03 & OffPixels
[r0
[3]]);
3945 dither
= Floyd4x4
[y
& 3];
3947 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
3949 if ((r0
[2] & 15) > dither
[x
& 3])
3950 *ptr
^= (0xf0 & OnPixels
[r0
[2]]);
3952 *ptr
^= (0xf0 & OffPixels
[r0
[2]]);
3954 if ((r0
[1] & 15) > dither
[x
& 3])
3955 *ptr
++ ^= (0x0f & OnPixels
[r0
[1]]);
3957 *ptr
++ ^= (0x0f & OffPixels
[r0
[1]]);
3959 if ((r0
[0] & 15) > dither
[x
& 3])
3960 *ptr
^= (0xf0 & OnPixels
[r0
[0]]);
3962 *ptr
^= (0xf0 & OffPixels
[r0
[0]]);
3964 if ((r0
[3] & 15) > dither
[x
& 3])
3965 *ptr
++ ^= (0x0f & OnPixels
[r0
[3]]);
3967 *ptr
++ ^= (0x0f & OffPixels
[r0
[3]]);
3972 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
3977 *ptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
3982 *ptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
3987 *ptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
3992 *ptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
3998 case CUPS_ORDER_BANDED
:
4000 mptr
= ptr
+ bandwidth
;
4001 cptr
= ptr
+ 2 * bandwidth
;
4002 kptr
= ptr
+ 3 * bandwidth
;
4004 switch (header
->cupsBitsPerColor
)
4007 bitmask
= 0x80 >> (bitoffset
& 7);
4008 dither
= Floyd16x16
[y
& 15];
4010 for (x
= xsize
; x
> 0; x
--)
4012 pc
= *r0
++ > dither
[x
& 15];
4013 pm
= *r0
++ > dither
[x
& 15];
4014 py
= *r0
++ > dither
[x
& 15];
4043 bitmask
= 0xc0 >> (bitoffset
& 7);
4044 dither
= Floyd8x8
[y
& 7];
4046 for (x
= xsize
; x
> 0; x
--)
4048 if ((*r0
& 63) > dither
[x
& 7])
4049 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
4051 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
4053 if ((*r0
& 63) > dither
[x
& 7])
4054 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
4056 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
4058 if ((*r0
& 63) > dither
[x
& 7])
4059 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
4061 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
4063 if ((*r0
& 63) > dither
[x
& 7])
4064 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
4066 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
4083 bitmask
= 0xf0 >> (bitoffset
& 7);
4084 dither
= Floyd4x4
[y
& 3];
4086 for (x
= xsize
; x
> 0; x
--)
4088 if ((*r0
& 15) > dither
[x
& 3])
4089 *cptr
^= (bitmask
& OnPixels
[*r0
++]);
4091 *cptr
^= (bitmask
& OffPixels
[*r0
++]);
4093 if ((*r0
& 15) > dither
[x
& 3])
4094 *mptr
^= (bitmask
& OnPixels
[*r0
++]);
4096 *mptr
^= (bitmask
& OffPixels
[*r0
++]);
4098 if ((*r0
& 15) > dither
[x
& 3])
4099 *yptr
^= (bitmask
& OnPixels
[*r0
++]);
4101 *yptr
^= (bitmask
& OffPixels
[*r0
++]);
4103 if ((*r0
& 15) > dither
[x
& 3])
4104 *kptr
^= (bitmask
& OnPixels
[*r0
++]);
4106 *kptr
^= (bitmask
& OffPixels
[*r0
++]);
4108 if (bitmask
== 0xf0)
4123 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
4128 *cptr
++ = (r0
[0] * yerr0
+ r1
[0] * yerr1
) / ysize
;
4133 *mptr
++ = (r0
[1] * yerr0
+ r1
[1] * yerr1
) / ysize
;
4138 *yptr
++ = (r0
[2] * yerr0
+ r1
[2] * yerr1
) / ysize
;
4143 *kptr
++ = (r0
[3] * yerr0
+ r1
[3] * yerr1
) / ysize
;
4149 case CUPS_ORDER_PLANAR
:
4150 switch (header
->cupsBitsPerColor
)
4153 bitmask
= 0x80 >> (bitoffset
& 7);
4154 dither
= Floyd16x16
[y
& 15];
4156 for (x
= xsize
; x
> 0; x
--)
4158 pc
= *r0
++ > dither
[x
& 15];
4159 pm
= *r0
++ > dither
[x
& 15];
4160 py
= *r0
++ > dither
[x
& 15];
4162 if ((pc
&& pm
&& py
&& z
== 3) ||
4163 (pc
&& z
== 2) || (pm
&& z
== 1) || (py
&& z
== 0))
4177 bitmask
= 0xc0 >> (bitoffset
& 7);
4178 dither
= Floyd8x8
[y
& 7];
4184 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
4186 if ((*r0
& 63) > dither
[x
& 7])
4187 *ptr
^= (bitmask
& OnPixels
[*r0
]);
4189 *ptr
^= (bitmask
& OffPixels
[*r0
]);
4203 bitmask
= 0xf0 >> (bitoffset
& 7);
4204 dither
= Floyd4x4
[y
& 3];
4210 for (x
= xsize
; x
> 0; x
--, r0
+= 4)
4212 if ((*r0
& 15) > dither
[x
& 3])
4213 *ptr
^= (bitmask
& OnPixels
[*r0
]);
4215 *ptr
^= (bitmask
& OffPixels
[*r0
]);
4217 if (bitmask
== 0xf0)
4240 for (x
= xsize
; x
> 0; x
--, r0
+= 4, r1
+= 4)
4245 *ptr
++ = (*r0
* yerr0
+ *r1
* yerr1
) / ysize
;
4255 * 'make_lut()' - Make a lookup table given gamma and brightness values.
4259 make_lut(cups_ib_t
*lut
, /* I - Lookup table */
4260 int colorspace
, /* I - Colorspace */
4261 float g
, /* I - Image gamma */
4262 float b
) /* I - Image brightness */
4264 int i
; /* Looping var */
4265 int v
; /* Current value */
4271 for (i
= 0; i
< 256; i
++)
4274 v
= 255.0 * b
* (1.0 - pow(1.0 - (float)i
/ 255.0, g
)) + 0.5;
4276 v
= 255.0 * (1.0 - b
* (1.0 - pow((float)i
/ 255.0, g
))) + 0.5;
4289 * 'raster_cb()' - Validate the page header.
4292 static int /* O - 0 if OK, -1 if not */
4294 cups_page_header2_t
*header
, /* IO - Raster header */
4295 int preferred_bits
) /* I - Preferred bits per color */
4298 * Ensure that colorimetric colorspaces use at least 8 bits per
4302 if ((header
->cupsColorSpace
== CUPS_CSPACE_CIEXYZ
||
4303 header
->cupsColorSpace
== CUPS_CSPACE_CIELab
||
4304 header
->cupsColorSpace
>= CUPS_CSPACE_ICC1
) &&
4305 header
->cupsBitsPerColor
< 8)
4306 header
->cupsBitsPerColor
= 8;
4313 * End of "$Id: imagetoraster.c 177 2006-06-21 00:20:03Z jlovell $".