summaryrefslogtreecommitdiff
path: root/uisimulator/sdl/lcd-bitmap.c
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2006-02-26 13:37:42 +0000
committerJens Arnold <amiconn@rockbox.org>2006-02-26 13:37:42 +0000
commit6a972e02497d3015236189f72931c3d59fa51755 (patch)
tree0c0185dd66b47d7d1ee2d91e4a3ffb6dbabcc7d1 /uisimulator/sdl/lcd-bitmap.c
parent14fe89aa8d2ef05595bdba0e0b78f021f3e8d087 (diff)
downloadrockbox-6a972e02497d3015236189f72931c3d59fa51755.tar.gz
rockbox-6a972e02497d3015236189f72931c3d59fa51755.zip
Finally - grayscale library support for the simulators. Currently SDL only, win32 and x11 won't link anymore due to missing simulator functions.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8845 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/sdl/lcd-bitmap.c')
-rw-r--r--uisimulator/sdl/lcd-bitmap.c89
1 files changed, 74 insertions, 15 deletions
diff --git a/uisimulator/sdl/lcd-bitmap.c b/uisimulator/sdl/lcd-bitmap.c
index 2fd7576ecc..788a5f662d 100644
--- a/uisimulator/sdl/lcd-bitmap.c
+++ b/uisimulator/sdl/lcd-bitmap.c
@@ -22,6 +22,7 @@
22#include "lcd-sdl.h" 22#include "lcd-sdl.h"
23 23
24SDL_Surface* lcd_surface; 24SDL_Surface* lcd_surface;
25int lcd_backlight_val;
25 26
26#if LCD_DEPTH <= 8 27#if LCD_DEPTH <= 8
27SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0}; 28SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0};
@@ -29,22 +30,27 @@ SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
29SDL_Color lcd_color_max = {0, 0, 0, 0}; 30SDL_Color lcd_color_max = {0, 0, 0, 0};
30#endif 31#endif
31 32
32static inline Uint32 get_lcd_pixel(int x, int y) 33#if LCD_DEPTH < 8
34int lcd_ex_shades = 0;
35unsigned long (*lcd_ex_getpixel)(int, int) = NULL;
36#endif
37
38static unsigned long get_lcd_pixel(int x, int y)
33{ 39{
34#if LCD_DEPTH == 1 40#if LCD_DEPTH == 1
35 return ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1); 41 return ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1);
36#elif LCD_DEPTH == 2 42#elif LCD_DEPTH == 2
37#if LCD_PIXELFORMAT == HORIZONTAL_PACKING 43#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
38 return ((lcd_framebuffer[y][x/4] >> (2 * (x & 3))) & 3); 44 return ((lcd_framebuffer[y][x/4] >> (2 * (x & 3))) & 3);
39#else 45#else
40 return ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3); 46 return ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3);
41#endif 47#endif
42#elif LCD_DEPTH == 16 48#elif LCD_DEPTH == 16
43#if LCD_PIXELFORMAT == RGB565SWAPPED 49#if LCD_PIXELFORMAT == RGB565SWAPPED
44 unsigned bits = lcd_framebuffer[y][x]; 50 unsigned bits = lcd_framebuffer[y][x];
45 return (bits >> 8) | (bits << 8); 51 return (bits >> 8) | (bits << 8);
46#else 52#else
47 return lcd_framebuffer[y][x]; 53 return lcd_framebuffer[y][x];
48#endif 54#endif
49#endif 55#endif
50} 56}
@@ -57,22 +63,41 @@ void lcd_update(void)
57 63
58void lcd_update_rect(int x_start, int y_start, int width, int height) 64void lcd_update_rect(int x_start, int y_start, int width, int height)
59{ 65{
60 sdl_update_rect(lcd_surface, x_start, y_start, width, height, LCD_WIDTH, LCD_HEIGHT, 66 sdl_update_rect(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
61 background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0, 67 LCD_HEIGHT, get_lcd_pixel);
62 get_lcd_pixel); 68 sdl_gui_update(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
69 LCD_HEIGHT, background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
63} 70}
64 71
65#ifdef CONFIG_BACKLIGHT 72#ifdef CONFIG_BACKLIGHT
66void sim_backlight(int value) 73void sim_backlight(int value)
67{ 74{
75 lcd_backlight_val = value;
76
68#if LCD_DEPTH <= 8 77#if LCD_DEPTH <= 8
69 if (value > 0) { 78 if (value > 0) {
70 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); 79 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero,
80 &lcd_color_max, 0, (1<<LCD_DEPTH));
71 } else { 81 } else {
72 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); 82 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max,
83 0, (1<<LCD_DEPTH));
73 } 84 }
74 85#if LCD_DEPTH < 8
75 lcd_update(); 86 if (lcd_ex_shades) {
87 if (value > 0) {
88 sdl_set_gradient(lcd_surface, &lcd_color_max,
89 &lcd_backlight_color_zero, (1<<LCD_DEPTH),
90 lcd_ex_shades);
91 } else {
92 sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero,
93 (1<<LCD_DEPTH), lcd_ex_shades);
94 }
95 }
96#endif
97
98 sdl_gui_update(lcd_surface, 0, 0, LCD_WIDTH, LCD_HEIGHT, LCD_WIDTH,
99 LCD_HEIGHT, background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
100
76#else 101#else
77 DEBUGF("backlight: %s\n", (value > 0) ? "on" : "off"); 102 DEBUGF("backlight: %s\n", (value > 0) ? "on" : "off");
78#endif 103#endif
@@ -91,7 +116,41 @@ void sim_lcd_init(void)
91#endif 116#endif
92 117
93#if LCD_DEPTH <= 8 118#if LCD_DEPTH <= 8
94 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); 119 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max,
120 0, (1<<LCD_DEPTH));
121#endif
122}
123
124#if LCD_DEPTH < 8
125void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int))
126{
127 lcd_ex_shades = shades;
128 lcd_ex_getpixel = getpixel;
129 if (shades) {
130#ifdef CONFIG_BACKLIGHT
131 if (lcd_backlight_val > 0) {
132 sdl_set_gradient(lcd_surface, &lcd_color_max,
133 &lcd_backlight_color_zero, (1<<LCD_DEPTH),
134 shades);
135 }
136 else
95#endif 137#endif
138 {
139 sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero,
140 (1<<LCD_DEPTH), shades);
141 }
142 }
96} 143}
97 144
145void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height)
146{
147 if (lcd_ex_getpixel) {
148 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
149 LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel);
150 sdl_gui_update(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
151 LCD_HEIGHT, background ? UI_LCD_POSX : 0,
152 background? UI_LCD_POSY : 0);
153 }
154}
155#endif
156