]>
git.ipfire.org Git - thirdparty/cups.git/blob - driver/testrgb.c
4 * Test the new RGB 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 * main() - Do color rgb tests.
18 * test_gray() - Test grayscale rgbs...
19 * test_rgb() - Test color rgbs...
23 * Include necessary headers.
26 #include <cups/string.h>
31 # include <lcms/lcms.h>
32 #endif /* HAVE_LIBLCMS */
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
);
43 * 'main()' - Do color rgb tests.
46 int /* O - Exit status */
47 main(int argc
, /* I - Number of command-line arguments */
48 char *argv
[]) /* I - Command-line arguments */
50 static cups_sample_t CMYK
[] = /* Basic 4-color sep */
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 } }
65 * Make the test directory...
71 * Run tests for CMYK and CMYK separations...
74 test_rgb(CMYK
, 8, 2, 4, "test/rgb-cmyk");
76 test_gray(CMYK
, 8, 2, 4, "test/gray-cmyk");
79 * Return with no errors...
87 * 'test_gray()' - Test grayscale rgbs...
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 */
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 */
114 * Open the test image...
117 in
= fopen("image.pgm", "rb");
118 while (fgets(line
, sizeof(line
), in
) != NULL
)
119 if (isdigit(line
[0]))
122 sscanf(line
, "%d%d", &width
, &height
);
124 fgets(line
, sizeof(line
), in
);
127 * Create the color rgb...
130 rgb
= cupsRGBNew(num_samples
, samples
, cube_size
, num_comps
);
133 * Open the color rgb files...
136 for (i
= 0; i
< num_comps
; i
++)
138 sprintf(filename
, "%s%d.pgm", basename
, i
);
139 out
[i
] = fopen(filename
, "wb");
141 fprintf(out
[i
], "P5\n%d %d 255\n", width
, height
);
144 sprintf(filename
, "%s.ppm", basename
);
145 comp
= fopen(filename
, "wb");
147 fprintf(comp
, "P6\n%d %d 255\n", width
, height
);
150 * Read the image and do the rgbs...
153 for (y
= 0; y
< height
; y
++)
155 fread(input
, width
, 1, in
);
157 cupsRGBDoGray(rgb
, input
, output
, width
);
159 for (x
= 0, outptr
= output
; x
< width
; x
++, outptr
+= num_comps
)
161 for (i
= 0; i
< num_comps
; i
++)
162 putc(255 - outptr
[i
], out
[i
]);
206 for (i
= 0; i
< num_comps
; i
++)
217 * 'test_rgb()' - Test color rgbs...
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 */
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 */
244 * Open the test image...
247 in
= fopen("image.ppm", "rb");
248 while (fgets(line
, sizeof(line
), in
) != NULL
)
249 if (isdigit(line
[0]))
252 sscanf(line
, "%d%d", &width
, &height
);
254 fgets(line
, sizeof(line
), in
);
257 * Create the color rgb...
260 rgb
= cupsRGBNew(num_samples
, samples
, cube_size
, num_comps
);
263 * Open the color rgb files...
266 for (i
= 0; i
< num_comps
; i
++)
268 sprintf(filename
, "%s%d.pgm", basename
, i
);
269 out
[i
] = fopen(filename
, "wb");
271 fprintf(out
[i
], "P5\n%d %d 255\n", width
, height
);
274 sprintf(filename
, "%s.ppm", basename
);
275 comp
= fopen(filename
, "wb");
277 fprintf(comp
, "P6\n%d %d 255\n", width
, height
);
280 * Read the image and do the rgbs...
283 for (y
= 0; y
< height
; y
++)
285 fread(input
, width
, 3, in
);
287 cupsRGBDoRGB(rgb
, input
, output
, width
);
289 for (x
= 0, outptr
= output
; x
< width
; x
++, outptr
+= num_comps
)
291 for (i
= 0; i
< num_comps
; i
++)
292 putc(255 - outptr
[i
], out
[i
]);
336 for (i
= 0; i
< num_comps
; i
++)