From fa7eb56c84f2e338ed5ff62dfb79e6bf513ddcdb Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Sun, 13 Jan 2008 18:39:09 +0000 Subject: Greyscale library: * Defer application of lcd linearisation + gamma in buffered mode to the actual update. This simplifies the update function (grey_update() and grey_update_rect() now are just calls to grey_ub_gray_bitmap_part()), and makes DRMODE_COMPLEMENT work properly. * Make the simulator version work and behave more similar to the target version. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16080 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/lib/grey.h | 4 -- apps/plugins/lib/grey_core.c | 133 +++++++++-------------------------------- apps/plugins/lib/grey_draw.c | 78 ++++++++++-------------- apps/plugins/lib/grey_parm.c | 6 +- apps/plugins/lib/grey_scroll.c | 80 ++++++++++--------------- 5 files changed, 95 insertions(+), 206 deletions(-) diff --git a/apps/plugins/lib/grey.h b/apps/plugins/lib/grey.h index 84b6687de3..4fc47e1886 100644 --- a/apps/plugins/lib/grey.h +++ b/apps/plugins/lib/grey.h @@ -155,14 +155,10 @@ struct _grey_info #endif unsigned long flags; /* various flags, see #defines */ struct plugin_api *rb; /* plugin API pointer */ -#ifndef SIMULATOR 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 */ - int fg_val; /* current foreground value */ - int bg_val; /* current background value */ int fg_brightness; /* current foreground brightness */ int bg_brightness; /* current background brightness */ int drawmode; /* current draw mode */ diff --git a/apps/plugins/lib/grey_core.c b/apps/plugins/lib/grey_core.c index 395a1130d5..0e2408b107 100644 --- a/apps/plugins/lib/grey_core.c +++ b/apps/plugins/lib/grey_core.c @@ -214,7 +214,27 @@ static inline void _deferred_update(void) _grey_info.rb->lcd_update_rect(x2, y1, LCD_WIDTH - x2, y2 - y1); } -#ifndef SIMULATOR +#ifdef SIMULATOR + +/* Callback function for grey_ub_gray_bitmap_part() to read a pixel from the + * greybuffer. Note that x and y are in LCD coordinates, not greybuffer + * coordinates! */ +static unsigned long _grey_get_pixel(int x, int y) +{ + int xg = x - _grey_info.x; + int yg = y - _grey_info.y; +#if LCD_PIXELFORMAT == HORIZONTAL_PACKING + int idx = _grey_info.width * yg + xg; +#else + int idx = _grey_info.width * (yg & ~_GREY_BMASK) + + (xg << _GREY_BSHIFT) + (~yg & _GREY_BMASK); +#endif + + return _grey_info.values[idx] + (1 << LCD_DEPTH); +} + +#else /* !SIMULATOR */ + /* Timer interrupt handler: display next frame */ static void _timer_isr(void) { @@ -236,6 +256,7 @@ static void _timer_isr(void) _grey_info.flags &= ~_GREY_DEFERRED_UPDATE; /* clear request */ } } + #endif /* !SIMULATOR */ /* fixed point exp() */ @@ -357,22 +378,18 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, gbuf += plane_size; buftaken += plane_size; } -#ifdef SIMULATOR - _grey_info.buffer = gbuf; -#else _grey_info.values = gbuf; gbuf += plane_size; _grey_info.phases = gbuf; -#endif buftaken += 2 * plane_size; if (buftaken > gbuf_size) return false; -#ifndef SIMULATOR /* Init to white */ _grey_info.rb->memset(_grey_info.values, 0x80, plane_size); +#ifndef SIMULATOR /* Init phases with random bits */ dst = (unsigned*)(_grey_info.phases); end = (unsigned*)(_grey_info.phases + plane_size); @@ -394,8 +411,6 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, _grey_info.bheight = bdim; #endif _grey_info.flags = 0; - _grey_info.fg_val = 0; - _grey_info.bg_val = 128; _grey_info.fg_brightness = 0; _grey_info.bg_brightness = 255; _grey_info.drawmode = DRMODE_SOLID; @@ -442,7 +457,8 @@ void grey_show(bool enable) _grey_info.flags |= _GREY_RUNNING; #ifdef SIMULATOR _grey_info.rb->sim_lcd_ex_init(129, _grey_get_pixel); - grey_update(); + _grey_info.rb->sim_lcd_ex_update_rect(_grey_info.x, _grey_info.y, + _grey_info.width, _grey_info.height); #else /* !SIMULATOR */ #ifdef NEED_BOOST _grey_info.rb->cpu_boost(true); @@ -484,91 +500,17 @@ void grey_show(bool enable) } } -#ifdef SIMULATOR -/* Callback function for grey_update_rect() to read a pixel from the greybuffer. - Note that x and y are in LCD coordinates, not greybuffer coordinates! */ -static unsigned long _grey_get_pixel(int x, int y) -{ - return _grey_info.buffer[(y - _grey_info.y) * _grey_info.width - + x - _grey_info.x] + (1 << LCD_DEPTH); -} - -/* Update a rectangular area of the greyscale overlay */ -void grey_update_rect(int x, int y, int width, int height) -{ - if (x + width > _grey_info.width) - width = _grey_info.width - x; - if (y + height > _grey_info.height) - height = _grey_info.height - y; - - x += _grey_info.x; - y += _grey_info.y; - - if (x + width > LCD_WIDTH) - width = LCD_WIDTH - x; - if (y + height > LCD_HEIGHT) - height = LCD_HEIGHT - y; - - _grey_info.rb->sim_lcd_ex_update_rect(x, y, width, height); -} - -#else /* !SIMULATOR */ - void grey_update_rect(int x, int y, int width, int height) { - unsigned char *src, *dst; - - if ((width <= 0) || (height <= 0)) - return; /* nothing to do */ - - if (y + height > _grey_info.height) - height = _grey_info.height - y; - if (x + width > _grey_info.width) - width = _grey_info.width - x; - - src = _grey_info.buffer + _GREY_MULUQ(_grey_info.width, y) + x; - -#if LCD_PIXELFORMAT == HORIZONTAL_PACKING - dst = _grey_info.values + _GREY_MULUQ(_grey_info.width, y) + x; - - do - { - _grey_info.rb->memcpy(dst, src, width); - dst += _grey_info.width; - src += _grey_info.width; - } - while (--height > 0); - -#else /* LCD_PIXELFORMAT == VRTICAL_PACKING */ - do - { - unsigned char *src_row = src; - unsigned char *src_end = src + width; - - dst = _grey_info.values - + _GREY_MULUQ(_grey_info.width, y & ~_GREY_BMASK) - + (x << _GREY_BSHIFT) + (~y & _GREY_BMASK); - do - { - *dst = *src_row++; - dst += _GREY_BSIZE; - } - while (src_row < src_end); - - y++; - src += _grey_info.width; - } - while (--height > 0); - -#endif /* LCD_PIXELFORMAT */ + grey_ub_gray_bitmap_part(_grey_info.buffer, x, y, _grey_info.width, + x, y, width, height); } -#endif /* !SIMULATOR */ - /* Update the whole greyscale overlay */ void grey_update(void) { - grey_update_rect(0, 0, _grey_info.width, _grey_info.height); + grey_ub_gray_bitmap_part(_grey_info.buffer, 0, 0, _grey_info.width, + 0, 0, _grey_info.width, _grey_info.height); } /* Do an lcd_update() to show changes done by rb->lcd_xxx() functions @@ -691,13 +633,8 @@ static void grey_screendump_hook(int fd) if (((unsigned)gy < (unsigned)_grey_info.height) && ((unsigned)gx < (unsigned)_grey_info.width)) { -#ifdef SIMULATOR - unsigned char *src = _grey_info.buffer - + _GREY_MULUQ(_grey_info.width, gy) + gx; -#else unsigned char *src = _grey_info.values + _GREY_MULUQ(_grey_info.width, gy) + gx; -#endif for (i = 0; i < 4; i++) linebuf[x + i] = BMP_FIXEDCOLORS + *src++; } @@ -724,17 +661,11 @@ static void grey_screendump_hook(int fd) if (((unsigned)gy < (unsigned)_grey_info.height) && ((unsigned)gx < (unsigned)_grey_info.width)) { -#ifdef SIMULATOR - linebuf[x] = BMP_FIXEDCOLORS - + _grey_info.buffer[_GREY_MULUQ(_grey_info.width, - gy) + gx]; -#else linebuf[x] = BMP_FIXEDCOLORS + _grey_info.values[_GREY_MULUQ(_grey_info.width, gy & ~_GREY_BMASK) + (gx << _GREY_BSHIFT) + (~gy & _GREY_BMASK)]; -#endif } else { @@ -753,17 +684,11 @@ static void grey_screendump_hook(int fd) if (((unsigned)gy < (unsigned)_grey_info.height) && ((unsigned)gx < (unsigned)_grey_info.width)) { -#ifdef SIMULATOR - linebuf[x] = BMP_FIXEDCOLORS - + _grey_info.buffer[_GREY_MULUQ(_grey_info.width, - gy) + gx]; -#else linebuf[x] = BMP_FIXEDCOLORS + _grey_info.values[_GREY_MULUQ(_grey_info.width, gy & ~_GREY_BMASK) + (gx << _GREY_BSHIFT) + (~gy & _GREY_BMASK)]; -#endif } else { diff --git a/apps/plugins/lib/grey_draw.c b/apps/plugins/lib/grey_draw.c index 9b8acd4c37..335d6d1b20 100644 --- a/apps/plugins/lib/grey_draw.c +++ b/apps/plugins/lib/grey_draw.c @@ -30,17 +30,17 @@ static void setpixel(unsigned char *address) { - *address = _grey_info.fg_val; + *address = _grey_info.fg_brightness; } static void clearpixel(unsigned char *address) { - *address = _grey_info.bg_val; + *address = _grey_info.bg_brightness; } static void flippixel(unsigned char *address) { - *address = 128 - *address; + *address = ~(*address); } static void nopixel(unsigned char *address) @@ -59,7 +59,7 @@ void (* const _grey_pixelfuncs[8])(unsigned char *address) = { void grey_clear_display(void) { int value = (_grey_info.drawmode & DRMODE_INVERSEVID) ? - _grey_info.fg_val : _grey_info.bg_val; + _grey_info.fg_brightness : _grey_info.bg_brightness; _grey_info.rb->memset(_grey_info.buffer, value, _GREY_MULUQ(_grey_info.width, _grey_info.height)); @@ -179,7 +179,7 @@ void grey_hline(int x1, int x2, int y) if (_grey_info.drawmode & DRMODE_BG) { fillopt = true; - value = _grey_info.bg_val; + value = _grey_info.bg_brightness; } } else @@ -187,7 +187,7 @@ void grey_hline(int x1, int x2, int y) if (_grey_info.drawmode & DRMODE_FG) { fillopt = true; - value = _grey_info.fg_val; + value = _grey_info.fg_brightness; } } pfunc = _grey_pixelfuncs[_grey_info.drawmode]; @@ -361,7 +361,7 @@ void grey_fillrect(int x, int y, int width, int height) if (_grey_info.drawmode & DRMODE_BG) { fillopt = true; - value = _grey_info.bg_val; + value = _grey_info.bg_brightness; } } else @@ -369,7 +369,7 @@ void grey_fillrect(int x, int y, int width, int height) if (_grey_info.drawmode & DRMODE_FG) { fillopt = true; - value = _grey_info.fg_val; + value = _grey_info.fg_brightness; } } pfunc = _grey_pixelfuncs[_grey_info.drawmode]; @@ -514,16 +514,9 @@ void grey_gray_bitmap_part(const unsigned char *src, int src_x, int src_y, do { - const unsigned char *src_row = src; - unsigned char *dst_row = dst; - unsigned char *row_end = dst_row + width; - - do - *dst_row++ = _grey_info.gvalue[*src_row++]; - while (dst_row < row_end); - - src += stride; + _grey_info.rb->memcpy(dst, src, width); dst += _grey_info.width; + src += stride; } while (dst < dst_end); } @@ -578,39 +571,27 @@ void grey_putsxy(int x, int y, const unsigned char *str) /*** Unbuffered drawing functions ***/ -#ifdef SIMULATOR - -/* Clear the whole display */ -void grey_ub_clear_display(void) -{ - grey_clear_display(); - grey_update(); -} - -/* Draw a partial greyscale bitmap, canonical format */ -void grey_ub_gray_bitmap_part(const unsigned char *src, int src_x, int src_y, - int stride, int x, int y, int width, int height) -{ - grey_gray_bitmap_part(src, src_x, src_y, stride, x, y, width, height); - grey_update_rect(x, y, width, height); -} - -#else /* !SIMULATOR */ - /* Clear the greyscale display (sets all pixels to white) */ void grey_ub_clear_display(void) { - int value = (_grey_info.drawmode & DRMODE_INVERSEVID) ? - _grey_info.fg_val : _grey_info.bg_val; - + int value = _grey_info.gvalue[(_grey_info.drawmode & DRMODE_INVERSEVID) ? + _grey_info.fg_brightness : + _grey_info.bg_brightness]; + _grey_info.rb->memset(_grey_info.values, value, _GREY_MULUQ(_grey_info.width, _grey_info.height)); +#ifdef SIMULATOR + _grey_info.rb->sim_lcd_ex_update_rect(_grey_info.x, _grey_info.y, + _grey_info.width, _grey_info.height); +#endif } /* Draw a partial greyscale bitmap, canonical format */ void grey_ub_gray_bitmap_part(const unsigned char *src, int src_x, int src_y, int stride, int x, int y, int width, int height) { + int yc, ye; + /* nothing to draw? */ if ((width <= 0) || (height <= 0) || (x >= _grey_info.width) || (y >= _grey_info.height) || (x + width <= 0) || (y + height <= 0)) @@ -634,15 +615,17 @@ void grey_ub_gray_bitmap_part(const unsigned char *src, int src_x, int src_y, if (y + height > _grey_info.height) height = _grey_info.height - y; - src += _GREY_MULUQ(stride, src_y) + src_x; /* move starting point */ + src += _GREY_MULUQ(stride, src_y) + src_x; /* move starting point */ + yc = y; + ye = y + height; do { #if LCD_PIXELFORMAT == HORIZONTAL_PACKING - int idx = _GREY_MULUQ(_grey_info.width, y) + x; + int idx = _GREY_MULUQ(_grey_info.width, yc) + x; #else - int idx = _GREY_MULUQ(_grey_info.width, y & ~_GREY_BMASK) - + (x << _GREY_BSHIFT) + (~y & _GREY_BMASK); + int idx = _GREY_MULUQ(_grey_info.width, yc & ~_GREY_BMASK) + + (x << _GREY_BSHIFT) + (~yc & _GREY_BMASK); #endif /* LCD_PIXELFORMAT */ unsigned char *dst_row = _grey_info.values + idx; const unsigned char *src_row = src; @@ -655,14 +638,15 @@ void grey_ub_gray_bitmap_part(const unsigned char *src, int src_x, int src_y, } while (src_row < src_end); - y++; src += stride; } - while (--height > 0); + while (++yc < ye); +#ifdef SIMULATOR + _grey_info.rb->sim_lcd_ex_update_rect(_grey_info.x + x, _grey_info.y + y, + width, height); +#endif } -#endif /* !SIMULATOR */ - /* Draw a full greyscale bitmap, canonical format */ void grey_ub_gray_bitmap(const unsigned char *src, int x, int y, int width, int height) diff --git a/apps/plugins/lib/grey_parm.c b/apps/plugins/lib/grey_parm.c index e2accee518..63d09dfd72 100644 --- a/apps/plugins/lib/grey_parm.c +++ b/apps/plugins/lib/grey_parm.c @@ -49,8 +49,10 @@ void grey_set_position(int x, int y) if (_grey_info.flags & _GREY_RUNNING) { #ifdef SIMULATOR + _grey_info.rb->sim_lcd_ex_update_rect(_grey_info.x, _grey_info.y, + _grey_info.width, + _grey_info.height); grey_deferred_lcd_update(); - grey_update(); #else _grey_info.flags |= _GREY_DEFERRED_UPDATE; #endif @@ -72,7 +74,6 @@ int grey_get_drawmode(void) /* Set the foreground shade for subsequent drawing operations */ void grey_set_foreground(unsigned brightness) { - _grey_info.fg_val = _grey_info.gvalue[brightness]; _grey_info.fg_brightness = brightness; } @@ -85,7 +86,6 @@ unsigned grey_get_foreground(void) /* Set the background shade for subsequent drawing operations */ void grey_set_background(unsigned brightness) { - _grey_info.bg_val = _grey_info.gvalue[brightness]; _grey_info.bg_brightness = brightness; } diff --git a/apps/plugins/lib/grey_scroll.c b/apps/plugins/lib/grey_scroll.c index 5040dd4c74..12a27daf23 100644 --- a/apps/plugins/lib/grey_scroll.c +++ b/apps/plugins/lib/grey_scroll.c @@ -41,7 +41,7 @@ void grey_scroll_left(int count) data_end = data + _GREY_MULUQ(_grey_info.width, _grey_info.height); length = _grey_info.width - count; blank = (_grey_info.drawmode & DRMODE_INVERSEVID) ? - _grey_info.fg_val : _grey_info.bg_val; + _grey_info.fg_brightness : _grey_info.bg_brightness; do { @@ -66,7 +66,7 @@ void grey_scroll_right(int count) data_end = data + _GREY_MULUQ(_grey_info.width, _grey_info.height); length = _grey_info.width - count; blank = (_grey_info.drawmode & DRMODE_INVERSEVID) ? - _grey_info.fg_val : _grey_info.bg_val; + _grey_info.fg_brightness : _grey_info.bg_brightness; do { @@ -89,7 +89,7 @@ void grey_scroll_up(int count) shift = _GREY_MULUQ(_grey_info.width, count); length = _GREY_MULUQ(_grey_info.width, _grey_info.height - count); blank = (_grey_info.drawmode & DRMODE_INVERSEVID) ? - _grey_info.fg_val : _grey_info.bg_val; + _grey_info.fg_brightness : _grey_info.bg_brightness; _grey_info.rb->memmove(_grey_info.buffer, _grey_info.buffer + shift, length); @@ -108,7 +108,7 @@ void grey_scroll_down(int count) shift = _GREY_MULUQ(_grey_info.width, count); length = _GREY_MULUQ(_grey_info.width, _grey_info.height - count); blank = (_grey_info.drawmode & DRMODE_INVERSEVID) ? - _grey_info.fg_val : _grey_info.bg_val; + _grey_info.fg_brightness : _grey_info.bg_brightness; _grey_info.rb->memmove(_grey_info.buffer + shift, _grey_info.buffer, length); @@ -117,38 +117,6 @@ void grey_scroll_down(int count) /*** Unbuffered scrolling functions ***/ -#ifdef SIMULATOR - -/* Scroll left */ -void grey_ub_scroll_left(int count) -{ - grey_scroll_left(count); - grey_update(); -} - -/* Scroll right */ -void grey_ub_scroll_right(int count) -{ - grey_scroll_right(count); - grey_update(); -} - -/* Scroll up */ -void grey_ub_scroll_up(int count) -{ - grey_scroll_up(count); - grey_update(); -} - -/* Scroll down */ -void grey_ub_scroll_down(int count) -{ - grey_scroll_down(count); - grey_update(); -} - -#else /* !SIMULATOR */ - /* Scroll left */ void grey_ub_scroll_left(int count) { @@ -162,9 +130,9 @@ void grey_ub_scroll_left(int count) data_end = data + _GREY_MULUQ(_grey_info.width, _grey_info.height); length = (_grey_info.width - count) << _GREY_BSHIFT; count <<= _GREY_BSHIFT; - blank = (_grey_info.drawmode & DRMODE_INVERSEVID) ? - _grey_info.fg_val : _grey_info.bg_val; - + blank = _grey_info.gvalue[(_grey_info.drawmode & DRMODE_INVERSEVID) ? + _grey_info.fg_brightness : + _grey_info.bg_brightness]; do { _grey_info.rb->memmove(data, data + count, length); @@ -173,6 +141,10 @@ void grey_ub_scroll_left(int count) data += count; } while (data < data_end); +#ifdef SIMULATOR + _grey_info.rb->sim_lcd_ex_update_rect(_grey_info.x, _grey_info.y, + _grey_info.width, _grey_info.height); +#endif } /* Scroll right */ @@ -188,9 +160,9 @@ void grey_ub_scroll_right(int count) data_end = data + _GREY_MULUQ(_grey_info.width, _grey_info.height); length = (_grey_info.width - count) << _GREY_BSHIFT; count <<= _GREY_BSHIFT; - blank = (_grey_info.drawmode & DRMODE_INVERSEVID) ? - _grey_info.fg_val : _grey_info.bg_val; - + blank = _grey_info.gvalue[(_grey_info.drawmode & DRMODE_INVERSEVID) ? + _grey_info.fg_brightness : + _grey_info.bg_brightness]; do { _grey_info.rb->memmove(data + count, data, length); @@ -198,6 +170,10 @@ void grey_ub_scroll_right(int count) data += _grey_info.width << _GREY_BSHIFT; } while (data < data_end); +#ifdef SIMULATOR + _grey_info.rb->sim_lcd_ex_update_rect(_grey_info.x, _grey_info.y, + _grey_info.width, _grey_info.height); +#endif } /* Scroll up */ @@ -211,8 +187,9 @@ void grey_ub_scroll_up(int count) dst = _grey_info.values; end = dst + _GREY_MULUQ(_grey_info.height, _grey_info.width); - blank = (_grey_info.drawmode & DRMODE_INVERSEVID) ? - _grey_info.fg_val : _grey_info.bg_val; + blank = _grey_info.gvalue[(_grey_info.drawmode & DRMODE_INVERSEVID) ? + _grey_info.fg_brightness : + _grey_info.bg_brightness]; #if LCD_PIXELFORMAT == VERTICAL_PACKING if (count & _GREY_BMASK) @@ -264,6 +241,10 @@ void grey_ub_scroll_up(int count) dst += blen; } _grey_info.rb->memset(dst, blank, end - dst); /* Fill remainder at once. */ +#ifdef SIMULATOR + _grey_info.rb->sim_lcd_ex_update_rect(_grey_info.x, _grey_info.y, + _grey_info.width, _grey_info.height); +#endif } /* Scroll down */ @@ -277,8 +258,9 @@ void grey_ub_scroll_down(int count) start = _grey_info.values; dst = start + _GREY_MULUQ(_grey_info.height, _grey_info.width); - blank = (_grey_info.drawmode & DRMODE_INVERSEVID) ? - _grey_info.fg_val : _grey_info.bg_val; + blank = _grey_info.gvalue[(_grey_info.drawmode & DRMODE_INVERSEVID) ? + _grey_info.fg_brightness : + _grey_info.bg_brightness]; #if LCD_PIXELFORMAT == VERTICAL_PACKING if (count & _GREY_BMASK) @@ -331,6 +313,8 @@ void grey_ub_scroll_down(int count) } _grey_info.rb->memset(start, blank, dst - start); /* Fill remainder at once. */ +#ifdef SIMULATOR + _grey_info.rb->sim_lcd_ex_update_rect(_grey_info.x, _grey_info.y, + _grey_info.width, _grey_info.height); +#endif } - -#endif /* !SIMULATOR */ -- cgit v1.2.3