Added tft method to draw a bmp from filesystem. Added another font to emulator.

This commit is contained in:
t-moe
2015-05-15 20:17:36 +02:00
parent 9a16865b00
commit b08a897e61
3 changed files with 72 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include "filesystem.h"
bool tft_init() { bool tft_init() {
return ll_tft_init(); return ll_tft_init();
@@ -67,3 +68,59 @@ void tft_print_formatted(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolo
tft_print_line(x,y,color,bgcolor,font,buffer); tft_print_line(x,y,color,bgcolor,font,buffer);
va_end(args); va_end(args);
} }
bool tft_draw_bitmap_file_unscaled(uint16_t x, uint16_t y, const char* filename) {
//Copied and modified from: http://stackoverflow.com/a/17040962/2606757
FILE_HANDLE* file = filesystem_file_open(filename);
if(file==NULL) {
return false;
}
unsigned char info[54];
if(filesystem_file_read(file,info,54)!=F_OK) {
filesystem_file_close(file);
return false;
}
// extract image height and width from header
uint32_t width = *(uint32_t*)&info[18]; //width in pixel
uint32_t height = *(uint32_t*)&info[22]; //height in pixel
uint16_t depth = *(uint16_t*)&info[28]; //bit's per pixel (color depth)
depth/=8; //we want the number of bytes per pixel
filesystem_file_seek(file,*(uint32_t*)&info[10]); //seek to the place where img data begins
uint32_t row_padded = (width*depth + 3) & (~3); //row size aligned to 4 bytes
unsigned char data [row_padded];
for(int i = 0; i < height; i++)
{
filesystem_file_read(file,data,row_padded);
for(int j = 0; j < width*depth; j += depth)
{
unsigned char a,r,g,b;
if(depth==4) {
a = data[j];
r = data[j+1];
g = data[j+2];
b = data[j+3];
} else if (depth==3) {
a = 255;
r = data[j+2];
g = data[j+1];
b = data[j];
}
if(a!=0) {
tft_draw_pixel(x+j/depth,y+height-1-i,RGB(r,g,b));
}
}
}
filesystem_file_close(file);
return true;
}

View File

@@ -103,6 +103,18 @@ void tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_
*/ */
void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat); void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat);
/**
* Draws a bitmap from the filesystem onto the display without scaling/cropping
* The bitmap must be saved in the windows bitmap format (.bmp) without compression and with 24 (b,g,r) or 32 (a,r,g,b) bits per pixel
* @param x The x-coordinate of the top-left corner to draw the bitmap at
* @param y The y-coordinate of the top-left corner to draw the bitmap at
* @param filename The absolute path to the .bmp file
* @return true on success
*/
bool tft_draw_bitmap_file_unscaled(uint16_t x, uint16_t y, const char* filename);
/** /**
* Draws the outline of a circle onto the display * Draws the outline of a circle onto the display
* @param x The x-Coordinate of the center point * @param x The x-Coordinate of the center point

View File

@@ -44,13 +44,15 @@ void ll_tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color) {
} }
uint8_t ll_tft_num_fonts() { uint8_t ll_tft_num_fonts() {
return 1; return 2;
} }
QFont get_font(uint8_t fontnum) { QFont get_font(uint8_t fontnum) {
switch(fontnum) { switch(fontnum) {
case 0: case 0:
return QFont("Monospace",8); return QFont("Monospace",8);
case 1:
return QFont("DejaVu Sans Mono",14);
default: default:
return QFont(); return QFont();
} }