forked from len0rd/rockbox
Greyscale library: Preparations for a gamma measurement plugin.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16492 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
8abe9cffe4
commit
8493f5bcf6
12 changed files with 41 additions and 24 deletions
|
@ -555,7 +555,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
xlcd_init(rb);
|
xlcd_init(rb);
|
||||||
#elif defined(USE_GSLIB)
|
#elif defined(USE_GSLIB)
|
||||||
gbuf = (unsigned char *)rb->plugin_get_buffer(&gbuf_size);
|
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");
|
rb->splash(HZ, "Couldn't init greyscale display");
|
||||||
return PLUGIN_ERROR;
|
return PLUGIN_ERROR;
|
||||||
|
|
|
@ -676,7 +676,7 @@ void I_InitGraphics(void)
|
||||||
|
|
||||||
#ifndef HAVE_LCD_COLOR
|
#ifndef HAVE_LCD_COLOR
|
||||||
gbuf=malloc(GREYBUFSIZE);
|
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 */
|
/* switch on greyscale overlay */
|
||||||
grey_show(true);
|
grey_show(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -278,7 +278,7 @@ int init_grey(void)
|
||||||
/* get the remainder of the plugin buffer */
|
/* get the remainder of the plugin buffer */
|
||||||
gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
|
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");
|
rb->splash(HZ, "not enough memory");
|
||||||
return PLUGIN_ERROR;
|
return PLUGIN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,8 @@ int main(void)
|
||||||
/* initialize the greyscale buffer:
|
/* initialize the greyscale buffer:
|
||||||
Archos: 112 pixels wide, 7 rows (56 pixels) high.
|
Archos: 112 pixels wide, 7 rows (56 pixels) high.
|
||||||
H1x0: 160 pixels wide, 30 rows (120 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.");
|
rb->splash(HZ, "Not enough memory.");
|
||||||
return PLUGIN_ERROR;
|
return PLUGIN_ERROR;
|
||||||
|
|
|
@ -3310,7 +3310,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USEGSLIB
|
#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");
|
rb->splash(HZ, "grey buf error");
|
||||||
return PLUGIN_ERROR;
|
return PLUGIN_ERROR;
|
||||||
|
|
|
@ -29,8 +29,10 @@
|
||||||
|
|
||||||
#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
|
#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
|
||||||
|
|
||||||
|
/* The greyscale lib uses 8 bit brightness values natively on input. */
|
||||||
#define GREY_BRIGHTNESS(y) (y)
|
#define GREY_BRIGHTNESS(y) (y)
|
||||||
|
|
||||||
|
/* Some predefined levels for convenience: */
|
||||||
#define GREY_BLACK GREY_BRIGHTNESS(0)
|
#define GREY_BLACK GREY_BRIGHTNESS(0)
|
||||||
#define GREY_DARKGRAY GREY_BRIGHTNESS(85)
|
#define GREY_DARKGRAY GREY_BRIGHTNESS(85)
|
||||||
#define GREY_LIGHTGRAY GREY_BRIGHTNESS(170)
|
#define GREY_LIGHTGRAY GREY_BRIGHTNESS(170)
|
||||||
|
@ -42,9 +44,13 @@
|
||||||
#define GREY_INFO_STRUCT struct _grey_info _grey_info;
|
#define GREY_INFO_STRUCT struct _grey_info _grey_info;
|
||||||
#define GREY_INFO_STRUCT_IRAM struct _grey_info _grey_info IBSS_ATTR;
|
#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 */
|
/* Library initialisation and release */
|
||||||
bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size,
|
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);
|
void grey_release(void);
|
||||||
|
|
||||||
/* Special functions */
|
/* Special functions */
|
||||||
|
|
|
@ -312,10 +312,12 @@ static int log_s16p16(int x)
|
||||||
newrb = pointer to plugin api
|
newrb = pointer to plugin api
|
||||||
gbuf = pointer to the memory area to use (e.g. plugin buffer)
|
gbuf = pointer to the memory area to use (e.g. plugin buffer)
|
||||||
gbuf_size = max usable size of the 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
|
This allows to use all drawing functions, but needs more
|
||||||
memory. Unbuffered operation provides only a subset of
|
memory. Unbuffered operation provides only a subset of
|
||||||
drawing functions. (only grey_bitmap drawing and scrolling)
|
drawing functions. (only grey_bitmap drawing and scrolling)
|
||||||
|
GREY_RAWMAPPED: no LCD linearisation and gamma correction
|
||||||
width = width in pixels (1..LCD_WIDTH)
|
width = width in pixels (1..LCD_WIDTH)
|
||||||
height = height in pixels (1..LCD_HEIGHT)
|
height = height in pixels (1..LCD_HEIGHT)
|
||||||
Note that depending on the target LCD, either height or
|
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
|
The function is authentic regarding memory usage on the simulator, even
|
||||||
if it doesn't use all of the allocated memory. */
|
if it doesn't use all of the allocated memory. */
|
||||||
bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size,
|
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;
|
int bdim, i;
|
||||||
long plane_size, buftaken;
|
long plane_size, buftaken;
|
||||||
|
@ -372,7 +374,7 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size,
|
||||||
#endif
|
#endif
|
||||||
gbuf += buftaken;
|
gbuf += buftaken;
|
||||||
|
|
||||||
if (buffered) /* chunky buffer */
|
if (features & GREY_BUFFERED) /* chunky buffer */
|
||||||
{
|
{
|
||||||
_grey_info.buffer = gbuf;
|
_grey_info.buffer = gbuf;
|
||||||
gbuf += plane_size;
|
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
|
/* precalculate the value -> pattern index conversion table, taking
|
||||||
linearisation and gamma correction into account */
|
linearisation and gamma correction into account */
|
||||||
for (i = 0; i < 256; i++)
|
if (features & GREY_RAWMAPPED)
|
||||||
{
|
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 = i << 7;
|
||||||
data = (lcdlinear[data] << 7) + 127;
|
_grey_info.gvalue[i] = (data + (data >> 8)) >> 8;
|
||||||
_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 */
|
/* approx. data / 255 */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf_taken) /* caller requested info about space taken */
|
if (buf_taken) /* caller requested info about space taken */
|
||||||
*buf_taken = buftaken;
|
*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);
|
_grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 70, 1, _timer_isr);
|
||||||
#elif CONFIG_LCD == LCD_IPOD2BPP
|
#elif CONFIG_LCD == LCD_IPOD2BPP
|
||||||
#ifdef IPOD_1G2G
|
#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
|
#elif defined IPOD_3G
|
||||||
_grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 87, 1, _timer_isr); /* verified */
|
_grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 87, 1, _timer_isr); /* verified */
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -620,7 +620,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
|
gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
|
||||||
|
|
||||||
/* initialize the greyscale buffer.*/
|
/* 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");
|
rb->splash(HZ, "Couldn't init greyscale display");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1006,8 +1006,8 @@ int stream_init(void)
|
||||||
graymem = mem;
|
graymem = mem;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
success = grey_init(rb, graymem, memsize, true, LCD_WIDTH,
|
success = grey_init(rb, graymem, memsize, GREY_BUFFERED,
|
||||||
LCD_HEIGHT, &graysize);
|
LCD_WIDTH, LCD_HEIGHT, &graysize);
|
||||||
|
|
||||||
/* This can run on another processor - align size */
|
/* This can run on another processor - align size */
|
||||||
graysize = CACHEALIGN_UP(graysize);
|
graysize = CACHEALIGN_UP(graysize);
|
||||||
|
|
|
@ -214,7 +214,7 @@ int main(void)
|
||||||
/* get the remainder of the plugin buffer */
|
/* get the remainder of the plugin buffer */
|
||||||
gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
|
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 */
|
/* switch on greyscale overlay */
|
||||||
grey_show(true);
|
grey_show(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -284,7 +284,7 @@ static void time_greyscale(void)
|
||||||
int fps, load;
|
int fps, load;
|
||||||
|
|
||||||
gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
|
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.");
|
log_text("greylib: out of memory.");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -74,9 +74,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
/* get the remainder of the plugin buffer */
|
/* get the remainder of the plugin buffer */
|
||||||
gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
|
gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
|
||||||
#ifdef USE_BUFFERED_GREY
|
#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
|
#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 */
|
#endif /* USE_BUFFERED_GREY */
|
||||||
/* switch on greyscale overlay */
|
/* switch on greyscale overlay */
|
||||||
grey_show(true);
|
grey_show(true);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue