]> git.ipfire.org Git - thirdparty/cups.git/blob - filter/testraster.c
Load cups into easysw/current.
[thirdparty/cups.git] / filter / testraster.c
1 /*
2 * "$Id: testraster.c 4545 2005-06-21 19:26:28Z mike $"
3 *
4 * Raster test program routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2005 by Easy Software Products.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights for the CUPS Raster source
11 * files are outlined in the GNU Library General Public License, located
12 * in the "pstoraster" directory. If this file is missing or damaged
13 * please contact Easy Software Products at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * This code and any derivative of it may be used and distributed
25 * freely under the terms of the GNU General Public License when
26 * used with GNU Ghostscript or its derivatives. Use of the code
27 * (or any derivative of it) with software other than GNU
28 * GhostScript (or its derivatives) is governed by the CUPS license
29 * agreement.
30 *
31 * This file is subject to the Apple OS-Developed Software exception.
32 *
33 * Contents:
34 *
35 */
36
37 /*
38 * Include necessary headers...
39 */
40
41 #include "raster.h"
42 #include <stdlib.h>
43 #include <cups/string.h>
44
45
46 /*
47 * 'main()' - Test the raster read/write functions.
48 */
49
50 int /* O - Exit status */
51 main(void)
52 {
53 int page, x, y; /* Looping vars */
54 FILE *fp; /* Raster file */
55 cups_raster_t *r; /* Raster stream */
56 cups_page_header2_t header; /* Page header */
57 unsigned char data[2048]; /* Raster data */
58
59
60 if ((fp = fopen("test.raster", "wb")) == NULL)
61 {
62 perror("Unable to create test.raster");
63 return (1);
64 }
65
66 if ((r = cupsRasterOpen(fileno(fp), CUPS_RASTER_WRITE)) == NULL)
67 {
68 perror("Unable to create raster output stream");
69 fclose(fp);
70 return (1);
71 }
72
73 for (page = 0; page < 4; page ++)
74 {
75 memset(&header, 0, sizeof(header));
76 header.cupsWidth = 256;
77 header.cupsHeight = 256;
78 header.cupsBytesPerLine = 256;
79
80 if (page & 1)
81 {
82 header.cupsBytesPerLine *= 2;
83 header.cupsColorSpace = CUPS_CSPACE_CMYK;
84 header.cupsColorOrder = CUPS_ORDER_CHUNKED;
85 }
86 else
87 {
88 header.cupsColorSpace = CUPS_CSPACE_K;
89 header.cupsColorOrder = CUPS_ORDER_BANDED;
90 }
91
92 if (page & 2)
93 {
94 header.cupsBytesPerLine *= 2;
95 header.cupsBitsPerColor = 16;
96 header.cupsBitsPerPixel = (page & 1) ? 64 : 16;
97 }
98 else
99 {
100 header.cupsBitsPerColor = 8;
101 header.cupsBitsPerPixel = (page & 1) ? 32 : 8;
102 }
103
104 cupsRasterWriteHeader2(r, &header);
105
106 memset(data, 0, header.cupsBytesPerLine);
107 for (y = 0; y < 64; y ++)
108 cupsRasterWritePixels(r, data, header.cupsBytesPerLine);
109
110 for (x = 0; x < header.cupsBytesPerLine; x ++)
111 data[x] = x;
112
113 for (y = 0; y < 64; y ++)
114 cupsRasterWritePixels(r, data, header.cupsBytesPerLine);
115
116 memset(data, 255, header.cupsBytesPerLine);
117 for (y = 0; y < 64; y ++)
118 cupsRasterWritePixels(r, data, header.cupsBytesPerLine);
119
120 for (x = 0; x < header.cupsBytesPerLine; x ++)
121 data[x] = x / 4;
122
123 for (y = 0; y < 64; y ++)
124 cupsRasterWritePixels(r, data, header.cupsBytesPerLine);
125 }
126
127 cupsRasterClose(r);
128 fclose(fp);
129
130 if ((fp = fopen("test.raster", "rb")) == NULL)
131 {
132 perror("Unable to open test.raster");
133 return (1);
134 }
135
136 if ((r = cupsRasterOpen(fileno(fp), CUPS_RASTER_READ)) == NULL)
137 {
138 perror("Unable to create raster input stream");
139 fclose(fp);
140 return (1);
141 }
142
143 for (page = 0; page < 4; page ++)
144 {
145 cupsRasterReadHeader2(r, &header);
146
147 printf("Page %d:\n", page + 1);
148 printf(" cupsWidth = %d\n", header.cupsWidth);
149 printf(" cupsHeight = %d\n", header.cupsHeight);
150 printf(" cupsBitsPerColor = %d\n", header.cupsBitsPerColor);
151 printf(" cupsBitsPerPixel = %d\n", header.cupsBitsPerPixel);
152 printf(" cupsColorSpace = %d\n", header.cupsColorSpace);
153 printf(" cupsColorOrder = %d\n", header.cupsColorOrder);
154 printf(" cupsBytesPerLine = %d\n", header.cupsBytesPerLine);
155
156 for (y = 0; y < 64; y ++)
157 {
158 cupsRasterReadPixels(r, data, header.cupsBytesPerLine);
159
160 if (data[0] != 0 || memcmp(data, data + 1, header.cupsBytesPerLine - 1))
161 printf(" RASTER LINE %d CORRUPT AT %d (%02X instead of 00!)\n",
162 y, x, data[x]);
163 }
164
165 for (y = 0; y < 64; y ++)
166 {
167 cupsRasterReadPixels(r, data, header.cupsBytesPerLine);
168
169 for (x = 0; x < header.cupsBytesPerLine; x ++)
170 if (data[x] != (x & 255))
171 break;
172
173 if (x < header.cupsBytesPerLine)
174 printf(" RASTER LINE %d CORRUPT AT %d (%02X instead of %02X!)\n",
175 y + 64, x, data[x], x & 255);
176 }
177
178 for (y = 0; y < 64; y ++)
179 {
180 cupsRasterReadPixels(r, data, header.cupsBytesPerLine);
181
182 if (data[0] != 255 || memcmp(data, data + 1, header.cupsBytesPerLine - 1))
183 printf(" RASTER LINE %d CORRUPT AT %d (%02X instead of FF!)\n",
184 y + 128, x, data[x]);
185 }
186
187 for (y = 0; y < 64; y ++)
188 {
189 cupsRasterReadPixels(r, data, header.cupsBytesPerLine);
190
191 for (x = 0; x < header.cupsBytesPerLine; x ++)
192 if (data[x] != ((x / 4) & 255))
193 break;
194
195 if (x < header.cupsBytesPerLine)
196 printf(" RASTER LINE %d CORRUPT AT %d (%02X instead of %02X!)\n",
197 y + 192, x, data[x], (x / 4) & 255);
198 }
199 }
200
201 cupsRasterClose(r);
202 fclose(fp);
203
204 return (0);
205 }
206
207
208 /*
209 * End of "$Id: testraster.c 4545 2005-06-21 19:26:28Z mike $".
210 */