bullshit commit, sync for travel (to zn00H!) :)
[my-code/arm.git] / betty / bmp2b.c
index 9baf3b5..0010f15 100644 (file)
 
 #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;
@@ -64,9 +66,18 @@ int main(int argc,char **argv) {
        /* 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);
@@ -81,30 +92,43 @@ int main(int argc,char **argv) {
        }
 
        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);
@@ -118,7 +142,7 @@ int main(int argc,char **argv) {
                                }
                        }
                        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))?' ':',');
                        }
                }
@@ -127,8 +151,11 @@ int main(int argc,char **argv) {
        if(stat==CHAR)
                dprintf(fd,"};\n");
 
+       bmp_write_file(&dst);
+
        close(fd);
        bmp_shutdown(&src);
+       bmp_shutdown(&dst);
 
        return 0;
 }