]>
git.ipfire.org Git - thirdparty/cups.git/blob - driver/testcmyk.c
4 * Test the CMYK color separation code for ESP Print Pro.
6 * Copyright 2007 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.
26 #include <cups/string.h>
31 void test_gray(int num_comps
, const char *basename
);
32 void test_rgb(int num_comps
, const char *basename
);
36 * 'main()' - Do color separation tests.
39 int /* O - Exit status */
40 main(int argc
, /* I - Number of command-line arguments */
41 char *argv
[]) /* I - Command-line arguments */
44 * Make the test directory...
50 * Run tests for K, Kk, CMY, CMYK, CcMmYK, and CcMmYKk separations...
53 test_rgb(1, "test/K-rgb");
54 test_rgb(2, "test/Kk-rgb");
55 test_rgb(3, "test/CMY-rgb");
56 test_rgb(4, "test/CMYK-rgb");
57 test_rgb(6, "test/CcMmYK-rgb");
58 test_rgb(7, "test/CcMmYKk-rgb");
60 test_gray(1, "test/K-gray");
61 test_gray(2, "test/Kk-gray");
62 test_gray(3, "test/CMY-gray");
63 test_gray(4, "test/CMYK-gray");
64 test_gray(6, "test/CcMmYK-gray");
65 test_gray(7, "test/CcMmYKk-gray");
68 * Return with no errors...
76 * 'test_gray()' - Test grayscale separations...
80 test_gray(int num_comps
, /* I - Number of components */
81 const char *basename
) /* I - Base filename of output */
83 int i
; /* Looping var */
84 char filename
[255]; /* Output filename */
85 char line
[255]; /* Line from PGM file */
86 int width
, height
; /* Width and height of test image */
87 int x
, y
; /* Current coordinate in image */
88 int r
, g
, b
; /* Current RGB color */
89 unsigned char input
[7000]; /* Line to separate */
90 short output
[48000], /* Output separation data */
91 *outptr
; /* Pointer in output */
92 FILE *in
; /* Input PPM file */
93 FILE *out
[CUPS_MAX_CHAN
];
94 /* Output PGM files */
95 FILE *comp
; /* Composite output */
96 cups_cmyk_t
*cmyk
; /* Color separation */
100 * Open the test image...
103 in
= fopen("image.pgm", "rb");
104 while (fgets(line
, sizeof(line
), in
) != NULL
)
105 if (isdigit(line
[0]))
108 sscanf(line
, "%d%d", &width
, &height
);
110 fgets(line
, sizeof(line
), in
);
113 * Create the color separation...
116 cmyk
= cupsCMYKNew(num_comps
);
121 cupsCMYKSetLtDk(cmyk
, 0, 0.5, 1.0);
125 cupsCMYKSetGamma(cmyk
, 2, 1.0, 0.9);
126 cupsCMYKSetBlack(cmyk
, 0.5, 1.0);
129 case 6 : /* CcMmYK */
130 cupsCMYKSetLtDk(cmyk
, 0, 0.5, 1.0);
131 cupsCMYKSetLtDk(cmyk
, 2, 0.5, 1.0);
132 cupsCMYKSetGamma(cmyk
, 4, 1.0, 0.9);
133 cupsCMYKSetBlack(cmyk
, 0.5, 1.0);
136 case 7 : /* CcMmYKk */
137 cupsCMYKSetLtDk(cmyk
, 0, 0.5, 1.0);
138 cupsCMYKSetLtDk(cmyk
, 2, 0.5, 1.0);
139 cupsCMYKSetGamma(cmyk
, 4, 1.0, 0.9);
140 cupsCMYKSetLtDk(cmyk
, 5, 0.5, 1.0);
145 * Open the color separation files...
148 for (i
= 0; i
< num_comps
; i
++)
150 sprintf(filename
, "%s%d.pgm", basename
, i
);
151 out
[i
] = fopen(filename
, "wb");
153 fprintf(out
[i
], "P5\n%d %d 255\n", width
, height
);
156 sprintf(filename
, "%s.ppm", basename
);
157 comp
= fopen(filename
, "wb");
159 fprintf(comp
, "P6\n%d %d 255\n", width
, height
);
162 * Read the image and do the separations...
165 for (y
= 0; y
< height
; y
++)
167 fread(input
, width
, 1, in
);
169 cupsCMYKDoGray(cmyk
, input
, output
, width
);
171 for (x
= 0, outptr
= output
; x
< width
; x
++, outptr
+= num_comps
)
173 for (i
= 0; i
< num_comps
; i
++)
174 putc(255 - 255 * outptr
[i
] / 4095, out
[i
]);
211 r
-= outptr
[0] + outptr
[1] / 2;
212 g
-= outptr
[2] + outptr
[3] / 3;
220 r
-= outptr
[0] + outptr
[1] / 2;
221 g
-= outptr
[2] + outptr
[3] / 3;
224 r
-= outptr
[5] + outptr
[6] / 2;
225 g
-= outptr
[5] + outptr
[6] / 2;
226 b
-= outptr
[5] + outptr
[6] / 2;
233 putc(255 * r
/ 4095, comp
);
238 putc(255 * g
/ 4095, comp
);
243 putc(255 * b
/ 4095, comp
);
247 for (i
= 0; i
< num_comps
; i
++)
253 cupsCMYKDelete(cmyk
);
258 * 'test_rgb()' - Test color separations...
262 test_rgb(int num_comps
, /* I - Number of components */
263 const char *basename
) /* I - Base filename of output */
265 int i
; /* Looping var */
266 char filename
[255]; /* Output filename */
267 char line
[255]; /* Line from PPM file */
268 int width
, height
; /* Width and height of test image */
269 int x
, y
; /* Current coordinate in image */
270 int r
, g
, b
; /* Current RGB color */
271 unsigned char input
[7000]; /* Line to separate */
272 short output
[48000], /* Output separation data */
273 *outptr
; /* Pointer in output */
274 FILE *in
; /* Input PPM file */
275 FILE *out
[CUPS_MAX_CHAN
];
276 /* Output PGM files */
277 FILE *comp
; /* Composite output */
278 cups_cmyk_t
*cmyk
; /* Color separation */
282 * Open the test image...
285 in
= fopen("image.ppm", "rb");
286 while (fgets(line
, sizeof(line
), in
) != NULL
)
287 if (isdigit(line
[0]))
290 sscanf(line
, "%d%d", &width
, &height
);
292 fgets(line
, sizeof(line
), in
);
295 * Create the color separation...
298 cmyk
= cupsCMYKNew(num_comps
);
300 cupsCMYKSetBlack(cmyk
, 0.5, 1.0);
305 cupsCMYKSetLtDk(cmyk
, 0, 0.5, 1.0);
307 case 6 : /* CcMmYK */
308 cupsCMYKSetGamma(cmyk
, 0, 1.0, 0.8);
309 cupsCMYKSetLtDk(cmyk
, 0, 0.5, 1.0);
310 cupsCMYKSetGamma(cmyk
, 2, 1.0, 0.8);
311 cupsCMYKSetLtDk(cmyk
, 2, 0.5, 1.0);
313 case 7 : /* CcMmYKk */
314 cupsCMYKSetGamma(cmyk
, 0, 1.0, 0.8);
315 cupsCMYKSetLtDk(cmyk
, 0, 0.5, 1.0);
316 cupsCMYKSetGamma(cmyk
, 2, 1.0, 0.8);
317 cupsCMYKSetLtDk(cmyk
, 2, 0.5, 1.0);
318 cupsCMYKSetLtDk(cmyk
, 5, 0.5, 1.0);
323 * Open the color separation files...
326 for (i
= 0; i
< num_comps
; i
++)
328 sprintf(filename
, "%s%d.pgm", basename
, i
);
329 out
[i
] = fopen(filename
, "wb");
331 fprintf(out
[i
], "P5\n%d %d 255\n", width
, height
);
334 sprintf(filename
, "%s.ppm", basename
);
335 comp
= fopen(filename
, "wb");
337 fprintf(comp
, "P6\n%d %d 255\n", width
, height
);
340 * Read the image and do the separations...
343 for (y
= 0; y
< height
; y
++)
345 fread(input
, width
, 3, in
);
347 cupsCMYKDoRGB(cmyk
, input
, output
, width
);
349 for (x
= 0, outptr
= output
; x
< width
; x
++, outptr
+= num_comps
)
351 for (i
= 0; i
< num_comps
; i
++)
352 putc(255 - 255 * outptr
[i
] / 4095, out
[i
]);
389 r
-= outptr
[0] + outptr
[1] / 2;
390 g
-= outptr
[2] + outptr
[3] / 3;
398 r
-= outptr
[0] + outptr
[1] / 2;
399 g
-= outptr
[2] + outptr
[3] / 3;
402 r
-= outptr
[5] + outptr
[6] / 2;
403 g
-= outptr
[5] + outptr
[6] / 2;
404 b
-= outptr
[5] + outptr
[6] / 2;
411 putc(255 * r
/ 4095, comp
);
416 putc(255 * g
/ 4095, comp
);
421 putc(255 * b
/ 4095, comp
);
425 for (i
= 0; i
< num_comps
; i
++)
431 cupsCMYKDelete(cmyk
);