4 * Test the CMYK color separation code for CUPS.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1993-2006 by Easy Software Products, All Rights Reserved.
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/".
17 * test_gray() - Test grayscale separations...
18 * test_rgb() - Test color separations...
19 * main() - Do color separation tests.
23 * Include necessary headers.
33 void test_gray(int num_comps, const char *basename);
34 void test_rgb(int num_comps, const char *basename);
38 * 'main()' - Do color separation tests.
41 int /* O - Exit status */
42 main(int argc, /* I - Number of command-line arguments */
43 char *argv[]) /* I - Command-line arguments */
46 * Make the test directory...
52 * Run tests for K, Kk, CMY, CMYK, CcMmYK, and CcMmYKk separations...
55 test_rgb(1, "test/K-rgb");
56 test_rgb(2, "test/Kk-rgb");
57 test_rgb(3, "test/CMY-rgb");
58 test_rgb(4, "test/CMYK-rgb");
59 test_rgb(6, "test/CcMmYK-rgb");
60 test_rgb(7, "test/CcMmYKk-rgb");
62 test_gray(1, "test/K-gray");
63 test_gray(2, "test/Kk-gray");
64 test_gray(3, "test/CMY-gray");
65 test_gray(4, "test/CMYK-gray");
66 test_gray(6, "test/CcMmYK-gray");
67 test_gray(7, "test/CcMmYKk-gray");
70 * Return with no errors...
78 * 'test_gray()' - Test grayscale separations...
82 test_gray(int num_comps, /* I - Number of components */
83 const char *basename) /* I - Base filename of output */
85 int i; /* Looping var */
86 char filename[255]; /* Output filename */
87 char line[255]; /* Line from PGM file */
88 int width, height; /* Width and height of test image */
89 int x, y; /* Current coordinate in image */
90 int r, g, b; /* Current RGB color */
91 unsigned char input[7000]; /* Line to separate */
92 short output[48000], /* Output separation data */
93 *outptr; /* Pointer in output */
94 FILE *in; /* Input PPM file */
95 FILE *out[CUPS_MAX_CHAN];
96 /* Output PGM files */
97 FILE *comp; /* Composite output */
98 cups_cmyk_t *cmyk; /* Color separation */
102 * Open the test image...
105 in = fopen("image.pgm", "rb");
106 while (fgets(line, sizeof(line), in) != NULL)
107 if (isdigit(line[0]))
110 sscanf(line, "%d%d", &width, &height);
112 fgets(line, sizeof(line), in);
115 * Create the color separation...
118 cmyk = cupsCMYKNew(num_comps);
123 cupsCMYKSetLtDk(cmyk, 0, 0.5, 1.0);
127 cupsCMYKSetGamma(cmyk, 2, 1.0, 0.9);
128 cupsCMYKSetBlack(cmyk, 0.5, 1.0);
131 case 6 : /* CcMmYK */
132 cupsCMYKSetLtDk(cmyk, 0, 0.5, 1.0);
133 cupsCMYKSetLtDk(cmyk, 2, 0.5, 1.0);
134 cupsCMYKSetGamma(cmyk, 4, 1.0, 0.9);
135 cupsCMYKSetBlack(cmyk, 0.5, 1.0);
138 case 7 : /* CcMmYKk */
139 cupsCMYKSetLtDk(cmyk, 0, 0.5, 1.0);
140 cupsCMYKSetLtDk(cmyk, 2, 0.5, 1.0);
141 cupsCMYKSetGamma(cmyk, 4, 1.0, 0.9);
142 cupsCMYKSetLtDk(cmyk, 5, 0.5, 1.0);
147 * Open the color separation files...
150 for (i = 0; i < num_comps; i ++)
152 sprintf(filename, "%s%d.pgm", basename, i);
153 out[i] = fopen(filename, "wb");
155 fprintf(out[i], "P5\n%d %d 255\n", width, height);
158 sprintf(filename, "%s.ppm", basename);
159 comp = fopen(filename, "wb");
161 fprintf(comp, "P6\n%d %d 255\n", width, height);
164 * Read the image and do the separations...
167 for (y = 0; y < height; y ++)
169 fread(input, width, 1, in);
171 cupsCMYKDoGray(cmyk, input, output, width);
173 for (x = 0, outptr = output; x < width; x ++, outptr += num_comps)
175 for (i = 0; i < num_comps; i ++)
176 putc(255 - 255 * outptr[i] / 4095, out[i]);
213 r -= outptr[0] + outptr[1] / 2;
214 g -= outptr[2] + outptr[3] / 3;
222 r -= outptr[0] + outptr[1] / 2;
223 g -= outptr[2] + outptr[3] / 3;
226 r -= outptr[5] + outptr[6] / 2;
227 g -= outptr[5] + outptr[6] / 2;
228 b -= outptr[5] + outptr[6] / 2;
235 putc(255 * r / 4095, comp);
240 putc(255 * g / 4095, comp);
245 putc(255 * b / 4095, comp);
249 for (i = 0; i < num_comps; i ++)
255 cupsCMYKDelete(cmyk);
260 * 'test_rgb()' - Test color separations...
264 test_rgb(int num_comps, /* I - Number of components */
265 const char *basename) /* I - Base filename of output */
267 int i; /* Looping var */
268 char filename[255]; /* Output filename */
269 char line[255]; /* Line from PPM file */
270 int width, height; /* Width and height of test image */
271 int x, y; /* Current coordinate in image */
272 int r, g, b; /* Current RGB color */
273 unsigned char input[7000]; /* Line to separate */
274 short output[48000], /* Output separation data */
275 *outptr; /* Pointer in output */
276 FILE *in; /* Input PPM file */
277 FILE *out[CUPS_MAX_CHAN];
278 /* Output PGM files */
279 FILE *comp; /* Composite output */
280 cups_cmyk_t *cmyk; /* Color separation */
284 * Open the test image...
287 in = fopen("image.ppm", "rb");
288 while (fgets(line, sizeof(line), in) != NULL)
289 if (isdigit(line[0]))
292 sscanf(line, "%d%d", &width, &height);
294 fgets(line, sizeof(line), in);
297 * Create the color separation...
300 cmyk = cupsCMYKNew(num_comps);
302 cupsCMYKSetBlack(cmyk, 0.5, 1.0);
307 cupsCMYKSetLtDk(cmyk, 0, 0.5, 1.0);
309 case 6 : /* CcMmYK */
310 cupsCMYKSetGamma(cmyk, 0, 1.0, 0.8);
311 cupsCMYKSetLtDk(cmyk, 0, 0.5, 1.0);
312 cupsCMYKSetGamma(cmyk, 2, 1.0, 0.8);
313 cupsCMYKSetLtDk(cmyk, 2, 0.5, 1.0);
315 case 7 : /* CcMmYKk */
316 cupsCMYKSetGamma(cmyk, 0, 1.0, 0.8);
317 cupsCMYKSetLtDk(cmyk, 0, 0.5, 1.0);
318 cupsCMYKSetGamma(cmyk, 2, 1.0, 0.8);
319 cupsCMYKSetLtDk(cmyk, 2, 0.5, 1.0);
320 cupsCMYKSetLtDk(cmyk, 5, 0.5, 1.0);
325 * Open the color separation files...
328 for (i = 0; i < num_comps; i ++)
330 sprintf(filename, "%s%d.pgm", basename, i);
331 out[i] = fopen(filename, "wb");
333 fprintf(out[i], "P5\n%d %d 255\n", width, height);
336 sprintf(filename, "%s.ppm", basename);
337 comp = fopen(filename, "wb");
339 fprintf(comp, "P6\n%d %d 255\n", width, height);
342 * Read the image and do the separations...
345 for (y = 0; y < height; y ++)
347 fread(input, width, 3, in);
349 cupsCMYKDoRGB(cmyk, input, output, width);
351 for (x = 0, outptr = output; x < width; x ++, outptr += num_comps)
353 for (i = 0; i < num_comps; i ++)
354 putc(255 - 255 * outptr[i] / 4095, out[i]);
391 r -= outptr[0] + outptr[1] / 2;
392 g -= outptr[2] + outptr[3] / 3;
400 r -= outptr[0] + outptr[1] / 2;
401 g -= outptr[2] + outptr[3] / 3;
404 r -= outptr[5] + outptr[6] / 2;
405 g -= outptr[5] + outptr[6] / 2;
406 b -= outptr[5] + outptr[6] / 2;
413 putc(255 * r / 4095, comp);
418 putc(255 * g / 4095, comp);
423 putc(255 * b / 4095, comp);
427 for (i = 0; i < num_comps; i ++)
433 cupsCMYKDelete(cmyk);