From: Jon Langseth Date: Thu, 27 Jun 2013 22:05:07 +0000 (+0200) Subject: Added support for drawing 8bpp images... Updated demo a bit... X-Git-Url: https://git.defcon.no/?a=commitdiff_plain;h=4ce0102c5fef814f9a42d18892166ec2809edf3f;p=avrfbosd Added support for drawing 8bpp images... Updated demo a bit... --- diff --git a/draw.c b/draw.c index 43af32b..567b923 100644 --- a/draw.c +++ b/draw.c @@ -63,7 +63,7 @@ Bresenham's line algorithm, optimized and simplified. void draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t c) { - if (x0 > hres_bytes*8 || y0 > VRES || x1 > hres_bytes*8 || y1 > VRES) + if (x0 > hres_bytes*8 || y0 > VRES) // || x1 > hres_bytes*8 || y1 > VRES) return; int dx, dy, sx, sy, err, p; @@ -78,6 +78,8 @@ void draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t c) { sp(x0, y0, c); if ( ( x0 == x1 ) && ( y0 == y1 ) ) return; + if ( x0 > hres_bytes*8 || y0 > VRES ) return; + p = 2 * err; if ( p > -dy ) { @@ -189,4 +191,27 @@ void fill_circle(uint8_t x0, uint8_t y0, uint8_t radius, char c) _draw_circle(x0, y0, radius, c, c); } +void draw_8bpp_bitmap( uint8_t pos_x, uint8_t pos_y, uint8_t width, uint8_t height, const uint8_t* image ) +{ + for ( int v = 0; v < height; v++ ) + { + for ( int h = 0; h < width; h++ ) + { + uint8_t t = image[v*width+h]; + set_pixel( pos_x + h, pos_y + v, t); + } + } +} + +void pgm_draw_8bpp_bitmap( uint8_t pos_x, uint8_t pos_y, uint8_t width, uint8_t height, const uint8_t* image ) +{ + for ( int v = 0; v < height; v++ ) + { + for ( int h = 0; h < width; h++ ) + { + uint8_t t = pgm_read_byte(&(image[v*width+h])); + set_pixel( pos_x + h, pos_y + v, t); + } + } +} diff --git a/draw.h b/draw.h index e7690a4..34e0d3c 100644 --- a/draw.h +++ b/draw.h @@ -2,6 +2,7 @@ #define DRAW_H #include +#include #include "video_properties.h" #define c_BLACK 0 @@ -33,5 +34,7 @@ void fill_circle(uint8_t x0, uint8_t y0, uint8_t radius, char c); // TODO: WILL need void draw_bitmap(uint8_t x, uint8_t y, const unsigned char * bmp, uint16_t i = 0, uint8_t width = 0, uint8_t lines = 0); // TODO draw_bitmap() will be useful for printing text, as printing text // TODO is drawing font elements, and font elements are ... bitmaps. +void draw_8bpp_bitmap( uint8_t pos_x, uint8_t pos_y, uint8_t width, uint8_t height, const uint8_t* image ); +void pgm_draw_8bpp_bitmap( uint8_t pos_x, uint8_t pos_y, uint8_t width, uint8_t height, const uint8_t* image ); #endif diff --git a/fbosd.c b/fbosd.c index 6b96e9b..075fa80 100644 --- a/fbosd.c +++ b/fbosd.c @@ -7,7 +7,9 @@ #include "video_properties.h" #include "render.h" #include "draw.h" -#include "font.h" + +//#include "font.h" +#include "testimage.h" void (*line_handler)( void ); @@ -139,7 +141,8 @@ int main(void) // Enable interrupts globally. sei(); -/* + int counter; + // Do some static drawing :P set_pixel(28, 8, 1); set_pixel(92, 82, 1); @@ -147,57 +150,70 @@ int main(void) set_pixel(92, 8, 1); set_pixel(28, 82, 1); - draw_line(0, 0, 128, 92, 1); - draw_line(128, 0, 0, 92, 1); + draw_line(0, 0, 128, 92, c_WHITE); + draw_line(128, 0, 0, 92, c_WHITE); - draw_rect( 0, 1, 127, 91, 1); + draw_rect( 0, 1, 127, 91, c_WHITE); - draw_rect( 34, 21, 60, 50, 1); - _draw_rect( 24, 11, 80, 70, 1, -1); - draw_rect( 34, 21, 60, 50, 1); + draw_rect( 34, 21, 60, 50, c_WHITE); + _draw_rect( 24, 11, 80, 70, 1, c_NONE); + draw_rect( 34, 21, 60, 50, c_WHITE); - fill_circle( 64,46, 45, 1 ); - fill_circle( 64,46, 40, 0 ); + fill_circle( 64,46, 45, c_WHITE ); + fill_circle( 64,46, 40, c_BLACK ); - _draw_circle( 64,46, 35, 1, -1 ); - draw_circle( 64,46, 30, 1 ); - fill_rect( 38, 25, 52, 42, 1); - fill_rect( 41, 28, 46, 36, 0); + _draw_circle( 64,46, 35, 1, c_NONE ); + draw_circle( 64,46, 30, c_WHITE ); + fill_rect( 38, 25, 52, 42, c_WHITE); + fill_rect( 41, 28, 46, 36, c_BLACK); - for (;;) + for (counter = 0; counter < 3; counter++) { // Toggle status LED PORTD ^= (uint8_t)(1 << PD6); for ( int j = 0; j < 92; j++ ) { - draw_line(0,0,128,j, 2); - draw_line(128,0,0,j, 2); - draw_line(0,92,128,92-j, 2); - draw_line(128,92,0,92-j, 2); + draw_line(0,0,128,j, c_INVERT); + draw_line(128,0,0,j, c_INVERT); + draw_line(0,92,128,92-j, c_INVERT); + draw_line(128,92,0,92-j, c_INVERT); Delay_ms(2); } for ( int j = 0; j < 92; j++ ) { - draw_line(0,0,128,j, 2); - draw_line(128,0,0,j, 2); - draw_line(0,92,128,92-j, 2); - draw_line(128,92,0,92-j, 2); + draw_line(0,0,128,j, c_INVERT); + draw_line(128,0,0,j, c_INVERT); + draw_line(0,92,128,92-j, c_INVERT); + draw_line(128,92,0,92-j, c_INVERT); Delay_ms(2); } Delay_ms(250); } -*/ + fill(c_BLACK); + int8_t hp = 10; + int8_t vp = 10; + + for (counter = 0; counter < 100; counter++) + { + hp += 2; + vp += 1; + + if ( hp > 125 ) hp = 10; + if ( vp > VRES ) vp = 10; + + pgm_draw_8bpp_bitmap(hp, vp, testimage_width, testimage_height, testimage); + Delay_ms(10); + fill_rect(hp, vp, testimage_width, testimage_height, 0); + } for (;;) { - } + } - - diff --git a/testimage.h b/testimage.h index 00dc78b..a5078d9 100644 --- a/testimage.h +++ b/testimage.h @@ -1,11 +1,14 @@ -image_widtdh = 23; // pixels -image_height = 9; // rows +const uint8_t testimage_width = 23; // pixels +const uint8_t testimage_height = 9; // rows -uint8_t image[] = { - 0b00001111, 0b00000001, 0b11100000, 0b00100001, 0b00000100, 0b00100000 - 0b10011001, 0b00010011, 0b00100010, 0b01001001, 0b01001001, 0b00101001 - 0b00001001, 0b00100001, 0b00101001, 0b00100101, 0b00100100, 0b10001001 - 0b10010001, 0b00110010, 0b00001000, 0b01000001, 0b00001000, 0b00001111 - 0b00000001, - 0b11100000 // Note, last byte padded to fill one byte by adding a 0 at the end.. +const uint8_t testimage[] PROGMEM = { + 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, + 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, + 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, + 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, + 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0 };