diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-03-05 11:31:43 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-03-05 11:31:43 +0000 |
commit | 75640f45ebeff048d8dfda6d300dec47d4ad4baa (patch) | |
tree | 62a2909bf8c1419ebc25c2d8bcc42532c1848ce7 /apps/plugins/lib | |
parent | b0f57cb88e27a5fdad792abfdd84ca1607582809 (diff) | |
download | rockbox-75640f45ebeff048d8dfda6d300dec47d4ad4baa.tar.gz rockbox-75640f45ebeff048d8dfda6d300dec47d4ad4baa.zip |
Player graphics library: fixed and more robust bounds check, added bitmap drawing.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6139 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r-- | apps/plugins/lib/playergfx.c | 45 | ||||
-rw-r--r-- | apps/plugins/lib/playergfx.h | 2 |
2 files changed, 40 insertions, 7 deletions
diff --git a/apps/plugins/lib/playergfx.c b/apps/plugins/lib/playergfx.c index d227d608a7..51e003b048 100644 --- a/apps/plugins/lib/playergfx.c +++ b/apps/plugins/lib/playergfx.c | |||
@@ -28,8 +28,8 @@ | |||
28 | static struct plugin_api *pgfx_rb = NULL; /* global api struct pointer */ | 28 | static struct plugin_api *pgfx_rb = NULL; /* global api struct pointer */ |
29 | static int char_width; | 29 | static int char_width; |
30 | static int char_height; | 30 | static int char_height; |
31 | static int pixel_height; | 31 | static unsigned pixel_height; |
32 | static int pixel_width; | 32 | static unsigned pixel_width; |
33 | static unsigned char gfx_chars[8]; | 33 | static unsigned char gfx_chars[8]; |
34 | static unsigned char gfx_buffer[56]; | 34 | static unsigned char gfx_buffer[56]; |
35 | 35 | ||
@@ -200,14 +200,12 @@ void pgfx_invertrect (int x, int y, int nx, int ny) | |||
200 | { | 200 | { |
201 | int i, j; | 201 | int i, j; |
202 | 202 | ||
203 | if (x > pixel_width) | 203 | if (((unsigned) x >= pixel_width) || ((unsigned) y >= pixel_height)) |
204 | return; | ||
205 | if (y > pixel_height) | ||
206 | return; | 204 | return; |
207 | 205 | ||
208 | if (x + nx > pixel_width) | 206 | if ((unsigned)(x + nx) > pixel_width) |
209 | nx = pixel_width - x; | 207 | nx = pixel_width - x; |
210 | if (y + ny > pixel_height) | 208 | if ((unsigned)(y + ny) > pixel_height) |
211 | ny = pixel_height - y; | 209 | ny = pixel_height - y; |
212 | 210 | ||
213 | for (i = 0; i < nx; i++) | 211 | for (i = 0; i < nx; i++) |
@@ -215,4 +213,37 @@ void pgfx_invertrect (int x, int y, int nx, int ny) | |||
215 | pgfx_invertpixel(x + i, y + j); | 213 | pgfx_invertpixel(x + i, y + j); |
216 | } | 214 | } |
217 | 215 | ||
216 | void pgfx_bitmap (const unsigned char *src, int x, int y, int nx, int ny, | ||
217 | bool clear) | ||
218 | { | ||
219 | int stride, i, j; | ||
220 | unsigned data; | ||
221 | |||
222 | if (((unsigned) x >= pixel_width) || ((unsigned) y >= pixel_height)) | ||
223 | return; | ||
224 | |||
225 | stride = nx; /* otherwise right-clipping will destroy the image */ | ||
226 | |||
227 | if (((unsigned)(x + nx)) >= pixel_width) | ||
228 | nx = pixel_width - x; | ||
229 | if (((unsigned)(y + ny)) >= pixel_height) | ||
230 | ny = pixel_height - y; | ||
231 | |||
232 | for (i = 0; i < nx; i++, src++) | ||
233 | { | ||
234 | data = src[0]; | ||
235 | if (ny > 8) /* ny is max. 14 */ | ||
236 | data |= src[stride] << 8; | ||
237 | for (j = 0; j < ny; j++) | ||
238 | { | ||
239 | if (data & 1) | ||
240 | pgfx_drawpixel(x + i, y + j); | ||
241 | else | ||
242 | if (clear) | ||
243 | pgfx_clearpixel(x + i, y + j); | ||
244 | data >>= 1; | ||
245 | } | ||
246 | } | ||
247 | } | ||
248 | |||
218 | #endif /* HAVE_LCD_CHARCELLS */ | 249 | #endif /* HAVE_LCD_CHARCELLS */ |
diff --git a/apps/plugins/lib/playergfx.h b/apps/plugins/lib/playergfx.h index 98664117aa..ced484398e 100644 --- a/apps/plugins/lib/playergfx.h +++ b/apps/plugins/lib/playergfx.h | |||
@@ -38,6 +38,8 @@ void pgfx_drawline(int x1, int y1, int x2, int y2); | |||
38 | void pgfx_clearline(int x1, int y1, int x2, int y2); | 38 | void pgfx_clearline(int x1, int y1, int x2, int y2); |
39 | void pgfx_invertline(int x1, int y1, int x2, int y2); | 39 | void pgfx_invertline(int x1, int y1, int x2, int y2); |
40 | void pgfx_invertrect (int x, int y, int nx, int ny); | 40 | void pgfx_invertrect (int x, int y, int nx, int ny); |
41 | void pgfx_bitmap (const unsigned char *src, int x, int y, int nx, int ny, | ||
42 | bool clear); | ||
41 | 43 | ||
42 | #endif /* HAVE_LCD_CHARCELLS */ | 44 | #endif /* HAVE_LCD_CHARCELLS */ |
43 | #endif /* __PGFX_H__ */ | 45 | #endif /* __PGFX_H__ */ |