diff --git a/apps/gui/splash.c b/apps/gui/splash.c index fc15294211..8d69068d3b 100644 --- a/apps/gui/splash.c +++ b/apps/gui/splash.c @@ -127,13 +127,8 @@ void internal_splash(struct screen * screen, int xx = (screen->width-maxw)/2 - 2; /* The new graphics routines handle clipping, so no need to check */ #if LCD_DEPTH > 1 -#ifdef HAVE_LCD_COLOR - screen->set_background((struct rgb){LCD_MAX_RED-1, LCD_MAX_GREEN-1, - LCD_MAX_BLUE-1}); -#else if(screen->depth>1) - screen->set_background(LCD_MAX_LEVEL-1); -#endif + screen->set_background(LCD_LIGHTGRAY); #endif screen->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); screen->fillrect(xx, y-2, maxw+4, screen->height-y*2+4); @@ -183,7 +178,7 @@ void internal_splash(struct screen * screen, #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH > 1) if(screen->depth > 1) - screen->set_background(LCD_WHITE); + screen->set_background(LCD_DEFAULT_BG); #endif #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR) screen->update(); diff --git a/apps/plugin.c b/apps/plugin.c index a30b089e55..d5607aa822 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -434,7 +434,7 @@ int plugin_load(const char* plugin, void* parameter) button_clear_queue(); #ifdef HAVE_LCD_BITMAP #if LCD_DEPTH > 1 - lcd_set_drawinfo(DRMODE_SOLID, LCD_BLACK, LCD_WHITE); + lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG); #else /* LCD_DEPTH == 1 */ lcd_set_drawmode(DRMODE_SOLID); #endif /* LCD_DEPTH */ diff --git a/apps/plugin.h b/apps/plugin.h index 8630ce7f17..f8e84f8cae 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -173,17 +173,10 @@ struct plugin_api { void (*lcd_mono_bitmap)(const unsigned char *src, int x, int y, int width, int height); #if LCD_DEPTH > 1 -#ifdef HAVE_LCD_COLOR - void (*lcd_set_foreground)(struct rgb color); - struct rgb (*lcd_get_foreground)(void); - void (*lcd_set_background)(struct rgb color); - struct rgb (*lcd_get_background)(void); -#else - void (*lcd_set_foreground)(int brightness); - int (*lcd_get_foreground)(void); - void (*lcd_set_background)(int brightness); - int (*lcd_get_background)(void); -#endif + void (*lcd_set_foreground)(unsigned foreground); + unsigned (*lcd_get_foreground)(void); + void (*lcd_set_background)(unsigned foreground); + unsigned (*lcd_get_background)(void); void (*lcd_bitmap_part)(const fb_data *src, int src_x, int src_y, int stride, int x, int y, int width, int height); void (*lcd_bitmap)(const fb_data *src, int x, int y, int width, diff --git a/apps/plugins/bounce.c b/apps/plugins/bounce.c index 3ff3a8d5f6..1bf8b3b34d 100644 --- a/apps/plugins/bounce.c +++ b/apps/plugins/bounce.c @@ -282,17 +282,14 @@ static void addclock(void) #define DRAW_WIDTH (LCD_WIDTH + LETTER_WIDTH*2) #if LCD_DEPTH > 1 +static const unsigned face_colors[] = +{ #ifdef HAVE_LCD_COLOR -static const struct rgb face_colors[] = -{ - LCD_BLACK, {0, 0, LCD_MAX_BLUE}, {LCD_MAX_RED, 0, 0} -}; + LCD_BLACK, LCD_RGBPACK(0, 0, 255), LCD_RGBPACK(255, 0, 0) #else -static const int face_colors[] = -{ - 0, 2*LCD_MAX_LEVEL/3, LCD_MAX_LEVEL/3 -}; + LCD_BLACK, LCD_LIGHTGRAY, LCD_DARKGRAY #endif +}; #endif static int scrollit(void) diff --git a/apps/plugins/cube.c b/apps/plugins/cube.c index 2360269aba..dc5b5706f4 100644 --- a/apps/plugins/cube.c +++ b/apps/plugins/cube.c @@ -152,18 +152,16 @@ static const struct face faces[6] = }; #if LCD_DEPTH > 1 +static const unsigned face_colors[6] = +{ #ifdef HAVE_LCD_COLOR -static const struct rgb face_colors[6] = -{ - {LCD_MAX_RED, 0, 0}, {LCD_MAX_RED, 0, 0}, {0, LCD_MAX_GREEN, 0}, - {0, LCD_MAX_GREEN, 0}, {0, 0, LCD_MAX_BLUE}, {0, 0, LCD_MAX_BLUE} -}; + LCD_RGBPACK(255, 0, 0), LCD_RGBPACK(255, 0, 0), LCD_RGBPACK(0, 255, 0), + LCD_RGBPACK(0, 255, 0), LCD_RGBPACK(0, 0, 255), LCD_RGBPACK(0, 0, 255) #else -static const int face_colors[6] = -{ - 2*LCD_MAX_LEVEL/3, 2*LCD_MAX_LEVEL/3, LCD_MAX_LEVEL/3, LCD_MAX_LEVEL/3, 0, 0 -}; + LCD_LIGHTGRAY, LCD_LIGHTGRAY, LCD_DARKGRAY, + LCD_DARKGRAY, LCD_BLACK, LCD_BLACK #endif +}; #endif enum { diff --git a/apps/plugins/lib/gray.h b/apps/plugins/lib/gray.h index dadac9298f..f82cf389c3 100644 --- a/apps/plugins/lib/gray.h +++ b/apps/plugins/lib/gray.h @@ -51,11 +51,11 @@ void gray_update_rect(int x, int y, int width, int height); void gray_set_position(int x, int by); void gray_set_drawmode(int mode); int gray_get_drawmode(void); -void gray_set_foreground(int brightness); -int gray_get_foreground(void); -void gray_set_background(int brightness); -int gray_get_background(void); -void gray_set_drawinfo(int mode, int fg_brightness, int bg_brightness); +void gray_set_foreground(unsigned brightness); +unsigned gray_get_foreground(void); +void gray_set_background(unsigned brightness); +unsigned gray_get_background(void); +void gray_set_drawinfo(int mode, unsigned fg_brightness, unsigned bg_brightness); void gray_setfont(int newfont); int gray_getstringsize(const unsigned char *str, int *w, int *h); diff --git a/apps/plugins/lib/gray_parm.c b/apps/plugins/lib/gray_parm.c index a8c238a4eb..c4ee92f9cc 100644 --- a/apps/plugins/lib/gray_parm.c +++ b/apps/plugins/lib/gray_parm.c @@ -53,7 +53,7 @@ int gray_get_drawmode(void) } /* Set the foreground shade for subsequent drawing operations */ -void gray_set_foreground(int brightness) +void gray_set_foreground(unsigned brightness) { unsigned data = MULU16(_gray_info.depth, brightness & 0xFF) + 127; @@ -61,14 +61,14 @@ void gray_set_foreground(int brightness) } /* Return the current foreground shade */ -int gray_get_foreground(void) +unsigned gray_get_foreground(void) { return (_gray_info.fg_brightness * 255 + (_gray_info.depth >> 1)) / _gray_info.depth; } /* Set the background shade for subsequent drawing operations */ -void gray_set_background(int brightness) +void gray_set_background(unsigned brightness) { unsigned data = MULU16(_gray_info.depth, brightness & 0xFF) + 127; @@ -76,14 +76,14 @@ void gray_set_background(int brightness) } /* Return the current background shade */ -int gray_get_background(void) +unsigned gray_get_background(void) { return (_gray_info.bg_brightness * 255 + (_gray_info.depth >> 1)) / _gray_info.depth; } /* Set draw mode, foreground and background shades at once */ -void gray_set_drawinfo(int mode, int fg_brightness, int bg_brightness) +void gray_set_drawinfo(int mode, unsigned fg_brightness, unsigned bg_brightness) { gray_set_drawmode(mode); gray_set_foreground(fg_brightness); diff --git a/apps/plugins/minesweeper.c b/apps/plugins/minesweeper.c index 097c1b0c43..4af467b516 100644 --- a/apps/plugins/minesweeper.c +++ b/apps/plugins/minesweeper.c @@ -67,16 +67,6 @@ use F3 to see how many mines are left (supposing all your flags are correct) #endif -#if LCD_DEPTH > 1 -#if HAVE_LCD_COLOR -#define LIGHT_GRAY ((struct rgb){2*LCD_MAX_RED/3, 2*LCD_MAX_GREEN/3, 2*LCD_MAX_BLUE/3}) -#define DARK_GRAY ((struct rgb){LCD_MAX_RED/3, LCD_MAX_GREEN/3, LCD_MAX_BLUE/3}) -#else -#define LIGHT_GRAY (2*LCD_MAX_LEVEL/3) -#define DARK_GRAY (LCD_MAX_LEVEL/3) -#endif -#endif - /* here is a global api struct pointer. while not strictly necessary, it's nice not to have to pass the api pointer in all function calls in the plugin */ @@ -385,7 +375,7 @@ int minesweeper(void) for(i=0;i 1 - rb->lcd_set_foreground(DARK_GRAY); + rb->lcd_set_foreground(LCD_DARKGRAY); rb->lcd_drawrect(j*8,i*8,8,8); rb->lcd_set_foreground(LCD_BLACK); #else @@ -404,7 +394,7 @@ int minesweeper(void) rb->lcd_drawline(j*8+2,i*8+5,j*8+5,i*8+2); } else { #if LCD_DEPTH > 1 - rb->lcd_set_foreground(LIGHT_GRAY); + rb->lcd_set_foreground(LCD_LIGHTGRAY); rb->lcd_fillrect(j*8+1,i*8+1,6,6); rb->lcd_set_foreground(LCD_BLACK); #else diff --git a/apps/plugins/sokoban.c b/apps/plugins/sokoban.c index 70f616d406..a341cf5416 100644 --- a/apps/plugins/sokoban.c +++ b/apps/plugins/sokoban.c @@ -59,10 +59,10 @@ #endif #if LCD_DEPTH > 1 -#if HAVE_LCD_COLOR -#define MEDIUM_GRAY ((struct rgb){LCD_MAX_RED/2, LCD_MAX_GREEN/2, LCD_MAX_BLUE/2}) +#ifdef HAVE_LCD_COLOR +#define MEDIUM_GRAY LCD_RGBPACK(127, 127, 127) #else -#define MEDIUM_GRAY (LCD_MAX_LEVEL/2) +#define MEDIUM_GRAY LCD_BRIGHTNESS(127) #endif #endif diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c index b2af0828e2..30405a582f 100644 --- a/apps/plugins/solitaire.c +++ b/apps/plugins/solitaire.c @@ -135,13 +135,13 @@ static struct plugin_api* rb; #endif #if LCD_DEPTH>1 +static const unsigned colors[4] = { #ifdef HAVE_LCD_COLOR -static const unsigned struct rgb colors[4] = { - { 0, 0, 0 }, { LCD_MAX_RED, 0, 0 }, { 0, 0, 0 }, { LCD_MAX_RED, 0, 0 } -}; + LCD_BLACK, LCD_RGBPACK(255, 0, 0), LCD_BLACK, LCD_RGBPACK(255, 0, 0) #else -static const int colors[4] = { LCD_BLACK, LCD_MAX_LEVEL/2, LCD_BLACK, LCD_MAX_LEVEL/2 }; + LCD_BLACK, LCD_BRIGHTNESS(127), LCD_BLACK, LCD_BRIGHTNESS(127) #endif +}; #endif static const unsigned char suits[4][8] = { diff --git a/apps/plugins/sudoku.c b/apps/plugins/sudoku.c index 526416d11e..bab53bbad4 100644 --- a/apps/plugins/sudoku.c +++ b/apps/plugins/sudoku.c @@ -362,16 +362,6 @@ static unsigned char num_inverse[10][8]= { #error SUDOKU: Unsupported LCD size #endif -#if LCD_DEPTH > 1 -#if HAVE_LCD_COLOR -#define LIGHT_GRAY ((struct rgb){2*LCD_MAX_RED/3, 2*LCD_MAX_GREEN/3, 2*LCD_MAX_BLUE/3}) -#define DARK_GRAY ((struct rgb){LCD_MAX_RED/3, LCD_MAX_GREEN/3, LCD_MAX_BLUE/3}) -#else -#define LIGHT_GRAY (2*LCD_MAX_LEVEL/3) -#define DARK_GRAY (LCD_MAX_LEVEL/3) -#endif -#endif - /* here is a global api struct pointer. while not strictly necessary, it's nice not to have to pass the api pointer in all function calls in the plugin */ diff --git a/apps/screen_access.h b/apps/screen_access.h index c167708fbf..6111de9de4 100644 --- a/apps/screen_access.h +++ b/apps/screen_access.h @@ -76,11 +76,7 @@ struct screen int x, int y, int width, int height); void (*set_drawmode)(int mode); #if LCD_DEPTH > 1 -#if HAVE_LCD_COLOR - void (*set_background)(struct rgb color); -#else - void (*set_background)(int brightness); -#endif + void (*set_background)(unsigned background); #endif /* LCD_DEPTH > 1 */ void (*update_rect)(int x, int y, int width, int height); void (*fillrect)(int x, int y, int width, int height); diff --git a/firmware/drivers/lcd-16bit.c b/firmware/drivers/lcd-16bit.c index 185f572182..1aed98e5f6 100644 --- a/firmware/drivers/lcd-16bit.c +++ b/firmware/drivers/lcd-16bit.c @@ -34,13 +34,11 @@ #define SCROLLABLE_LINES 26 -#define RGB_PACK(r,g,b) (htobe16(((r)<<11)|((g)<<5)|(b))) - /*** globals ***/ fb_data lcd_framebuffer[LCD_HEIGHT][LCD_WIDTH] __attribute__ ((aligned (4))); -static unsigned fg_pattern; -static unsigned bg_pattern; +static unsigned fg_pattern = LCD_DEFAULT_FG; +static unsigned bg_pattern = LCD_DEFAULT_BG; static int drawmode = DRMODE_SOLID; static int xmargin = 0; static int ymargin = 0; @@ -72,9 +70,6 @@ int lcd_default_contrast(void) /* LCD init */ void lcd_init(void) { - fg_pattern = 0x0000; /* Black */ - bg_pattern = RGB_PACK(0x17, 0x31, 0x1d); /* "Rockbox blue" */ - lcd_clear_display(); /* Call device specific init */ lcd_init_device(); @@ -94,43 +89,32 @@ int lcd_get_drawmode(void) return drawmode; } -void lcd_set_foreground(struct rgb color) +void lcd_set_foreground(unsigned color) { - fg_pattern = RGB_PACK(color.red, color.green, color.blue); + fg_pattern = color; } -struct rgb lcd_get_foreground(void) +unsigned lcd_get_foreground(void) { - struct rgb colour; - - colour.red = (fg_pattern >> 11) & 0x1f; - colour.green = (fg_pattern >> 5) & 0x3f; - colour.blue = fg_pattern & 0x1f; - return colour; + return fg_pattern; } -void lcd_set_background(struct rgb color) +void lcd_set_background(unsigned color) { - bg_pattern = RGB_PACK(color.red, color.green, color. blue); + bg_pattern = color; } -struct rgb lcd_get_background(void) +unsigned lcd_get_background(void) { - struct rgb colour; - - colour.red = (bg_pattern >> 11) & 0x1f; - colour.green = (bg_pattern >> 5) & 0x3f; - colour.blue = bg_pattern & 0x1f; - return colour; + return bg_pattern; } -void lcd_set_drawinfo(int mode, struct rgb fg_color, - struct rgb bg_color) +void lcd_set_drawinfo(int mode, unsigned fg_color, unsigned bg_color) { lcd_set_drawmode(mode); - lcd_set_foreground(fg_color); - lcd_set_background(bg_color); + fg_pattern = fg_color; + bg_pattern = bg_color; } void lcd_setmargins(int x, int y) diff --git a/firmware/drivers/lcd-h100.c b/firmware/drivers/lcd-h100.c index e8541f7621..1005cf6b5f 100644 --- a/firmware/drivers/lcd-h100.c +++ b/firmware/drivers/lcd-h100.c @@ -307,27 +307,27 @@ int lcd_get_drawmode(void) return drawmode; } -void lcd_set_foreground(int brightness) +void lcd_set_foreground(unsigned brightness) { fg_pattern = 0x55 * (~brightness & 3); } -int lcd_get_foreground(void) +unsigned lcd_get_foreground(void) { return ~fg_pattern & 3; } -void lcd_set_background(int brightness) +void lcd_set_background(unsigned brightness) { bg_pattern = 0x55 * (~brightness & 3); } -int lcd_get_background(void) +unsigned lcd_get_background(void) { return ~bg_pattern & 3; } -void lcd_set_drawinfo(int mode, int fg_brightness, int bg_brightness) +void lcd_set_drawinfo(int mode, unsigned fg_brightness, unsigned bg_brightness) { lcd_set_drawmode(mode); lcd_set_foreground(fg_brightness); diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h index 2d04cec054..48244fe2a8 100644 --- a/firmware/export/lcd.h +++ b/firmware/export/lcd.h @@ -140,29 +140,39 @@ typedef void lcd_blockfunc_type(unsigned char *address, unsigned mask, unsigned #ifdef HAVE_LCD_COLOR #if LCD_DEPTH == 16 -#define LCD_MAX_RED ((1 << 5) - 1) -#define LCD_MAX_GREEN ((1 << 6) - 1) -#define LCD_MAX_BLUE ((1 << 5) - 1) +#define LCD_MAX_RED 31 +#define LCD_MAX_GREEN 63 +#define LCD_MAX_BLUE 31 +#define _RGBPACK(r, g, b) ( ((((r) * 31 + 127) / 255) << 11) \ + |((((g) * 63 + 127) / 255) << 5) \ + | (((b) * 31 + 127) / 255)) +#if (CONFIG_LCD == LCD_IPODCOLOR) || (CONFIG_LCD == LCD_IPODNANO) +#define LCD_RGBPACK(r, g, b) ( ((_RGBPACK((r), (g), (b)) & 0xff00) >> 8) \ + |((_RGBPACK((r), (g), (b)) & 0x00ff) << 8)) #else -#define LCD_MAX_RED ((1 << (LCD_DEPTH/3)) - 1) -#define LCD_MAX_GREEN ((1 << (LCD_DEPTH/3)) - 1) -#define LCD_MAX_BLUE ((1 << (LCD_DEPTH/3)) - 1) +#define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b)) #endif -struct rgb { - unsigned char red; - unsigned char green; - unsigned char blue; -}; -#define LCD_BLACK ((struct rgb){0, 0, 0}) -#define LCD_DARKGRAY ((struct rgb){LCD_MAX_RED/3, LCD_MAX_GREEN/3, LCD_MAX_BLUE/3}) -#define LCD_LIGHTGRAY ((struct rgb){2*LCD_MAX_RED/3, 2*LCD_MAX_GREEN/3, 2*LCD_MAX_BLUE/3}) -#define LCD_WHITE ((struct rgb){LCD_MAX_RED, LCD_MAX_GREEN, LCD_MAX_BLUE}) -#else /* monochrome */ +#else +/* other colour depths */ +#endif + +#define LCD_BLACK LCD_RGBPACK(0, 0, 0) +#define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85) +#define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170) +#define LCD_WHITE LCD_RGBPACK(255, 255, 255) +#define LCD_DEFAULT_FG LCD_BLACK +#define LCD_DEFAULT_BG LCD_RGBPACK(182, 198, 229) /* rockbox blue */ + +#elif LCD_DEPTH > 1 /* greyscale */ #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1) -#define LCD_BLACK 0 -#define LCD_DARKGRAY (LCD_MAX_LEVEL/3) -#define LCD_LIGHTGRAY (2*LCD_MAX_LEVEL/3) -#define LCD_WHITE LCD_MAX_LEVEL +#define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255) + +#define LCD_BLACK LCD_BRIGHTNESS(0) +#define LCD_DARKGRAY LCD_BRIGHTNESS(85) +#define LCD_LIGHTGRAY LCD_BRIGHTNESS(170) +#define LCD_WHITE LCD_BRIGHTNESS(255) +#define LCD_DEFAULT_FG LCD_BLACK +#define LCD_DEFAULT_BG LCD_WHITE #endif /* Memory copy of display bitmap */ @@ -207,20 +217,13 @@ extern void lcd_bidir_scroll(int threshold); extern void lcd_scroll_step(int pixels); #if LCD_DEPTH > 1 -#ifdef HAVE_LCD_COLOR -extern void lcd_set_foreground(struct rgb color); -extern struct rgb lcd_get_foreground(void); -extern void lcd_set_background(struct rgb color); -extern struct rgb lcd_get_background(void); -extern void lcd_set_drawinfo(int mode, struct rgb fg_color, - struct rgb bg_color); -#else /* monochrome */ -extern void lcd_set_foreground(int brightness); -extern int lcd_get_foreground(void); -extern void lcd_set_background(int brightness); -extern int lcd_get_background(void); -extern void lcd_set_drawinfo(int mode, int fg_brightness, int bg_brightness); -#endif +extern void lcd_set_foreground(unsigned foreground); +extern unsigned lcd_get_foreground(void); +extern void lcd_set_background(unsigned background); +extern unsigned lcd_get_background(void); +extern void lcd_set_drawinfo(int mode, unsigned foreground, + unsigned background); + 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,