From 6a56c14e17f6ba113ec0d4d40e75bffd61b293cc Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Wed, 9 Jan 2008 23:48:26 +0000 Subject: Greyscale library: Changed the internal data format once more (separated pixel values and phases), allowing for further optimisation of drawing, scrolling etc. * Optimised grey phase blitting in the core reduces CPU load on all architectures, most significantly on coldfire. Previous version was too slow to keep up at 45MHz, leading to unwanted graininess (update frequency was halved). Also fixed screendump on 2bpp targets with vertical pixel packing. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16043 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugin.h | 9 +++--- apps/plugins/lib/grey.h | 9 +++--- apps/plugins/lib/grey_core.c | 69 +++++++++++++++++++++++------------------- apps/plugins/lib/grey_draw.c | 17 +++-------- apps/plugins/lib/grey_scroll.c | 16 +++++----- 5 files changed, 61 insertions(+), 59 deletions(-) (limited to 'apps') diff --git a/apps/plugin.h b/apps/plugin.h index 849c10bb89..a3ec9c3148 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -119,12 +119,12 @@ #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 95 +#define PLUGIN_API_VERSION 96 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 95 +#define PLUGIN_MIN_API_VERSION 96 /* plugin return codes */ enum plugin_status { @@ -268,8 +268,9 @@ struct plugin_api { int height); #endif #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) && !defined(SIMULATOR) - void (*lcd_grey_phase_blit)(const struct grey_data *data, int bx, int by, - int bwidth, int bheight, int stride); + void (*lcd_grey_phase_blit)(unsigned char *values, unsigned char *phases, + int bx, int by, int bwidth, int bheight, + int stride); #endif #if defined(HAVE_LCD_COLOR) void (*lcd_yuv_blit)(unsigned char * const src[3], diff --git a/apps/plugins/lib/grey.h b/apps/plugins/lib/grey.h index 136794bd26..9a3bd7d3f8 100644 --- a/apps/plugins/lib/grey.h +++ b/apps/plugins/lib/grey.h @@ -121,12 +121,12 @@ void grey_ub_scroll_down(int count); #endif #if LCD_PIXELFORMAT == HORIZONTAL_PACKING -#define _GREY_X_ADVANCE sizeof(struct grey_data) +#define _GREY_X_ADVANCE 1 #else #if LCD_DEPTH == 1 -#define _GREY_X_ADVANCE (8*sizeof(struct grey_data)) +#define _GREY_X_ADVANCE 8 #elif LCD_DEPTH == 2 -#define _GREY_X_ADVANCE (4*sizeof(struct grey_data)) +#define _GREY_X_ADVANCE 4 #endif #endif /* LCD_PIXELFORMAT */ @@ -146,7 +146,8 @@ struct _grey_info #endif unsigned long flags; /* various flags, see #defines */ #ifndef SIMULATOR - struct grey_data *data; /* start of greyscale display data */ + unsigned char *values; /* start of greyscale pixel values */ + unsigned char *phases; /* start of greyscale pixel phases */ #endif unsigned char *buffer; /* start of chunky pixel buffer (for buffered mode) */ unsigned char gvalue[256]; /* calculated brightness -> greyvalue table */ diff --git a/apps/plugins/lib/grey_core.c b/apps/plugins/lib/grey_core.c index b3ab640602..43eed9b022 100644 --- a/apps/plugins/lib/grey_core.c +++ b/apps/plugins/lib/grey_core.c @@ -222,11 +222,13 @@ static inline void _deferred_update(void) static void _timer_isr(void) { #if LCD_PIXELFORMAT == HORIZONTAL_PACKING - _grey_rb->lcd_grey_phase_blit(_grey_info.data, _grey_info.bx, _grey_info.y, + _grey_rb->lcd_grey_phase_blit(_grey_info.values, _grey_info.phases, + _grey_info.bx, _grey_info.y, _grey_info.bwidth, _grey_info.height, _grey_info.width); #else - _grey_rb->lcd_grey_phase_blit(_grey_info.data, _grey_info.x, _grey_info.by, + _grey_rb->lcd_grey_phase_blit(_grey_info.values, _grey_info.phases, + _grey_info.x, _grey_info.by, _grey_info.width, _grey_info.bheight, _grey_info.width); #endif @@ -321,7 +323,7 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, long plane_size, buftaken; unsigned data; #ifndef SIMULATOR - struct grey_data *grey_data, *grey_end; + unsigned *dst, *end; #endif _grey_rb = newrb; @@ -343,35 +345,41 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, #endif #endif - /* the buffer has to be long aligned */ - buftaken = (-(long)gbuf) & 3; - gbuf += buftaken; - plane_size = _GREY_MULUQ(width, height); +#ifdef CPU_COLDFIRE + plane_size += (-plane_size) & 0xf; /* All buffers should be line aligned */ + buftaken = (-(long)gbuf) & 0xf; +#else + buftaken = (-(long)gbuf) & 3; /* All buffers must be long aligned. */ +#endif + gbuf += buftaken; if (buffered) /* chunky buffer */ { - buftaken += plane_size; _grey_info.buffer = gbuf; - gbuf += plane_size; + gbuf += plane_size; + buftaken += plane_size; } - buftaken += sizeof(struct grey_data) * plane_size; - if (buftaken > gbuf_size) - return false; - #ifdef SIMULATOR _grey_info.buffer = gbuf; #else - grey_data = (struct grey_data *)gbuf; - grey_end = grey_data + plane_size; - _grey_info.data = grey_data; + _grey_info.values = gbuf; + gbuf += plane_size; + _grey_info.phases = gbuf; +#endif + buftaken += 2 * plane_size; - while (grey_data < grey_end) - { - grey_data->phase = _grey_rb->rand() & 0xff; - grey_data->value = 128; /* init to white */ - grey_data++; - } + if (buftaken > gbuf_size) + return false; + +#ifndef SIMULATOR + _grey_rb->memset(_grey_info.values, 0x80, plane_size); + dst = (unsigned*)(_grey_info.phases); + end = (unsigned*)(_grey_info.phases + plane_size); + + do + *dst++ = _grey_rb->rand(); + while (dst < end); #endif _grey_info.x = 0; @@ -393,8 +401,7 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, _grey_info.drawmode = DRMODE_SOLID; _grey_info.curfont = FONT_SYSFIXED; - - /* precalculate the value -> pattern index conversion table, taking + /* precalculate the value -> pattern index conversion table, taking linearisation and gamma correction into account */ for (i = 0; i < 256; i++) { @@ -532,7 +539,7 @@ void grey_update_rect(int x, int y, int width, int height) int idx = _GREY_MULUQ(_grey_info.width, y & ~3) + (x << 2) + (~y & 3); #endif #endif /* LCD_PIXELFORMAT */ - unsigned char *dst_row = &_grey_info.data[idx].value; + unsigned char *dst_row = _grey_info.values + idx; unsigned char *src_row = src; unsigned char *src_end = src + width; @@ -684,8 +691,8 @@ static void grey_screendump_hook(int fd) for (i = 0; i < 4; i++) linebuf[x + i] = BMP_FIXEDCOLORS + *src++; #else - unsigned char *src = &_grey_info.data[_GREY_MULUQ(_grey_info.width, - gy) + gx].value; + unsigned char *src = _grey_info.values + + _GREY_MULUQ(_grey_info.width, gy) + gx; for (i = 0; i < 4; i++) { linebuf[x + i] = BMP_FIXEDCOLORS + *src; @@ -722,8 +729,8 @@ static void grey_screendump_hook(int fd) gy) + gx]; #else linebuf[x] = BMP_FIXEDCOLORS - + _grey_info.data[_GREY_MULUQ(_grey_info.width, - gy & ~7) + (gx << 3) + (~gy & 7)].value; + + _grey_info.values[_GREY_MULUQ(_grey_info.width, + gy & ~7) + (gx << 3) + (~gy & 7)]; #endif } else @@ -749,8 +756,8 @@ static void grey_screendump_hook(int fd) gy) + gx]; #else linebuf[x] = BMP_FIXEDCOLORS - + _grey_info.data[_GREY_MULUQ(_grey_info.width, - gy & ~3) + (gx << 2) + (~gy & 7)].value; + + _grey_info.values[_GREY_MULUQ(_grey_info.width, + gy & ~3) + (gx << 2) + (~gy & 3)]; #endif } else diff --git a/apps/plugins/lib/grey_draw.c b/apps/plugins/lib/grey_draw.c index e243b5fbce..ccb8deae7b 100644 --- a/apps/plugins/lib/grey_draw.c +++ b/apps/plugins/lib/grey_draw.c @@ -601,17 +601,10 @@ void grey_ub_gray_bitmap_part(const unsigned char *src, int src_x, int src_y, void grey_ub_clear_display(void) { int value = (_grey_info.drawmode & DRMODE_INVERSEVID) ? - _grey_info.fg_val : _grey_info.bg_val; - unsigned char *dst = &_grey_info.data[0].value; - unsigned char *dst_end = dst + sizeof(struct grey_data) - * _GREY_MULUQ(_grey_info.width, _grey_info.height); - - do - { - *dst = value; - dst += sizeof(struct grey_data); - } - while (dst < dst_end); + _grey_info.fg_val : _grey_info.bg_val; + + _grey_rb->memset(_grey_info.values, value, + _GREY_MULUQ(_grey_info.width, _grey_info.height)); } /* Draw a partial greyscale bitmap, canonical format */ @@ -654,7 +647,7 @@ void grey_ub_gray_bitmap_part(const unsigned char *src, int src_x, int src_y, int idx = _GREY_MULUQ(_grey_info.width, y & ~3) + (x << 2) + (~y & 3); #endif #endif /* LCD_PIXELFORMAT */ - unsigned char *dst_row = &_grey_info.data[idx].value; + unsigned char *dst_row = _grey_info.values + idx; const unsigned char *src_row = src; const unsigned char *src_end = src + width; diff --git a/apps/plugins/lib/grey_scroll.c b/apps/plugins/lib/grey_scroll.c index 80496e7706..4a18d7d29e 100644 --- a/apps/plugins/lib/grey_scroll.c +++ b/apps/plugins/lib/grey_scroll.c @@ -169,7 +169,7 @@ void grey_ub_scroll_left(int count) idx = _GREY_MULUQ(_grey_info.width, y & ~3) + (~y & 3); #endif #endif /* LCD_PIXELFORMAT */ - dst = &_grey_info.data[idx].value; + dst = _grey_info.values + idx; src = dst + count * _GREY_X_ADVANCE; end = dst + _grey_info.width * _GREY_X_ADVANCE; @@ -213,7 +213,7 @@ void grey_ub_scroll_right(int count) idx = _GREY_MULUQ(_grey_info.width, y & ~3) + (~y & 3); #endif #endif /* LCD_PIXELFORMAT */ - start = &_grey_info.data[idx].value; + start = _grey_info.values + idx; dst = start + _grey_info.width * _GREY_X_ADVANCE; src = dst - count * _GREY_X_ADVANCE; @@ -259,8 +259,8 @@ void grey_ub_scroll_up(int count) is = _GREY_MULUQ(_grey_info.width, ys & ~3) + (~ys & 3); #endif #endif /* LCD_PIXELFORMAT */ - dst = &_grey_info.data[id].value; - src = &_grey_info.data[is].value; + dst = _grey_info.values + id; + src = _grey_info.values + is; dst_end = dst + _grey_info.width * _GREY_X_ADVANCE; do @@ -282,7 +282,7 @@ void grey_ub_scroll_up(int count) id = _GREY_MULUQ(_grey_info.width, yd & ~3) + (~yd & 3); #endif #endif /* LCD_PIXELFORMAT */ - dst = &_grey_info.data[id].value; + dst = _grey_info.values + id; dst_end = dst + _grey_info.width * _GREY_X_ADVANCE; do @@ -320,8 +320,8 @@ void grey_ub_scroll_down(int count) is = _GREY_MULUQ(_grey_info.width, ys & ~3) + (~ys & 3); #endif #endif /* LCD_PIXELFORMAT */ - dst = &_grey_info.data[id].value; - src = &_grey_info.data[is].value; + dst = _grey_info.values + id; + src = _grey_info.values + is; dst_end = dst + _grey_info.width * _GREY_X_ADVANCE; do @@ -343,7 +343,7 @@ void grey_ub_scroll_down(int count) id = _GREY_MULUQ(_grey_info.width, yd & ~3) + (~yd & 3); #endif #endif /* LCD_PIXELFORMAT */ - dst = &_grey_info.data[id].value; + dst = _grey_info.values + id; dst_end = dst + _grey_info.width * _GREY_X_ADVANCE; do -- cgit v1.2.3