68
70
xmldata=fread(buf,1,679,infile); /* 1 less than 680 */
69
printf("nextcmd: read starting XML %d %d\n", *xml_read, startxml);
71
fprintf(stderr,"nextcmd: read starting XML %d %d\n", *xml_read, startxml);
71
73
}else if (*xml_read==1) {
74
76
xmldata=fread(buf,1,262,infile); /* 1 less than 263*/
75
printf("nextcmd: read ending XML %d %d\n", *xml_read, endxml);
77
fprintf(stderr,"nextcmd: read ending XML %d %d\n", *xml_read, endxml);
78
80
/* no alternatives yet */
90
92
if (*cnt){ /* read arguments */
92
94
if((read=fread(buf,1,*cnt,infile)) != *cnt){
93
printf("nextcmd: read error - not enough data %d %d\n", read, *cnt);
95
fprintf(stderr,"nextcmd: read error - not enough data %d %d\n", read, *cnt);
98
100
}else if(c2 == '@'){ /* ESC@ */
99
printf("ESC @ Return to neutral mode\n");
101
fprintf(stderr,"ESC @ Return to neutral mode\n");
101
printf("unknown byte following ESC %x \n",c2);
103
fprintf(stderr,"unknown byte following ESC %x \n",c2);
103
105
}else if(c1==0x0c){ /* Form Feed */
104
printf("-->Form Feed\n");
106
fprintf(stderr,"-->Form Feed\n");
106
printf("UNKNOWN BYTE 0x%x @ %lu\n",c1,ftell(infile));
108
fprintf(stderr,"UNKNOWN BYTE 0x%x @ %lu\n",c1,ftell(infile));
166
168
int cur_line=0; /* line relative to block begin */
167
169
unsigned char* dst=malloc(len*256); /* the destination buffer */
168
170
unsigned char* dstr=dst;
170
printf("no matching color for %c (0x%x, %i) in the database => ignoring %i bytes\n",color_name,color_name,color_name, len);
172
printf("no matching color for %c (0x%x, %i) in the database => ignoring %i bytes\n",color_name,color_name,color_name, len);
175
fprintf(stderr,"DEBUG enter Raster len=%i,color=%c\n",len,color_name);
172
/*printf("DEBUG enter Raster len=%i,color=%c\n",len,color_name);*/
174
178
/* decode pack bits */
175
179
while( len > 0){ /* why does this not work: because unsigned integer wraps! */
499
printf("ESC (c set media (len=%i):\n",cnt);
500
printf(" model id %x bw %x",buf[0]>> 4,buf[0]&0xf);
501
printf(" media %x",buf[1]);
502
printf(" direction %x quality %x\n",(buf[2]>>4)&3 ,buf[2]&0xf);
504
fprintf(stderr,"ESC (c set media (len=%i):\n",cnt);
505
fprintf(stderr," model id %x bw %x",buf[0]>> 4,buf[0]&0xf);
506
fprintf(stderr," media %x",buf[1]);
507
fprintf(stderr," direction %x quality %x\n",(buf[2]>>4)&3 ,buf[2]&0xf);
505
510
if(buf[1]==0x1f){
506
printf("ESC [K go to command mode\n");
511
fprintf(stderr,"ESC [K go to command mode\n");
508
513
fgets((char*)buf,0xFFFF,in);
514
fprintf(stderr," %s",buf);
510
515
}while(strcmp((char*)buf,"BJLEND\n"));
511
516
}else if(cnt == 2 && buf[1]==0x0f){
512
printf("ESC [K reset printer\n");
517
fprintf(stderr,"ESC [K reset printer\n");
516
printf("ESC [K unsupported param (len=%i): %x\n",cnt,buf[1]);
521
fprintf(stderr,"ESC [K unsupported param (len=%i): %x\n",cnt,buf[1]);
519
printf("ESC (b set data compression (len=%i): %x\n",cnt,buf[0]);
525
fprintf(stderr,"ESC (b set data compression (len=%i): %x\n",cnt,buf[0]);
522
printf("ESC (I select data transmission (len=%i): ",cnt);
523
if(buf[0]==0)printf("default");
524
else if(buf[0]==1)printf("multi raster");
525
else printf("unknown 0x%x %i",buf[0],buf[0]);
528
fprintf(stderr,"ESC (I select data transmission (len=%i): ",cnt);
529
if(buf[0]==0)fprintf(stderr,"default");
530
else if(buf[0]==1)fprintf(stderr,"multi raster");
531
else fprintf(stderr,"unknown 0x%x %i",buf[0],buf[0]);
532
fprintf(stderr,"\n");
529
printf("ESC (l select paper loading (len=%i):\n",cnt);
530
printf(" model id 0x%x ",buf[0]>>4);
531
printf(" source 0x%x",buf[0]&15);
532
printf(" media: %x",buf[1]);
533
printf(" paper gap: %x\n",buf[2]);
535
fprintf(stderr,"ESC (l select paper loading (len=%i):\n",cnt);
536
fprintf(stderr," model id 0x%x ",buf[0]>>4);
537
fprintf(stderr," source 0x%x",buf[0]&15);
539
fprintf(stderr," media: %x",buf[1]);
540
fprintf(stderr," paper gap: %x\n",buf[2]);
542
fprintf(stderr," media: %x\n",buf[1]);
536
545
img->xres = (buf[0]<<8)|buf[1];
537
546
img->yres = (buf[2]<<8)|buf[3];
538
printf("ESC (d set raster resolution (len=%i): %i x %i\n",cnt,img->xres,img->yres);
547
fprintf(stderr,"ESC (d set raster resolution (len=%i): %i x %i\n",cnt,img->xres,img->yres);
541
printf("ESC (t set image cnt %i\n",cnt);
550
fprintf(stderr,"ESC (t set image cnt %i\n",cnt);
543
552
/* usual order */
544
553
/*char order[]="CMYKcmykHRGABDEFIJLMNOPQSTUVWXZabdef";*/
545
554
/* iP3500 test */
546
/*char order[]="CMYKcmykHRGBCMYcmykabd";*/
547
char order[]="CMYKcmykHpnoPQRSTykabd";
555
char order[]="CMYKcmykHRGBCMYcmykabd";
556
/*char order[]="CMYKcmykHpnoPQRSTykabd";*/
557
/*char order[]="KCMYkcmyHpnoPQRSTykabd";*/
548
558
/* MP960 photo modes: k instead of K */
549
559
/* char order[]="CMYkcmyKHRGABDEFIJLMNOPQSTUVWXZabdef";*/
550
560
/* T-shirt transfer mode: y changed to k --- no y, no K */
555
565
/* char order[]="KCcMmYykRHGABDEFIJLMNOPQSTUVWXZabdef"; */
556
566
int black_found = 0;
557
567
int num_colors = (cnt - 3)/3;
558
printf(" bit_info: using detailed color settings for max %i colors\n",num_colors);
568
fprintf(stderr," bit_info: using detailed color settings for max %i colors\n",num_colors);
560
printf(" format: BJ indexed color image format\n");
570
fprintf(stderr," format: BJ indexed color image format\n");
561
571
else if(buf[1]==0x00)
562
printf(" format: iP8500 flag set, BJ indexed color image format\n");
572
fprintf(stderr," format: iP8500 flag set, BJ indexed color image format\n");
563
573
else if(buf[1]==0x90)
564
printf(" format: Pro9500 flag set, BJ indexed color image format\n");
574
fprintf(stderr," format: Pro9500 flag set, BJ indexed color image format\n");
566
printf(" format: settings not supported 0x%x\n",buf[1]);
576
fprintf(stderr," format: settings not supported 0x%x\n",buf[1]);
567
577
/* returnv = -2; */
570
printf(" ink: BJ indexed setting, also for iP8500 flag\n");
580
fprintf(stderr," ink: BJ indexed setting, also for iP8500 flag\n");
571
581
else if(buf[2]==0x4)
572
printf(" ink: Pro series setting \n");
582
fprintf(stderr," ink: Pro series setting \n");
574
printf(" ink: settings not supported 0x%x\n",buf[2]);
584
fprintf(stderr," ink: settings not supported 0x%x\n",buf[2]);
575
585
/* returnv = -2; */
612
623
order[i+1] = 'y';
614
625
img->color[i].density = 255;
616
printf(" Color %c Compression: %i bpp %i level %i\n",img->color[i].name,
629
fprintf(stderr," Color %c Compression: %i bpp %i level %i\n",img->color[i].name,
617
630
img->color[i].compression,img->color[i].bpp,img->color[i].level);
619
printf(" Color %c Compression: %i bpp %i level %i\n",img->color[i].name,
632
fprintf(stderr," Color %c Compression: %i bpp %i level %i\n",img->color[i].name,
620
633
img->color[i].compression,img->color[i].bpp,img->color[i].level);
621
634
/*printf(" Color ignoring setting %x %x %x\n",buf[3+i*3],buf[3+i*3+1],buf[3+i*3+2]);*/
643
656
img->color[i].level=2;
644
657
img->color[i].density = 255;
645
658
/*add color printout for this type also %c */
646
printf(" Color %c Compression: %i bpp %i level %i\n",img->color[i].name,
659
fprintf(stderr," Color %c Compression: %i bpp %i level %i\n",img->color[i].name,
647
660
img->color[i].compression,img->color[i].bpp,img->color[i].level);
649
printf(" Color %c Compression: %i bpp %i level %i\n",img->color[i].name,
662
fprintf(stderr," Color %c Compression: %i bpp %i level %i\n",img->color[i].name,
650
663
img->color[i].compression,img->color[i].bpp,img->color[i].level);
651
664
/*printf(" Color ignoring setting %x %x %x\n",buf[3+i*3],buf[3+i*3+1],buf[3+i*3+2]);*/
655
printf(" bit_info: unknown settings 0x%x 0x%x 0x%x\n",buf[0],buf[1],buf[2]);
668
fprintf(stderr," bit_info: unknown settings 0x%x 0x%x 0x%x\n",buf[0],buf[1],buf[2]);
656
669
/* returnv=-2; */
660
printf("ESC (L set component order for F raster command (len=%i): ",cnt);
673
fprintf(stderr,"ESC (L set component order for F raster command (len=%i): ",cnt);
661
674
img->color_order=calloc(1,cnt+1);
662
675
/* check if the colors are sane => the iP4000 driver appends invalid bytes in the highest resolution mode */
663
676
for(i=0;i<cnt;i++){
671
684
buf[i]=buf[i]-0x60;
672
printf("subtracting 0x60 to give [corrected]: %c\n", buf[i]);
685
fprintf(stderr,"subtracting 0x60 to give [corrected]: %c\n", buf[i]);
675
printf("found valid color char: %c\n",buf[i]);
688
fprintf(stderr,"found valid color char: %c\n",buf[i]);
678
691
memcpy(img->color_order,buf,cnt);
679
printf("%s\n",img->color_order);
692
fprintf(stderr,"%s\n",img->color_order);
680
693
img->num_colors = cnt;
681
694
img->cur_color=0;
684
printf("ESC (p set extended margin (len=%i):\n",cnt);
685
printf(" printed length %i left %i\n",((buf[0]<<8 )+buf[1]) *6 / 5,(buf[2]<<8) + buf[3]);
686
printf(" printed width %i top %i\n",((buf[4]<<8 )+buf[5]) * 6 / 5,(buf[6]<<8) + buf[7]);
697
fprintf(stderr,"ESC (p set extended margin (len=%i):\n",cnt);
698
fprintf(stderr," printed length %i left %i\n",((buf[0]<<8 )+buf[1]) *6 / 5,(buf[2]<<8) + buf[3]);
699
fprintf(stderr," printed width %i top %i\n",((buf[4]<<8 )+buf[5]) * 6 / 5,(buf[6]<<8) + buf[7]);
689
702
int unit = (buf[12] << 8)| buf[13];
695
708
int paper_top = read_uint32(buf+34);
696
709
unsigned int paper_width = read_uint32(buf+38);
697
710
unsigned int paper_length = read_uint32(buf+42);
698
printf(" unknown %i\n",read_uint32(buf+8));
699
printf(" unit %i [1/in]\n",unit);
700
printf(" area_right %i %.1f mm\n",area_right,area_right * 25.4 / unit);
701
printf(" area_top %i %.1f mm\n",area_top,area_top * 25.4 / unit);
702
printf(" area_width %u %.1f mm\n",area_width, area_width * 25.4 / unit);
703
printf(" area_length %u %.1f mm\n",area_length,area_length * 25.4 / unit);
704
printf(" paper_right %i %.1f mm\n",paper_right,paper_right * 25.4 / unit);
705
printf(" paper_top %i %.1f mm\n",paper_top,paper_top * 25.4 / unit);
706
printf(" paper_width %u %.1f mm\n",paper_width,paper_width * 25.4 / unit);
707
printf(" paper_length %u %.1f mm\n",paper_length,paper_length * 25.4 / unit);
711
fprintf(stderr," unknown %i\n",read_uint32(buf+8));
712
fprintf(stderr," unit %i [1/in]\n",unit);
713
fprintf(stderr," area_right %i %.1f mm\n",area_right,area_right * 25.4 / unit);
714
fprintf(stderr," area_top %i %.1f mm\n",area_top,area_top * 25.4 / unit);
715
fprintf(stderr," area_width %u %.1f mm\n",area_width, area_width * 25.4 / unit);
716
fprintf(stderr," area_length %u %.1f mm\n",area_length,area_length * 25.4 / unit);
717
fprintf(stderr," paper_right %i %.1f mm\n",paper_right,paper_right * 25.4 / unit);
718
fprintf(stderr," paper_top %i %.1f mm\n",paper_top,paper_top * 25.4 / unit);
719
fprintf(stderr," paper_width %u %.1f mm\n",paper_width,paper_width * 25.4 / unit);
720
fprintf(stderr," paper_length %u %.1f mm\n",paper_length,paper_length * 25.4 / unit);
708
721
img->top = (float)area_top / unit;
709
722
img->left = (float)area_top / unit;
713
printf("ESC ($ set duplex (len=%i)\n",cnt);
726
fprintf(stderr,"ESC ($ set duplex (len=%i)\n",cnt);
716
printf("ESC (J select number of raster lines per block (len=%i): %i\n",cnt,buf[0]);
729
fprintf(stderr,"ESC (J select number of raster lines per block (len=%i): %i\n",cnt,buf[0]);
717
730
img->lines_per_block=buf[0];
721
printf("ESC (F raster block (len=%i):\n",cnt);
734
fprintf(stderr,"ESC (F raster block (len=%i):\n",cnt);
722
735
if((returnv = Raster(img,buf,cnt,img->color_order[img->cur_color],maxw)))
724
737
++img->cur_color;
731
printf("ESC (q set page id (len=%i):%i\n",cnt,buf[0]);
744
fprintf(stderr,"ESC (q set page id (len=%i):%i\n",cnt,buf[0]);
734
printf("ESC (r printer specific command (len=%i): ",cnt);
747
fprintf(stderr,"ESC (r printer specific command (len=%i): ",cnt);
735
748
for(i=0;i<cnt;i++)
736
printf("0x%x ",buf[i]);
749
fprintf(stderr,"0x%x ",buf[i]);
750
fprintf(stderr,"\n");
741
printf("ESC (A raster line (len=%i): color %c\n",cnt,buf[0]);
754
fprintf(stderr,"ESC (A raster line (len=%i): color %c\n",cnt,buf[0]);
742
755
/* the single line rasters are not terminated by 0x80 => do it here
743
756
* instead of 0x80 every raster A command is followed by a 0x0d byte
744
757
* the selected color is stored in the first byte
760
773
img->height += (buf[0]*256+buf[1]);
762
775
default: /* Last but not least completely unknown commands */
763
printf("ESC (%c UNKNOWN (len=%i)\n",cmd,cnt);
776
fprintf(stderr,"ESC (%c UNKNOWN (len=%i)\n",cmd,cnt);
764
777
for(i=0;i<cnt;i++)
765
printf(" 0x%x",buf[i]);
778
fprintf(stderr," 0x%x",buf[i]);
779
fprintf(stderr,"\n");
771
printf("-------- finished parsing --------\n");
784
fprintf(stderr,"-------- finished parsing --------\n");
772
785
if(returnv < -2){ /* was < 0 : work around to see what we get */
773
printf("error: parsing the printjob failed error %i\n",returnv);
786
fprintf(stderr,"error: parsing the printjob failed error %i\n",returnv);
776
printf("created bit image with width %i height %i\n",img->width,img->height);
789
fprintf(stderr,"created bit image with width %i height %i\n",img->width,img->height);
778
printf("limiting height to %u\n",maxh);
791
fprintf(stderr,"limiting height to %u\n",maxh);
779
792
img->height=maxh;