]> hackdaworld.org Git - my-code/arm.git/commitdiff
added a bitmap to betty lcd ram conversion tool
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Wed, 12 Sep 2007 08:42:26 +0000 (10:42 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Wed, 12 Sep 2007 08:42:26 +0000 (10:42 +0200)
betty/Makefile
betty/bmp2b.c [new file with mode: 0644]
betty/readme

index ad7c7d4f26daa8b8c30b3c9792621c45ec39fc33..3807986fd7b6403768b82b4243ded301b47cc46b 100644 (file)
@@ -15,7 +15,7 @@ CROSS_RAM_LDFLAGS = -Tlpc2220_ram.ld -nostartfiles -nostdlib
 CROSS_ROM_LDFLAGS = -Tlpc2220_rom.ld -nostartfiles -nostdlib
 
 # build objects
-HOST_TARGET = lpcload fwdump
+HOST_TARGET = lpcload fwdump bmp2b
 CROSS_TARGET = fwbc.hex fwflash.hex betty.hex
 
 # betty deps
@@ -23,7 +23,16 @@ BETTY_DEPS = system.o uart.o buttons.o spi.o display.o flash.o functions.o
 #BETTY_DEPS += pffs.o
 
 # all projects
-all: $(HOST_TARGET) $(CROSS_TARGET)
+all: links $(HOST_TARGET) $(CROSS_TARGET)
+
+# bmp2b
+links:
+       ln -sfv ../../api/bmp/bmp.{c,h} .
+
+bmp.o: bmp.c
+       $(CC) -c $(CFLAGS) -o $@ $<
+
+bmp2b: bmp.o
 
 # arm code
 arm: arm_clean $(CROSS_TARGET)
diff --git a/betty/bmp2b.c b/betty/bmp2b.c
new file mode 100644 (file)
index 0000000..9baf3b5
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * bmp2b.c - convert colored 24 bit bmp to the betty display ram format
+ *
+ * author: hackbard@hackdaworld.org
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "bmp.h"
+
+#define DX     128
+#define DY     160
+#define PM     (DY/8)
+
+#define BINARY 1
+#define CHAR   2
+
+int main(int argc,char **argv) {
+
+       int i,fd;
+       t_bmp src;
+       char in[128];
+       char out[128];
+       unsigned char stat;
+       unsigned char buf[2];
+       int page,col;
+       int b,pix;
+
+       stat=0;
+       for(i=1;i<argc;i++) {
+               if(argv[i][0]!='-')
+                       continue;
+               switch(argv[i][1]) {
+                       case 'i':
+                               strncpy(in,argv[++i],128);
+                               break;
+                       case 'o':
+                               strncpy(out,argv[++i],128);
+                               break;
+                       case 'b':
+                               stat=BINARY;
+                               break;
+                       case 'c':
+                               stat=CHAR;
+                               break;
+                       default:
+                               printf("usage:\n\n");
+                               printf("%s -i <bitmap> -o <out file> [-b/c]\n",
+                                      argv[0]);
+                               printf("\n");
+                               printf("  -b: binary out\n");
+                               printf("  -c: char array\n\n");
+                               return -1;
+               }
+       }
+
+       /* the bitmap infile */
+       bmp_init(&src,1);
+       src.mode=READ;
+       strcpy(src.file,in);
+       bmp_read_file(&src);
+
+       if((src.width!=DX)|(src.height=!DY)) {
+               printf("wrong dimensions: %d %d (need: %d %d)\n",
+                      src.width,src.height,DX,DY);
+               return -1;
+       }
+
+       /* out file */
+       fd=open(out,O_WRONLY|O_CREAT);
+       if(fd<0) {
+               perror("open outfile");
+               return fd;
+       }
+
+       if(stat==CHAR)
+               dprintf(fd,"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;
+                               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
+                                       continue;
+                               }
+                               if(b<=(0.5*255)) {
+                                       buf[0]|=(1<<i); // 1 0
+                                       continue;
+                               }
+                               if(b<=(0.75*255)) {
+                                       buf[1]|=(1<<i); // 0 1
+                                       continue;
+                               }
+                               // 0 0 .. do nothing!
+                       }
+                       if(stat==BINARY) {
+                               i=write(fd,buf,2);
+                               if(i<0) {
+                                       perror("bin write");
+                                       return i;
+                               }
+                               if(i!=2) {
+                                       printf("write failure\n");
+                                       return -1;
+                               }
+                       }
+                       else if(stat==CHAR) {
+                               dprintf(fd,"\t%02x,%02x%c\n",buf[0],buf[1],
+                                       ((page+1==PM)&(col+1==DX))?' ':',');
+                       }
+               }
+       }
+
+       if(stat==CHAR)
+               dprintf(fd,"};\n");
+
+       close(fd);
+       bmp_shutdown(&src);
+
+       return 0;
+}
+
index 65c0bc230bee0d02fe295af5e95d43f87535c79e..c57ba8a892e742b75c7f5295ba0d84af8dc10593 100644 (file)
@@ -19,6 +19,10 @@ contents/todo:
 * fwflash.c - firmware handling the flash access
 
 * betty.c - replacement firmware for the betty tv remote
+            (follow the makefile + includes in betty.h to find more source!)
+
+* bmp2b.c - converts colored bmp images to a format according to the lcd ram
+            (you need my bmb api [my-projects/api])
 
 to be continued ...