]>
git.ipfire.org Git - thirdparty/cups.git/blob - driver/testdither.c
4 * Dither test program for ESP Print Pro.
8 * testdither 0 255 > filename.ppm
9 * testdither 0 127 255 > filename.ppm
10 * testdither 0 85 170 255 > filename.ppm
11 * testdither 0 63 127 170 198 227 255 > filename.ppm
12 * testdither 0 210 383 > filename.ppm
13 * testdither 0 82 255 > filename.ppm
15 * Copyright 2007 by Apple Inc.
16 * Copyright 1993-2005 by Easy Software Products.
18 * These coded instructions, statements, and computer programs are the
19 * property of Apple Inc. and are protected by Federal copyright
20 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
21 * which should have been included with this file. If this file is
22 * file is missing or damaged, see the license at "http://www.cups.org/".
26 * main() - Test dithering and output a PPM file.
27 * usage() - Show program usage...
31 * Include necessary headers.
35 #include <cups/string.h>
46 * 'main()' - Test dithering and output a PPM file.
49 int /* O - Exit status */
50 main(int argc
, /* I - Number of command-line arguments */
51 char *argv
[]) /* I - Command-line arguments */
53 int x
, y
; /* Current coordinate in image */
54 short line
[512]; /* Line to dither */
55 unsigned char pixels
[512], /* Dither pixels */
56 *pixptr
; /* Pointer in line */
57 int output
; /* Output pixel */
58 cups_lut_t
*lut
; /* Dither lookup table */
59 cups_dither_t
*dither
; /* Dither state */
60 int nlutvals
; /* Number of lookup values */
61 float lutvals
[16]; /* Lookup values */
62 int pixvals
[16]; /* Pixel values */
66 * See if we have lookup table values on the command-line...
72 * Yes, collect them...
77 for (x
= 1; x
< argc
; x
++)
78 if (isdigit(argv
[x
][0]) && nlutvals
< 16)
80 pixvals
[nlutvals
] = atoi(argv
[x
]);
81 lutvals
[nlutvals
] = atof(argv
[x
]) / 255.0;
88 * See if we have at least 2 values...
97 * Otherwise use the default 2-entry LUT with values of 0 and 255...
108 * Create the lookup table and dither state...
111 lut
= cupsLutNew(nlutvals
, lutvals
);
112 dither
= cupsDitherNew(512);
115 * Put out the PGM header for a raw 256x256x8-bit grayscale file...
118 puts("P5\n512\n512\n255");
121 * Dither 512 lines, which are written out in 256 image lines...
124 for (y
= 0; y
< 512; y
++)
127 * Create the grayscale data for the current line...
130 for (x
= 0; x
< 512; x
++)
131 line
[x
] = 4095 * ((y
/ 32) * 16 + x
/ 32) / 255;
137 cupsDitherLine(dither
, lut
, line
, 1, pixels
);
141 fputs("DEBUG: pixels =", stderr
);
142 for (x
= 0; x
< 512; x
++)
143 fprintf(stderr
, " %d", pixels
[x
]);
148 * Add or set the output pixel values...
151 for (x
= 0, pixptr
= pixels
; x
< 512; x
++, pixptr
++)
153 output
= 255 - pixvals
[*pixptr
];
163 * Free the dither state and lookup table...
166 cupsDitherDelete(dither
);
170 * Return with no errors...
178 * 'usage()' - Show program usage...
184 puts("Usage: testdither [val1 val2 [... val16]] >filename.ppm");