Debian Codegraph @

test/unprint.c

raw symbols SCIP
1 /*
2 * Generate PPM files from printer output
3 *
4 * Copyright 2000-2001 Eric Sharkey <[email protected]>
5 * Andy Thaller <[email protected]>
6 * Robert Krawitz <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`!
23 #include <config.h>cxx . . $ `<file>/config.h`/
24 #endif
25 #include <gutenprint/util.h>cxx . . $ `<file>/include/gutenprint/util.h`/
26 #include<stdio.h>
27 #include<stdlib.h>
28 #ifdef HAVE_LIMITS_Hcxx . . $ `config.h:94:9`!
29 #include<limits.h>
30 #endif
31 #include<string.h>
32
33 #ifdef __GNUC__cxx . . $ `<built-in>:8:9`!
34 #define inlinecxx . . $ `test/unprint.c:34:9`! __inline__
35 #endif
36
37 typedef enumcxx . . $ $anonymous_type_23194501580ea33e_0# {
38 QT_NONEcxx . . $ QT_NONE.,
39 QT_QUADcxx . . $ QT_QUAD.,
40 QT_MIScxx . . $ QT_MIS.
41 } quadtone_tcxx . . $ quadtone_t#;
42
43 /*
44 * Printer state variable.
45 */
46 typedef structcxx . . $ $anonymous_type_23194501580ea33e_1# {
47 unsigned char unidirectionalcxx . . $ $anonymous_type_23194501580ea33e_1#unidirectional.;
48 unsigned char printer_weavecxx . . $ $anonymous_type_23194501580ea33e_1#printer_weave.;
49 int page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.; /* dpi */
50 int relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units.; /* dpi */
51 int absolute_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_horizontal_units.; /* dpi, assumed to be >= relative */
52 unsigned int relative_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_vertical_units.; /* dpi */
53 unsigned int absolute_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_vertical_units.; /* dpi, assumed to be >= relative */
54 int horizontal_spacingcxx . . $ $anonymous_type_23194501580ea33e_1#horizontal_spacing.; /* Horizontal dot spacing */
55 unsigned int top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.; /* dots */
56 unsigned int bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin.; /* dots */
57 unsigned int page_heightcxx . . $ $anonymous_type_23194501580ea33e_1#page_height.; /* dots */
58 int dotsizecxx . . $ $anonymous_type_23194501580ea33e_1#dotsize.;
59 int bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.; /* bits per pixel */
60 int current_colorcxx . . $ $anonymous_type_23194501580ea33e_1#current_color.;
61 int xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition.; /* dots */
62 unsigned int ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition.; /* dots */
63 int monomodecxx . . $ $anonymous_type_23194501580ea33e_1#monomode.;
64 int nozzle_separationcxx . . $ $anonymous_type_23194501580ea33e_1#nozzle_separation.;
65 int nozzlescxx . . $ $anonymous_type_23194501580ea33e_1#nozzles.;
66 int extraskipcxx . . $ $anonymous_type_23194501580ea33e_1#extraskip.;
67 int got_graphicscxx . . $ $anonymous_type_23194501580ea33e_1#got_graphics.;
68 int left_edgecxx . . $ $anonymous_type_23194501580ea33e_1#left_edge.;
69 int right_edgecxx . . $ $anonymous_type_23194501580ea33e_1#right_edge.;
70 unsigned int top_edgecxx . . $ $anonymous_type_23194501580ea33e_1#top_edge.;
71 unsigned int bottom_edgecxx . . $ $anonymous_type_23194501580ea33e_1#bottom_edge.;
72 quadtone_tcxx . . $ quadtone_t# quadtonecxx . . $ $anonymous_type_23194501580ea33e_1#quadtone.;
73 } pstate_tcxx . . $ pstate_t#;
74
75 /* We'd need about a gigabyte of ram to hold a ppm file of an 8.5 x 11
76 * 1440 x 720 dpi page. That's more than I have in my laptop, so, let's
77 * play some games to reduce memory. Allocate each scan line separately,
78 * and don't require that the allocated height be full page width. This
79 * way, if we only want to print a 2x2 image, we only need to allocate the
80 * ram that we need. We'll build up the printed image in ram at low
81 * color depth, KCMYcm color basis, and then write out the RGB ppm file
82 * as output. This way we never need to have the full data in RAM at any
83 * time. 2 bits per color of KCMYcm is half the size of 8 bits per color
84 * of RGB.
85 *
86 * We would like to be able to print in bands, so that we don't have to
87 * read the entire page into memory in order to print it. Unfortunately,
88 * we may not know what the left and right margins are until we've read the
89 * entire file. If we can read it in two passes we could do it; use one
90 * pass to scan the file looking at the margins, and another pass to
91 * actually read in the data. This optimization may be worthwhile.
92 */
93
94 #define MAX_INKScxx . . $ `test/unprint.c:94:9`! 20
95 typedef structcxx . . $ $anonymous_type_23194501580ea33e_2# {
96 unsigned char *linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[MAX_INKScxx . . $ `test/unprint.c:94:9`!];
97 int startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[MAX_INKScxx . . $ `test/unprint.c:94:9`!];
98 int stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[MAX_INKScxx . . $ `test/unprint.c:94:9`!];
99 } line_typecxx . . $ line_type#;
100
101 typedef unsigned char ppmpixelcxx . . $ ppmpixel#[3];
102
103 unsigned char *bufcxx . . $ buf.;
104 unsigned valid_bufsizecxx . . $ valid_bufsize.;
105 unsigned char minibufcxx . . $ minibuf.[256];
106 unsigned bufsizecxx . . $ bufsize.;
107 unsigned save_bufsizecxx . . $ save_bufsize.;
108 unsigned char chcxx . . $ ch.;
109 unsigned short shcxx . . $ sh.;
110 int ejectcxx . . $ eject. = 0;
111 int global_countercxx . . $ global_counter. = 0;
112 int global_countcxx . . $ global_count. = 0;
113 unsigned color_maskcxx . . $ color_mask. = 0xffffffff;
114
115 pstate_tcxx . . $ pstate_t# pstatecxx . . $ pstate.;
116 int unweavecxx . . $ unweave.;
117
118 line_typecxx . . $ line_type# **pagecxx . . $ page.=NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
119
120 /* Color Codes:
121 color Epson1 Epson2 Sequential
122 Black 0 0 0/16
123 Magenta 1 1 1/17
124 Cyan 2 2 2/18
125 Yellow 4 4 3/19
126 L.Mag. 17 257 4
127 L.Cyan 18 258 5
128 L.Black 16 256 6
129 D.Yellow 36 516 7
130 Red 7 N/A 8
131 Blue 8 N/A 9
132 P.Black 64 N/A 0
133 Gloss 9 N/A 10
134 LL.Black 48 768 11
135 Orange 10 N/A 12
136 */
137
138 /* convert either Epson1 or Epson2 color encoding into a sequential encoding */
139 static int
140 seqcolorcxx . . $ seqcolor(7864480464b09eea).(int c)
141 {
142 switch (c)
143 {
144 case 0:
145 return 0;
146 case 1:
147 return 1;
148 case 2:
149 return 2;
150 case 4:
151 return 3;
152 case 17:
153 case 257:
154 return 4;
155 case 18:
156 case 258:
157 return 5;
158 case 16:
159 case 256:
160 return 6;
161 case 36:
162 case 516:
163 return 7;
164 case 7:
165 return 8;
166 case 8:
167 return 9;
168 case 9:
169 return 10;
170 case 48:
171 case 768:
172 return 11;
173 case 10:
174 return 12;
175 case 64:
176 return 16;
177 case 65:
178 return 17;
179 case 66:
180 return 18;
181 case 68:
182 return 19;
183 default:
184 return 0;
185 }
186 }
187
188 extern void merge_linecxx . . $ merge_line(c730ee936e3ce712).(line_typecxx . . $ line_type# *p, unsigned char *l, int startl, int stopl,
189 int color);
190 extern void expand_linecxx . . $ expand_line(a8772d07b9556e11). (unsigned char *src, unsigned char *dst, int height,
191 int skip, int left_ignore);
192 extern void write_outputcxx . . $ write_output(c6135fd8b50e22d5). (FILEcxx . . $ FILE# *fp_w, int dontwrite, int allblack);
193 extern void find_whitecxx . . $ find_white(fc6e082944ccf997). (unsigned char *buff,unsigned int npix, unsigned int *left, unsigned int *right);
194 extern int update_pagecxx . . $ update_page(65af5a48aab227c6). (unsigned char *buff, unsigned int buffsize, unsigned int m, unsigned int n,
195 int color, int density);
196 extern void parse_escp2cxx . . $ parse_escp2(8d4262d45fc644ab). (FILEcxx . . $ FILE# *fp_r);
197 extern void reverse_bit_ordercxx . . $ reverse_bit_order(fc0f0e1646c32816). (unsigned char *buff, int n);
198 extern int rle_decodecxx . . $ rle_decode(c2394cdaf83c3d9). (unsigned char *inbuf, int n, int max);
199 extern void parse_canoncxx . . $ parse_canon(8d4262d45fc644ab). (FILEcxx . . $ FILE# *fp_r);
200
201 unsigned get_mask_1cxx . . $ get_mask_1.[] = { 7, 6, 5, 4, 3, 2, 1, 0 };
202 unsigned get_mask_2cxx . . $ get_mask_2.[] = { 6, 4, 2, 0 };
203 unsigned get_mask_4cxx . . $ get_mask_4.[] = { 4, 0 };
204
205 static inlinecxx . . $ `test/unprint.c:34:9`! int
206 get_bitscxx . . $ get_bits(7405b416d0535413).(unsigned char *p, int idx)
207 {
208 /*
209 * p is a pointer to a bit stream, ordered MSb first. Extract the
210 * indexth bpp bit width field and return that value. Ignore byte
211 * boundaries.
212 */
213 int value, b;
214 unsigned addr;
215 switch (pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.)
216 {
217 case 1:
218 return (p[idx >> 3] >> (7 - (idx & 7))) & 1;
219 case 2:
220 b = get_mask_2cxx . . $ get_mask_2.[idx & 3];
221 return (p[idx >> 2] >> b) & 3;
222 case 4:
223 b = get_mask_4cxx . . $ get_mask_4.[idx & 1];
224 return (p[idx >> 1] >> b) & 0xf;
225 case 8:
226 return p[idx];
227 default:
228 addr = (idx * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.);
229 value = 0;
230 for (b = 0; b < pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.; b++)
231 {
232 value += value;
233 value |= (p[(addr + b) >> 3] >> (7 - ((addr + b) & 7))) & 1;
234 }
235 return(value);
236 }
237 }
238
239 static unsigned clr_mask_1cxx . . $ clr_mask_1.[] = { 0xfe, 0xfd, 0xfb, 0xf7,
240 0xef, 0xdf, 0xbf, 0x7f };
241 static unsigned clr_mask_2cxx . . $ clr_mask_2.[] = { 0xfc, 0, 0xf3, 0, 0xcf, 0, 0x3f, 0 };
242 static unsigned clr_mask_4cxx . . $ clr_mask_4.[] = { 0xf0, 0, 0, 0, 0xf, 0, 0, 0 };
243
244 static inlinecxx . . $ `test/unprint.c:34:9`! void
245 set_bitscxx . . $ set_bits(49a5bbab55ea8abc).(unsigned char *p,int idx,int value)
246 {
247
248 /*
249 * p is a pointer to a bit stream, ordered MSb first. Set the
250 * indexth bpp bit width field to value value. Ignore byte
251 * boundaries.
252 */
253
254 int b;
255 switch (pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.)
256 {
257 case 1:
258 b = (7 - (idx & 7));
259 p[idx >> 3] &= clr_mask_1cxx . . $ clr_mask_1.[b];
260 p[idx >> 3] |= value << b;
261 break;
262 case 2:
263 b = get_mask_2cxx . . $ get_mask_2.[idx & 3];
264 p[idx >> 2] &= clr_mask_2cxx . . $ clr_mask_2.[b];
265 p[idx >> 2] |= value << b;
266 break;
267 case 4:
268 b = get_mask_4cxx . . $ get_mask_4.[idx & 1];
269 p[idx >> 1] &= clr_mask_4cxx . . $ clr_mask_4.[b];
270 p[idx >> 1] |= value << b;
271 break;
272 case 8:
273 p[idx] = value;
274 break;
275 default:
276 for (b = pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. - 1; b >= 0; b--)
277 {
278 if (value & 1)
279 p[(idx * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. + b) / 8] |=
280 1 << (7 - ((idx * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. + b) % 8));
281 else
282 p[(idx * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. + b) / 8] &=
283 ~(1 << (7 - ((idx * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. + b) % 8)));
284 value/=2;
285 }
286 }
287 }
288
289 static float ink_colorscxx . . $ ink_colors.[MAX_INKScxx . . $ `test/unprint.c:94:9`!][4] =
290 /* C(R) M(G) Y(B) K(W) */
291 {{ 0, 0, 0, 1 }, /* 0 K */
292 { 1, .1, 1, 1 }, /* 1 M */
293 { .1, 1, 1, 1 }, /* 2 C */
294 { 1, 1, .1, 1 }, /* 3 Y */
295 { 1, .7, 1, 1 }, /* 4 m */
296 { .7, 1, 1, 1 }, /* 5 c */
297 { .7, .7, .7, 1 }, /* 6 k */
298 { .7, .7, 0, 1 }, /* 7 dY */
299 { 1, 0, 0, 1 }, /* 8 R */
300 { 0, 0, 1, 1 }, /* 8 B */
301 { 1, 1, 1, 1 }, /* 10 Gloss */
302 { .8, .8, .8, 1 }, /* 11 llk */
303 { .9, .3, 0, 1 }, /* 12 Orange */
304 { 0, 0, 0, 1 }, /* 13 K */
305 { 0, 0, 0, 1 }, /* 14 K */
306 { 0, 0, 0, 1 }, /* 15 K */
307 { 0, 0, 0, 1 }, /* 16 K */
308 { 1, .1, 1, 1 }, /* 17 M */
309 { .1, 1, 1, 1 }, /* 18 C */
310 { 1, 1, .1, 1 }, /* 19 Y */
311 };
312
313 static float quadtone_inkscxx . . $ quadtone_inks.[] = { 0.0, .5, .25, .75, .9, .8 };
314
315 static float mis_quadtone_inkscxx . . $ mis_quadtone_inks.[] = { 0.0, .25, .75, .5, .55, .85 };
316
317 static float bpp_shiftcxx . . $ bpp_shift.[] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
318
319 static inlinecxx . . $ `test/unprint.c:34:9`! void
320 mix_inkcxx . . $ mix_ink(ece42ade91a96c0b).(ppmpixelcxx . . $ ppmpixel# p, int color, unsigned int amount, float *ink, quadtone_tcxx . . $ quadtone_t# quadtone)
321 {
322 /* this is pretty crude */
323
324 if (((1 << color) & color_maskcxx . . $ color_mask.) && amount)
325 {
326 int i;
327 float size;
328
329 size = (float) amount / bpp_shiftcxx . . $ bpp_shift.[pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.];
330 switch (quadtone)
331 {
332 case QT_QUADcxx . . $ QT_QUAD.:
333 for (i = 0; i < 3; i++)
334 p[i] *= (1 - size) + size * quadtone_inkscxx . . $ quadtone_inks.[color];
335 break;
336 case QT_MIScxx . . $ QT_MIS.:
337 for (i = 0; i < 3; i++)
338 p[i] *= (1 - size) + size * mis_quadtone_inkscxx . . $ mis_quadtone_inks.[color];
339 break;
340 default:
341 for (i = 0; i < 3; i++)
342 p[i] *= (1 - size) + size * ink[i];
343 }
344 }
345 }
346
347 void
348 merge_linecxx . . $ merge_line(c730ee936e3ce712).(line_typecxx . . $ line_type# *p, unsigned char *l, int startl, int stopl, int color)
349 {
350
351 int i;
352 int temp, shift, height, lvalue, pvalue, oldstop;
353 int width, owidth;
354 unsigned char *tempp;
355 int reversed = 0;
356 int need_realloc = 0;
357
358 /*
359 * If we have a pixel to the left of anything previously printed,
360 * we need to expand our margins to the left. This is a bit tricky...
361 */
362 if (startl < p->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[color])
363 {
364 temp = p->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[color];
365 p->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[color] = startl;
366 startl = temp;
367
368 temp = p->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[color];
369 p->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[color] = stopl;
370 stopl = temp;
371
372 tempp = p->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[color];
373 p->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[color] = l;
374 l = tempp;
375 reversed = 1;
376 }
377 shift = startl - p->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[color];
378 height = stopl - startl + 1;
379
380 oldstop = p->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[color];
381 if (stopl > p->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[color])
382 {
383 p->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[color] = stopl;
384 need_realloc = 1;
385 }
386 if (need_realloc || reversed)
387 {
388 width = ((p->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[color] - p->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[color] + 1) * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. + 7) / 8;
389 owidth = ((oldstop - p->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[color] + 1) * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. + 7) / 8;
390 p->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[color] = stp_realloccxx . . $ stp_realloc(417ab160f6baadc6).(p->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[color], width);
391 memsetcxx . . $ memset(d1de1e4fb215f1c6).((p->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[color] + owidth), 0, (width - owidth));
392 }
393 /*
394 * Can we do an empty line optimization?
395 */
396 for (i = 0; i < height; i++)
397 {
398 lvalue = get_bitscxx . . $ get_bits(7405b416d0535413).(l, i);
399 if (lvalue)
400 {
401 pvalue = get_bitscxx . . $ get_bits(7405b416d0535413).(p->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[color], i + shift);
402 pvalue += lvalue;
403 if (pvalue > (1 << pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.) - 1)
404 pvalue = (1 << pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.) - 1;
405 set_bitscxx . . $ set_bits(49a5bbab55ea8abc).(p->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[color], i + shift, pvalue);
406 }
407 }
408 stp_freecxx . . $ stp_free(5d22bdacc48458e8).(l);
409 }
410
411 void
412 expand_linecxx . . $ expand_line(a8772d07b9556e11). (unsigned char *src, unsigned char *dst, int height, int skip,
413 int left_ignore)
414 {
415
416 /*
417 * src is a pointer to a bit stream which is composed of fields of height
418 * bpp starting with the most significant bit of the first byte and
419 * proceeding from there with no regard to byte boundaries. For the
420 * existing Epson printers, bpp is 1 or 2, which means fields will never
421 * cross byte boundaries. However, if bpp were 3, this would undoubtedly
422 * happen. This routine will make no assumptions about bpp, and handle each
423 * bit individually. It's slow, but, it's the only way that will work in
424 * the general case of arbitrary bpp.
425 *
426 * We want to copy each field from the src to the dst, spacing the fields
427 * out every skip fields. We should ignore the first left_ignore fields
428 * pointed to by src, though.
429 */
430
431 int i;
432
433 if ((skip == 1) && !(left_ignore * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. % 8))
434 {
435 /* the trivial case, this should be faster */
436 memcpycxx . . $ memcpy(cc817cb175f282d).(dst, src + left_ignore * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. / 8,
437 (height * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. + 7) / 8);
438 }
439 else
440 {
441 for (i = 0; i < height; i++)
442 set_bitscxx . . $ set_bits(49a5bbab55ea8abc).(dst, i * skip, get_bitscxx . . $ get_bits(7405b416d0535413).(src, i + left_ignore));
443 }
444 }
445
446 int donothingcxx . . $ donothing.;
447
448 void
449 write_outputcxx . . $ write_output(c6135fd8b50e22d5).(FILEcxx . . $ FILE# *fp_w, int dontwrite, int allblack)
450 {
451 int c, l, p, left, right, first, last, width, height, i;
452 unsigned int amount;
453 ppmpixelcxx . . $ ppmpixel# *out_row;
454 int oversample = pstatecxx . . $ pstate..absolute_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_horizontal_units. /
455 pstatecxx . . $ pstate..absolute_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_vertical_units.;
456 if (oversample == 0)
457 oversample = 1;
458
459 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Margins: top: %d bottom: top+%d\n", pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.,
460 pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin.);
461
462 first = pstatecxx . . $ pstate..top_edgecxx . . $ $anonymous_type_23194501580ea33e_1#top_edge.;
463 last = pstatecxx . . $ pstate..bottom_edgecxx . . $ $anonymous_type_23194501580ea33e_1#bottom_edge.;
464 left = pstatecxx . . $ pstate..left_edgecxx . . $ $anonymous_type_23194501580ea33e_1#left_edge.;
465 right = pstatecxx . . $ pstate..right_edgecxx . . $ $anonymous_type_23194501580ea33e_1#right_edge.;
466 height = oversample * (last - first + 1);
467
468 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Image from (%d,%d) (%.3fx%.3f) to (%d,%d) (%.3fx%.3f) size (%dx%d) (%.3fx%.3f)\n",
469 left, first - pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.,
470 (left / (double) pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.),
471 (first / (double) pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.),
472 right, last - pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.,
473 (right / (double) pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.),
474 (last / (double) pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.),
475 right - left + 1, last - first + 1,
476 (right - left + 1) / (double) pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.,
477 (last - first + 1) / (double) pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.);
478
479 width = right - left + 1;
480 if (width < 0)
481 width=0;
482
483 out_row = stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(sizeof(ppmpixelcxx . . $ ppmpixel#) * width);
484 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Writing output...\n");
485
486 if (dontwrite)
487 return;
488 /* write out the PPM header */
489 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(fp_w, "P6\n");
490 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(fp_w, "%d %d\n", width, height);
491 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(fp_w, "255\n");
492 for (l = first; l <= last; l++)
493 {
494 line_typecxx . . $ line_type# *lt = pagecxx . . $ page.[l];
495 memsetcxx . . $ memset(d1de1e4fb215f1c6).(out_row, ~0, (sizeof(ppmpixelcxx . . $ ppmpixel#) * width));
496 if (lt)
497 {
498 for (c = 0; c < MAX_INKScxx . . $ `test/unprint.c:94:9`!; c++)
499 {
500 int inknum = allblack ? 0 : c;
501 float *ink = ink_colorscxx . . $ ink_colors.[inknum];
502 if (lt->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[c])
503 {
504 for (p = lt->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[c]; p <= lt->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[c]; p++)
505 {
506 amount = get_bitscxx . . $ get_bits(7405b416d0535413).(lt->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[c], p - lt->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[c]);
507 mix_inkcxx . . $ mix_ink(ece42ade91a96c0b).(out_row[p - left], c, amount, ink,
508 pstatecxx . . $ pstate..quadtonecxx . . $ $anonymous_type_23194501580ea33e_1#quadtone.);
509 }
510 }
511 }
512 }
513 for (i = 0; i < oversample; i++)
514 fwritecxx . . $ fwrite(ab0609fa07c47d6e).(out_row, sizeof(ppmpixelcxx . . $ ppmpixel#), width, fp_w);
515 }
516 stp_freecxx . . $ stp_free(5d22bdacc48458e8).(out_row);
517 }
518
519 void
520 find_whitecxx . . $ find_white(fc6e082944ccf997).(unsigned char *buff,unsigned int npix, unsigned int *left, unsigned int *right)
521 {
522
523 /*
524 * If a line has white borders on either side, count the number of
525 * pixels and fill that info into left and right.
526 */
527
528 unsigned int i, j, max;
529 unsigned int words, bytes, bits, extra;
530
531 *left = *right = 0;
532 bits = npix * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.;
533 bytes = bits / 8;
534 extra = bits % 8;
535 words = bytes / sizeof(int);
536
537 /*
538 * First, find the leftmost pixel. We first identify the word
539 * containing the byte, then the byte, and finally the pixel within
540 * the byte. It does seem like this is unnecessarily complex, perhaps?
541 */
542 max = words;
543 for (i = 0; (i < max) && (((int *)buff)[i] == 0); i++)
544 ;
545 max = (i < words) ? (i + 1) * sizeof(int) : bytes;
546
547 i *= sizeof(int); /* Convert from ints to bytes */
548 for (; (i < max) && (buff[i] == 0); i++)
549 ;
550 max = (i < bytes) ? 8 : extra;
551 for (j = 0; (j < max) && !(buff[i] & (1 << (7 - j))); j++)
552 ;
553 *left = (i * 8 + j) / pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.;
554 *right = 0;
555
556 /* if left is everything, then right is nothing */
557 if (*left == npix)
558 return;
559
560 /* right side, this is a little trickier */
561 for (i = 0; (i < extra) && !(buff[bytes] & (1 << (i + 8 - extra))); i++)
562 ;
563 if (i < extra)
564 {
565 *right = i / pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.;
566 return;
567 }
568 *right = extra; /*temporarily store right in bits to avoid rounding error*/
569
570 for (i = 0; (i < bytes % sizeof(int)) && !(buff[bytes - 1 - i]); i++)
571 ;
572 if (i < bytes % sizeof(int))
573 {
574 for (j = 0; (j < 8) && !(buff[bytes - 1 - i] & (1 << j)); j++)
575 ;
576 *right = (*right + i * 8 + j) / pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.;
577 return;
578 }
579 *right += i * 8;
580
581 for (i = 0; (i < words) && !(((int *)buff)[words - 1 - i]); i++)
582 ;
583
584 if (i < words)
585 {
586 *right += i * sizeof(int) * 8;
587 for (j = 0;
588 (j < sizeof(int)) && !(buff[(words - i) * sizeof(int) - 1 - j]);
589 j++)
590 ;
591 if (j < sizeof(int))
592 {
593 *right += j * 8;
594 max = (words - i) * sizeof(int) - 1 - j;
595 for (j = 0; (j < 8) && !(buff[max] & (1 << j)); j++)
596 ;
597 if (j < 8)
598 {
599 *right = (*right + j) / pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.;
600 return;
601 }
602 }
603 }
604 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Warning: Reality failure. The impossible happened.\n");
605 }
606
607 int
608 update_pagecxx . . $ update_page(65af5a48aab227c6).(unsigned char *buff, /* I - pixel data */
609 unsigned int buffsize, /* I - size of buff in bytes */
610 unsigned int m, /* I - height of area in pixels */
611 unsigned int n, /* I - width of area in pixels */
612 int color, /* I - color of pixel data */
613 int density /* I - horizontal density in dpi */
614 )
615 {
616 unsigned int y;
617 int skip, oldstart, oldstop, mi = 0;
618 unsigned int left_white, right_white, width;
619 unsigned char *oldline;
620 int sep;
621
622 (void)buffsize;
623
624 if ((n == 0) || (m == 0))
625 return(0); /* shouldn't happen */
626
627 skip = pstatecxx . . $ pstate..relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units. / density;
628 skip *= pstatecxx . . $ pstate..extraskipcxx . . $ $anonymous_type_23194501580ea33e_1#extraskip.;
629
630 if (skip == 0)
631 {
632 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Warning! Attempting to print at %d DPI but units are "
633 "set to %d DPI.\n", density, pstatecxx . . $ pstate..relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units.);
634 return(0);
635 }
636
637 if (!pagecxx . . $ page.)
638 {
639 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,
640 "Warning! Attempting to print before setting up page!\n");
641 /*
642 * Let's hope that we've at least initialized the printer with
643 * with an ESC @ and allocate the default page. Otherwise, we'll
644 * have unpredictable results. But, that's a pretty acurate statement
645 * for a real printer, too!
646 */
647 pagecxx . . $ page. = (line_typecxx . . $ line_type# **)
648 stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).((pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin. - pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.) *
649 sizeof(line_typecxx . . $ line_type# *));
650 }
651 if (pstatecxx . . $ pstate..printer_weavecxx . . $ $anonymous_type_23194501580ea33e_1#printer_weave.)
652 sep = 1;
653 else
654 sep = pstatecxx . . $ pstate..nozzle_separationcxx . . $ $anonymous_type_23194501580ea33e_1#nozzle_separation.;
655 for (y=pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition.; y < pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition. + m * sep; y += sep, mi++)
656 {
657 if (y >= pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin. - pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.)
658 {
659 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,
660 "Warning: Unprinter out of unpaper (limit %d, pos %d).\n",
661 pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin., y);
662 return(1);
663 }
664 find_whitecxx . . $ find_white(fc6e082944ccf997).(buff + mi * ((n * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. + 7) / 8), n,
665 &left_white, &right_white);
666 if (left_white == n)
667 continue; /* ignore blank lines */
668 if (!(pagecxx . . $ page.[y]))
669 {
670 pagecxx . . $ page.[y] = (line_typecxx . . $ line_type# *) stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(sizeof(line_typecxx . . $ line_type#));
671 if (y < pstatecxx . . $ pstate..top_edgecxx . . $ $anonymous_type_23194501580ea33e_1#top_edge.)
672 pstatecxx . . $ pstate..top_edgecxx . . $ $anonymous_type_23194501580ea33e_1#top_edge. = y;
673 if (y > pstatecxx . . $ pstate..bottom_edgecxx . . $ $anonymous_type_23194501580ea33e_1#bottom_edge.)
674 pstatecxx . . $ pstate..bottom_edgecxx . . $ $anonymous_type_23194501580ea33e_1#bottom_edge. = y;
675 }
676 if ((left_white * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. < 8) && (skip == 1))
677 {
678 left_white=0; /* if it's just a few bits, don't bother cropping */
679 } /* unless we need to expand the line anyway */
680 if (pagecxx . . $ page.[y]->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[color])
681 {
682 oldline = pagecxx . . $ page.[y]->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[color];
683 oldstart = pagecxx . . $ page.[y]->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[color];
684 oldstop = pagecxx . . $ page.[y]->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[color];
685 }
686 else
687 {
688 oldline = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
689 oldstart = -1;
690 oldstop = -1;
691 }
692 pagecxx . . $ page.[y]->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[color] = pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition. + left_white * skip;
693 pagecxx . . $ page.[y]->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[color] =pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition. + ((n - 1 - right_white) * skip);
694 if (pagecxx . . $ page.[y]->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[color] < pstatecxx . . $ pstate..left_edgecxx . . $ $anonymous_type_23194501580ea33e_1#left_edge.)
695 pstatecxx . . $ pstate..left_edgecxx . . $ $anonymous_type_23194501580ea33e_1#left_edge. = pagecxx . . $ page.[y]->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[color];
696 if (pagecxx . . $ page.[y]->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[color] > pstatecxx . . $ pstate..right_edgecxx . . $ $anonymous_type_23194501580ea33e_1#right_edge.)
697 pstatecxx . . $ pstate..right_edgecxx . . $ $anonymous_type_23194501580ea33e_1#right_edge. = pagecxx . . $ page.[y]->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[color];
698 width = pagecxx . . $ page.[y]->stopxcxx . . $ $anonymous_type_23194501580ea33e_2#stopx.[color] - pagecxx . . $ page.[y]->startxcxx . . $ $anonymous_type_23194501580ea33e_2#startx.[color];
699 pagecxx . . $ page.[y]->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[color] =
700 stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(((width * skip + 1) * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. + 7) / 8);
701 expand_linecxx . . $ expand_line(a8772d07b9556e11).(buff + mi * ((n * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. + 7) / 8), pagecxx . . $ page.[y]->linecxx . . $ $anonymous_type_23194501580ea33e_2#line.[color],
702 width+1, skip, left_white);
703 if (oldline)
704 merge_linecxx . . $ merge_line(c730ee936e3ce712).(pagecxx . . $ page.[y], oldline, oldstart, oldstop, color);
705 }
706 if (n)
707 pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition. += (n - 1) * skip + 1;
708 return(0);
709 }
710
711 #define get1cxx . . $ `test/unprint.c:711:9`!(error) \
712 do \
713 { \
714 if (!(global_count = fread(&ch, 1, 1, fp_r))) \
715 { \
716 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s at %d (%x), read %d", \
717 error, global_counter, global_counter, global_count); \
718 eject = 1; \
719 continue; \
720 } \
721 else \
722 global_counter += global_count; \
723 } while (0)
724
725 #define get2cxx . . $ `test/unprint.c:725:9`!(error) \
726 do \
727 { \
728 if (!(global_count = fread(minibuf, 1, 2, fp_r))) \
729 { \
730 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s at %d (%x), read %d", \
731 error, global_counter, global_counter, global_count); \
732 eject = 1; \
733 continue; \
734 } \
735 else \
736 { \
737 global_counter += global_count; \
738 sh = minibuf[0] + minibuf[1] * 256; \
739 } \
740 } while (0)
741
742 #define getncxx . . $ `test/unprint.c:742:9`!(n,error) \
743 do \
744 { \
745 if (!(global_count = fread(buf, 1, n, fp_r))) \
746 { \
747 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s at %d (%x), read %d", \
748 error, global_counter, global_counter, global_count); \
749 eject = 1; \
750 continue; \
751 } \
752 else \
753 global_counter += global_count; \
754 } while (0)
755
756 #define getnoffcxx . . $ `test/unprint.c:756:9`!(n,offset,error) \
757 do \
758 { \
759 if (!(global_count = fread(buf + offset, 1, n, fp_r))) \
760 { \
761 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s at %d (%x), read %d", \
762 error, global_counter, global_counter, global_count); \
763 eject = 1; \
764 continue; \
765 } \
766 else \
767 global_counter += global_count; \
768 } while (0)
769
770 static void
771 parse_escp2_datacxx . . $ parse_escp2_data(8d4262d45fc644ab).(FILEcxx . . $ FILE# *fp_r)
772 {
773 unsigned int i, m = 0, n = 0, c = 0;
774 int currentcolor = 0;
775 int density = 0;
776 unsigned int bandsize;
777 switch (chcxx . . $ ch.)
778 {
779 case 'i':
780 get1cxx . . $ `test/unprint.c:711:9`!("Error reading color.\n");
781 currentcolor = seqcolorcxx . . $ seqcolor(7864480464b09eea).(chcxx . . $ ch.);
782 get1cxx . . $ `test/unprint.c:711:9`!("Error reading compression mode!\n");
783 c = chcxx . . $ ch.;
784 get1cxx . . $ `test/unprint.c:711:9`!("Error reading bpp!\n");
785 if (chcxx . . $ ch. != pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.)
786 {
787 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Warning! Color depth altered by ESC i.\n");
788 pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.=chcxx . . $ ch.;
789 }
790 if (pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. > 2)
791 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Warning! Excessively deep color detected.\n");
792 if (pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. == 0)
793 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Warning! Zero bit pixel depth detected.\n");
794 get2cxx . . $ `test/unprint.c:725:9`!("Error reading number of horizontal dots!\n");
795 n = (unsigned) shcxx . . $ sh. * 8 / pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.;
796 get2cxx . . $ `test/unprint.c:725:9`!("Error reading number of vertical dots!\n");
797 m = (unsigned) shcxx . . $ sh.;
798 density = pstatecxx . . $ pstate..horizontal_spacingcxx . . $ $anonymous_type_23194501580ea33e_1#horizontal_spacing.;
799 break;
800 case '.':
801 get1cxx . . $ `test/unprint.c:711:9`!("Error reading compression mode!\n");
802 c=chcxx . . $ ch.;
803 if (c > 2)
804 {
805 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Warning! Unknown compression mode.\n");
806 break;
807 }
808 get1cxx . . $ `test/unprint.c:711:9`!("Error reading vertical density!\n");
809 /* What should we do with the vertical density here??? */
810 get1cxx . . $ `test/unprint.c:711:9`!("Error reading horizontal density!\n");
811 density=3600/chcxx . . $ ch.;
812 get1cxx . . $ `test/unprint.c:711:9`!("Error reading number of vertical dots!\n");
813 m=chcxx . . $ ch.;
814 get2cxx . . $ `test/unprint.c:725:9`!("Error reading number of horizontal dots!\n");
815 n=shcxx . . $ sh.;
816 currentcolor=pstatecxx . . $ pstate..current_colorcxx . . $ $anonymous_type_23194501580ea33e_1#current_color.;
817 break;
818 }
819 bandsize = m * ((n * pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. + 7) / 8);
820 if (valid_bufsizecxx . . $ valid_bufsize. < bandsize)
821 {
822 bufcxx . . $ buf. = stp_realloccxx . . $ stp_realloc(417ab160f6baadc6).(bufcxx . . $ buf., bandsize);
823 valid_bufsizecxx . . $ valid_bufsize. = bandsize;
824 }
825 switch (c)
826 {
827 case 0: /* uncompressed */
828 bufsizecxx . . $ bufsize. = bandsize;
829 getncxx . . $ `test/unprint.c:742:9`!(bufsize,"Error reading raster data!\n");
830 update_pagecxx . . $ update_page(65af5a48aab227c6).(bufcxx . . $ buf., bufsizecxx . . $ bufsize., m, n, currentcolor, density);
831 break;
832 case 1: /* run length encoding */
833 i = 0;
834 while (!ejectcxx . . $ eject. && (i < bandsize))
835 {
836 get1cxx . . $ `test/unprint.c:711:9`!("Error reading global_counter!\n");
837 if (chcxx . . $ ch. < 128)
838 {
839 bufsizecxx . . $ bufsize. = chcxx . . $ ch. + 1;
840 getnoffcxx . . $ `test/unprint.c:756:9`!(bufsize, i, "Error reading RLE raster data!\n");
841 }
842 else
843 {
844 bufsizecxx . . $ bufsize. = 257 - (unsigned int) chcxx . . $ ch.;
845 get1cxx . . $ `test/unprint.c:711:9`!("Error reading compressed RLE raster data!\n");
846 memsetcxx . . $ memset(d1de1e4fb215f1c6).(bufcxx . . $ buf. + i, chcxx . . $ ch., bufsizecxx . . $ bufsize.);
847 }
848 i += bufsizecxx . . $ bufsize.;
849 }
850 if (i != bandsize)
851 {
852 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error decoding RLE data.\n");
853 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Total bufsize %d, expected %d\n",
854 i, bandsize);
855 ejectcxx . . $ eject. = 1;
856 }
857 else
858 update_pagecxx . . $ update_page(65af5a48aab227c6).(bufcxx . . $ buf., i, m, n, currentcolor, density);
859 break;
860 case 2: /* TIFF compression */
861 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "TIFF mode not yet supported!\n");
862 /* FIXME: write TIFF stuff */
863 break;
864 default: /* unknown */
865 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Unknown compression mode %d.\n", c);
866 break;
867 }
868 }
869
870 static void
871 parse_escp2_extendedcxx . . $ parse_escp2_extended(8d4262d45fc644ab).(FILEcxx . . $ FILE# *fp_r)
872 {
873 int unit_base;
874 int i;
875
876 get1cxx . . $ `test/unprint.c:711:9`!("Corrupt file. Incomplete extended command.\n");
877 if (ejectcxx . . $ eject.)
878 return;
879 get2cxx . . $ `test/unprint.c:725:9`!("Corrupt file. Error reading buffer size.\n");
880 bufsizecxx . . $ bufsize. = shcxx . . $ sh.;
881 getncxx . . $ `test/unprint.c:742:9`!(bufsize, "Corrupt file. Error reading command payload.\n");
882 /* fprintf(stderr,"Command %X bufsize %d.\n",ch,bufsize); */
883 switch (chcxx . . $ ch.)
884 {
885 case 'R':
886 if (bufsizecxx . . $ bufsize. == 8 && memcmpcxx . . $ memcmp(36f949851efa3055).(bufcxx . . $ buf., "\0REMOTE1", 8) == 0)
887 {
888 int rc1 = 0, rc2 = 0;
889 /* Remote mode 1 */
890 do
891 {
892 get1cxx . . $ `test/unprint.c:711:9`!("Corrupt file. Error in remote mode.\n");
893 rc1 = chcxx . . $ ch.;
894 get1cxx . . $ `test/unprint.c:711:9`!("Corrupt file. Error reading remote mode command.\n");
895 rc2 = chcxx . . $ ch.;
896 get2cxx . . $ `test/unprint.c:725:9`!("Corrupt file. Error reading remote mode command size.\n");
897 bufsizecxx . . $ bufsize. = shcxx . . $ sh.;
898 if (bufsizecxx . . $ bufsize.)
899 getncxx . . $ `test/unprint.c:742:9`!(bufsize, "Corrupt file. Error reading remote mode command parameters.\n");
900 if (rc1 == 0x1b && rc2 == 0) /* ignore quietly */
901 ;
902 else
903 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,
904 "Remote mode command `%c%c' ignored.\n",
905 rc1,rc2);
906 }
907 while (!ejectcxx . . $ eject. && !(rc1 == 0x1b && rc2 == 0));
908 }
909 else
910 {
911 /*
912 fprintf(stderr,"Warning! Commands in unrecognised remote mode %s ignored.\n", buf);
913 */
914 do
915 {
916 while((!ejectcxx . . $ eject.) && (chcxx . . $ ch.!=0x1b))
917 get1cxx . . $ `test/unprint.c:711:9`!("Error in remote mode.\n");
918 get1cxx . . $ `test/unprint.c:711:9`!("Error reading remote mode terminator\n");
919 }
920 while ((!ejectcxx . . $ eject.) && (chcxx . . $ ch. != 0));
921 }
922 break;
923 case 'G': /* select graphics mode */
924 /* FIXME: this is supposed to have more side effects */
925 pstatecxx . . $ pstate..printer_weavecxx . . $ $anonymous_type_23194501580ea33e_1#printer_weave. = 0;
926 pstatecxx . . $ pstate..dotsizecxx . . $ $anonymous_type_23194501580ea33e_1#dotsize. = 0;
927 pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. = 1;
928 break;
929 case 'U': /* set page units */
930 switch (bufsizecxx . . $ bufsize.)
931 {
932 case 1:
933 pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units. =
934 pstatecxx . . $ pstate..absolute_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_horizontal_units. =
935 pstatecxx . . $ pstate..relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units. =
936 pstatecxx . . $ pstate..relative_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_vertical_units. =
937 pstatecxx . . $ pstate..horizontal_spacingcxx . . $ $anonymous_type_23194501580ea33e_1#horizontal_spacing. =
938 pstatecxx . . $ pstate..absolute_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_vertical_units. = 3600 / bufcxx . . $ buf.[0];
939 if (pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units. < 720)
940 pstatecxx . . $ pstate..extraskipcxx . . $ $anonymous_type_23194501580ea33e_1#extraskip. = 1;
941 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting units to 1/%d\n",
942 pstatecxx . . $ pstate..absolute_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_horizontal_units.);
943 break;
944 case 5:
945 unit_base = bufcxx . . $ buf.[4] * 256 + bufcxx . . $ buf.[3];
946 pstatecxx . . $ pstate..extraskipcxx . . $ $anonymous_type_23194501580ea33e_1#extraskip.=1;
947 pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.= unit_base / bufcxx . . $ buf.[0];
948 pstatecxx . . $ pstate..relative_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_vertical_units. =
949 pstatecxx . . $ pstate..absolute_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_vertical_units. = unit_base/bufcxx . . $ buf.[1];
950 pstatecxx . . $ pstate..relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units. =
951 pstatecxx . . $ pstate..horizontal_spacingcxx . . $ $anonymous_type_23194501580ea33e_1#horizontal_spacing. =
952 pstatecxx . . $ pstate..absolute_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_horizontal_units. = unit_base / bufcxx . . $ buf.[2];
953 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting page management units to 1/%d\n",
954 pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.);
955 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting vertical units to 1/%d\n",
956 pstatecxx . . $ pstate..relative_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_vertical_units.);
957 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting horizontal units to 1/%d\n",
958 pstatecxx . . $ pstate..relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units.);
959 break;
960 }
961 break;
962 case 'i': /* set printer weave mode */
963 if (bufsizecxx . . $ bufsize. != 1)
964 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Malformed printer weave setting command.\n");
965 else
966 pstatecxx . . $ pstate..printer_weavecxx . . $ $anonymous_type_23194501580ea33e_1#printer_weave. = bufcxx . . $ buf.[0] % 0x30;
967 break;
968 case 'e': /* set dot size */
969 if ((bufsizecxx . . $ bufsize. != 2) || (bufcxx . . $ buf.[0] != 0))
970 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Malformed dotsize setting command.\n");
971 else if (pstatecxx . . $ pstate..got_graphicscxx . . $ $anonymous_type_23194501580ea33e_1#got_graphics.)
972 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Changing dotsize while printing not supported.\n");
973 else
974 {
975 pstatecxx . . $ pstate..dotsizecxx . . $ $anonymous_type_23194501580ea33e_1#dotsize. = bufcxx . . $ buf.[1];
976 if (pstatecxx . . $ pstate..dotsizecxx . . $ $anonymous_type_23194501580ea33e_1#dotsize. > 0x10)
977 pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. = 2;
978 else
979 pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. = 1;
980 }
981 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting dot size to 0x%x (bits %d)\n",
982 pstatecxx . . $ pstate..dotsizecxx . . $ $anonymous_type_23194501580ea33e_1#dotsize., pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.);
983 break;
984 case 'c': /* set page format */
985 if (pagecxx . . $ page.)
986 {
987 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Setting the page format in the middle of printing a page is not supported.\n");
988 break;
989 }
990 switch (bufsizecxx . . $ bufsize.)
991 {
992 case 4:
993 pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin. = bufcxx . . $ buf.[1] * 256 + bufcxx . . $ buf.[0];
994 pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin. = bufcxx . . $ buf.[3] * 256 + bufcxx . . $ buf.[2];
995 break;
996 case 8:
997 pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin. = (bufcxx . . $ buf.[3] << 24) +
998 (bufcxx . . $ buf.[2] << 16) + (bufcxx . . $ buf.[1] << 8) + bufcxx . . $ buf.[0];
999 pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin. = (bufcxx . . $ buf.[7] << 24) +
1000 (bufcxx . . $ buf.[6] << 16) + (bufcxx . . $ buf.[5] << 8) + bufcxx . . $ buf.[4];
1001 break;
1002 default:
1003 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Malformed page format. Ignored.\n");
1004 }
1005 pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition. = 0;
1006 if (pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin. + pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin. > pstatecxx . . $ pstate..page_heightcxx . . $ $anonymous_type_23194501580ea33e_1#page_height.)
1007 pstatecxx . . $ pstate..page_heightcxx . . $ $anonymous_type_23194501580ea33e_1#page_height. = pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin. + pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin.;
1008 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting top margin to %d (%.3f)\n",
1009 pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.,
1010 (double) pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin. / pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.);
1011 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting bottom margin to %d (%.3f)\n",
1012 pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin.,
1013 (double) pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin. / pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.);
1014 pagecxx . . $ page. = (line_typecxx . . $ line_type# **)
1015 stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).((pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin. - pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.) *
1016 sizeof(line_typecxx . . $ line_type# *));
1017 break;
1018 case 'V': /* set absolute vertical position */
1019 i = 0;
1020 switch (bufsizecxx . . $ bufsize.)
1021 {
1022 case 4:
1023 i = (bufcxx . . $ buf.[2] << 16) + (bufcxx . . $ buf.[3]<<24);
1024 /* FALLTHROUGH */
1025 case 2:
1026 i += (bufcxx . . $ buf.[0]) + (256 * bufcxx . . $ buf.[1]);
1027 if (pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin. + i * (pstatecxx . . $ pstate..relative_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_vertical_units. /
1028 pstatecxx . . $ pstate..absolute_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_vertical_units.) >=
1029 pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition.)
1030 pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition. = i * (pstatecxx . . $ pstate..relative_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_vertical_units. /
1031 pstatecxx . . $ pstate..absolute_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_vertical_units.) +
1032 pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.;
1033 else
1034 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Warning: Setting Y position in negative direction ignored\n");
1035 break;
1036 default:
1037 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Malformed absolute vertical position set.\n");
1038 }
1039 if (pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition. > pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin. - pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.)
1040 {
1041 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,
1042 "Warning! Printer head moved past bottom margin. Dumping output and exiting.\n");
1043 ejectcxx . . $ eject. = 1;
1044 }
1045 break;
1046 case 'v': /* set relative vertical position */
1047 i = 0;
1048 switch (bufsizecxx . . $ bufsize.)
1049 {
1050 case 4:
1051 i = (bufcxx . . $ buf.[2] << 16) + (bufcxx . . $ buf.[3] << 24);
1052 /* FALLTHROUGH */
1053 case 2:
1054 i += (bufcxx . . $ buf.[0]) + (256 * bufcxx . . $ buf.[1]);
1055 if (unweavecxx . . $ unweave.)
1056 i = pstatecxx . . $ pstate..nozzlescxx . . $ $anonymous_type_23194501580ea33e_1#nozzles.;
1057 pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition.+=i;
1058 break;
1059 default:
1060 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Malformed relative vertical position set.\n");
1061 }
1062 if (pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition. > pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin. - pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.)
1063 {
1064 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Warning! Printer head moved past bottom margin. Dumping output and exiting.\n");
1065 ejectcxx . . $ eject. = 1;
1066 }
1067 break;
1068 case 'K':
1069 if (bufsizecxx . . $ bufsize.!=2)
1070 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Malformed monochrome/color mode selection.\n");
1071 else if (bufcxx . . $ buf.[0])
1072 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Non-zero first byte in monochrome selection command. Ignored.\n");
1073 else if (bufcxx . . $ buf.[0] > 0x02)
1074 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Unknown color mode 0x%X.\n",bufcxx . . $ buf.[1]);
1075 else
1076 pstatecxx . . $ pstate..monomodecxx . . $ $anonymous_type_23194501580ea33e_1#monomode. = bufcxx . . $ buf.[1];
1077
1078 break;
1079 case 's': /* Set print speed */
1080 case 'm': /* Set paper type */
1081 break;
1082 case 'S': /* set paper dimensions */
1083 switch (bufsizecxx . . $ bufsize.)
1084 {
1085 case 4:
1086 i = (bufcxx . . $ buf.[1] << 16) + bufcxx . . $ buf.[0];
1087 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting paper width to %d (%.3f)\n", i,
1088 (double) i / pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.);
1089 i = (bufcxx . . $ buf.[3] << 16) + bufcxx . . $ buf.[2];
1090 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting paper height to %d (%.3f)\n", i,
1091 (double) i / pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.);
1092 break;
1093 case 8:
1094 i = (bufcxx . . $ buf.[3] << 24) + (bufcxx . . $ buf.[2] << 16) + (bufcxx . . $ buf.[1] << 8) + bufcxx . . $ buf.[0];
1095 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting paper width to %d (%.3f)\n", i,
1096 (double) i / pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.);
1097 i = (bufcxx . . $ buf.[7] << 24) + (bufcxx . . $ buf.[6] << 16) + (bufcxx . . $ buf.[5] << 8) + bufcxx . . $ buf.[4];
1098 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting paper height to %d (%.3f)\n", i,
1099 (double) i / pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.);
1100 break;
1101 default:
1102 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Invalid set paper dimensions command.\n");
1103 }
1104 break;
1105 case 'D':
1106 if (bufsizecxx . . $ bufsize. != 4)
1107 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Malformed set resolution request.\n");
1108 else
1109 {
1110 int res_base = (256 * bufcxx . . $ buf.[1]) + bufcxx . . $ buf.[0];
1111 pstatecxx . . $ pstate..nozzle_separationcxx . . $ $anonymous_type_23194501580ea33e_1#nozzle_separation. =
1112 pstatecxx . . $ pstate..absolute_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_vertical_units. / (res_base / bufcxx . . $ buf.[2]);
1113 pstatecxx . . $ pstate..horizontal_spacingcxx . . $ $anonymous_type_23194501580ea33e_1#horizontal_spacing. = res_base / bufcxx . . $ buf.[3];
1114 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting nozzle separation to %d\n",
1115 pstatecxx . . $ pstate..nozzle_separationcxx . . $ $anonymous_type_23194501580ea33e_1#nozzle_separation.);
1116 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting vertical spacing to 1/%d\n",
1117 res_base / bufcxx . . $ buf.[2]);
1118 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting horizontal spacing to 1/%d\n",
1119 pstatecxx . . $ pstate..horizontal_spacingcxx . . $ $anonymous_type_23194501580ea33e_1#horizontal_spacing.);
1120 }
1121 break;
1122 case 'r': /* select color */
1123 if (bufsizecxx . . $ bufsize.!=2)
1124 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Malformed color selection request.\n");
1125 else
1126 {
1127 shcxx . . $ sh. = 256 * bufcxx . . $ buf.[0] + bufcxx . . $ buf.[1];
1128 if ((bufcxx . . $ buf.[1] > 4) || (bufcxx . . $ buf.[1] == 3) || (bufcxx . . $ buf.[0] > 1) ||
1129 (bufcxx . . $ buf.[0] && (bufcxx . . $ buf.[1]==0)))
1130 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Invalid color 0x%X.\n",shcxx . . $ sh.);
1131 else
1132 pstatecxx . . $ pstate..current_colorcxx . . $ $anonymous_type_23194501580ea33e_1#current_color. = seqcolorcxx . . $ seqcolor(7864480464b09eea).(shcxx . . $ sh.);
1133 }
1134 break;
1135 case '\\': /* set relative horizontal position */
1136 case '/':
1137 i = (bufcxx . . $ buf.[3] << 8) + bufcxx . . $ buf.[2];
1138 if (pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition. + i < 0)
1139 {
1140 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Warning! Attempt to move to -X region ignored.\n");
1141 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!," Command: ESC ( %c %X %X %X %X Original "
1142 "position: %d\n",
1143 chcxx . . $ ch., bufcxx . . $ buf.[0], bufcxx . . $ buf.[1], bufcxx . . $ buf.[2], bufcxx . . $ buf.[3], pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition.);
1144 }
1145 else /* FIXME: Where is the right margin??? */
1146 pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition.+=i;
1147 break;
1148 case '$': /* set absolute horizontal position */
1149 i = (bufcxx . . $ buf.[3] << 24) + (bufcxx . . $ buf.[2] << 16) + (bufcxx . . $ buf.[1] << 8) + bufcxx . . $ buf.[0];
1150 pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition. = i * (pstatecxx . . $ pstate..relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units. /
1151 pstatecxx . . $ pstate..absolute_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_horizontal_units.);
1152 break;
1153 case 'C': /* set page height */
1154 switch (bufsizecxx . . $ bufsize.)
1155 {
1156 case 2:
1157 i = (bufcxx . . $ buf.[1] << 8) | bufcxx . . $ buf.[0];
1158 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting page height to %d (%.3f)\n", i,
1159 (double) i / pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.);
1160 break;
1161 case 4:
1162 i = (bufcxx . . $ buf.[3] << 24) + (bufcxx . . $ buf.[2] << 16) + (bufcxx . . $ buf.[1] << 8) + bufcxx . . $ buf.[0];
1163 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Setting page height to %d (%.3f)\n", i,
1164 (double) i / pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.);
1165 break;
1166 default:
1167 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Invalid set page height command.\n");
1168 }
1169 break;
1170 default:
1171 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Warning: Unknown command ESC ( 0x%X at 0x%08X.\n",
1172 chcxx . . $ ch., global_countercxx . . $ global_counter. - 5 - bufsizecxx . . $ bufsize.);
1173 }
1174 }
1175
1176 static void
1177 parse_escp2_commandcxx . . $ parse_escp2_command(8d4262d45fc644ab).(FILEcxx . . $ FILE# *fp_r)
1178 {
1179 get1cxx . . $ `test/unprint.c:711:9`!("Corrupt file. No command found.\n");
1180 switch (chcxx . . $ ch.)
1181 {
1182 case 1: /* Magic EJL stuff to get USB port working */
1183 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Ignoring EJL commands.\n");
1184 do
1185 {
1186 get1cxx . . $ `test/unprint.c:711:9`!("Error reading EJL commands.\n");
1187 }
1188 while (!ejectcxx . . $ eject. && chcxx . . $ ch. != 0x1b);
1189 if (ejectcxx . . $ eject.)
1190 break;
1191 get1cxx . . $ `test/unprint.c:711:9`!("Expect esc-NULL to close EJL command.\n");
1192 if (chcxx . . $ ch. != 0x40)
1193 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Expect esc-NULL to close EJL command.\n");
1194 break;
1195 case '@': /* initialize printer */
1196 if (pagecxx . . $ page.)
1197 ejectcxx . . $ eject. = 1;
1198 else
1199 {
1200 pstatecxx . . $ pstate..unidirectionalcxx . . $ $anonymous_type_23194501580ea33e_1#unidirectional. = 0;
1201 pstatecxx . . $ pstate..printer_weavecxx . . $ $anonymous_type_23194501580ea33e_1#printer_weave. = 0;
1202 pstatecxx . . $ pstate..dotsizecxx . . $ $anonymous_type_23194501580ea33e_1#dotsize. = 0;
1203 pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp. = 1;
1204 pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units. = 360;
1205 pstatecxx . . $ pstate..relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units. = 180;
1206 pstatecxx . . $ pstate..absolute_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_horizontal_units. = 60;
1207 pstatecxx . . $ pstate..relative_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_vertical_units. = 360;
1208 pstatecxx . . $ pstate..absolute_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_vertical_units. = 360;
1209 pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin. = 120;
1210 pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin. =
1211 pstatecxx . . $ pstate..page_heightcxx . . $ $anonymous_type_23194501580ea33e_1#page_height. = 22 * 360; /* 22 inches is default ??? */
1212 pstatecxx . . $ pstate..monomodecxx . . $ $anonymous_type_23194501580ea33e_1#monomode. = 0;
1213 pstatecxx . . $ pstate..left_edgecxx . . $ $anonymous_type_23194501580ea33e_1#left_edge. = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!;
1214 pstatecxx . . $ pstate..right_edgecxx . . $ $anonymous_type_23194501580ea33e_1#right_edge. = 0;
1215 pstatecxx . . $ pstate..top_edgecxx . . $ $anonymous_type_23194501580ea33e_1#top_edge. = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!;
1216 pstatecxx . . $ pstate..bottom_edgecxx . . $ $anonymous_type_23194501580ea33e_1#bottom_edge. = 0;
1217 }
1218 break;
1219 case 'U': /* turn unidirectional mode on/off */
1220 get1cxx . . $ `test/unprint.c:711:9`!("Error reading unidirectionality.\n");
1221 if ((chcxx . . $ ch. <= 2) || ((chcxx . . $ ch. >= 0x30) && (chcxx . . $ ch. <= 0x32)))
1222 pstatecxx . . $ pstate..unidirectionalcxx . . $ $anonymous_type_23194501580ea33e_1#unidirectional.=chcxx . . $ ch.;
1223 break;
1224 case 'i': /* transfer raster image */
1225 case '.':
1226 pstatecxx . . $ pstate..got_graphicscxx . . $ $anonymous_type_23194501580ea33e_1#got_graphics. = 1;
1227 parse_escp2_datacxx . . $ parse_escp2_data(8d4262d45fc644ab).(fp_r);
1228 break;
1229 case '\\': /* set relative horizontal position */
1230 get2cxx . . $ `test/unprint.c:725:9`!("Error reading relative horizontal position.\n");
1231 if (pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition. + (signed short)shcxx . . $ sh. < 0)
1232 {
1233 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Warning! Move off left of region ignored.\n");
1234 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " Command: ESC %c %X %X "
1235 "Original Position: %d\n",
1236 chcxx . . $ ch., minibufcxx . . $ minibuf.[0], minibufcxx . . $ minibuf.[1], pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition.);
1237 }
1238 else /* FIXME: Where is the right margin??? */
1239 pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition. += (signed short)shcxx . . $ sh.;
1240 break;
1241 case '$': /* set absolute horizontal position */
1242 get2cxx . . $ `test/unprint.c:725:9`!("Error reading absolute horizontal position.\n");
1243 pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition. = shcxx . . $ sh. * (pstatecxx . . $ pstate..relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units. /
1244 pstatecxx . . $ pstate..absolute_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_horizontal_units.);
1245 break;
1246 case 0x0: /* Exit remote mode */
1247 get2cxx . . $ `test/unprint.c:725:9`!("Error exiting remote mode.\n");
1248 break;
1249 case 0x6: /* flush buffers */
1250 /* Woosh. Consider them flushed. */
1251 break;
1252 case 0x19: /* control paper loading */
1253 get1cxx . . $ `test/unprint.c:711:9`!("Error reading paper control byte.\n");
1254 /* paper? */
1255 break;
1256 case 'r': /* select printing color */
1257 get1cxx . . $ `test/unprint.c:711:9`!("Error reading color.\n");
1258 if ((chcxx . . $ ch. <= 4) && (chcxx . . $ ch. != 3))
1259 pstatecxx . . $ pstate..current_colorcxx . . $ $anonymous_type_23194501580ea33e_1#current_color. = seqcolorcxx . . $ seqcolor(7864480464b09eea).(chcxx . . $ ch.);
1260 else
1261 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Invalid color %d.\n", chcxx . . $ ch.);
1262 break;
1263 case '(': /* commands with a payload */
1264 parse_escp2_extendedcxx . . $ parse_escp2_extended(8d4262d45fc644ab).(fp_r);
1265 break;
1266 default:
1267 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Warning: Unknown command ESC 0x%X at 0x%08X.\n",chcxx . . $ ch.,global_countercxx . . $ global_counter.-2);
1268 }
1269 }
1270
1271 void
1272 parse_escp2cxx . . $ parse_escp2(8d4262d45fc644ab).(FILEcxx . . $ FILE# *fp_r)
1273 {
1274 global_countercxx . . $ global_counter. = 0;
1275
1276 while ((!ejectcxx . . $ eject.) && (freadcxx . . $ fread(738fc8ac1d711e58).(&chcxx . . $ ch., 1, 1, fp_r)))
1277 {
1278 global_countercxx . . $ global_counter.++;
1279 switch (chcxx . . $ ch.)
1280 {
1281 case 0xd: /* carriage return */
1282 pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition. = 0;
1283 break;
1284 case 0xc: /* form feed */
1285 ejectcxx . . $ eject. = 1;
1286 break;
1287 case 0x0:
1288 break;
1289 case 0x1b: /* Command! */
1290 parse_escp2_commandcxx . . $ parse_escp2_command(8d4262d45fc644ab).(fp_r);
1291 break;
1292 default:
1293 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,
1294 "Corrupt file? No ESC found. Found: %02X at 0x%08X\n",
1295 chcxx . . $ ch., global_countercxx . . $ global_counter.-1);
1296 break;
1297 }
1298 }
1299 }
1300
1301
1302 /* 'reverse_bit_order'
1303 *
1304 * reverse the bit order in an array of bytes - does not reverse byte order!
1305 */
1306 void
1307 reverse_bit_ordercxx . . $ reverse_bit_order(fc0f0e1646c32816).(unsigned char *buff, int n)
1308 {
1309 int i;
1310 unsigned char a;
1311 if (!n) return; /* nothing to do */
1312
1313 for (i= 0; i<n; i++) {
1314 a= buff[i];
1315 buff[i]=
1316 (a & 0x01) << 7 |
1317 (a & 0x02) << 5 |
1318 (a & 0x04) << 3 |
1319 (a & 0x08) << 1 |
1320 (a & 0x10) >> 1 |
1321 (a & 0x20) >> 3 |
1322 (a & 0x40) >> 5 |
1323 (a & 0x80) >> 7;
1324 }
1325 }
1326
1327 /* 'rle_decode'
1328 *
1329 * run-length-decodes a given buffer of height "n"
1330 * and stores the result in the same buffer
1331 * not exceeding a size of "max" bytes.
1332 */
1333 int
1334 rle_decodecxx . . $ rle_decode(c2394cdaf83c3d9).(unsigned char *inbuf, int n, int max)
1335 {
1336 unsigned char outbuf[1440*3];
1337 signed char *ib= (signed char *)inbuf;
1338 signed char cnt;
1339 int num;
1340 int i= 0, j;
1341 int o= 0;
1342
1343 #ifdef DEBUG_RLE
1344 fprintf(stderr,"input: %d\n",n);
1345 #endif
1346 if (n<=0) return 0;
1347 if (max>1440*3) max= 1440*3; /* FIXME: this can be done much better! */
1348
1349 while (i<n && o<max) {
1350 cnt= ib[i];
1351 if (cnt<0) {
1352 /* cnt identical bytes */
1353 /* fprintf(stderr,"rle 0x%02x = %4d = %4d\n",cnt&0xff,cnt,1-cnt); */
1354 num= 1-cnt;
1355 /* fprintf (stderr,"+%6d ",num); */
1356 for (j=0; j<num && o+j<max; j++) outbuf[o+j]= inbuf[i+1];
1357 o+= num;
1358 i+= 2;
1359 } else {
1360 /* cnt individual bytes */
1361 /* fprintf(stderr,"raw 0x%02x = %4d = %4d\n",cnt&0xff,cnt,cnt + 1); */
1362 num= cnt+1;
1363 /* fprintf (stderr,"*%6d ",num); */
1364 for (j=0; j<num && o+j<max; j++) outbuf[o+j]= inbuf[i+j+1];
1365 o+= num;
1366 i+= num+1;
1367 }
1368 }
1369 if (o>=max) {
1370 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Warning: rle decompression exceeds output buffer.\n");
1371 return 0;
1372 }
1373 /* copy decompressed data to inbuf: */
1374 memsetcxx . . $ memset(d1de1e4fb215f1c6).(inbuf,0,max-1);
1375 memcpycxx . . $ memcpy(cc817cb175f282d).(inbuf,outbuf,o);
1376 #ifdef DEBUG_RLE
1377 fprintf(stderr,"output: %d\n",o);
1378 #endif
1379 return o;
1380 }
1381
1382 void
1383 parse_canoncxx . . $ parse_canon(8d4262d45fc644ab).(FILEcxx . . $ FILE# *fp_r)
1384 {
1385
1386 int m=0;
1387 int currentcolor,currentbpp,density,l_eject;
1388 // int cmdcounter;
1389 int delay_c=0, delay_m=0, delay_y=0, delay_C=0,
1390 delay_M=0, delay_Y=0, delay_K=0, currentdelay=0;
1391
1392 global_countercxx . . $ global_counter.=0;
1393
1394 pagecxx . . $ page.= 0;
1395 l_eject=pstatecxx . . $ pstate..got_graphicscxx . . $ $anonymous_type_23194501580ea33e_1#got_graphics.=currentbpp=currentcolor=density=0;
1396 while ((!l_eject)&&(freadcxx . . $ fread(738fc8ac1d711e58).(&chcxx . . $ ch.,1,1,fp_r))){
1397 global_countercxx . . $ global_counter.++;
1398 if (chcxx . . $ ch.==0xd) { /* carriage return */
1399 pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition.=0;
1400 #ifdef DEBUG_CANON
1401 fprintf(stderr,"< ");
1402 #endif
1403 continue;
1404 }
1405 if (chcxx . . $ ch.==0xc) { /* form feed */
1406 l_eject=1;
1407 continue;
1408 }
1409 if (chcxx . . $ ch.=='B') {
1410 fgetscxx . . $ fgets(efb0aaba7ac866ae).((char *)bufcxx . . $ buf.,sizeof(bufcxx . . $ buf.),fp_r);
1411 global_countercxx . . $ global_counter.+= strlencxx . . $ strlen(751346f8406fd082).((char *)bufcxx . . $ buf.);
1412 if (!strncmpcxx . . $ strncmp(fd278af2f295fa2e).((char *)bufcxx . . $ buf.,"JLSTART",7)) {
1413 while (strncmpcxx . . $ strncmp(fd278af2f295fa2e).((char *)bufcxx . . $ buf.,"BJLEND",6)) {
1414 fgetscxx . . $ fgets(efb0aaba7ac866ae).((char *)bufcxx . . $ buf.,sizeof(bufcxx . . $ buf.),fp_r);
1415 global_countercxx . . $ global_counter.+= strlencxx . . $ strlen(751346f8406fd082).((char *)bufcxx . . $ buf.);
1416 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"got BJL-plaintext-command %s",bufcxx . . $ buf.);
1417 }
1418 } else {
1419 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Error: expected BJLSTART but got B%s",bufcxx . . $ buf.);
1420 }
1421 global_countercxx . . $ global_counter.= ftellcxx . . $ ftell(1dcafcd8ef4c6e6c).(fp_r);
1422 continue;
1423 }
1424 if (chcxx . . $ ch.!=0x1b) {
1425 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Corrupt file? No ESC found. Found: %02X at 0x%08X\n",
1426 chcxx . . $ ch.,global_countercxx . . $ global_counter.-1);
1427 continue;
1428 }
1429 get1cxx . . $ `test/unprint.c:711:9`!("Corrupt file. No command found.\n");
1430 /* fprintf(stderr,"Got a %X.\n",ch); */
1431 switch (chcxx . . $ ch.) {
1432 case '[': /* 0x5b initialize printer */
1433 get1cxx . . $ `test/unprint.c:711:9`!("Error reading CEM-code.\n");
1434 // cmdcounter= global_counter;
1435 get2cxx . . $ `test/unprint.c:725:9`!("Error reading CEM-data size.\n");
1436 getncxx . . $ `test/unprint.c:742:9`!(sh,"Error reading CEM-data.\n");
1437
1438 if (chcxx . . $ ch.=='K') /* 0x4b */ {
1439 if (shcxx . . $ sh.!=2 || bufcxx . . $ buf.[0]!=0x00 ) {
1440 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Error initializing printer with ESC [ K\n");
1441 l_eject=1;
1442 continue;
1443 }
1444 if (pagecxx . . $ page.) {
1445 l_eject=1;
1446 continue;
1447 } else {
1448 pstatecxx . . $ pstate..unidirectionalcxx . . $ $anonymous_type_23194501580ea33e_1#unidirectional.=0;
1449 pstatecxx . . $ pstate..printer_weavecxx . . $ $anonymous_type_23194501580ea33e_1#printer_weave.=0;
1450 pstatecxx . . $ pstate..dotsizecxx . . $ $anonymous_type_23194501580ea33e_1#dotsize.=0;
1451 pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.=1;
1452 pstatecxx . . $ pstate..page_management_unitscxx . . $ $anonymous_type_23194501580ea33e_1#page_management_units.=360;
1453 pstatecxx . . $ pstate..relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units.=180;
1454 pstatecxx . . $ pstate..absolute_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_horizontal_units.=60;
1455 pstatecxx . . $ pstate..relative_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_vertical_units.=360;
1456 pstatecxx . . $ pstate..absolute_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_vertical_units.=360;
1457 pstatecxx . . $ pstate..top_margincxx . . $ $anonymous_type_23194501580ea33e_1#top_margin.=120;
1458 pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin.=
1459 pstatecxx . . $ pstate..page_heightcxx . . $ $anonymous_type_23194501580ea33e_1#page_height.=22*360; /* 22 inches is default ??? */
1460 pstatecxx . . $ pstate..monomodecxx . . $ $anonymous_type_23194501580ea33e_1#monomode.=0;
1461 pstatecxx . . $ pstate..xpositioncxx . . $ $anonymous_type_23194501580ea33e_1#xposition.= 0;
1462 pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition.= 0;
1463 pstatecxx . . $ pstate..left_edgecxx . . $ $anonymous_type_23194501580ea33e_1#left_edge. = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!;
1464 pstatecxx . . $ pstate..right_edgecxx . . $ $anonymous_type_23194501580ea33e_1#right_edge. = 0;
1465 pstatecxx . . $ pstate..top_edgecxx . . $ $anonymous_type_23194501580ea33e_1#top_edge. = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!;
1466 pstatecxx . . $ pstate..bottom_edgecxx . . $ $anonymous_type_23194501580ea33e_1#bottom_edge. = 0;
1467 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"canon: init printer\n");
1468 }
1469 } else {
1470 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Warning: Unknown command ESC %c 0x%X at 0x%08X.\n",
1471 0x5b,chcxx . . $ ch.,global_countercxx . . $ global_counter.);
1472 }
1473 break;
1474
1475 case '@': /* 0x40 */
1476 l_eject=1;
1477 break;
1478
1479 case '(': /* 0x28 */
1480 get1cxx . . $ `test/unprint.c:711:9`!("Corrupt file. Incomplete extended command.\n");
1481 // cmdcounter= global_counter;
1482 get2cxx . . $ `test/unprint.c:725:9`!("Corrupt file. Error reading buffer size.\n");
1483 bufsizecxx . . $ bufsize.=shcxx . . $ sh.;
1484 getncxx . . $ `test/unprint.c:742:9`!(bufsize,"Corrupt file. Error reading data buffer.\n");
1485
1486 switch(chcxx . . $ ch.) {
1487 /* Color Codes:
1488 color Epson1 Epson2 Sequential
1489 Black 0 0 0 K
1490 Magenta 1 1 1 M
1491 Cyan 2 2 2 C
1492 Yellow 4 4 3 Y
1493 L.Mag. 17 257 4 m
1494 L.Cyan 18 258 5 c
1495 L.Yellow NA NA 6 y
1496 */
1497 case 'A': /* 0x41 - transfer graphics data */
1498 switch (*bufcxx . . $ buf.) {
1499 case 'K': currentcolor= 0; currentdelay= delay_K; break;
1500 case 'M': currentcolor= 1; currentdelay= delay_M; break;
1501 case 'C': currentcolor= 2; currentdelay= delay_C; break;
1502 case 'Y': currentcolor= 3; currentdelay= delay_Y; break;
1503 case 'm': currentcolor= 4; currentdelay= delay_m; break;
1504 case 'c': currentcolor= 5; currentdelay= delay_c; break;
1505 case 'y': currentcolor= 6; currentdelay= delay_y; break;
1506 default:
1507 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Error: unsupported color type 0x%02x.\n",*bufcxx . . $ buf.);
1508 /* exit(-1); */
1509 }
1510 pstatecxx . . $ pstate..current_colorcxx . . $ $anonymous_type_23194501580ea33e_1#current_color.= currentcolor;
1511 m= rle_decodecxx . . $ rle_decode(c2394cdaf83c3d9).(bufcxx . . $ buf.+1,bufsizecxx . . $ bufsize.-1,sizeof(bufcxx . . $ buf.)-1);
1512 /* reverse_bit_order(buf+1,m); */
1513 pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition.+= currentdelay;
1514 if (m) update_pagecxx . . $ update_page(65af5a48aab227c6).(bufcxx . . $ buf.+1,m,1,(m*8)/pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.,currentcolor,
1515 pstatecxx . . $ pstate..absolute_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_horizontal_units.);
1516 pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition.-= currentdelay;
1517 #ifdef DEBUG_CANON
1518 fprintf(stderr,"%c:%d>%d ",*buf,sh-1,m);
1519 #endif
1520 break;
1521 case 'a': /* 0x61 - turn something on/off */
1522 break;
1523 case 'b': /* 0x62 - turn something else on/off */
1524 break;
1525 case 'c': /* 0x63 - some information about the print job */
1526 break;
1527 case 'd': /* 0x64 - set resolution */
1528 if (pagecxx . . $ page.) {
1529 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Setting the page format in the middle of printing "
1530 "a page is not supported.\n");
1531 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
1532 }
1533 pstatecxx . . $ pstate..relative_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_vertical_units.=
1534 pstatecxx . . $ pstate..absolute_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_vertical_units.=
1535 bufcxx . . $ buf.[1]+256*bufcxx . . $ buf.[0];
1536 pstatecxx . . $ pstate..relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units.=
1537 pstatecxx . . $ pstate..absolute_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#absolute_horizontal_units.=
1538 bufcxx . . $ buf.[3]+256*bufcxx . . $ buf.[2];
1539 pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin.= pstatecxx . . $ pstate..relative_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_vertical_units.* 22;
1540 /* FIXME: replace with real page height */
1541 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"canon: res is %d x %d dpi\n",
1542 pstatecxx . . $ pstate..relative_horizontal_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_horizontal_units.,
1543 pstatecxx . . $ pstate..relative_vertical_unitscxx . . $ $anonymous_type_23194501580ea33e_1#relative_vertical_units.);
1544
1545 pagecxx . . $ page.= (line_typecxx . . $ line_type# **) stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(pstatecxx . . $ pstate..bottom_margincxx . . $ $anonymous_type_23194501580ea33e_1#bottom_margin. *
1546 sizeof(line_typecxx . . $ line_type# *));
1547 break;
1548 case 'e': /* 0x65 - vertical head movement */
1549 pstatecxx . . $ pstate..ypositioncxx . . $ $anonymous_type_23194501580ea33e_1#yposition.+= (bufcxx . . $ buf.[1]+256*bufcxx . . $ buf.[0]);
1550 #ifdef DEBUG_CANON
1551 fprintf(stderr,"\n");
1552 #endif
1553 break;
1554 case 'l': /* 0x6c - some more information about the print job*/
1555 break;
1556 case 'm': /* 0x6d - used printheads and other things */
1557 break;
1558 case 'p': /* 0x70 - set printable area */
1559 break;
1560 case 'q': /* 0x71 - turn yet something else on/off */
1561 break;
1562 case 't': /* 0x74 - contains bpp and line delaying*/
1563 pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.= bufcxx . . $ buf.[0];
1564 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"canon: using %d bpp\n",pstatecxx . . $ pstate..bppcxx . . $ $anonymous_type_23194501580ea33e_1#bpp.);
1565 if (bufcxx . . $ buf.[1]&0x04) {
1566 delay_y= 0;
1567 delay_m= 0;
1568 delay_c= 0;
1569 delay_Y= 0;
1570 delay_M= delay_Y+112;
1571 delay_C= delay_M+112;
1572 delay_K= delay_C+112;
1573 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"canon: using line delay code\n");
1574 }
1575 break;
1576
1577 default:
1578 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Warning: Unknown command ESC ( 0x%X at 0x%08X.\n",
1579 chcxx . . $ ch.,global_countercxx . . $ global_counter.);
1580 }
1581 break;
1582
1583 default:
1584 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Warning: Unknown command ESC 0x%X at 0x%08X.\n",
1585 chcxx . . $ ch.,global_countercxx . . $ global_counter.-2);
1586 }
1587 }
1588 }
1589
1590 int
1591 maincxx . . $ main(afcd3168fc1188a4).(int argc,char *argv[])
1592 {
1593
1594 int arg;
1595 char *s;
1596 char *UNPRINT;
1597 FILEcxx . . $ FILE# *fp_r, *fp_w;
1598 int force_extraskip = -1;
1599 int no_output = 0;
1600 int all_black = 0;
1601
1602 unweavecxx . . $ unweave. = 0;
1603 pstatecxx . . $ pstate..nozzle_separationcxx . . $ $anonymous_type_23194501580ea33e_1#nozzle_separation. = 6;
1604 fp_r = fp_w = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
1605 for (arg = 1; arg < argc; arg++)
1606 {
1607 if (argv[arg][0] == '-')
1608 {
1609 switch (argv[arg][1])
1610 {
1611 case 0:
1612 if (fp_r)
1613 fp_w = stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!;
1614 else
1615 fp_r = stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!;
1616 break;
1617 case 'h':
1618 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Usage: %s [-m mask] [-n nozzle_sep] [-s extra] [-b] [-q] [-Q] [-M] [-u] [in [out]]\n", argv[0]);
1619 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -m mask Color mask to unprint\n");
1620 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -n nozzle_sep Nozzle separation in vertical units for old printers\n");
1621 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -s extra Extra feed requirement for old printers (typically 1)\n");
1622 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -b Unprint everything in black\n");
1623 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -q Don't produce output\n");
1624 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -Q Assume quadtone inks\n");
1625 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -M Assume MIS quadtone inks\n");
1626 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -u Unweave\n");
1627 return 1;
1628 case 'm':
1629 if (argv[arg][2])
1630 {
1631 s = argv[arg] + 2;
1632 }
1633 else
1634 {
1635 if (argc <= arg + 1)
1636 {
1637 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Missing color mask\n");
1638 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
1639 }
1640 else
1641 {
1642 s = argv[++arg];
1643 }
1644 }
1645 if (!sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(s, "%x", &color_maskcxx . . $ color_mask.))
1646 {
1647 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Error parsing mask\n");
1648 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
1649 }
1650 break;
1651 case 'n':
1652 if (argv[arg][2])
1653 {
1654 s = argv[arg] + 2;
1655 }
1656 else
1657 {
1658 if (argc <= arg + 1)
1659 {
1660 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Missing nozzle separation\n");
1661 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
1662 }
1663 else
1664 {
1665 s = argv[++arg];
1666 }
1667 }
1668 if (!sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(s, "%d", &pstatecxx . . $ pstate..nozzle_separationcxx . . $ $anonymous_type_23194501580ea33e_1#nozzle_separation.))
1669 {
1670 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Error parsing nozzle separation\n");
1671 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
1672 }
1673 break;
1674 case 's':
1675 if (argv[arg][2])
1676 {
1677 s = argv[arg] + 2;
1678 }
1679 else
1680 {
1681 if (argc <= arg + 1)
1682 {
1683 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Missing extra skip\n");
1684 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
1685 }
1686 else
1687 {
1688 s = argv[++arg];
1689 }
1690 }
1691 if (!sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(s, "%d", &force_extraskip))
1692 {
1693 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error parsing extra skip\n");
1694 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
1695 }
1696 break;
1697 case 'b':
1698 all_black = 1;
1699 break;
1700 case 'q':
1701 no_output = 1;
1702 break;
1703 case 'Q':
1704 pstatecxx . . $ pstate..quadtonecxx . . $ $anonymous_type_23194501580ea33e_1#quadtone. = QT_QUADcxx . . $ QT_QUAD.;
1705 break;
1706 case 'M':
1707 pstatecxx . . $ pstate..quadtonecxx . . $ $anonymous_type_23194501580ea33e_1#quadtone. = QT_MIScxx . . $ QT_MIS.;
1708 break;
1709 case 'u':
1710 unweavecxx . . $ unweave. = 1;
1711 break;
1712 }
1713 }
1714 else
1715 {
1716 if (fp_r)
1717 {
1718 if (!(fp_w = fopencxx . . $ fopen(82ec0787cd37e0a3).(argv[arg],"wb")))
1719 {
1720 perrorcxx . . $ perror(85c52e162fed56f9).("Error opening output file");
1721 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
1722 }
1723 }
1724 else
1725 {
1726 if (!(fp_r = fopencxx . . $ fopen(82ec0787cd37e0a3).(argv[arg],"rb")))
1727 {
1728 perrorcxx . . $ perror(85c52e162fed56f9).("Error opening input file");
1729 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
1730 }
1731 }
1732 }
1733 }
1734 if (!fp_r)
1735 fp_r = stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!;
1736 if (!fp_w)
1737 fp_w = stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!;
1738
1739 if (unweavecxx . . $ unweave.) {
1740 pstatecxx . . $ pstate..nozzle_separationcxx . . $ $anonymous_type_23194501580ea33e_1#nozzle_separation. = 1;
1741 }
1742 pstatecxx . . $ pstate..nozzlescxx . . $ $anonymous_type_23194501580ea33e_1#nozzles. = 96;
1743 bufcxx . . $ buf. = stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(256 * 256);
1744 valid_bufsizecxx . . $ valid_bufsize. = 256 * 256;
1745
1746 UNPRINT = getenvcxx . . $ getenv(a8b8e32347182212).("UNPRINT");
1747 if ((UNPRINT)&&(!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(UNPRINT,"canon")))
1748 {
1749 if (force_extraskip > 0)
1750 pstatecxx . . $ pstate..extraskipcxx . . $ $anonymous_type_23194501580ea33e_1#extraskip. = force_extraskip;
1751 else
1752 pstatecxx . . $ pstate..extraskipcxx . . $ $anonymous_type_23194501580ea33e_1#extraskip. = 1;
1753 parse_canoncxx . . $ parse_canon(8d4262d45fc644ab).(fp_r);
1754 }
1755 else
1756 {
1757 if (force_extraskip > 0)
1758 pstatecxx . . $ pstate..extraskipcxx . . $ $anonymous_type_23194501580ea33e_1#extraskip. = force_extraskip;
1759 else
1760 pstatecxx . . $ pstate..extraskipcxx . . $ $anonymous_type_23194501580ea33e_1#extraskip. = 2;
1761 parse_escp2cxx . . $ parse_escp2(8d4262d45fc644ab).(fp_r);
1762 }
1763 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Done reading.\n");
1764 write_outputcxx . . $ write_output(c6135fd8b50e22d5).(fp_w, no_output, all_black);
1765 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp_w);
1766 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Image dump complete.\n");
1767
1768 return(0);
1769 }