#define BINARY 1
#define CHAR 2
+#define SHOW 3
int main(int argc,char **argv) {
int i,fd;
- t_bmp src;
+ t_bmp src,dst;
char in[128];
char out[128];
+ char blook[128+8];
unsigned char stat;
unsigned char buf[2];
int page,col;
/* the bitmap infile */
bmp_init(&src,1);
src.mode=READ;
- strcpy(src.file,in);
+ strncpy(src.file,in,128);
bmp_read_file(&src);
+ /* the bitmap outfile */
+ sprintf(blook,"blook_%s",in);
+ bmp_init(&dst,1);
+ dst.mode=WRITE;
+ strncpy(dst.file,blook,128+8);
+ dst.width=src.width;
+ dst.height=src.height;
+ bmp_alloc_map(&dst);
+
if((src.width!=DX)|(src.height=!DY)) {
printf("wrong dimensions: %d %d (need: %d %d)\n",
src.width,src.height,DX,DY);
}
if(stat==CHAR)
- dprintf(fd,"unsigned char default_logo[%d]={\n",DX*PM*2);
+ dprintf(fd,"const unsigned char default_logo[%d]={\n",DX*PM*2);
for(page=0;page<PM;page++) {
for(col=0;col<DX;col++) {
buf[0]=0;
buf[1]=0;
for(i=0;i<8;i++) {
- pix=((page*8+i)*DX)+col;
+ // bmp: bottom rows first ... (i forgot that!)
+ pix=((DY-1-(page*8+i))*DX)+col;
b=src.map[pix].r+src.map[pix].g+src.map[pix].b;
b/=3;
if(b<=(0.25*255)) {
buf[0]|=(1<<i);
buf[1]|=(1<<i); // 1 1
+ dst.map[pix].r=0;
+ dst.map[pix].g=0;
+ dst.map[pix].b=0;
continue;
}
if(b<=(0.5*255)) {
buf[0]|=(1<<i); // 1 0
+ dst.map[pix].r=0.25*255;
+ dst.map[pix].g=0.25*255;
+ dst.map[pix].b=0.25*255;
continue;
}
if(b<=(0.75*255)) {
buf[1]|=(1<<i); // 0 1
+ dst.map[pix].r=0.75*255;
+ dst.map[pix].g=0.75*255;
+ dst.map[pix].b=0.75*255;
continue;
}
// 0 0 .. do nothing!
+ dst.map[pix].r=255;
+ dst.map[pix].g=255;
+ dst.map[pix].b=255;
}
if(stat==BINARY) {
i=write(fd,buf,2);
}
}
else if(stat==CHAR) {
- dprintf(fd,"\t%02x,%02x%c\n",buf[0],buf[1],
+ dprintf(fd,"\t0x%02x,0x%02x%c\n",buf[0],buf[1],
((page+1==PM)&(col+1==DX))?' ':',');
}
}
if(stat==CHAR)
dprintf(fd,"};\n");
+ bmp_write_file(&dst);
+
close(fd);
bmp_shutdown(&src);
+ bmp_shutdown(&dst);
return 0;
}