Added bitmap decoding/drawing example

This commit is contained in:
t-moe
2015-05-10 02:22:17 +02:00
parent e2bce8f163
commit 790f60269a
2 changed files with 48 additions and 1 deletions

View File

@@ -12,6 +12,9 @@ static void b_back_cb(void* button) {
gui_screen_back(); gui_screen_back();
} }
static void image_test();
static void enter(void* screen) { static void enter(void* screen) {
tft_clear(HEX(0xBABECD)); tft_clear(HEX(0xBABECD));
@@ -103,7 +106,8 @@ static void enter(void* screen) {
} }
filesystem_file_close(file); filesystem_file_close(file);
image_test();
} }
static void leave(void* screen) { static void leave(void* screen) {
@@ -125,4 +129,47 @@ SCREEN_STRUCT* get_screen_filetest() {
return &screen; return &screen;
} }
static void image_test() {
//Source: http://stackoverflow.com/a/17040962/2606757
FILE_HANDLE* file = filesystem_file_open("cpu.bmp");
if(file==NULL) {
tft_print_line(10,180,BLUE,TRANSPARENT,0,"Could not open cpu.bmp");
return;
}
unsigned char info[54];
if(filesystem_file_read(file,info,54)!=F_OK) {
tft_print_line(10,180,BLUE,TRANSPARENT,0,"Could not read header of cpu.bmp");
filesystem_file_close(file);
return;
}
// extract image height and width from header
int width = *(int*)&info[18];
int height = *(int*)&info[22];
filesystem_file_seek(file,*(int*)&info[10]);
unsigned char data [width*4];
tft_draw_rectangle(100-1,160-1,100-1+width,160-1+height,BLACK);
for(int i = 0; i < height; i++)
{
filesystem_file_read(file,data,width*4);
for(int j = 0; j < width*4; j += 4)
{
unsigned char a = data[j];
unsigned char r = data[j+1];
unsigned char g = data[j+2];
unsigned char b = data[j+3];
if(a!=0) {
tft_draw_pixel(100+j/4,160+height-1-i,RGB(r,g,b));
}
}
}
filesystem_file_close(file);
}

BIN
emulator/emulated/cpu.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB