From 281403a4d839924df41480fc020f401211a6e88b Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Sat, 28 Jan 2006 23:12:20 +0000 Subject: Work-in-progress transparent bitmaps with 255,0,255 as the transparent color, not yet working on the H100 series git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8476 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/gwps-common.c | 9 ++++--- apps/screen_access.c | 6 +++++ apps/screen_access.h | 2 ++ firmware/drivers/lcd-16bit.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ firmware/export/lcd.h | 11 +++++++++ 5 files changed, 82 insertions(+), 4 deletions(-) diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index d15dbba888..b32deba479 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c @@ -219,7 +219,7 @@ bool wps_data_preload_tags(struct wps_data *data, char *buf, data->img[n].bm.data = data->img_buf_ptr; ret = read_bmp_file(imgname, &data->img[n].bm, data->img_buf_free, - FORMAT_ANY); + FORMAT_ANY|FORMAT_TRANSPARENT); if (ret > 0) { data->img_buf_ptr += ret; @@ -1252,9 +1252,10 @@ static void wps_draw_image(struct gui_wps *gwps, int n) data->img[n].bm.height); #if LCD_DEPTH > 1 } else { - display->bitmap((fb_data *)data->img[n].bm.data, data->img[n].x, - data->img[n].y, data->img[n].bm.width, - data->img[n].bm.height); + display->transparent_bitmap((fb_data *)data->img[n].bm.data, + data->img[n].x, + data->img[n].y, data->img[n].bm.width, + data->img[n].bm.height); } #endif } diff --git a/apps/screen_access.c b/apps/screen_access.c index 8f7f5c5aae..d38f1ca6a9 100644 --- a/apps/screen_access.c +++ b/apps/screen_access.c @@ -121,6 +121,12 @@ void screen_init(struct screen * screen, enum screen_type screen_type) screen->set_drawmode=&lcd_set_drawmode; #if LCD_DEPTH > 1 screen->bitmap=&lcd_bitmap; +#if LCD_DEPTH == 2 + /* No transparency yet for grayscale lcd */ + screen->transparent_bitmap=&lcd_bitmap; +#else + screen->transparent_bitmap=&lcd_bitmap_transparent; +#endif screen->set_background=&lcd_set_background; #endif screen->update_rect=&lcd_update_rect; diff --git a/apps/screen_access.h b/apps/screen_access.h index af52527fc0..3664ecb13d 100644 --- a/apps/screen_access.h +++ b/apps/screen_access.h @@ -84,6 +84,8 @@ struct screen int x, int y, int width, int height); void (*bitmap)(const fb_data *src, int x, int y, int width, int height); + void (*transparent_bitmap)(const fb_data *src, + int x, int y, int width, int height); void (*set_drawmode)(int mode); #if (LCD_DEPTH > 1) || (LCD_REMOTE_DEPTH > 1) void (*set_background)(unsigned background); diff --git a/firmware/drivers/lcd-16bit.c b/firmware/drivers/lcd-16bit.c index b13e4cee90..4a6348f9db 100644 --- a/firmware/drivers/lcd-16bit.c +++ b/firmware/drivers/lcd-16bit.c @@ -540,6 +540,64 @@ void lcd_bitmap(const fb_data *src, int x, int y, int width, int height) lcd_bitmap_part(src, 0, 0, width, x, y, width, height); } +/* Draw a partial native bitmap */ +void lcd_bitmap_transparent_part(const fb_data *src, int src_x, int src_y, + int stride, int x, int y, int width, + int height) ICODE_ATTR; +void lcd_bitmap_transparent_part(const fb_data *src, int src_x, int src_y, + int stride, int x, int y, int width, + int height) +{ + fb_data *dst, *dst_end; + + /* nothing to draw? */ + if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || (y >= LCD_HEIGHT) + || (x + width <= 0) || (y + height <= 0)) + return; + + /* clipping */ + if (x < 0) + { + width += x; + src_x -= x; + x = 0; + } + if (y < 0) + { + height += y; + src_y -= y; + y = 0; + } + if (x + width > LCD_WIDTH) + width = LCD_WIDTH - x; + if (y + height > LCD_HEIGHT) + height = LCD_HEIGHT - y; + + src += stride * src_y + src_x; /* move starting point */ + dst = LCDADDR(x, y); + dst_end = dst + height * LCD_WIDTH; + + do + { + int i; + for(i = 0;i < width;i++) + { + if(src[i] != TRANSPARENT_COLOR) + dst[i] = src[i]; + } + src += stride; + dst += LCD_WIDTH; + } + while (dst < dst_end); +} + +/* Draw a full native bitmap with a transparent color */ +void lcd_bitmap_transparent(const fb_data *src, int x, int y, + int width, int height) +{ + lcd_bitmap_transparent_part(src, 0, 0, width, x, y, width, height); +} + /* put a string at a given pixel position, skipping first ofs pixel columns */ static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str) { diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h index 393e91f93e..f4c40fb88c 100644 --- a/firmware/export/lcd.h +++ b/firmware/export/lcd.h @@ -201,11 +201,16 @@ enum FORMAT_ANY /* For passing to read_bmp_file() */ }; +#define FORMAT_TRANSPARENT 0x40000000 + +#define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255) + struct bitmap { int width; int height; #if LCD_DEPTH > 1 int format; + unsigned char *maskdata; #endif unsigned char *data; }; @@ -265,6 +270,12 @@ extern void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y, int stride, int x, int y, int width, int height); extern void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width, int height); +extern void lcd_bitmap_transparent_part(const fb_data *src, + int src_x, int src_y, + int stride, int x, int y, int width, + int height); +extern void lcd_bitmap_transparent(const fb_data *src, int x, int y, + int width, int height); #else /* LCD_DEPTH == 1 */ #define lcd_mono_bitmap lcd_bitmap #define lcd_mono_bitmap_part lcd_bitmap_part -- cgit v1.2.3