Initial transfer from sourceforge

This commit is contained in:
Telekatz 2017-07-01 21:56:25 +02:00
commit f2259c5424
415 changed files with 73200 additions and 0 deletions

69
bmp2b/trunk/Makefile Normal file
View file

@ -0,0 +1,69 @@
# native builds
CC = gcc
CFLAGS = -Wall -I/usr/src/linux/include
# cross build
ARCH = arm-elf
CROSS_CC = $(ARCH)-gcc
CROSS_AS = $(ARCH)-as
CROSS_LD = $(ARCH)-ld
CROSS_OBJCOPY = $(ARCH)-objcopy
CROSS_OPTS = -mcpu=arm7tdmi-s
CROSS_CFLAGS = $(CROSS_OPTS) -Wall -Os
CROSS_ASLAGS = $(CROSS_OPTS) --gstabs
CROSS_RAM_LDFLAGS = -Tlpc2220_ram.ld -nostartfiles -nostdlib
CROSS_ROM_LDFLAGS = -Tlpc2220_rom.ld -nostartfiles -nostdlib
# build objects
HOST_TARGET = lpcload fwdump font2b
CROSS_TARGET = fwbc.hex fwflash.hex betty.hex
# betty deps
BETTY_DEPS = system.o uart.o buttons.o spi.o display.o flash.o functions.o
BETTY_DEPS += interrupts.o pwm.o #pffs.o
# all projects
all: $(HOST_TARGET) $(CROSS_TARGET)
# bmp2b / font2b
links:
bmp.c: links
bmp.o: bmp.c
$(CC) -c $(CFLAGS) -o $@ $<
bmp2b: bmp.o
# arm code
arm: arm_clean $(CROSS_TARGET)
# .o out of .c
%.o: %.c
$(CROSS_CC) -c $(CROSS_CFLAGS) -o $@ $<
# .o out of .s
%.o: %.s
$(CROSS_AS) $(CROSS_ASLAGS) -o $@ $<
# .elf out of .o
%.elf: %.o startup.o interrupts.o
$(CROSS_LD) $(CROSS_RAM_LDFLAGS) startup.o interrupts.o -o $@ $<
# betty is special ;)
betty.elf: betty.o startup.o $(BETTY_DEPS)
#$(CROSS_LD) $(CROSS_ROM_LDFLAGS) startup.o $(BETTY_DEPS) -o $@ $<
$(CROSS_LD) $(CROSS_RAM_LDFLAGS) startup.o $(BETTY_DEPS) -o $@ $<
# .hex out of .elf
%.hex: %.elf
$(CROSS_OBJCOPY) -O ihex $< $@
# host clean
clean:
rm -vf lpcload fwdump
# arm clean
arm_clean:
rm -vf *.o *.hex *.elf

34
bmp2b/trunk/README1ST Normal file
View file

@ -0,0 +1,34 @@
folgendes:
um ein Bild betty-tauglich umzuwandeln:
1. das bild MUSS (!!!1einself) im 24bit-rgb-farbraum sein
2. das bild MUSS 128 px breit und 160 px hoch sein
3. "make bmp2b" eingeben
4. "./bmp2b -c -i bild.bmp -o out" eingeben, wobei bild.bmp die eingangsdatei ist und out die ausgangsdatei
5. es werden zwei dateien erzeugt: erstens "out", also die ausgabedatei; zweitens blook_bild.bmp
in dieser zweiten datei wird das bild mit 4 graustufen dargestellt, so wie es voraussichtlich auf der
betty aussieht
6. das bild kann verwendet werden. zur benutzung als logo zB einfach nach display/boop_logo kopieren.
...fertig
viel erfolg.
damaltor
das grundprogramm kommt von hackbard@hackdaworld.org, ich habe das makefile etwas angepasst und die ersten zeilen
der ausgabe angepasst.
zur erzeugung eines 24bpp bildes aus einem 8bpp:
gimp öffnen
neue datei
128x160 und rgb auswählen
das bild hineinkopieren
speichern als bmp, erweiterte optionen -> 24 bpp auswählen (!!)
fertig

BIN
bmp2b/trunk/betty.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
bmp2b/trunk/betty2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

219
bmp2b/trunk/bmp.c Normal file
View file

@ -0,0 +1,219 @@
/* bmp.c -- bmp write/read api
*
* author: hackbard@hackdaworld.dyndns.org
*
*/
#include "bmp.h"
int bmp_init(t_bmp *bmp,int outfd) {
dprintf(outfd,"[bmp] initializing bmp api ...\n");
memset(bmp,0,sizeof(t_bmp));
bmp->outfd=outfd;
return B_SUCCESS;
}
int bmp_shutdown(t_bmp *bmp) {
if(bmp->map!=NULL) {
dprintf(bmp->outfd,"[bmp] free pixmap memory\n");
free(bmp->map);
}
dprintf(bmp->outfd,"[bmp] shutdown\n");
return B_SUCCESS;
}
int bmp_check_header_and_info(t_bmp *bmp) {
dprintf(bmp->outfd,"[bmp] magic identifier: %c%c\n",
bmp->hdr.identifier&0xff,bmp->hdr.identifier>>8);
if(bmp->info.compression!=0) {
dprintf(bmp->outfd,"[bmp] compression not supported\n");
return B_NO_SUPPORT;
}
if(bmp->info.bpp!=24) {
dprintf(bmp->outfd,"[bmp] only true color (24bpp) supported\n");
return B_NO_SUPPORT;
}
if(bmp->hdr.offset!=BMP_H_SIZE+BMP_I_SIZE) {
dprintf(bmp->outfd,"[bmp] files with %d bytes offset not supported\n",
bmp->hdr.offset);
return B_NO_SUPPORT;
}
if(bmp->info.size!=BMP_I_SIZE) {
dprintf(bmp->outfd,"[bmp] files with %d bytes info size not supported\n",
bmp->info.size);
return B_NO_SUPPORT;
}
return B_SUCCESS;
}
int bmp_alloc_map(t_bmp *bmp) {
int size;
size=bmp->width*bmp->height*3;
dprintf(bmp->outfd,"[bmp] alloc map memory (%d bytes)\n",size);
if((bmp->map=(t_pixel *)malloc(size))==NULL) {
dprintf(bmp->outfd,"[bmp] memory map alloc failed\n");
return B_E_MEM;
}
return B_SUCCESS;
}
int bmp_write_file(t_bmp *bmp) {
int fill,xsize,size;
int y;
unsigned char buf[3];
memset(buf,0,3);
if(!(bmp->mode&WRITE)) {
dprintf(bmp->outfd,"[bmp] write mode not specified\n");
return B_WRONG_MODE;
}
xsize=bmp->width*3;
fill=(4-(xsize%4))%4;
size=(xsize+fill)*bmp->height;
/* construct it */
bmp->hdr.identifier='B'|('M'<<8);
bmp->hdr.size=size+BMP_H_SIZE+BMP_I_SIZE;
bmp->hdr.offset=BMP_H_SIZE+BMP_I_SIZE;
bmp->info.size=BMP_I_SIZE;
bmp->info.width=bmp->width;
bmp->info.height=bmp->height;
bmp->info.planes=1;
bmp->info.bpp=24;
bmp->info.imagesize=size;
if(bmp->info.xres==0) bmp->info.xres=2048;
if(bmp->info.yres==0) bmp->info.yres=2048;
bmp->info.noc=0;
bmp->info.ic=0;
/* write it */
if((bmp->fd=open(bmp->file,O_WRONLY|O_CREAT))<0) {
dprintf(bmp->outfd,"[bmp] unable to open file %s\n",bmp->file);
return B_NO_FILE;
}
if(write(bmp->fd,&(bmp->hdr),BMP_H_SIZE)<BMP_H_SIZE) {
dprintf(bmp->outfd,"[bmp] unable to write bmp header\n");
return B_E_WRITE_DATA;
}
if(write(bmp->fd,&(bmp->info),BMP_I_SIZE)<BMP_I_SIZE) {
dprintf(bmp->outfd,"[bmp] unable to write bmp info\n");
return B_E_WRITE_DATA;
}
for(y=0;y<bmp->height;y++) {
if(write(bmp->fd,bmp->map+y*bmp->width,xsize)<xsize) {
dprintf(bmp->outfd,"[bmp] unable to write image data line %d\n",y);
return B_E_WRITE_DATA;
}
if(write(bmp->fd,buf,fill)<fill) {
dprintf(bmp->outfd,"[bmp] unable to write fill bytes\n");
return B_E_WRITE_DATA;
}
}
close(bmp->fd);
return B_SUCCESS;
}
int bmp_cut_grab_bottom(t_bmp *dst,t_bmp *src,int dz,unsigned char m) {
int off;
dst->width=src->width;
dst->height=dz;
if(dz>src->height) {
dprintf(src->outfd,"[bmp] cut region greater than image height\n");
return B_E_GEOMETRY;
}
if(bmp_alloc_map(dst)!=B_SUCCESS) {
dprintf(dst->outfd,"[bmp] no map memory\n");
return B_E_MEM;
}
off=(m==GRAB)?0:(src->height-dz)*src->width;
memcpy(dst->map,src->map+off,dz*src->width*sizeof(t_pixel));
return B_SUCCESS;
}
int bmp_read_file(t_bmp *bmp) {
unsigned char buf[BMP_H_SIZE+BMP_I_SIZE];
int y,xsize;
int crop;
if(!(bmp->mode&READ)) {
dprintf(bmp->outfd,"[bmp] read mode not specified\n");
return B_WRONG_MODE;
}
if((bmp->fd=open(bmp->file,O_RDONLY))<0) {
dprintf(bmp->outfd,"[bmp] unable to open file %s\n",bmp->file);
return B_NO_FILE;
}
if(read(bmp->fd,buf,BMP_H_SIZE+BMP_I_SIZE)<BMP_H_SIZE+BMP_I_SIZE) {
dprintf(bmp->outfd,"[bmp] error reading bmp header & info\n");
return B_NO_HI;
}
memcpy(&(bmp->hdr),buf,BMP_H_SIZE);
memcpy(&(bmp->info),buf+BMP_H_SIZE,BMP_I_SIZE);
if(bmp_check_header_and_info(bmp)!=B_SUCCESS) {
dprintf(bmp->outfd,"[bmp] header/info check failed\n");
return B_HI_FAIL;
}
bmp->width=bmp->info.width;
bmp->height=bmp->info.height;
bmp->map=(t_pixel *)malloc(bmp->width*bmp->height*sizeof(t_pixel));
if(bmp->map==NULL) {
dprintf(bmp->outfd,"[bmp] malloc of map memory failed\n");
return B_E_MEM;
}
crop=bmp->info.imagesize/bmp->height-bmp->width*(bmp->info.bpp/8);
xsize=(bmp->info.bpp/8)*bmp->width;
for(y=0;y<bmp->height;y++) {
if(read(bmp->fd,bmp->map+y*bmp->width,xsize)<xsize) {
dprintf(bmp->outfd,"[bmp] reading image data of line %d failed\n",y);
return B_E_READ_DATA;
}
if(read(bmp->fd,buf,crop)<crop) {
dprintf(bmp->outfd,"[bmp] failed reading rest of line\n");
return B_E_READ_DATA;
}
}
close(bmp->fd);
return B_SUCCESS;
}

85
bmp2b/trunk/bmp.h Normal file
View file

@ -0,0 +1,85 @@
/* bmp.h -- bmp headers */
#ifndef BMP_H
#define BMP_H
/* includes */
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
/* defines */
#define B_SUCCESS 1
#define B_ERROR -1
#define B_WRONG_MODE -2
#define B_NO_FILE -3
#define B_NO_HI -4
#define B_NO_SUPPORT -5
#define B_HI_FAIL -6
#define B_E_MEM -7
#define B_E_READ_DATA -8
#define B_E_WRITE_DATA -9
#define B_E_GEOMETRY -10
#define MAX_CHARS_FILE 128
#define BMP_H_SIZE 14
#define BMP_I_SIZE 40
#define GRAB 'g'
/* bmp specific variables */
typedef struct s_bmp_hdr {
unsigned short int identifier;
unsigned int size;
unsigned short int reserved1;
unsigned short int reserved2;
unsigned int offset; /* <- 14 + 40 bytes = 0x36 */
} __attribute__ ((packed)) t_bmp_hdr; /* 14 bytes */
typedef struct s_bmp_info {
unsigned int size; /* 40 bytes = 0x28 */
int width;
int height;
unsigned short int planes;
unsigned short int bpp;
unsigned int compression;
unsigned int imagesize;
unsigned int xres;
unsigned int yres;
unsigned int noc;
unsigned int ic;
} __attribute__ ((packed)) t_bmp_info; /* 40 bytes */
typedef struct s_pixel {
unsigned char b;
unsigned char g;
unsigned char r;
} __attribute__ ((packed)) t_pixel;
typedef struct s_bmp {
int outfd;
int width;
int height;
unsigned char mode;
#define READ (1<<0)
#define WRITE (1<<1)
char file[MAX_CHARS_FILE];
int fd;
t_bmp_hdr hdr;
t_bmp_info info;
t_pixel *map;
} t_bmp;
/* function prototypes */
int bmp_init(t_bmp *bmp,int outfd);
int bmp_shutdown(t_bmp *bmp);
int bmp_check_header_and_info(t_bmp *bmp);
int bmp_alloc_map(t_bmp *bmp);
int bmp_write_file(t_bmp *bmp);
int bmp_cut_grab_bottom(t_bmp *dst,t_bmp *src,int dz,unsigned char m);
int bmp_read_file(t_bmp *bmp);
#endif

168
bmp2b/trunk/bmp2b.c Normal file
View file

@ -0,0 +1,168 @@
/*
* bmp2b.c - convert colored 24 bit bmp to the betty display ram format
*
* author: hackbard@hackdaworld.org
* changed: damaltor@gmail.com
* changelog: edited the first lines of output to fit boop's requirements
* the old line is still there, but commented
*
*/
#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
#define SHOW 3
int main(int argc,char **argv) {
int i,fd;
t_bmp src,dst;
char in[128];
char out[128];
char blook[128+8];
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;
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);
return -1;
}
/* out file */
fd=open(out,O_WRONLY|O_CREAT);
if(fd<0) {
perror("open outfile");
return fd;
}
if(stat==CHAR)
dprintf(fd,"const unsigned char b_w = %d;\nconst unsigned char b_h = %d;\nconst char b_data[] = {\n",DX,DY);
// dprintf(fd,"const unsigned char default_logo[%d]={\n",DX*PM*2);
// was the old function
for(page=0;page<PM;page++) {
for(col=0;col<DX;col++) {
buf[0]=0;
buf[1]=0;
for(i=0;i<8;i++) {
// 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);
if(i<0) {
perror("bin write");
return i;
}
if(i!=2) {
printf("write failure\n");
return -1;
}
}
else if(stat==CHAR) {
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;
}

BIN
bmp2b/trunk/bmp2b.tar.bz2 Normal file

Binary file not shown.