diff options
author | Jens Arnold <amiconn@rockbox.org> | 2008-03-02 23:31:09 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2008-03-02 23:31:09 +0000 |
commit | 8493f5bcf6bd9142f1730e8f3a8126294800826d (patch) | |
tree | 4c0ca8d540b1be9144026838eddefe1c1e703c24 /apps | |
parent | 8abe9cffe4b495f64a0a440c9d99125115b9a002 (diff) |
Greyscale library: Preparations for a gamma measurement plugin.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16492 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/cube.c | 3 | ||||
-rw-r--r-- | apps/plugins/doom/i_video.c | 2 | ||||
-rw-r--r-- | apps/plugins/fire.c | 2 | ||||
-rw-r--r-- | apps/plugins/greyscale.c | 3 | ||||
-rw-r--r-- | apps/plugins/jpeg.c | 2 | ||||
-rw-r--r-- | apps/plugins/lib/grey.h | 8 | ||||
-rw-r--r-- | apps/plugins/lib/grey_core.c | 31 | ||||
-rw-r--r-- | apps/plugins/mandelbrot.c | 2 | ||||
-rw-r--r-- | apps/plugins/mpegplayer/stream_mgr.c | 4 | ||||
-rw-r--r-- | apps/plugins/plasma.c | 2 | ||||
-rw-r--r-- | apps/plugins/test_fps.c | 2 | ||||
-rw-r--r-- | apps/plugins/zxbox/zxbox.c | 4 |
12 files changed, 41 insertions, 24 deletions
diff --git a/apps/plugins/cube.c b/apps/plugins/cube.c index 966111001a..dfc6bb329b 100644 --- a/apps/plugins/cube.c +++ b/apps/plugins/cube.c @@ -555,7 +555,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) xlcd_init(rb); #elif defined(USE_GSLIB) gbuf = (unsigned char *)rb->plugin_get_buffer(&gbuf_size); - if (!grey_init(rb, gbuf, gbuf_size, true, LCD_WIDTH, LCD_HEIGHT, NULL)) + if (!grey_init(rb, gbuf, gbuf_size, GREY_BUFFERED, + LCD_WIDTH, LCD_HEIGHT, NULL)) { rb->splash(HZ, "Couldn't init greyscale display"); return PLUGIN_ERROR; diff --git a/apps/plugins/doom/i_video.c b/apps/plugins/doom/i_video.c index b466392319..e6cc272808 100644 --- a/apps/plugins/doom/i_video.c +++ b/apps/plugins/doom/i_video.c @@ -676,7 +676,7 @@ void I_InitGraphics(void) #ifndef HAVE_LCD_COLOR gbuf=malloc(GREYBUFSIZE); - grey_init(rb, gbuf, GREYBUFSIZE, false, LCD_WIDTH, LCD_HEIGHT, NULL); + grey_init(rb, gbuf, GREYBUFSIZE, 0, LCD_WIDTH, LCD_HEIGHT, NULL); /* switch on greyscale overlay */ grey_show(true); #endif diff --git a/apps/plugins/fire.c b/apps/plugins/fire.c index 6a0175f958..35432377f9 100644 --- a/apps/plugins/fire.c +++ b/apps/plugins/fire.c @@ -278,7 +278,7 @@ int init_grey(void) /* get the remainder of the plugin buffer */ gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); - if (!grey_init(rb, gbuf, gbuf_size, false, FIRE_WIDTH, LCD_HEIGHT, NULL)){ + if (!grey_init(rb, gbuf, gbuf_size, 0, FIRE_WIDTH, LCD_HEIGHT, NULL)){ rb->splash(HZ, "not enough memory"); return PLUGIN_ERROR; } diff --git a/apps/plugins/greyscale.c b/apps/plugins/greyscale.c index aa69f18349..522a81fc28 100644 --- a/apps/plugins/greyscale.c +++ b/apps/plugins/greyscale.c @@ -199,7 +199,8 @@ int main(void) /* initialize the greyscale buffer: Archos: 112 pixels wide, 7 rows (56 pixels) high. H1x0: 160 pixels wide, 30 rows (120 pixels) high. */ - if (!grey_init(rb, gbuf, gbuf_size, true, LCD_WIDTH, GFX_HEIGHT, NULL)) + if (!grey_init(rb, gbuf, gbuf_size, GREY_BUFFERED, + LCD_WIDTH, GFX_HEIGHT, NULL)) { rb->splash(HZ, "Not enough memory."); return PLUGIN_ERROR; diff --git a/apps/plugins/jpeg.c b/apps/plugins/jpeg.c index 156944d720..ad0ce6c857 100644 --- a/apps/plugins/jpeg.c +++ b/apps/plugins/jpeg.c @@ -3310,7 +3310,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) #endif #ifdef USEGSLIB - if (!grey_init(rb, buf, buf_size, false, LCD_WIDTH, LCD_HEIGHT, &greysize)) + if (!grey_init(rb, buf, buf_size, 0, LCD_WIDTH, LCD_HEIGHT, &greysize)) { rb->splash(HZ, "grey buf error"); return PLUGIN_ERROR; diff --git a/apps/plugins/lib/grey.h b/apps/plugins/lib/grey.h index 4fc47e1886..ce37e17829 100644 --- a/apps/plugins/lib/grey.h +++ b/apps/plugins/lib/grey.h @@ -29,8 +29,10 @@ #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) +/* The greyscale lib uses 8 bit brightness values natively on input. */ #define GREY_BRIGHTNESS(y) (y) +/* Some predefined levels for convenience: */ #define GREY_BLACK GREY_BRIGHTNESS(0) #define GREY_DARKGRAY GREY_BRIGHTNESS(85) #define GREY_LIGHTGRAY GREY_BRIGHTNESS(170) @@ -42,9 +44,13 @@ #define GREY_INFO_STRUCT struct _grey_info _grey_info; #define GREY_INFO_STRUCT_IRAM struct _grey_info _grey_info IBSS_ATTR; +/* Features you can request on library init (ORed together): */ +#define GREY_BUFFERED 0x0001 +#define GREY_RAWMAPPED 0x0002 + /* Library initialisation and release */ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, - bool buffered, int width, int height, long *buf_taken); + unsigned features, int width, int height, long *buf_taken); void grey_release(void); /* Special functions */ diff --git a/apps/plugins/lib/grey_core.c b/apps/plugins/lib/grey_core.c index 015c637eeb..80daf494a0 100644 --- a/apps/plugins/lib/grey_core.c +++ b/apps/plugins/lib/grey_core.c @@ -312,10 +312,12 @@ static int log_s16p16(int x) newrb = pointer to plugin api gbuf = pointer to the memory area to use (e.g. plugin buffer) gbuf_size = max usable size of the buffer - buffered = use chunky pixel buffering? + features = flags for requesting features + GREY_BUFFERED: use chunky pixel buffering This allows to use all drawing functions, but needs more memory. Unbuffered operation provides only a subset of drawing functions. (only grey_bitmap drawing and scrolling) + GREY_RAWMAPPED: no LCD linearisation and gamma correction width = width in pixels (1..LCD_WIDTH) height = height in pixels (1..LCD_HEIGHT) Note that depending on the target LCD, either height or @@ -335,7 +337,7 @@ static int log_s16p16(int x) The function is authentic regarding memory usage on the simulator, even if it doesn't use all of the allocated memory. */ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, - bool buffered, int width, int height, long *buf_taken) + unsigned features, int width, int height, long *buf_taken) { int bdim, i; long plane_size, buftaken; @@ -372,7 +374,7 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, #endif gbuf += buftaken; - if (buffered) /* chunky buffer */ + if (features & GREY_BUFFERED) /* chunky buffer */ { _grey_info.buffer = gbuf; gbuf += plane_size; @@ -418,14 +420,21 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, /* precalculate the value -> pattern index conversion table, taking linearisation and gamma correction into account */ - for (i = 0; i < 256; i++) - { - data = exp_s16p16(((2<<8) * log_s16p16(i * 257 + 1)) >> 8) + 128; - data = (data - (data >> 8)) >> 8; /* approx. data /= 257 */ - data = (lcdlinear[data] << 7) + 127; - _grey_info.gvalue[i] = (data + (data >> 8)) >> 8; + if (features & GREY_RAWMAPPED) + for (i = 0; i < 256; i++) + { + data = i << 7; + _grey_info.gvalue[i] = (data + (data >> 8)) >> 8; + } + else + for (i = 0; i < 256; i++) + { + data = exp_s16p16(((2<<8) * log_s16p16(i * 257 + 1)) >> 8) + 128; + data = (data - (data >> 8)) >> 8; /* approx. data /= 257 */ + data = (lcdlinear[data] << 7) + 127; + _grey_info.gvalue[i] = (data + (data >> 8)) >> 8; /* approx. data / 255 */ - } + } if (buf_taken) /* caller requested info about space taken */ *buf_taken = buftaken; @@ -469,7 +478,7 @@ void grey_show(bool enable) _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 70, 1, _timer_isr); #elif CONFIG_LCD == LCD_IPOD2BPP #ifdef IPOD_1G2G - _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 95, 1, _timer_isr); /* verified */ + _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 96, 1, _timer_isr); /* verified */ #elif defined IPOD_3G _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 87, 1, _timer_isr); /* verified */ #else diff --git a/apps/plugins/mandelbrot.c b/apps/plugins/mandelbrot.c index 5f3caa7bee..4c5e7d7458 100644 --- a/apps/plugins/mandelbrot.c +++ b/apps/plugins/mandelbrot.c @@ -620,7 +620,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); /* initialize the greyscale buffer.*/ - if (!grey_init(rb, gbuf, gbuf_size, false, LCD_WIDTH, LCD_HEIGHT, NULL)) + if (!grey_init(rb, gbuf, gbuf_size, 0, LCD_WIDTH, LCD_HEIGHT, NULL)) { rb->splash(HZ, "Couldn't init greyscale display"); return 0; diff --git a/apps/plugins/mpegplayer/stream_mgr.c b/apps/plugins/mpegplayer/stream_mgr.c index e79c5fd595..9da664effe 100644 --- a/apps/plugins/mpegplayer/stream_mgr.c +++ b/apps/plugins/mpegplayer/stream_mgr.c @@ -1006,8 +1006,8 @@ int stream_init(void) graymem = mem; #endif - success = grey_init(rb, graymem, memsize, true, LCD_WIDTH, - LCD_HEIGHT, &graysize); + success = grey_init(rb, graymem, memsize, GREY_BUFFERED, + LCD_WIDTH, LCD_HEIGHT, &graysize); /* This can run on another processor - align size */ graysize = CACHEALIGN_UP(graysize); diff --git a/apps/plugins/plasma.c b/apps/plugins/plasma.c index ca6f0d43a4..b54e6a9ed2 100644 --- a/apps/plugins/plasma.c +++ b/apps/plugins/plasma.c @@ -214,7 +214,7 @@ int main(void) /* get the remainder of the plugin buffer */ gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); - grey_init(rb, gbuf, gbuf_size, false, LCD_WIDTH, LCD_HEIGHT, NULL); + grey_init(rb, gbuf, gbuf_size, 0, LCD_WIDTH, LCD_HEIGHT, NULL); /* switch on greyscale overlay */ grey_show(true); #endif diff --git a/apps/plugins/test_fps.c b/apps/plugins/test_fps.c index 6da5255e13..edb6a68123 100644 --- a/apps/plugins/test_fps.c +++ b/apps/plugins/test_fps.c @@ -284,7 +284,7 @@ static void time_greyscale(void) int fps, load; gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); - if (!grey_init(rb, gbuf, gbuf_size, false, LCD_WIDTH, LCD_HEIGHT, NULL)) + if (!grey_init(rb, gbuf, gbuf_size, 0, LCD_WIDTH, LCD_HEIGHT, NULL)) { log_text("greylib: out of memory."); return; diff --git a/apps/plugins/zxbox/zxbox.c b/apps/plugins/zxbox/zxbox.c index 3d395986af..198aeecb37 100644 --- a/apps/plugins/zxbox/zxbox.c +++ b/apps/plugins/zxbox/zxbox.c @@ -74,9 +74,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) /* get the remainder of the plugin buffer */ gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); #ifdef USE_BUFFERED_GREY - grey_init(rb, gbuf, gbuf_size, true, LCD_WIDTH, LCD_HEIGHT, NULL); + grey_init(rb, gbuf, gbuf_size, GREY_BUFFERED, LCD_WIDTH, LCD_HEIGHT, NULL); #else - grey_init(rb, gbuf, gbuf_size, false, LCD_WIDTH, LCD_HEIGHT, NULL); + grey_init(rb, gbuf, gbuf_size, 0, LCD_WIDTH, LCD_HEIGHT, NULL); #endif /* USE_BUFFERED_GREY */ /* switch on greyscale overlay */ grey_show(true); |