A program which converts xbm to pr150 format

0 views
Skip to first unread message

Takanori Oshiro

unread,
Jul 23, 2021, 7:53:48 AM7/23/21
to
In order not to see graphic screen
print picture file program becomes to be needed
Because I do not know control code of USB printer
I wrote program for NEC PC-PR150
This program is no error check
Please refer to source code about detail
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define ON 1
int main(argc,argv)
int argc;
char *argv[];
{ FILE *fp;
char c,d,e,f,g,h;
char str[80];
int width,height;
int i,j,k,l,m,n,o,p;
char raster[5000][24];
unsigned char datum[60000];
unsigned char x;
i=0;
fp=fopen(*++argv,"r");
while((c=getc(fp)) != ' ')
;
while((c=getc(fp)) != ' ')
;
while((c=getc(fp)) != '\n')
str[i++]=c;
str[i]='\0';
width = atoi(str);
i=0;
while((c=getc(fp))!=' ')
;
while((c=getc(fp))!=' ')
;
while((c=getc(fp))!='\n')
str[i++]=c;
str[i]='\0';
height= atoi(str);
i=0;
while((c=getc(fp))!='{')
;
while((c=getc(fp)) != '}'){
if(c == ' ' || c==',' || c=='\n')
break;
if(c == '0')
c=getc(fp);
if(c =='x')
c=getc(fp);
if(isdigit(c)){
d=c-48;
d<<4;
datum[i]=d;
} else {
d=toupper(c);
d=d-56;
d<<4;
datum[i]=d;
}
c=getc(fp);
if(isdigit(c)){
d=c-48;
datum[i]+=d;
} else {
d=toupper(c);
d-=56;
datum[i]+=d;
}
i++;
}
j=width/8;
k=width % 8;
for(i=0;i<height;i++){
for(l=0;l<j;l++){
d=datum[m++];
if(d & 0x80)
raster[l*8][i]=ON;
if(d & 0x40)
raster[l*8+1][i]=ON;
if(d & 0x20)
raster[l*8+2][i]=ON;
if(d & 0x10)
raster[l*8+3][i]=ON;
if(d & 0x08)
raster[l*8+4][i]=ON;
if(d & 0x04)
raster[l*8+5][i]=ON;
if(d & 0x02)
raster[l*8+6][i]=ON;
if(d & 0x01)
raster[l*8+7][i]=ON;
if(k)
d=datum[m++];
else
break;
p = 0x80;;
for(o=0;o<k;o++){
if(d & p)
raster[l*8+8+o][i]=ON;
p >> 1;
}
}
}
j = height / 24;
k = height % 24;
putchar(0x1c);
putchar(0x64);
putchar(0x33);
putchar(0x32);
putchar(0x30);
putchar(0x2e);
for(i=0;i<60000;i++)
;
putchar(0x1b);
putchar(0x54);
putchar('0');
putchar('9');
for(i=0;i<60000;i++)
;
e = height / 1000 + '0';
f = (height % 1000) / 100 + '0';
g = (height % 100) / 10 + '0';
h = height % 10 + '0';
for(i=0;i<j;i++){
putchar(0x1b);
putchar(0x4a);
putchar(e);
putchar(f);
putchar(g);
putchar(h);
for(l=0;l<width;l++){
for(m=0;m<3;m++){
for(n=0;n<8;n++){
if(raster[l][i*24+m*8+n]){
d=0x01;
d << n;
x+= d;
}
}
putchar(x);
x=0;
}
}
putchar('\r');
putchar('\n');
}
putchar(0x1b);
putchar(0x4a);
putchar(e);
putchar(f);
putchar(g);
putchar(h);
for(l=0;l<width;l++){
if(k<8){
for(n=0;n<k;n++){
if(raster[l][j*24+k]){
d=0x01;
d<<n;
x+=d;
}
}
putchar(x);
putchar(0);
putchar(0);
} else if(k<16){
for(n=0;n<8;n++){
if(raster[l][j*24+n]){
d=0x01;
d<<n;
x+=d;
}
}
putchar(x);
x=0;
for(n=0;n<k-8;n++){
if(raster[l][j*24+8+n]){
d=0x01;
d<<n;
x+=d;
}
}
putchar(x);
putchar(0);
} else {
for(n=0;n<8;n++){
if(raster[l][j*24+n]){
d=0x01;
d<<n;
x+=d;
}
}
putchar(x);
for(n=0;n<8;n++){
if(raster[l][j*24+8+n]){
d=0x01;
d<<n;
x+=d;
}
}
putchar(x);
x=0;
for(n=0;n<k-16;n++){
if(raster[l][j*24+16+n]){
d=0x01;
d<<n;
x+=d;
}
}
putchar(x);
}
}
putchar('\r');
putchar('\n');
}
Reply all
Reply to author
Forward
0 new messages