]>
Commit | Line | Data |
---|---|---|
ac884b6a MS |
1 | /* |
2 | * "$Id$" | |
3 | * | |
71e16022 | 4 | * Test the new RGB color separation code for CUPS. |
ac884b6a | 5 | * |
71e16022 | 6 | * Copyright 2007-2010 by Apple Inc. |
ac884b6a MS |
7 | * Copyright 1993-2006 by Easy Software Products, All Rights Reserved. |
8 | * | |
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/". | |
14 | * | |
15 | * Contents: | |
16 | * | |
17 | * main() - Do color rgb tests. | |
18 | * test_gray() - Test grayscale rgbs... | |
19 | * test_rgb() - Test color rgbs... | |
20 | */ | |
21 | ||
22 | /* | |
23 | * Include necessary headers. | |
24 | */ | |
25 | ||
71e16022 | 26 | #include <cups/string-private.h> |
ac884b6a MS |
27 | #include "driver.h" |
28 | #include <sys/stat.h> | |
29 | ||
30 | #ifdef HAVE_LIBLCMS | |
31 | # include <lcms/lcms.h> | |
32 | #endif /* HAVE_LIBLCMS */ | |
33 | ||
34 | ||
35 | void test_gray(cups_sample_t *samples, int num_samples, | |
36 | int cube_size, int num_comps, const char *basename); | |
37 | void test_rgb(cups_sample_t *samples, int num_samples, | |
38 | int cube_size, int num_comps, | |
39 | const char *basename); | |
40 | ||
41 | ||
42 | /* | |
43 | * 'main()' - Do color rgb tests. | |
44 | */ | |
45 | ||
46 | int /* O - Exit status */ | |
47 | main(int argc, /* I - Number of command-line arguments */ | |
48 | char *argv[]) /* I - Command-line arguments */ | |
49 | { | |
50 | static cups_sample_t CMYK[] = /* Basic 4-color sep */ | |
51 | { | |
52 | /*{ r, g, b }, { C, M, Y, K }*/ | |
53 | { { 0, 0, 0 }, { 0, 0, 0, 255 } }, | |
54 | { { 255, 0, 0 }, { 0, 255, 240, 0 } }, | |
55 | { { 0, 255, 0 }, { 200, 0, 200, 0 } }, | |
56 | { { 255, 255, 0 }, { 0, 0, 240, 0 } }, | |
57 | { { 0, 0, 255 }, { 200, 200, 0, 0 } }, | |
58 | { { 255, 0, 255 }, { 0, 200, 0, 0 } }, | |
59 | { { 0, 255, 255 }, { 200, 0, 0, 0 } }, | |
60 | { { 255, 255, 255 }, { 0, 0, 0, 0 } } | |
61 | }; | |
62 | ||
63 | ||
64 | /* | |
65 | * Make the test directory... | |
66 | */ | |
67 | ||
68 | mkdir("test", 0755); | |
69 | ||
70 | /* | |
71 | * Run tests for CMYK and CMYK separations... | |
72 | */ | |
73 | ||
74 | test_rgb(CMYK, 8, 2, 4, "test/rgb-cmyk"); | |
75 | ||
76 | test_gray(CMYK, 8, 2, 4, "test/gray-cmyk"); | |
77 | ||
78 | /* | |
79 | * Return with no errors... | |
80 | */ | |
81 | ||
82 | return (0); | |
83 | } | |
84 | ||
85 | ||
86 | /* | |
87 | * 'test_gray()' - Test grayscale rgbs... | |
88 | */ | |
89 | ||
90 | void | |
91 | test_gray(cups_sample_t *samples, /* I - Sample values */ | |
92 | int num_samples, /* I - Number of samples */ | |
93 | int cube_size, /* I - Cube size */ | |
94 | int num_comps, /* I - Number of components */ | |
95 | const char *basename) /* I - Base filename of output */ | |
96 | { | |
97 | int i; /* Looping var */ | |
98 | char filename[255]; /* Output filename */ | |
99 | char line[255]; /* Line from PPM file */ | |
100 | int width, height; /* Width and height of test image */ | |
101 | int x, y; /* Current coordinate in image */ | |
102 | int r, g, b; /* Current RGB color */ | |
103 | unsigned char input[7000]; /* Line to rgbarate */ | |
104 | unsigned char output[48000], /* Output rgb data */ | |
105 | *outptr; /* Pointer in output */ | |
106 | FILE *in; /* Input PPM file */ | |
107 | FILE *out[CUPS_MAX_CHAN]; | |
108 | /* Output PGM files */ | |
109 | FILE *comp; /* Composite output */ | |
110 | cups_rgb_t *rgb; /* Color separation */ | |
111 | ||
112 | ||
113 | /* | |
114 | * Open the test image... | |
115 | */ | |
116 | ||
117 | in = fopen("image.pgm", "rb"); | |
118 | while (fgets(line, sizeof(line), in) != NULL) | |
119 | if (isdigit(line[0])) | |
120 | break; | |
121 | ||
122 | sscanf(line, "%d%d", &width, &height); | |
123 | ||
124 | fgets(line, sizeof(line), in); | |
125 | ||
126 | /* | |
127 | * Create the color rgb... | |
128 | */ | |
129 | ||
130 | rgb = cupsRGBNew(num_samples, samples, cube_size, num_comps); | |
131 | ||
132 | /* | |
133 | * Open the color rgb files... | |
134 | */ | |
135 | ||
136 | for (i = 0; i < num_comps; i ++) | |
137 | { | |
138 | sprintf(filename, "%s%d.pgm", basename, i); | |
139 | out[i] = fopen(filename, "wb"); | |
140 | ||
141 | fprintf(out[i], "P5\n%d %d 255\n", width, height); | |
142 | } | |
143 | ||
144 | sprintf(filename, "%s.ppm", basename); | |
145 | comp = fopen(filename, "wb"); | |
146 | ||
147 | fprintf(comp, "P6\n%d %d 255\n", width, height); | |
148 | ||
149 | /* | |
150 | * Read the image and do the rgbs... | |
151 | */ | |
152 | ||
153 | for (y = 0; y < height; y ++) | |
154 | { | |
155 | fread(input, width, 1, in); | |
156 | ||
157 | cupsRGBDoGray(rgb, input, output, width); | |
158 | ||
159 | for (x = 0, outptr = output; x < width; x ++, outptr += num_comps) | |
160 | { | |
161 | for (i = 0; i < num_comps; i ++) | |
162 | putc(255 - outptr[i], out[i]); | |
163 | ||
164 | r = 255; | |
165 | g = 255; | |
166 | b = 255; | |
167 | ||
168 | r -= outptr[0]; | |
169 | g -= outptr[1]; | |
170 | b -= outptr[2]; | |
171 | ||
172 | r -= outptr[3]; | |
173 | g -= outptr[3]; | |
174 | b -= outptr[3]; | |
175 | ||
176 | if (num_comps > 4) | |
177 | { | |
178 | r -= outptr[4] / 2; | |
179 | g -= outptr[5] / 2; | |
180 | } | |
181 | ||
182 | if (num_comps > 6) | |
183 | { | |
184 | r -= outptr[6] / 2; | |
185 | g -= outptr[6] / 2; | |
186 | b -= outptr[6] / 2; | |
187 | } | |
188 | ||
189 | if (r < 0) | |
190 | putc(0, comp); | |
191 | else | |
192 | putc(r, comp); | |
193 | ||
194 | if (g < 0) | |
195 | putc(0, comp); | |
196 | else | |
197 | putc(g, comp); | |
198 | ||
199 | if (b < 0) | |
200 | putc(0, comp); | |
201 | else | |
202 | putc(b, comp); | |
203 | } | |
204 | } | |
205 | ||
206 | for (i = 0; i < num_comps; i ++) | |
207 | fclose(out[i]); | |
208 | ||
209 | fclose(comp); | |
210 | fclose(in); | |
211 | ||
212 | cupsRGBDelete(rgb); | |
213 | } | |
214 | ||
215 | ||
216 | /* | |
217 | * 'test_rgb()' - Test color rgbs... | |
218 | */ | |
219 | ||
220 | void | |
221 | test_rgb(cups_sample_t *samples, /* I - Sample values */ | |
222 | int num_samples, /* I - Number of samples */ | |
223 | int cube_size, /* I - Cube size */ | |
224 | int num_comps, /* I - Number of components */ | |
225 | const char *basename) /* I - Base filename of output */ | |
226 | { | |
227 | int i; /* Looping var */ | |
228 | char filename[255]; /* Output filename */ | |
229 | char line[255]; /* Line from PPM file */ | |
230 | int width, height; /* Width and height of test image */ | |
231 | int x, y; /* Current coordinate in image */ | |
232 | int r, g, b; /* Current RGB color */ | |
233 | unsigned char input[7000]; /* Line to rgbarate */ | |
234 | unsigned char output[48000], /* Output rgb data */ | |
235 | *outptr; /* Pointer in output */ | |
236 | FILE *in; /* Input PPM file */ | |
237 | FILE *out[CUPS_MAX_CHAN]; | |
238 | /* Output PGM files */ | |
239 | FILE *comp; /* Composite output */ | |
240 | cups_rgb_t *rgb; /* Color separation */ | |
241 | ||
242 | ||
243 | /* | |
244 | * Open the test image... | |
245 | */ | |
246 | ||
247 | in = fopen("image.ppm", "rb"); | |
248 | while (fgets(line, sizeof(line), in) != NULL) | |
249 | if (isdigit(line[0])) | |
250 | break; | |
251 | ||
252 | sscanf(line, "%d%d", &width, &height); | |
253 | ||
254 | fgets(line, sizeof(line), in); | |
255 | ||
256 | /* | |
257 | * Create the color rgb... | |
258 | */ | |
259 | ||
260 | rgb = cupsRGBNew(num_samples, samples, cube_size, num_comps); | |
261 | ||
262 | /* | |
263 | * Open the color rgb files... | |
264 | */ | |
265 | ||
266 | for (i = 0; i < num_comps; i ++) | |
267 | { | |
268 | sprintf(filename, "%s%d.pgm", basename, i); | |
269 | out[i] = fopen(filename, "wb"); | |
270 | ||
271 | fprintf(out[i], "P5\n%d %d 255\n", width, height); | |
272 | } | |
273 | ||
274 | sprintf(filename, "%s.ppm", basename); | |
275 | comp = fopen(filename, "wb"); | |
276 | ||
277 | fprintf(comp, "P6\n%d %d 255\n", width, height); | |
278 | ||
279 | /* | |
280 | * Read the image and do the rgbs... | |
281 | */ | |
282 | ||
283 | for (y = 0; y < height; y ++) | |
284 | { | |
285 | fread(input, width, 3, in); | |
286 | ||
287 | cupsRGBDoRGB(rgb, input, output, width); | |
288 | ||
289 | for (x = 0, outptr = output; x < width; x ++, outptr += num_comps) | |
290 | { | |
291 | for (i = 0; i < num_comps; i ++) | |
292 | putc(255 - outptr[i], out[i]); | |
293 | ||
294 | r = 255; | |
295 | g = 255; | |
296 | b = 255; | |
297 | ||
298 | r -= outptr[0]; | |
299 | g -= outptr[1]; | |
300 | b -= outptr[2]; | |
301 | ||
302 | r -= outptr[3]; | |
303 | g -= outptr[3]; | |
304 | b -= outptr[3]; | |
305 | ||
306 | if (num_comps > 4) | |
307 | { | |
308 | r -= outptr[4] / 2; | |
309 | g -= outptr[5] / 2; | |
310 | } | |
311 | ||
312 | if (num_comps > 6) | |
313 | { | |
314 | r -= outptr[6] / 2; | |
315 | g -= outptr[6] / 2; | |
316 | b -= outptr[6] / 2; | |
317 | } | |
318 | ||
319 | if (r < 0) | |
320 | putc(0, comp); | |
321 | else | |
322 | putc(r, comp); | |
323 | ||
324 | if (g < 0) | |
325 | putc(0, comp); | |
326 | else | |
327 | putc(g, comp); | |
328 | ||
329 | if (b < 0) | |
330 | putc(0, comp); | |
331 | else | |
332 | putc(b, comp); | |
333 | } | |
334 | } | |
335 | ||
336 | for (i = 0; i < num_comps; i ++) | |
337 | fclose(out[i]); | |
338 | ||
339 | fclose(comp); | |
340 | fclose(in); | |
341 | ||
342 | cupsRGBDelete(rgb); | |
343 | } | |
344 | ||
345 | ||
346 | /* | |
347 | * End of "$Id$". | |
348 | */ |