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 | |
parent | 8abe9cffe4b495f64a0a440c9d99125115b9a002 (diff) | |
download | rockbox-8493f5bcf6bd9142f1730e8f3a8126294800826d.tar.gz rockbox-8493f5bcf6bd9142f1730e8f3a8126294800826d.zip |
Greyscale library: Preparations for a gamma measurement plugin.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16492 a1c6a512-1295-4272-9138-f99709370657
-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) | |||
555 | xlcd_init(rb); | 555 | xlcd_init(rb); |
556 | #elif defined(USE_GSLIB) | 556 | #elif defined(USE_GSLIB) |
557 | gbuf = (unsigned char *)rb->plugin_get_buffer(&gbuf_size); | 557 | gbuf = (unsigned char *)rb->plugin_get_buffer(&gbuf_size); |
558 | if (!grey_init(rb, gbuf, gbuf_size, true, LCD_WIDTH, LCD_HEIGHT, NULL)) | 558 | if (!grey_init(rb, gbuf, gbuf_size, GREY_BUFFERED, |
559 | LCD_WIDTH, LCD_HEIGHT, NULL)) | ||
559 | { | 560 | { |
560 | rb->splash(HZ, "Couldn't init greyscale display"); | 561 | rb->splash(HZ, "Couldn't init greyscale display"); |
561 | return PLUGIN_ERROR; | 562 | 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) | |||
676 | 676 | ||
677 | #ifndef HAVE_LCD_COLOR | 677 | #ifndef HAVE_LCD_COLOR |
678 | gbuf=malloc(GREYBUFSIZE); | 678 | gbuf=malloc(GREYBUFSIZE); |
679 | grey_init(rb, gbuf, GREYBUFSIZE, false, LCD_WIDTH, LCD_HEIGHT, NULL); | 679 | grey_init(rb, gbuf, GREYBUFSIZE, 0, LCD_WIDTH, LCD_HEIGHT, NULL); |
680 | /* switch on greyscale overlay */ | 680 | /* switch on greyscale overlay */ |
681 | grey_show(true); | 681 | grey_show(true); |
682 | #endif | 682 | #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) | |||
278 | /* get the remainder of the plugin buffer */ | 278 | /* get the remainder of the plugin buffer */ |
279 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); | 279 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); |
280 | 280 | ||
281 | if (!grey_init(rb, gbuf, gbuf_size, false, FIRE_WIDTH, LCD_HEIGHT, NULL)){ | 281 | if (!grey_init(rb, gbuf, gbuf_size, 0, FIRE_WIDTH, LCD_HEIGHT, NULL)){ |
282 | rb->splash(HZ, "not enough memory"); | 282 | rb->splash(HZ, "not enough memory"); |
283 | return PLUGIN_ERROR; | 283 | return PLUGIN_ERROR; |
284 | } | 284 | } |
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) | |||
199 | /* initialize the greyscale buffer: | 199 | /* initialize the greyscale buffer: |
200 | Archos: 112 pixels wide, 7 rows (56 pixels) high. | 200 | Archos: 112 pixels wide, 7 rows (56 pixels) high. |
201 | H1x0: 160 pixels wide, 30 rows (120 pixels) high. */ | 201 | H1x0: 160 pixels wide, 30 rows (120 pixels) high. */ |
202 | if (!grey_init(rb, gbuf, gbuf_size, true, LCD_WIDTH, GFX_HEIGHT, NULL)) | 202 | if (!grey_init(rb, gbuf, gbuf_size, GREY_BUFFERED, |
203 | LCD_WIDTH, GFX_HEIGHT, NULL)) | ||
203 | { | 204 | { |
204 | rb->splash(HZ, "Not enough memory."); | 205 | rb->splash(HZ, "Not enough memory."); |
205 | return PLUGIN_ERROR; | 206 | 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) | |||
3310 | #endif | 3310 | #endif |
3311 | 3311 | ||
3312 | #ifdef USEGSLIB | 3312 | #ifdef USEGSLIB |
3313 | if (!grey_init(rb, buf, buf_size, false, LCD_WIDTH, LCD_HEIGHT, &greysize)) | 3313 | if (!grey_init(rb, buf, buf_size, 0, LCD_WIDTH, LCD_HEIGHT, &greysize)) |
3314 | { | 3314 | { |
3315 | rb->splash(HZ, "grey buf error"); | 3315 | rb->splash(HZ, "grey buf error"); |
3316 | return PLUGIN_ERROR; | 3316 | 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 @@ | |||
29 | 29 | ||
30 | #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) | 30 | #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) |
31 | 31 | ||
32 | /* The greyscale lib uses 8 bit brightness values natively on input. */ | ||
32 | #define GREY_BRIGHTNESS(y) (y) | 33 | #define GREY_BRIGHTNESS(y) (y) |
33 | 34 | ||
35 | /* Some predefined levels for convenience: */ | ||
34 | #define GREY_BLACK GREY_BRIGHTNESS(0) | 36 | #define GREY_BLACK GREY_BRIGHTNESS(0) |
35 | #define GREY_DARKGRAY GREY_BRIGHTNESS(85) | 37 | #define GREY_DARKGRAY GREY_BRIGHTNESS(85) |
36 | #define GREY_LIGHTGRAY GREY_BRIGHTNESS(170) | 38 | #define GREY_LIGHTGRAY GREY_BRIGHTNESS(170) |
@@ -42,9 +44,13 @@ | |||
42 | #define GREY_INFO_STRUCT struct _grey_info _grey_info; | 44 | #define GREY_INFO_STRUCT struct _grey_info _grey_info; |
43 | #define GREY_INFO_STRUCT_IRAM struct _grey_info _grey_info IBSS_ATTR; | 45 | #define GREY_INFO_STRUCT_IRAM struct _grey_info _grey_info IBSS_ATTR; |
44 | 46 | ||
47 | /* Features you can request on library init (ORed together): */ | ||
48 | #define GREY_BUFFERED 0x0001 | ||
49 | #define GREY_RAWMAPPED 0x0002 | ||
50 | |||
45 | /* Library initialisation and release */ | 51 | /* Library initialisation and release */ |
46 | bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, | 52 | bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, |
47 | bool buffered, int width, int height, long *buf_taken); | 53 | unsigned features, int width, int height, long *buf_taken); |
48 | void grey_release(void); | 54 | void grey_release(void); |
49 | 55 | ||
50 | /* Special functions */ | 56 | /* 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) | |||
312 | newrb = pointer to plugin api | 312 | newrb = pointer to plugin api |
313 | gbuf = pointer to the memory area to use (e.g. plugin buffer) | 313 | gbuf = pointer to the memory area to use (e.g. plugin buffer) |
314 | gbuf_size = max usable size of the buffer | 314 | gbuf_size = max usable size of the buffer |
315 | buffered = use chunky pixel buffering? | 315 | features = flags for requesting features |
316 | GREY_BUFFERED: use chunky pixel buffering | ||
316 | This allows to use all drawing functions, but needs more | 317 | This allows to use all drawing functions, but needs more |
317 | memory. Unbuffered operation provides only a subset of | 318 | memory. Unbuffered operation provides only a subset of |
318 | drawing functions. (only grey_bitmap drawing and scrolling) | 319 | drawing functions. (only grey_bitmap drawing and scrolling) |
320 | GREY_RAWMAPPED: no LCD linearisation and gamma correction | ||
319 | width = width in pixels (1..LCD_WIDTH) | 321 | width = width in pixels (1..LCD_WIDTH) |
320 | height = height in pixels (1..LCD_HEIGHT) | 322 | height = height in pixels (1..LCD_HEIGHT) |
321 | Note that depending on the target LCD, either height or | 323 | Note that depending on the target LCD, either height or |
@@ -335,7 +337,7 @@ static int log_s16p16(int x) | |||
335 | The function is authentic regarding memory usage on the simulator, even | 337 | The function is authentic regarding memory usage on the simulator, even |
336 | if it doesn't use all of the allocated memory. */ | 338 | if it doesn't use all of the allocated memory. */ |
337 | bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, | 339 | bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, |
338 | bool buffered, int width, int height, long *buf_taken) | 340 | unsigned features, int width, int height, long *buf_taken) |
339 | { | 341 | { |
340 | int bdim, i; | 342 | int bdim, i; |
341 | long plane_size, buftaken; | 343 | long plane_size, buftaken; |
@@ -372,7 +374,7 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, | |||
372 | #endif | 374 | #endif |
373 | gbuf += buftaken; | 375 | gbuf += buftaken; |
374 | 376 | ||
375 | if (buffered) /* chunky buffer */ | 377 | if (features & GREY_BUFFERED) /* chunky buffer */ |
376 | { | 378 | { |
377 | _grey_info.buffer = gbuf; | 379 | _grey_info.buffer = gbuf; |
378 | gbuf += plane_size; | 380 | gbuf += plane_size; |
@@ -418,14 +420,21 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, | |||
418 | 420 | ||
419 | /* precalculate the value -> pattern index conversion table, taking | 421 | /* precalculate the value -> pattern index conversion table, taking |
420 | linearisation and gamma correction into account */ | 422 | linearisation and gamma correction into account */ |
421 | for (i = 0; i < 256; i++) | 423 | if (features & GREY_RAWMAPPED) |
422 | { | 424 | for (i = 0; i < 256; i++) |
423 | data = exp_s16p16(((2<<8) * log_s16p16(i * 257 + 1)) >> 8) + 128; | 425 | { |
424 | data = (data - (data >> 8)) >> 8; /* approx. data /= 257 */ | 426 | data = i << 7; |
425 | data = (lcdlinear[data] << 7) + 127; | 427 | _grey_info.gvalue[i] = (data + (data >> 8)) >> 8; |
426 | _grey_info.gvalue[i] = (data + (data >> 8)) >> 8; | 428 | } |
429 | else | ||
430 | for (i = 0; i < 256; i++) | ||
431 | { | ||
432 | data = exp_s16p16(((2<<8) * log_s16p16(i * 257 + 1)) >> 8) + 128; | ||
433 | data = (data - (data >> 8)) >> 8; /* approx. data /= 257 */ | ||
434 | data = (lcdlinear[data] << 7) + 127; | ||
435 | _grey_info.gvalue[i] = (data + (data >> 8)) >> 8; | ||
427 | /* approx. data / 255 */ | 436 | /* approx. data / 255 */ |
428 | } | 437 | } |
429 | 438 | ||
430 | if (buf_taken) /* caller requested info about space taken */ | 439 | if (buf_taken) /* caller requested info about space taken */ |
431 | *buf_taken = buftaken; | 440 | *buf_taken = buftaken; |
@@ -469,7 +478,7 @@ void grey_show(bool enable) | |||
469 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 70, 1, _timer_isr); | 478 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 70, 1, _timer_isr); |
470 | #elif CONFIG_LCD == LCD_IPOD2BPP | 479 | #elif CONFIG_LCD == LCD_IPOD2BPP |
471 | #ifdef IPOD_1G2G | 480 | #ifdef IPOD_1G2G |
472 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 95, 1, _timer_isr); /* verified */ | 481 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 96, 1, _timer_isr); /* verified */ |
473 | #elif defined IPOD_3G | 482 | #elif defined IPOD_3G |
474 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 87, 1, _timer_isr); /* verified */ | 483 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 87, 1, _timer_isr); /* verified */ |
475 | #else | 484 | #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) | |||
620 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); | 620 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); |
621 | 621 | ||
622 | /* initialize the greyscale buffer.*/ | 622 | /* initialize the greyscale buffer.*/ |
623 | if (!grey_init(rb, gbuf, gbuf_size, false, LCD_WIDTH, LCD_HEIGHT, NULL)) | 623 | if (!grey_init(rb, gbuf, gbuf_size, 0, LCD_WIDTH, LCD_HEIGHT, NULL)) |
624 | { | 624 | { |
625 | rb->splash(HZ, "Couldn't init greyscale display"); | 625 | rb->splash(HZ, "Couldn't init greyscale display"); |
626 | return 0; | 626 | 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) | |||
1006 | graymem = mem; | 1006 | graymem = mem; |
1007 | #endif | 1007 | #endif |
1008 | 1008 | ||
1009 | success = grey_init(rb, graymem, memsize, true, LCD_WIDTH, | 1009 | success = grey_init(rb, graymem, memsize, GREY_BUFFERED, |
1010 | LCD_HEIGHT, &graysize); | 1010 | LCD_WIDTH, LCD_HEIGHT, &graysize); |
1011 | 1011 | ||
1012 | /* This can run on another processor - align size */ | 1012 | /* This can run on another processor - align size */ |
1013 | graysize = CACHEALIGN_UP(graysize); | 1013 | 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) | |||
214 | /* get the remainder of the plugin buffer */ | 214 | /* get the remainder of the plugin buffer */ |
215 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); | 215 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); |
216 | 216 | ||
217 | grey_init(rb, gbuf, gbuf_size, false, LCD_WIDTH, LCD_HEIGHT, NULL); | 217 | grey_init(rb, gbuf, gbuf_size, 0, LCD_WIDTH, LCD_HEIGHT, NULL); |
218 | /* switch on greyscale overlay */ | 218 | /* switch on greyscale overlay */ |
219 | grey_show(true); | 219 | grey_show(true); |
220 | #endif | 220 | #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) | |||
284 | int fps, load; | 284 | int fps, load; |
285 | 285 | ||
286 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); | 286 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); |
287 | if (!grey_init(rb, gbuf, gbuf_size, false, LCD_WIDTH, LCD_HEIGHT, NULL)) | 287 | if (!grey_init(rb, gbuf, gbuf_size, 0, LCD_WIDTH, LCD_HEIGHT, NULL)) |
288 | { | 288 | { |
289 | log_text("greylib: out of memory."); | 289 | log_text("greylib: out of memory."); |
290 | return; | 290 | 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) | |||
74 | /* get the remainder of the plugin buffer */ | 74 | /* get the remainder of the plugin buffer */ |
75 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); | 75 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); |
76 | #ifdef USE_BUFFERED_GREY | 76 | #ifdef USE_BUFFERED_GREY |
77 | grey_init(rb, gbuf, gbuf_size, true, LCD_WIDTH, LCD_HEIGHT, NULL); | 77 | grey_init(rb, gbuf, gbuf_size, GREY_BUFFERED, LCD_WIDTH, LCD_HEIGHT, NULL); |
78 | #else | 78 | #else |
79 | grey_init(rb, gbuf, gbuf_size, false, LCD_WIDTH, LCD_HEIGHT, NULL); | 79 | grey_init(rb, gbuf, gbuf_size, 0, LCD_WIDTH, LCD_HEIGHT, NULL); |
80 | #endif /* USE_BUFFERED_GREY */ | 80 | #endif /* USE_BUFFERED_GREY */ |
81 | /* switch on greyscale overlay */ | 81 | /* switch on greyscale overlay */ |
82 | grey_show(true); | 82 | grey_show(true); |