summaryrefslogtreecommitdiff
path: root/apps/plugins/lib
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-03-05 11:31:43 +0000
committerJens Arnold <amiconn@rockbox.org>2005-03-05 11:31:43 +0000
commit75640f45ebeff048d8dfda6d300dec47d4ad4baa (patch)
tree62a2909bf8c1419ebc25c2d8bcc42532c1848ce7 /apps/plugins/lib
parentb0f57cb88e27a5fdad792abfdd84ca1607582809 (diff)
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.c45
-rw-r--r--apps/plugins/lib/playergfx.h2
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 @@
static struct plugin_api *pgfx_rb = NULL; /* global api struct pointer */
static int char_width;
static int char_height;
-static int pixel_height;
-static int pixel_width;
+static unsigned pixel_height;
+static unsigned pixel_width;
static unsigned char gfx_chars[8];
static unsigned char gfx_buffer[56];
@@ -200,14 +200,12 @@ void pgfx_invertrect (int x, int y, int nx, int ny)
{
int i, j;
- if (x > pixel_width)
- return;
- if (y > pixel_height)
+ if (((unsigned) x >= pixel_width) || ((unsigned) y >= pixel_height))
return;
- if (x + nx > pixel_width)
+ if ((unsigned)(x + nx) > pixel_width)
nx = pixel_width - x;
- if (y + ny > pixel_height)
+ if ((unsigned)(y + ny) > pixel_height)
ny = pixel_height - y;
for (i = 0; i < nx; i++)
@@ -215,4 +213,37 @@ void pgfx_invertrect (int x, int y, int nx, int ny)
pgfx_invertpixel(x + i, y + j);
}
+void pgfx_bitmap (const unsigned char *src, int x, int y, int nx, int ny,
+ bool clear)
+{
+ int stride, i, j;
+ unsigned data;
+
+ if (((unsigned) x >= pixel_width) || ((unsigned) y >= pixel_height))
+ return;
+
+ stride = nx; /* otherwise right-clipping will destroy the image */
+
+ if (((unsigned)(x + nx)) >= pixel_width)
+ nx = pixel_width - x;
+ if (((unsigned)(y + ny)) >= pixel_height)
+ ny = pixel_height - y;
+
+ for (i = 0; i < nx; i++, src++)
+ {
+ data = src[0];
+ if (ny > 8) /* ny is max. 14 */
+ data |= src[stride] << 8;
+ for (j = 0; j < ny; j++)
+ {
+ if (data & 1)
+ pgfx_drawpixel(x + i, y + j);
+ else
+ if (clear)
+ pgfx_clearpixel(x + i, y + j);
+ data >>= 1;
+ }
+ }
+}
+
#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);
void pgfx_clearline(int x1, int y1, int x2, int y2);
void pgfx_invertline(int x1, int y1, int x2, int y2);
void pgfx_invertrect (int x, int y, int nx, int ny);
+void pgfx_bitmap (const unsigned char *src, int x, int y, int nx, int ny,
+ bool clear);
#endif /* HAVE_LCD_CHARCELLS */
#endif /* __PGFX_H__ */