Add 4g grayscale support for the win32 sim
[Rockbox.git] / uisimulator / win32 / lcd-win32.c
bloba50fbd11f6dbb9ad8761c61072a5206d9f3a4647
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Felix Arends
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <windows.h>
21 #include <process.h>
22 #include "uisw32.h"
23 #include "lcd.h"
24 #include "lcd-playersim.h"
26 #if LCD_DEPTH == 16
27 unsigned short bitmap[LCD_HEIGHT][LCD_WIDTH]; /* the ui display */
29 BITMAPINFO256 bmi =
31 {sizeof (BITMAPINFOHEADER),
32 LCD_WIDTH, -LCD_HEIGHT, 1, 16,
33 BI_BITFIELDS, 0, 0, 0, 3, 3,
34 }, /* bitfield masks (RGB565) */
35 {{0x00, 0xf8, 0, 0}, {0xe0, 0x07, 0, 0}, {0x1f, 0x00, 0, 0}}
36 }; /* bitmap information */
37 #else
38 unsigned char bitmap[LCD_HEIGHT][LCD_WIDTH]; /* the ui display */
39 RGBQUAD color_zero = {UI_LCD_BGCOLORLIGHT, 0};
40 RGBQUAD color_max = {0, 0, 0, 0};
42 BITMAPINFO256 bmi =
44 {sizeof (BITMAPINFOHEADER),
45 LCD_WIDTH, -LCD_HEIGHT, 1, 8,
46 BI_RGB, 0, 0, 0, 2, 2,
48 {} /* colour lookup table gets filled later */
49 }; /* bitmap information */
50 #endif
52 #ifdef HAVE_LCD_BITMAP
54 #ifdef HAVE_REMOTE_LCD
55 unsigned char remote_bitmap[LCD_REMOTE_HEIGHT][LCD_REMOTE_WIDTH];
56 RGBQUAD remote_color_zero = {UI_REMOTE_BGCOLORLIGHT, 0};
57 RGBQUAD remote_color_max = {0, 0, 0, 0};
59 BITMAPINFO256 remote_bmi =
61 {sizeof (BITMAPINFOHEADER),
62 LCD_REMOTE_WIDTH, -LCD_REMOTE_HEIGHT, 1, 8,
63 BI_RGB, 0, 0, 0, 2, 2,
65 {} /* colour lookup table gets filled later */
67 #endif
69 void lcd_update(void)
71 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
74 void lcd_update_rect(int x_start, int y_start,
75 int width, int height)
77 int x, y;
78 int xmax, ymax;
79 RECT r;
81 ymax = y_start + height;
82 xmax = x_start + width;
84 if (hGUIWnd == NULL)
85 _endthread ();
87 if(xmax > LCD_WIDTH)
88 xmax = LCD_WIDTH;
89 if(ymax >= LCD_HEIGHT)
90 ymax = LCD_HEIGHT;
92 for (x = x_start; x < xmax; x++)
93 for (y = y_start; y < ymax; y++)
95 #if LCD_DEPTH == 1
96 bitmap[y][x] = ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1);
97 #elif LCD_DEPTH == 2
98 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
99 bitmap[y][x] = ((lcd_framebuffer[y][x/4] >> (2 * (x & 3))) & 3);
100 #else
101 bitmap[y][x] = ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3);
102 #endif
103 #elif LCD_DEPTH == 16
104 #if LCD_PIXELFORMAT == RGB565SWAPPED
105 unsigned bits = lcd_framebuffer[y][x];
106 bitmap[y][x] = (bits >> 8) | (bits << 8);
107 #else
108 bitmap[y][x] = lcd_framebuffer[y][x];
109 #endif
110 #endif
113 /* Invalidate only the window part that actually did change */
114 GetClientRect (hGUIWnd, &r);
115 r.left = (UI_LCD_POSX + (UI_LCD_WIDTH * x_start / LCD_WIDTH))
116 * r.right / UI_WIDTH;
117 r.top = (UI_LCD_POSY + (UI_LCD_HEIGHT * y_start / LCD_HEIGHT))
118 * r.bottom / UI_HEIGHT;
119 r.right = (UI_LCD_POSX + (UI_LCD_WIDTH * xmax / LCD_WIDTH))
120 * r.right / UI_WIDTH;
121 r.bottom = (UI_LCD_POSY + (UI_LCD_HEIGHT * ymax / LCD_HEIGHT))
122 * r.bottom / UI_HEIGHT;
123 InvalidateRect (hGUIWnd, &r, FALSE);
126 #ifdef HAVE_REMOTE_LCD
128 extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
130 void lcd_remote_update (void)
132 lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
135 void lcd_remote_update_rect(int x_start, int y_start,
136 int width, int height)
138 int x, y;
139 int xmax, ymax;
140 RECT r;
142 ymax = y_start + height;
143 xmax = x_start + width;
145 if (hGUIWnd == NULL)
146 _endthread ();
148 if(xmax > LCD_REMOTE_WIDTH)
149 xmax = LCD_REMOTE_WIDTH;
150 if(ymax >= LCD_REMOTE_HEIGHT)
151 ymax = LCD_REMOTE_HEIGHT;
153 for (x = x_start; x < xmax; x++)
154 for (y = y_start; y < ymax; y++)
155 remote_bitmap[y][x] = ((lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 1);
157 /* Invalidate only the window part that actually did change */
158 GetClientRect (hGUIWnd, &r);
159 r.left = (UI_REMOTE_POSX + (UI_REMOTE_WIDTH * x_start / LCD_REMOTE_WIDTH))
160 * r.right / UI_WIDTH;
161 r.top = (UI_REMOTE_POSY + (UI_REMOTE_HEIGHT * y_start / LCD_REMOTE_HEIGHT))
162 * r.bottom / UI_HEIGHT;
163 r.right = (UI_REMOTE_POSX + (UI_REMOTE_WIDTH * xmax / LCD_REMOTE_WIDTH))
164 * r.right / UI_WIDTH;
165 r.bottom = (UI_REMOTE_POSY + (UI_REMOTE_HEIGHT * ymax / LCD_REMOTE_HEIGHT))
166 * r.bottom / UI_HEIGHT;
167 InvalidateRect (hGUIWnd, &r, FALSE);
170 #endif /* HAVE_REMOTE_LCD */
171 #endif /* HAVE_LCD_BITMAP */
173 #ifdef HAVE_LCD_CHARCELLS
174 /* Defined in lcd-playersim.c */
175 extern void lcd_print_char(int x, int y);
176 extern bool lcd_display_redraw;
177 extern unsigned char hardware_buffer_lcd[11][2];
178 static unsigned char lcd_buffer_copy[11][2];
180 void lcd_update(void)
182 int x, y;
183 bool changed = false;
184 RECT r;
186 if (hGUIWnd == NULL)
187 _endthread ();
189 for (y = 0; y < 2; y++)
191 for (x = 0; x < 11; x++)
193 if (lcd_display_redraw ||
194 lcd_buffer_copy[x][y] != hardware_buffer_lcd[x][y])
196 lcd_buffer_copy[x][y] = hardware_buffer_lcd[x][y];
197 lcd_print_char(x, y);
198 changed = true;
202 if (changed)
204 /* Invalidate only the window part that actually did change */
205 GetClientRect (hGUIWnd, &r);
206 r.left = UI_LCD_POSX * r.right / UI_WIDTH;
207 r.top = UI_LCD_POSY * r.bottom / UI_HEIGHT;
208 r.right = (UI_LCD_POSX + UI_LCD_WIDTH) * r.right / UI_WIDTH;
209 r.bottom = (UI_LCD_POSY + UI_LCD_HEIGHT) * r.bottom / UI_HEIGHT;
210 InvalidateRect (hGUIWnd, &r, FALSE);
212 lcd_display_redraw = false;
215 void drawdots(int color, struct coordinate *points, int count)
217 while (count--)
219 bitmap[points[count].y][points[count].x] = color;
223 void drawrectangles(int color, struct rectangle *points, int count)
225 while (count--)
227 int x;
228 int y;
229 int ix;
230 int iy;
232 for (x = points[count].x, ix = 0; ix < points[count].width; x++, ix++)
234 for (y = points[count].y, iy = 0; iy < points[count].height; y++, iy++)
236 bitmap[y][x] = color;
241 #endif /* HAVE_LCD_CHARCELLS */
243 #if 0
244 /* set backlight state of lcd */
245 void lcd_backlight (bool on)
247 if (on)
248 color_zero = {UI_LCD_BGCOLORLIGHT, 0};
249 else
250 color_zero = {UI_LCD_BGCOLOR, 0};
252 lcdcolors(0, (1<<LCD_DEPTH), &color_zero, &color_max);
253 InvalidateRect (hGUIWnd, NULL, FALSE);
255 #endif
257 #if LCD_DEPTH <= 8
258 /* set a range of bitmap indices to a gradient from startcolour to endcolour */
259 void lcdcolors(int index, int count, RGBQUAD *start, RGBQUAD *end)
261 int i;
263 bmi.bmiHeader.biClrUsed = index + count;
264 bmi.bmiHeader.biClrImportant = index + count;
266 count--;
267 for (i = 0; i <= count; i++)
269 bmi.bmiColors[i+index].rgbRed = start->rgbRed
270 + (end->rgbRed - start->rgbRed) * i / count;
271 bmi.bmiColors[i+index].rgbGreen = start->rgbGreen
272 + (end->rgbGreen - start->rgbGreen) * i / count;
273 bmi.bmiColors[i+index].rgbBlue = start->rgbBlue
274 + (end->rgbBlue - start->rgbBlue) * i / count;
277 #endif
279 #ifdef HAVE_REMOTE_LCD
280 /* set a range of bitmap indices to a gradient from startcolour to endcolour */
281 void lcdremotecolors(int index, int count, RGBQUAD *start, RGBQUAD *end)
283 int i;
285 remote_bmi.bmiHeader.biClrUsed = index + count;
286 remote_bmi.bmiHeader.biClrImportant = index + count;
288 count--;
289 for (i = 0; i <= count; i++)
291 remote_bmi.bmiColors[i+index].rgbRed = start->rgbRed
292 + (end->rgbRed - start->rgbRed) * i / count;
293 remote_bmi.bmiColors[i+index].rgbGreen = start->rgbGreen
294 + (end->rgbGreen - start->rgbGreen) * i / count;
295 remote_bmi.bmiColors[i+index].rgbBlue = start->rgbBlue
296 + (end->rgbBlue - start->rgbBlue) * i / count;
299 #endif
301 /* initialise simulator lcd driver */
302 void simlcdinit(void)
304 #if LCD_DEPTH <= 8
305 lcdcolors(0, (1<<LCD_DEPTH), &color_zero, &color_max);
306 #endif
307 #ifdef HAVE_REMOTE_LCD
308 lcdremotecolors(0, (1<<LCD_REMOTE_DEPTH), &remote_color_zero, &remote_color_max);
309 #endif