From aedf3e93e811c6c9d504274172861d266e1c5c97 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Mon, 19 Jun 2017 08:38:07 +0200 Subject: New upstream version 5.2.13~pre1 --- test/pixma_parse.c | 181 ++++++++++++++++++++++++++++------------------------- 1 file changed, 94 insertions(+), 87 deletions(-) (limited to 'test/pixma_parse.c') diff --git a/test/pixma_parse.c b/test/pixma_parse.c index ec79c5a..872a7cd 100644 --- a/test/pixma_parse.c +++ b/test/pixma_parse.c @@ -26,7 +26,7 @@ #define MAX_COLORS 36 /* was: 8 maximum number of Colors: CMYKcmyk */ -#define DEBUG 0 /* 1 for debugging only */ +#define DEBUG 0 /* 1 for debugging only: all output goes to stderr */ #include "pixma_parse.h" @@ -35,7 +35,8 @@ 2. keep iP6700 workaround, but check what happens with the real printer. */ - +/* redirection for debug output */ +FILE* fout; /* nextcmd(): find a command in a printjob * commands in the printjob start with either ESC[ or ESC( @@ -67,13 +68,13 @@ static int nextcmd( FILE *infile,unsigned char* cmd,unsigned char *buf, unsigned /* start */ startxml=680-1; fread(buf,1,startxml,infile); /* 1 less than 680 */ - fprintf(stderr,"nextcmd: read starting XML %d %d\n", *xml_read, startxml); + fprintf(fout,"nextcmd: read starting XML %d %d\n", *xml_read, startxml); *xml_read=1; }else if (*xml_read==1) { /* end */ endxml=263-1; fread(buf,1,endxml,infile); /* 1 less than 263*/ - fprintf(stderr,"nextcmd: read ending XML %d %d\n", *xml_read, endxml); + fprintf(fout,"nextcmd: read ending XML %d %d\n", *xml_read, endxml); *xml_read=2; } /* no alternatives yet */ @@ -91,20 +92,20 @@ static int nextcmd( FILE *infile,unsigned char* cmd,unsigned char *buf, unsigned if (*cnt){ /* read arguments */ unsigned int read; if((read=fread(buf,1,*cnt,infile)) != *cnt){ - fprintf(stderr,"nextcmd: read error - not enough data %d %d\n", read, *cnt); + fprintf(fout,"nextcmd: read error - not enough data %d %d\n", read, *cnt); return -1; } } return 0; }else if(c2 == '@'){ /* ESC@ */ - fprintf(stderr,"ESC @ Return to neutral mode\n"); + fprintf(fout,"ESC @ Return to neutral mode\n"); } else { - fprintf(stderr,"unknown byte following ESC %x \n",c2); + fprintf(fout,"unknown byte following ESC %x \n",c2); } }else if(c1==0x0c){ /* Form Feed */ - fprintf(stderr,"-->Form Feed\n"); + fprintf(fout,"-->Form Feed\n"); }else{ - fprintf(stderr,"UNKNOWN BYTE 0x%x @ %lu\n",c1,ftell(infile)); + fprintf(fout,"UNKNOWN BYTE 0x%x @ %lu\n",c1,ftell(infile)); } } return -1; @@ -140,7 +141,7 @@ static int valid_color(unsigned char color){ for(i=0;i ignoring %i bytes\n",color_name,color_name,color_name, len); } */ if (DEBUG) { - fprintf(stderr,"DEBUG enter Raster len=%i,color=%c\n",len,color_name); + fprintf(fout,"DEBUG enter Raster len=%i,color=%c\n",len,color_name); } /* decode pack bits */ @@ -453,9 +454,9 @@ static void write_line(image_t*img,FILE* fp,int pos_y){ /*if (img->color[i].value != 0) printf("what pixel values for color %d: %x\n",i,img->color[i].value);*/ if (i>7){ - fprintf(stderr,"getting pixel values for color %d\n",i);/* only going 0 1 2 4 5 --- missing i>7 bugger! */ + fprintf(fout,"getting pixel values for color %d\n",i);/* only going 0 1 2 4 5 --- missing i>7 bugger! */ /*img->color[i].value = 1;*/ - fprintf(stderr,"color %c has value %d\n",img->color[i].name,img->color[i].value); + fprintf(fout,"color %c has value %d\n",img->color[i].name,img->color[i].value); } /* add 0x80 to colors where 0x80 is seen added in inkset */ } @@ -516,7 +517,7 @@ static void write_line(image_t*img,FILE* fp,int pos_y){ /* output line */ if((written = fwrite(line,img->width,3,fp)) != 3) { - fprintf(stderr,"fwrite failed %u vs %u\n",written,img->width*3); + fprintf(fout,"fwrite failed %u vs %u\n",written,img->width*3); } free(line); } @@ -599,7 +600,7 @@ static int process(FILE* in, FILE* out,int verbose,unsigned int maxw,unsigned in unsigned int xml_read; xml_read=0; - fprintf(stderr,"------- parsing the printjob -------\n"); + fprintf(fout,"------- parsing the printjob -------\n"); while(!returnv && !feof(in)){ unsigned char cmd; unsigned int cnt = 0; @@ -607,53 +608,53 @@ static int process(FILE* in, FILE* out,int verbose,unsigned int maxw,unsigned in break; switch(cmd){ case 'c': - fprintf(stderr,"ESC (c set media (len=%i):\n",cnt); - fprintf(stderr," model id %x bw %x",buf[0]>> 4,buf[0]&0xf); - fprintf(stderr," media %x",buf[1]); - fprintf(stderr," direction %x quality %x\n",(buf[2]>>4)&3 ,buf[2]&0xf); + fprintf(fout,"ESC (c set media (len=%i):\n",cnt); + fprintf(fout," model id %x bw %x",buf[0]>> 4,buf[0]&0xf); + fprintf(fout," media %x",buf[1]); + fprintf(fout," direction %x quality %x\n",(buf[2]>>4)&3 ,buf[2]&0xf); break; case 'K': if(buf[1]==0x1f){ - fprintf(stderr,"ESC [K go to command mode\n"); + fprintf(fout,"ESC [K go to command mode\n"); do{ fgets((char*)buf,0xFFFF,in); - fprintf(stderr," %s",buf); + fprintf(fout," %s",buf); }while(strcmp((char*)buf,"BJLEND\n")); }else if(cnt == 2 && buf[1]==0x0f){ - fprintf(stderr,"ESC [K reset printer\n"); + fprintf(fout,"ESC [K reset printer\n"); img->width=0; img->height=0; }else{ - fprintf(stderr,"ESC [K unsupported param (len=%i): %x\n",cnt,buf[1]); + fprintf(fout,"ESC [K unsupported param (len=%i): %x\n",cnt,buf[1]); } break; case 'b': - fprintf(stderr,"ESC (b set data compression (len=%i): %x\n",cnt,buf[0]); + fprintf(fout,"ESC (b set data compression (len=%i): %x\n",cnt,buf[0]); break; case 'I': - fprintf(stderr,"ESC (I select data transmission (len=%i): ",cnt); - if(buf[0]==0)fprintf(stderr,"default"); - else if(buf[0]==1)fprintf(stderr,"multi raster"); - else fprintf(stderr,"unknown 0x%x %i",buf[0],buf[0]); - fprintf(stderr,"\n"); + fprintf(fout,"ESC (I select data transmission (len=%i): ",cnt); + if(buf[0]==0)fprintf(fout,"default"); + else if(buf[0]==1)fprintf(fout,"multi raster"); + else fprintf(fout,"unknown 0x%x %i",buf[0],buf[0]); + fprintf(fout,"\n"); break; case 'l': - fprintf(stderr,"ESC (l select paper loading (len=%i):\n",cnt); - fprintf(stderr," model id 0x%x ",buf[0]>>4); - fprintf(stderr," source 0x%x",buf[0]&15); + fprintf(fout,"ESC (l select paper loading (len=%i):\n",cnt); + fprintf(fout," model id 0x%x ",buf[0]>>4); + fprintf(fout," source 0x%x",buf[0]&15); if ( cnt == 3 ) { - fprintf(stderr," media: %x",buf[1]); - fprintf(stderr," paper gap: %x\n",buf[2]); + fprintf(fout," media: %x",buf[1]); + fprintf(fout," paper gap: %x\n",buf[2]); } else - fprintf(stderr," media: %x\n",buf[1]); + fprintf(fout," media: %x\n",buf[1]); break; case 'd': img->xres = (buf[0]<<8)|buf[1]; img->yres = (buf[2]<<8)|buf[3]; - fprintf(stderr,"ESC (d set raster resolution (len=%i): %i x %i\n",cnt,img->xres,img->yres); + fprintf(fout,"ESC (d set raster resolution (len=%i): %i x %i\n",cnt,img->xres,img->yres); break; case 't': - fprintf(stderr,"ESC (t set image cnt %i\n",cnt); + fprintf(fout,"ESC (t set image cnt %i\n",cnt); if(buf[0]>>7){ /* usual order */ char order[]="CMYKcmyk"; @@ -672,23 +673,23 @@ static int process(FILE* in, FILE* out,int verbose,unsigned int maxw,unsigned in /* char order[]="KCcMmYykRHGABDEFIJLMNOPQSTUVWXZabdef"; */ /* int black_found = 0; */ num_colors = (cnt - 3)/3; - fprintf(stderr," bit_info: using detailed color settings for max %i colors\n",num_colors); + fprintf(fout," bit_info: using detailed color settings for max %i colors\n",num_colors); if(buf[1]==0x80) - fprintf(stderr," format: BJ indexed color image format\n"); + fprintf(fout," format: BJ indexed color image format\n"); else if(buf[1]==0x00) - fprintf(stderr," format: iP8500 flag set, BJ indexed color image format\n"); + fprintf(fout," format: iP8500 flag set, BJ indexed color image format\n"); else if(buf[1]==0x90) - fprintf(stderr," format: Pro9500 flag set, BJ indexed color image format\n"); + fprintf(fout," format: Pro9500 flag set, BJ indexed color image format\n"); else{ - fprintf(stderr," format: settings not supported 0x%x\n",buf[1]); + fprintf(fout," format: settings not supported 0x%x\n",buf[1]); /* returnv = -2; */ } if(buf[2]==0x1) - fprintf(stderr," ink: BJ indexed setting, also for iP8500 flag\n"); + fprintf(fout," ink: BJ indexed setting, also for iP8500 flag\n"); else if(buf[2]==0x4) - fprintf(stderr," ink: Pro series setting \n"); + fprintf(fout," ink: Pro series setting \n"); else{ - fprintf(stderr," ink: settings not supported 0x%x\n",buf[2]); + fprintf(fout," ink: settings not supported 0x%x\n",buf[2]); /* returnv = -2; */ } @@ -735,10 +736,10 @@ static int process(FILE* in, FILE* out,int verbose,unsigned int maxw,unsigned in } */ /* %c*/ - fprintf(stderr," Color %c Compression: %i bpp %i level %i\n",img->color[i].name, + fprintf(fout," Color %c Compression: %i bpp %i level %i\n",img->color[i].name, img->color[i].compression,img->color[i].bpp,img->color[i].level); }else{ - fprintf(stderr," Color %i out of bounds!\n", i); + fprintf(fout," Color %i out of bounds!\n", i); /*printf(" Color ignoring setting %x %x %x\n",buf[3+i*3],buf[3+i*3+1],buf[3+i*3+2]);*/ } @@ -746,7 +747,7 @@ static int process(FILE* in, FILE* out,int verbose,unsigned int maxw,unsigned in }else if(buf[0]==0x1 && buf[1]==0x0 && buf[2]==0x1){ - fprintf(stderr," 1bit-per pixel\n"); + fprintf(fout," 1bit-per pixel\n"); num_colors = cnt*3; /*no idea yet! 3 for iP4000 */ /*num_colors=9;*/ /*for(i=0;icolor[i].level=2; img->color[i].density = 255; /*add color printout for this type also %c */ - fprintf(stderr," Color %c Compression: %i bpp %i level %i\n",img->color[i].name, + fprintf(fout," Color %c Compression: %i bpp %i level %i\n",img->color[i].name, img->color[i].compression,img->color[i].bpp,img->color[i].level); }else{ - fprintf(stderr," Color %i out of bounds!", i); + fprintf(fout," Color %i out of bounds!", i); /*printf(" Color ignoring setting %x %x %x\n",buf[3+i*3],buf[3+i*3+1],buf[3+i*3+2]);*/ } } }else{ - fprintf(stderr," bit_info: unknown settings 0x%x 0x%x 0x%x\n",buf[0],buf[1],buf[2]); + fprintf(fout," bit_info: unknown settings 0x%x 0x%x 0x%x\n",buf[0],buf[1],buf[2]); /* returnv=-2; */ } break; case 'L': - fprintf(stderr,"ESC (L set component order for F raster command (len=%i): ",cnt); + fprintf(fout,"ESC (L set component order for F raster command (len=%i): ",cnt); img->color_order=calloc(1,cnt+1); /* check if the colors are sane => the iP4000 driver appends invalid bytes in the highest resolution mode */ for(i=0;icolor_order,buf,cnt); - fprintf(stderr,"%s\n",img->color_order); + fprintf(fout,"%s\n",img->color_order); img->num_colors = cnt; img->cur_color=0; break; case 'p': - fprintf(stderr,"ESC (p set extended margin (len=%i):\n",cnt); - fprintf(stderr," printed length %i left %i\n",((buf[0]<<8 )+buf[1]) *6 / 5 - 1,(buf[2]<<8) + buf[3]); - fprintf(stderr," printed width %i top %i\n",((buf[4]<<8 )+buf[5]) * 6 / 5 - 1,(buf[6]<<8) + buf[7]); + fprintf(fout,"ESC (p set extended margin (len=%i):\n",cnt); + fprintf(fout," printed length %i left %i\n",((buf[0]<<8 )+buf[1]) *6 / 5 - 1,(buf[2]<<8) + buf[3]); + fprintf(fout," printed width %i top %i\n",((buf[4]<<8 )+buf[5]) * 6 / 5 - 1,(buf[6]<<8) + buf[7]); if(cnt > 8){ int unit = (buf[12] << 8)| buf[13]; @@ -816,30 +817,30 @@ static int process(FILE* in, FILE* out,int verbose,unsigned int maxw,unsigned in int paper_top = read_uint32(buf+34); unsigned int paper_width = read_uint32(buf+38); unsigned int paper_length = read_uint32(buf+42); - fprintf(stderr," unknown %i\n",read_uint32(buf+8)); - fprintf(stderr," unit %i [1/in]\n",unit); - fprintf(stderr," area_right %i %.1f mm\n",area_right,area_right * 25.4 / unit); - fprintf(stderr," area_top %i %.1f mm\n",area_top,area_top * 25.4 / unit); - fprintf(stderr," area_width %u %.1f mm\n",area_width, area_width * 25.4 / unit); - fprintf(stderr," area_length %u %.1f mm\n",area_length,area_length * 25.4 / unit); - fprintf(stderr," paper_right %i %.1f mm\n",paper_right,paper_right * 25.4 / unit); - fprintf(stderr," paper_top %i %.1f mm\n",paper_top,paper_top * 25.4 / unit); - fprintf(stderr," paper_width %u %.1f mm\n",paper_width,paper_width * 25.4 / unit); - fprintf(stderr," paper_length %u %.1f mm\n",paper_length,paper_length * 25.4 / unit); + fprintf(fout," unknown %i\n",read_uint32(buf+8)); + fprintf(fout," unit %i [1/in]\n",unit); + fprintf(fout," area_right %i %.1f mm\n",area_right,area_right * 25.4 / unit); + fprintf(fout," area_top %i %.1f mm\n",area_top,area_top * 25.4 / unit); + fprintf(fout," area_width %u %.1f mm\n",area_width, area_width * 25.4 / unit); + fprintf(fout," area_length %u %.1f mm\n",area_length,area_length * 25.4 / unit); + fprintf(fout," paper_right %i %.1f mm\n",paper_right,paper_right * 25.4 / unit); + fprintf(fout," paper_top %i %.1f mm\n",paper_top,paper_top * 25.4 / unit); + fprintf(fout," paper_width %u %.1f mm\n",paper_width,paper_width * 25.4 / unit); + fprintf(fout," paper_length %u %.1f mm\n",paper_length,paper_length * 25.4 / unit); img->top = (float)area_top / unit; img->left = (float)area_top / unit; } break; case '$': - fprintf(stderr,"ESC ($ set duplex (len=%i)\n",cnt); + fprintf(fout,"ESC ($ set duplex (len=%i)\n",cnt); break; case 'J': - fprintf(stderr,"ESC (J select number of raster lines per block (len=%i): %i\n",cnt,buf[0]); + fprintf(fout,"ESC (J select number of raster lines per block (len=%i): %i\n",cnt,buf[0]); img->lines_per_block=buf[0]; break; case 'F': if(verbose) - fprintf(stderr,"ESC (F raster block (len=%i):\n",cnt); + fprintf(fout,"ESC (F raster block (len=%i):\n",cnt); if((returnv = Raster(img,buf,cnt,img->color_order[img->cur_color],maxw))) break; ++img->cur_color; @@ -849,17 +850,17 @@ static int process(FILE* in, FILE* out,int verbose,unsigned int maxw,unsigned in } break; case 'q': - fprintf(stderr,"ESC (q set page id (len=%i):%i\n",cnt,buf[0]); + fprintf(fout,"ESC (q set page id (len=%i):%i\n",cnt,buf[0]); break; case 'r': - fprintf(stderr,"ESC (r printer specific command (len=%i): ",cnt); + fprintf(fout,"ESC (r printer specific command (len=%i): ",cnt); for(i=0;i do it here * instead of 0x80 every raster A command is followed by a 0x0d byte * the selected color is stored in the first byte @@ -867,13 +868,13 @@ static int process(FILE* in, FILE* out,int verbose,unsigned int maxw,unsigned in buf[cnt]=0x80; returnv = Raster(img,buf+1,cnt,buf[0],maxw); if (fgetc(in)!=0x0d){ - fprintf(stderr,"Raster A not terminated by 0x0d\n"); + fprintf(fout,"Raster A not terminated by 0x0d\n"); returnv=-4; } break; case 'e': /* Raster skip */ if(verbose) - fprintf(stderr,"ESC (e advance (len=%i): %i\n",cnt,buf[0]*256+buf[1]); + fprintf(fout,"ESC (e advance (len=%i): %i\n",cnt,buf[0]*256+buf[1]); if(img->lines_per_block){ img->height += (buf[0]*256+buf[1])*img->lines_per_block; img->cur_color=0; @@ -881,22 +882,22 @@ static int process(FILE* in, FILE* out,int verbose,unsigned int maxw,unsigned in img->height += (buf[0]*256+buf[1]); break; default: /* Last but not least completely unknown commands */ - fprintf(stderr,"ESC (%c UNKNOWN (len=%i)\n",cmd,cnt); + fprintf(fout,"ESC (%c UNKNOWN (len=%i)\n",cmd,cnt); for(i=0;iwidth,img->height); + fprintf(fout,"created bit image with width %i height %i\n",img->width,img->height); if(maxh > 0){ - fprintf(stderr,"limiting height to %u\n",maxh); + fprintf(fout,"limiting height to %u\n",maxh); img->height=maxh; } @@ -905,7 +906,7 @@ static int process(FILE* in, FILE* out,int verbose,unsigned int maxw,unsigned in */ if(out) write_ppm(img,out); - fprintf(stderr,"dots: %u\n",img->dots); + fprintf(fout,"dots: %u\n",img->dots); } /* deallocate resources */ @@ -947,7 +948,13 @@ int main(int argc,char* argv[]){ char* filename_in=NULL,*filename_out=NULL; FILE *in,*out=NULL; int i; - printf("pixma_parse - parser for Canon BJL printjobs (c) 2005-2007 Sascha Sommer \nPlease note parse output now goes to stderr.\n"); + + if (DEBUG) + fout = stderr; /* unbuffered */ + else + fout = stdout; /* buffered */ + + printf("pixma_parse - parser for Canon BJL printjobs (c) 2005-2007 Sascha Sommer \n"); /* parse args */ for(i=1;i