Debian Codegraph @

test/bjc-unprint.c

raw symbols SCIP
1 /*
2 * Convert BJC-printjobs to xbm files, one for each color channel
3 *
4 * Copyright 2001 Andy Thaller <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20
21 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`!
22 #include <config.h>cxx . . $ `<file>/config.h`/
23 #endif
24 #include <gutenprint/util.h>cxx . . $ `<file>/include/gutenprint/util.h`/
25 #include <stdio.h>
26 #include <string.h>
27 #include <unistd.h>
28
29 char *efnlccxx . . $ efnlc.= 0,*efnlmcxx . . $ efnlm.= 0,*efnccxx . . $ efnc.= 0,*efnmcxx . . $ efnm.= 0,*efnycxx . . $ efny.= 0,*efnkcxx . . $ efnk.= 0;
30
31 int lc_cntcxx . . $ lc_cnt.= 0,lm_cntcxx . . $ lm_cnt.= 0,ly_cntcxx . . $ ly_cnt.= 0,c_cntcxx . . $ c_cnt.= 0,m_cntcxx . . $ m_cnt.= 0,y_cntcxx . . $ y_cnt.= 0,k_cntcxx . . $ k_cnt.= 0;
32
33 FILEcxx . . $ FILE# *outfilelccxx . . $ outfilelc.= 0;
34 FILEcxx . . $ FILE# *outfilelmcxx . . $ outfilelm.= 0;
35 FILEcxx . . $ FILE# *outfilelycxx . . $ outfilely.= 0;
36 FILEcxx . . $ FILE# *outfileccxx . . $ outfilec.= 0;
37 FILEcxx . . $ FILE# *outfilemcxx . . $ outfilem.= 0;
38 FILEcxx . . $ FILE# *outfileycxx . . $ outfiley.= 0;
39 FILEcxx . . $ FILE# *outfilekcxx . . $ outfilek.= 0;
40
41 int xsizecxx . . $ xsize.,ysizecxx . . $ ysize.,pixcntcxx . . $ pixcnt.;
42
43 typedef struct scanline_t_cxx . . $ scanline_t_# {
44 int sizecxx . . $ scanline_t_#size.;
45 int osizecxx . . $ scanline_t_#osize.;
46 unsigned char *bufcxx . . $ scanline_t_#buf.;
47 int xmincxx . . $ scanline_t_#xmin.;
48 int xmaxcxx . . $ scanline_t_#xmax.;
49 int widthcxx . . $ scanline_t_#width.;
50 int ycxx . . $ scanline_t_#y.;
51 struct scanline_t_cxx . . $ scanline_t_# *nextcxx . . $ scanline_t_#next.;
52 } scanline_tcxx . . $ scanline_t#;
53
54 typedef struct bitimage_t_cxx . . $ bitimage_t_# {
55 unsigned char *bufcxx . . $ bitimage_t_#buf.;
56 int y0cxx . . $ bitimage_t_#y0.;
57 int widthcxx . . $ bitimage_t_#width.;
58 int heightcxx . . $ bitimage_t_#height.;
59 int xmincxx . . $ bitimage_t_#xmin.;
60 int xmaxcxx . . $ bitimage_t_#xmax.;
61 } bitimage_tcxx . . $ bitimage_t#;
62
63 typedef struct level_t_cxx . . $ level_t_# {
64 /* Max number of bits per ink so far known is 8
65 Thus max number of levels is 256 (including value 0)
66 */
67 int levelvalscxx . . $ level_t_#levelvals.[256]; /* number of occurrences of each level */
68 int numlevelscxx . . $ level_t_#numlevels.; /* number of actual levels used */
69 int maxlevelcxx . . $ level_t_#maxlevel.; /* maximum value */
70 int numbitscxx . . $ level_t_#numbits.; /* deduced number bits used for numlevels */
71 } level_tcxx . . $ level_t#;
72
73 bitimage_tcxx . . $ bitimage_t# *bitimage_newcxx . . $ bitimage_new(30d12856ca4d4a85). (void);
74 int last_bitcxx . . $ last_bit(b27dbea426b7b93). (unsigned char i);
75 int first_bitcxx . . $ first_bit(b27dbea426b7b93). (unsigned char i);
76 void rle_infocxx . . $ rle_info(204c1b4edd7133b6). (const unsigned char *inbuf, int n, int *first, int *last,
77 int *width, int *length);
78 int rle_decodecxx . . $ rle_decode(a6b8c9c092b7ec13). (unsigned char *inbuf, int n, unsigned char *outbuf, int max, level_tcxx . . $ level_t# *levels);
79 scanline_tcxx . . $ scanline_t#* scanline_newcxx . . $ scanline_new(f7be530fc632185b). (void);
80 level_tcxx . . $ level_t#* level_newcxx . . $ level_new(27514427a1156c16). (void);
81 int calc_bitscxx . . $ calc_bits(7864480464b09eea).(int numlevels);
82 scanline_tcxx . . $ scanline_t# *scanline_storecxx . . $ scanline_store(1c5bd6b8847417f). (scanline_tcxx . . $ scanline_t# *line, int y, unsigned char *buf,
83 int size);
84 bitimage_tcxx . . $ bitimage_t# *scanlines2bitimagecxx . . $ scanlines2bitimage(44902414626158d5). (scanline_tcxx . . $ scanline_t# *slimg, level_tcxx . . $ level_t# *levels);
85 char convcxx . . $ conv(e6e5e845b55315fc). (char i);
86 void save2xbmcxx . . $ save2xbm(77f76d418212b52b). (const char *filename,char col, bitimage_tcxx . . $ bitimage_t# *img,
87 int xmin, int ymin, int xmax, int ymax);
88 int nextcmdcxx . . $ nextcmd(1e3de8e51be89455). (FILEcxx . . $ FILE# *infile, unsigned char *inbuff, unsigned int *cnt);
89 int processcxx . . $ process(4391f69cd3f47ff3).(FILEcxx . . $ FILE# *infile, scanline_tcxx . . $ scanline_t# *sf[7], int *xmin_, int *xmax_,
90 int *ymin_, int *ymax_, level_tcxx . . $ level_t# *lv[7]);
91
92
93 bitimage_tcxx . . $ bitimage_t# *bitimage_newcxx . . $ bitimage_new(30d12856ca4d4a85).(void)
94 {
95 bitimage_tcxx . . $ bitimage_t# *tmp= (bitimage_tcxx . . $ bitimage_t#*) stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64). (sizeof(bitimage_tcxx . . $ bitimage_t#));
96 tmp->bufcxx . . $ bitimage_t_#buf.= 0;
97 tmp->y0cxx . . $ bitimage_t_#y0.= 0;
98 tmp->widthcxx . . $ bitimage_t_#width.= 0;
99 tmp->heightcxx . . $ bitimage_t_#height.= 0;
100 tmp->xmincxx . . $ bitimage_t_#xmin.= 0;
101 tmp->xmaxcxx . . $ bitimage_t_#xmax.= 0;
102 return tmp;
103 }
104
105 int last_bitcxx . . $ last_bit(b27dbea426b7b93).(unsigned char i) {
106 if (i & 0x1) return 0;
107 if (i & 0x2) return 1;
108 if (i & 0x4) return 2;
109 if (i & 0x8) return 3;
110 if (i & 0x10) return 4;
111 if (i & 0x20) return 5;
112 if (i & 0x40) return 6;
113 if (i & 0x80) return 7;
114 return 0;
115 }
116
117 int first_bitcxx . . $ first_bit(b27dbea426b7b93).(unsigned char i) {
118 if (i & 0x80) return 7;
119 if (i & 0x40) return 6;
120 if (i & 0x20) return 5;
121 if (i & 0x10) return 4;
122 if (i & 0x8) return 3;
123 if (i & 0x4) return 2;
124 if (i & 0x2) return 1;
125 if (i & 0x1) return 0;
126 return 0;
127 }
128
129 void rle_infocxx . . $ rle_info(204c1b4edd7133b6).(const unsigned char *inbuf, int n, int *first, int *last, int *width, int *length)
130 {
131 const char *ib= (const char *)inbuf;
132 char cnt;
133 int o= 0;
134 int i=0,j,num,f=-1,l=0;
135
136 *first= 0;
137 *last= 0;
138 *width= 0;
139
140 if (n<=0) return;
141 while (i<n) {
142 cnt= ib[i];
143 if (cnt<0) {
144 num= 1-cnt;
145 if (inbuf[i+1]) {
146 if (f<0) f=o*8 + first_bitcxx . . $ first_bit(b27dbea426b7b93).(inbuf[i+1]);
147 l= o*8 + last_bitcxx . . $ last_bit(b27dbea426b7b93).(inbuf[i+1]);
148 }
149 o+= num;
150 i+= 2;
151 } else {
152 num= cnt+1;
153 for (j=0; j<num; j++) {
154 if (inbuf[i+j+1]) {
155 if (f<0) f=(o+j)*8 + first_bitcxx . . $ first_bit(b27dbea426b7b93).(inbuf[i+j+1]);
156 l= o*8 + last_bitcxx . . $ last_bit(b27dbea426b7b93).(inbuf[i+j+1]);
157 }
158 }
159 o+= num;
160 i+= num+1;
161 }
162 }
163
164 if (first) *first= f;
165 if (last) *last= l;
166 if (length) *length= o;
167 if (width) *width= (f<0) ? 0 : l-f+1;
168 }
169
170 /* n is the size of the scanline */
171 int rle_decodecxx . . $ rle_decode(a6b8c9c092b7ec13).(unsigned char *inbuf, int n, unsigned char *outbuf,int max, level_tcxx . . $ level_t# *levels)
172 {
173 const char *ib= (const char *)inbuf; /* input scanline */
174 char cnt;
175 int o= 0;
176 int i=0,j,num;
177
178 (void)max;
179
180 /* Results of the decoding are in the output buffer already.
181 We want to organize the decoded numbers to see
182 the total number of levels, and their values.
183 */
184 /*fprintf(stderr,"rle_decode: decoding scanline\n");*/
185 if (n<=0) return 0;
186 while (i<n) {
187 cnt= ib[i];
188 if (cnt<0) {
189 num= 1-cnt;
190 /*for (j=0; j<num; j++) outbuf[o+j]=inbuf[i+1];*/
191 for (j=0; j<num; j++) {
192 outbuf[o+j]=inbuf[i+1];
193 /*fprintf(stderr," %d ",outbuf[o+j]);*/
194 levels->levelvalscxx . . $ level_t_#levelvals.[outbuf[o+j]] += 1;
195 if ( outbuf[o+j] > levels->maxlevelcxx . . $ level_t_#maxlevel. ) levels->maxlevelcxx . . $ level_t_#maxlevel. = outbuf[o+j];
196 }
197 o+= num;
198 i+= 2;
199 } else {
200 num= cnt+1;
201 /* for (j=0; j<num; j++) outbuf[o+j]=inbuf[i+j+1]; */
202 for (j=0; j<num; j++) {
203 outbuf[o+j]=inbuf[i+j+1];
204 /*fprintf(stderr," %d ",outbuf[o+j]);*/
205 levels->levelvalscxx . . $ level_t_#levelvals.[outbuf[o+j]] += 1;
206 if ( outbuf[o+j] > levels->maxlevelcxx . . $ level_t_#maxlevel. ) levels->maxlevelcxx . . $ level_t_#maxlevel. = outbuf[o+j];
207 }
208 o+= num;
209 i+= num+1;
210 }
211 }
212 /*fprintf(stderr,"\n");*/
213 return o;
214 }
215
216 scanline_tcxx . . $ scanline_t#* scanline_newcxx . . $ scanline_new(f7be530fc632185b).(void)
217 {
218 scanline_tcxx . . $ scanline_t#* tmp= (scanline_tcxx . . $ scanline_t#*) stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64). (sizeof(scanline_tcxx . . $ scanline_t#));
219 tmp->sizecxx . . $ scanline_t_#size.= 0;
220 tmp->osizecxx . . $ scanline_t_#osize.= 0;
221 tmp->bufcxx . . $ scanline_t_#buf.= 0;
222 tmp->xmincxx . . $ scanline_t_#xmin.= 0;
223 tmp->xmaxcxx . . $ scanline_t_#xmax.= 0;
224 tmp->widthcxx . . $ scanline_t_#width.= 0;
225 tmp->ycxx . . $ scanline_t_#y.= 0;
226 tmp->nextcxx . . $ scanline_t_#next.= 0;
227 return tmp;
228 }
229
230 level_tcxx . . $ level_t# *level_newcxx . . $ level_new(27514427a1156c16).(void)
231 {
232 int i;
233 level_tcxx . . $ level_t#* tmp = (level_tcxx . . $ level_t#*) stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64). (sizeof(level_tcxx . . $ level_t#));
234 tmp->numlevelscxx . . $ level_t_#numlevels.=0;
235 tmp->maxlevelcxx . . $ level_t_#maxlevel.=0;
236 tmp->numbitscxx . . $ level_t_#numbits.=0;
237 for (i=0; i<256; i++) tmp->levelvalscxx . . $ level_t_#levelvals.[i]=0;
238 return tmp;
239 }
240
241 int calc_bitscxx . . $ calc_bits(7864480464b09eea).(int numlevels) {
242 if (numlevels > 128) return 8;
243 else if (numlevels > 64) return 7;
244 else if (numlevels > 32) return 6;
245 else if (numlevels > 16) return 5;
246 else if (numlevels > 8) return 4;
247 else if (numlevels > 4) return 3;
248 else if (numlevels > 2) return 2;
249 else if (numlevels > 1) return 1;
250 else return 0;
251 }
252
253 scanline_tcxx . . $ scanline_t# *scanline_storecxx . . $ scanline_store(1c5bd6b8847417f).(scanline_tcxx . . $ scanline_t# *line, int y, unsigned char *buf, int size) {
254 if (!line && !(line= scanline_newcxx . . $ scanline_new(f7be530fc632185b).()))
255 return 0;
256 line->sizecxx . . $ scanline_t_#size.= size; /* from cnt in nextcmd function */
257 line->bufcxx . . $ scanline_t_#buf.= (unsigned char *) stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64). (size);
258 memcpycxx . . $ memcpy(cc817cb175f282d).(line->bufcxx . . $ scanline_t_#buf.,buf,size);
259 rle_infocxx . . $ rle_info(204c1b4edd7133b6).(buf,size,&line->xmincxx . . $ scanline_t_#xmin.,&line->xmaxcxx . . $ scanline_t_#xmax.,&line->widthcxx . . $ scanline_t_#width.,&line->osizecxx . . $ scanline_t_#osize.);
260 /*fprintf(stderr,"Scanline size %d, xmin %d, xmax %d, width %d\n",size,line->xmin,line->xmax,line->width);*/
261 line->ycxx . . $ scanline_t_#y.= y;
262 return line;
263 }
264
265 bitimage_tcxx . . $ bitimage_t# *scanlines2bitimagecxx . . $ scanlines2bitimage(44902414626158d5).(scanline_tcxx . . $ scanline_t# *slimg, level_tcxx . . $ level_t# *level)
266 {
267 bitimage_tcxx . . $ bitimage_t# *img= 0;
268 scanline_tcxx . . $ scanline_t# *sl;
269 int w= 0;
270 int y0= -1;
271 int y= 0;
272 int h,i;
273
274 for (sl=slimg; sl!=0; sl=sl->nextcxx . . $ scanline_t_#next.) {
275 if (sl->widthcxx . . $ scanline_t_#width.) {
276 if (w<sl->osizecxx . . $ scanline_t_#osize.) w= sl->osizecxx . . $ scanline_t_#osize.;
277 if (y0<0) y0= sl->ycxx . . $ scanline_t_#y.;
278 y= sl->ycxx . . $ scanline_t_#y.;
279 }
280 }
281 h= y-y0+1;
282
283 if ((!w) || (!h))
284 return 0;
285
286 img= bitimage_newcxx . . $ bitimage_new(30d12856ca4d4a85).();
287
288 img->bufcxx . . $ bitimage_t_#buf.= (unsigned char*) stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(h*w);
289 memsetcxx . . $ memset(d1de1e4fb215f1c6).(img->bufcxx . . $ bitimage_t_#buf.,0,h*w);
290 img->widthcxx . . $ bitimage_t_#width.= w;
291 img->heightcxx . . $ bitimage_t_#height.= h;
292 img->y0cxx . . $ bitimage_t_#y0.= y0;
293
294 for (sl=slimg; sl!=0; sl=sl->nextcxx . . $ scanline_t_#next.) {
295 y= sl->ycxx . . $ scanline_t_#y.- y0;
296 if ((y>=0) && (y<h)) {
297 rle_decodecxx . . $ rle_decode(a6b8c9c092b7ec13).(sl->bufcxx . . $ scanline_t_#buf.,sl->sizecxx . . $ scanline_t_#size.,img->bufcxx . . $ bitimage_t_#buf.+y*w,w,level);
298 }
299 }
300
301 /* print out stats of levels */
302 for (i=0;i<256;i++) {
303 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"level %d: %d\n",i,level->levelvalscxx . . $ level_t_#levelvals.[i]);
304 if (level->levelvalscxx . . $ level_t_#levelvals.[i] > 0) level->numlevelscxx . . $ level_t_#numlevels. += 1;
305 }
306 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"numlevels: %d\n",level->numlevelscxx . . $ level_t_#numlevels.);
307 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"maxlevel: %d\n",level->maxlevelcxx . . $ level_t_#maxlevel.);
308 level->numbitscxx . . $ level_t_#numbits. = calc_bitscxx . . $ calc_bits(7864480464b09eea).(level->maxlevelcxx . . $ level_t_#maxlevel.);
309 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"numbits: %d\n",level->numbitscxx . . $ level_t_#numbits.);
310
311 return img;
312 }
313
314 char convcxx . . $ conv(e6e5e845b55315fc).(char i) {
315 char o= 0;
316 if (i & 0x80) o|=0x01;
317 if (i & 0x40) o|=0x02;
318 if (i & 0x20) o|=0x04;
319 if (i & 0x10) o|=0x08;
320 if (i & 0x08) o|=0x10;
321 if (i & 0x04) o|=0x20;
322 if (i & 0x02) o|=0x40;
323 if (i & 0x01) o|=0x80;
324 return o;
325 }
326
327 void save2xbmcxx . . $ save2xbm(77f76d418212b52b).(const char *filename,char col, bitimage_tcxx . . $ bitimage_t# *img,
328 int xmin, int ymin, int xmax, int ymax)
329 {
330 char *outfilename= (char*) stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(strlencxx . . $ strlen(751346f8406fd082).(filename)+16);
331 FILEcxx . . $ FILE# *o;
332 int i,j,k,i0,i1,j0,j1,w,h;
333
334 if (!img) return;
335
336 if (col)
337 sprintfcxx . . $ sprintf(26c8642d26409d6d).(outfilename,"%s_%c.xbm",filename,col);
338 else
339 sprintfcxx . . $ sprintf(26c8642d26409d6d).(outfilename,"%s.xbm",filename);
340
341 if (!(o= fopencxx . . $ fopen(82ec0787cd37e0a3).(outfilename,"w"))) {
342 stp_freecxx . . $ stp_free(5d22bdacc48458e8).(outfilename);
343 return;
344 }
345
346 i0= (ymin>0) ? ymin-img->y0cxx . . $ bitimage_t_#y0. : 0;
347 i1= (ymax>0) ? ymax-img->y0cxx . . $ bitimage_t_#y0. : img->heightcxx . . $ bitimage_t_#height.;
348 j0= (xmin>0 && xmin<img->widthcxx . . $ bitimage_t_#width.*8) ? xmin/8 : 0;
349 j1= (xmax>0 && xmax<img->widthcxx . . $ bitimage_t_#width.*8) ? xmax/8 : img->widthcxx . . $ bitimage_t_#width.-1;
350
351 w= j1-j0+1;
352 h= i1-i0;
353
354 if (col)
355 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(o,"#define %s_%c_width %d\n#define %s_%c_height %d\nstatic char %s_%c_bits[] = {",
356 outfilename,col,w*8,
357 outfilename,col,h,
358 outfilename,col);
359 else
360 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(o,"#define %s_width %d\n#define %s_height %d\nstatic char %s_bits[] = {",
361 outfilename,w*8,
362 outfilename,h,
363 outfilename);
364
365 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"%d %d %d %d\n",i0,h,j0,w);
366 for (i=i0,k=0; i<i1; i++) {
367 for (j=j0; j<=j1; j++) {
368 if (k%16 == 0) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(o,"\n");
369 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(o,"0x%02x, ",(i>=0 && i<img->heightcxx . . $ bitimage_t_#height.)? convcxx . . $ conv(e6e5e845b55315fc).(img->bufcxx . . $ bitimage_t_#buf.[i*img->widthcxx . . $ bitimage_t_#width.+j])&0xff : 0);
370 k++;
371 }
372 }
373
374 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(o," 0x00 };\n");
375
376 fclosecxx . . $ fclose(89bc1efcdac0ca22).(o);
377 }
378
379 int nextcmdcxx . . $ nextcmd(1e3de8e51be89455).(FILEcxx . . $ FILE# *infile,unsigned char *inbuff,unsigned int *cnt)
380 {
381 unsigned char c1=0,c2=0;
382 int c;
383 int cmd;
384
385 while (!feofcxx . . $ feof(89bc1efcdac0ca22).(infile) && c1!=0x1b && (c2!=0x28 && c2!=0x5b)) {
386 c1=c2; c2=fgetccxx . . $ fgetc(89bc1efcdac0ca22).(infile);
387 }
388 if (feofcxx . . $ feof(89bc1efcdac0ca22).(infile)) return 0;
389
390 cmd=fgetccxx . . $ fgetc(89bc1efcdac0ca22).(infile);
391 if (feofcxx . . $ feof(89bc1efcdac0ca22).(infile)) return 0;
392
393 c1= fgetccxx . . $ fgetc(89bc1efcdac0ca22).(infile);
394 if (feofcxx . . $ feof(89bc1efcdac0ca22).(infile)) return 0;
395 c2= fgetccxx . . $ fgetc(89bc1efcdac0ca22).(infile);
396 if (feofcxx . . $ feof(89bc1efcdac0ca22).(infile)) return 0;
397
398 /* 2 bytes: seems to be the size+1 of one scanline in cases where command is a scanline */
399 *cnt= c1+256*c2;
400
401 if ((c=freadcxx . . $ fread(738fc8ac1d711e58).(inbuff,1,*cnt,infile) != *cnt)) {
402 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"read error for 0x%02x - not enough data (%d/%d)!\n",cmd,
403 c,*cnt);
404 return 0;
405 }
406
407 return cmd;
408 }
409
410 int processcxx . . $ process(4391f69cd3f47ff3).(FILEcxx . . $ FILE# *infile,scanline_tcxx . . $ scanline_t# *sf[7],int *xmin_,int *xmax_,int *ymin_,int *ymax_,level_tcxx . . $ level_t# *lv[7])
411 {
412 unsigned char inbuff[65540];
413 scanline_tcxx . . $ scanline_t# *sl[7], *nsl;
414
415 int xres,yres;
416 int xmin=1000000,xmax=0,ymin=-1,ymax=0,width=0;
417 int col=0;
418 int line=0;
419 int i;
420 unsigned int cnt;
421 int cmd;
422
423 for (i=0; i<7; i++) sf[i]= sl[i]= 0;
424
425 for (i=0; i<7; i++) lv[i] = level_newcxx . . $ level_new(27514427a1156c16).();
426
427 if (!infile) return 0;
428 fseekcxx . . $ fseek(543fae30d249f6b1).(infile,0,SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!);
429
430 while ((cmd= nextcmdcxx . . $ nextcmd(1e3de8e51be89455).(infile,inbuff,&cnt))) {
431 switch(cmd) {
432 case 0x64:
433 yres=inbuff[0]*256+inbuff[1];
434 xres=inbuff[2]*256+inbuff[3];
435 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"res=%dx%ddpi\n",xres,yres);
436 break;
437 case 0x65:
438 line+=(inbuff[0]*256+inbuff[1]);
439 break;
440 case 0x41:
441 switch(inbuff[0]) {
442 case 0x4b: col= 0; break; /* black */
443 case 0x59: col= 1; break; /* yellow */
444 case 0x4d: col= 2; break; /* magenta */
445 case 0x43: col= 3; break; /* cyan */
446 case 0x79: col= 4; break; /* lightyellow */
447 case 0x6d: col= 5; break; /* lightmagenta */
448 case 0x63: col= 6; break; /* lightcyan */
449 default:
450 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"unknown color component 0x%02x\n",inbuff[0]);
451 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
452 }
453
454 nsl= scanline_storecxx . . $ scanline_store(1c5bd6b8847417f).(0,line,inbuff+1,cnt-1);
455
456 if (nsl) {
457 if (nsl->widthcxx . . $ scanline_t_#width.) {
458 if (ymin<0) ymin=line;
459 ymax=line;
460 if (nsl->xmincxx . . $ scanline_t_#xmin.<xmin) xmin=nsl->xmincxx . . $ scanline_t_#xmin.;
461 if (nsl->xmaxcxx . . $ scanline_t_#xmax.>xmax) xmax=nsl->xmaxcxx . . $ scanline_t_#xmax.;
462 if (nsl->widthcxx . . $ scanline_t_#width.>width) width=nsl->widthcxx . . $ scanline_t_#width.;
463 if (!sf[col])
464 sf[col]=nsl;
465 else
466 sl[col]->nextcxx . . $ scanline_t_#next.= nsl;
467 sl[col]= nsl;
468 } else {
469 stp_freecxx . . $ stp_free(5d22bdacc48458e8). (nsl);
470 nsl= 0;
471 }
472
473 if (fgetccxx . . $ fgetc(89bc1efcdac0ca22).(infile)!=0x0d) {
474 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"COLOR LINE NOT TERMINATED BY 0x0d @ %lx!!\n",
475 ftellcxx . . $ ftell(1dcafcd8ef4c6e6c).(infile));
476 }
477 }
478 break;
479 case 0x62:
480 break;
481 default:
482 ;
483 }
484 }
485
486 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"size=%d..%d:%d..%d = %dx%d\n",xmin,xmax,ymin,ymax,width,ymax-ymin+1);
487
488 *xmin_= xmin;
489 *xmax_= xmax;
490 *ymin_= ymin;
491 *ymax_= ymax;
492
493 return 1;
494 }
495
496 /*
497 const char *fbin(char b) {
498 static char bf[9];
499
500 bf[0]= (b & 0x80) ? '1' : '0';
501 bf[1]= (b & 0x40) ? '1' : '0';
502 bf[2]= (b & 0x20) ? '1' : '0';
503 bf[3]= (b & 0x10) ? '1' : '0';
504 bf[4]= (b & 0x08) ? '1' : '0';
505 bf[5]= (b & 0x04) ? '1' : '0';
506 bf[6]= (b & 0x02) ? '1' : '0';
507 bf[7]= (b & 0x01) ? '1' : '0';
508 bf[8]=0;
509 return bf;
510 }
511 */
512
513 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv)
514 {
515 char *infilename= 0, *outfilename=0;
516 FILEcxx . . $ FILE# *infile= 0;
517 scanline_tcxx . . $ scanline_t# *scanlines[7];
518 char colname[7] = { 'K', 'Y', 'M', 'C', 'y', 'm', 'c' };
519 level_tcxx . . $ level_t# *levels[7];
520 int xmin,xmax;
521 int ymin,ymax;
522
523 if (argc>1) {
524 if (argc>2)
525 outfilename= argv[2];
526 else
527 outfilename= argv[1];
528
529 infilename= argv[1];
530 infile= fopencxx . . $ fopen(82ec0787cd37e0a3).(infilename,"r");
531
532 xsizecxx . . $ xsize.=ysizecxx . . $ ysize.=0;
533
534 processcxx . . $ process(4391f69cd3f47ff3).(infile,scanlines,&xmin,&xmax,&ymin,&ymax,levels);
535
536 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Color %c\n",colname[0]);
537 save2xbmcxx . . $ save2xbm(77f76d418212b52b).(outfilename,colname[0],scanlines2bitimagecxx . . $ scanlines2bitimage(44902414626158d5).(scanlines[0],levels[0]),xmin,ymin,xmax,ymax);
538 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Color %c\n",colname[1]);
539 save2xbmcxx . . $ save2xbm(77f76d418212b52b).(outfilename,colname[1],scanlines2bitimagecxx . . $ scanlines2bitimage(44902414626158d5).(scanlines[1],levels[1]),xmin,ymin,xmax,ymax);
540 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Color %c\n",colname[2]);
541 save2xbmcxx . . $ save2xbm(77f76d418212b52b).(outfilename,colname[2],scanlines2bitimagecxx . . $ scanlines2bitimage(44902414626158d5).(scanlines[2],levels[2]),xmin,ymin,xmax,ymax);
542 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Color %c\n",colname[3]);
543 save2xbmcxx . . $ save2xbm(77f76d418212b52b).(outfilename,colname[3],scanlines2bitimagecxx . . $ scanlines2bitimage(44902414626158d5).(scanlines[3],levels[3]),xmin,ymin,xmax,ymax);
544 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Color %c\n",colname[4]);
545 save2xbmcxx . . $ save2xbm(77f76d418212b52b).(outfilename,colname[4],scanlines2bitimagecxx . . $ scanlines2bitimage(44902414626158d5).(scanlines[4],levels[4]),xmin,ymin,xmax,ymax);
546 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Color %c\n",colname[5]);
547 save2xbmcxx . . $ save2xbm(77f76d418212b52b).(outfilename,colname[5],scanlines2bitimagecxx . . $ scanlines2bitimage(44902414626158d5).(scanlines[5],levels[5]),xmin,ymin,xmax,ymax);
548 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Color %c\n",colname[6]);
549 save2xbmcxx . . $ save2xbm(77f76d418212b52b).(outfilename,colname[6],scanlines2bitimagecxx . . $ scanlines2bitimage(44902414626158d5).(scanlines[6],levels[6]),xmin,ymin,xmax,ymax);
550
551 } else {
552 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"\nusage: bjc-unprint INFILE [OUTFILE]\n\n");
553 }
554
555 return 0;
556 }