1
0
Fork 0
forked from len0rd/rockbox

Updated with the latest grayscale framework

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4604 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2004-05-10 22:00:51 +00:00
parent f304356248
commit 9ecfacc475

View file

@ -34,18 +34,17 @@ static int max_iter;
static unsigned char *gbuf; static unsigned char *gbuf;
static unsigned int gbuf_size = 0; static unsigned int gbuf_size = 0;
/**************** Begin grayscale framework ******************/ /*********************** Begin grayscale framework *************************/
/* This is a generic framework to use grayscale display within /* This is a generic framework to use grayscale display within rockbox
* rockbox plugins. It obviously does not work for the player. * plugins. It obviously does not work for the player.
* *
* If you want to use grayscale display within a plugin, copy * If you want to use grayscale display within a plugin, copy this section
* this section (up to "End grayscale framework") into your * (up to "End grayscale framework") into your source and you are able to use
* source and you are able to use it. For detailed documentation * it. For detailed documentation look at the head of each public function.
* look at the head of each public function.
* *
* It requires a global Rockbox api pointer in "rb" and uses * It requires a global Rockbox api pointer in "rb" and uses the rockbox
* timer 4 so you cannot use timer 4 for other purposes while * timer api so you cannot use that timer for other purposes while
* displaying grayscale. * displaying grayscale.
* *
* The framework consists of 3 sections: * The framework consists of 3 sections:
@ -54,17 +53,15 @@ static unsigned int gbuf_size = 0;
* - public core functions * - public core functions
* - public optional functions * - public optional functions
* *
* Usually you will use functions from the latter two sections * Usually you will use functions from the latter two sections in your code.
* in your code. You can cut out functions from the third section * You can cut out functions from the third section that you do not need in
* that you do not need in order to not waste space. Don't forget * order to not waste space. Don't forget to cut the prototype as well.
* to cut the prototype as well.
*/ */
/**** internal core functions and definitions ****/ /**** internal core functions and definitions ****/
/* You do not want to touch these if you don't know exactly what /* You do not want to touch these if you don't know exactly what you're
* you're doing. * doing. */
*/
#define GRAY_RUNNING 0x0001 /* grayscale overlay is running */ #define GRAY_RUNNING 0x0001 /* grayscale overlay is running */
#define GRAY_DEFERRED_UPDATE 0x0002 /* lcd_update() requested */ #define GRAY_DEFERRED_UPDATE 0x0002 /* lcd_update() requested */
@ -89,14 +86,14 @@ static tGraybuf *graybuf = NULL;
/** prototypes **/ /** prototypes **/
void timer4_isr(void); void timer_isr(void);
void graypixel(int x, int y, unsigned long pattern); void graypixel(int x, int y, unsigned long pattern);
void grayinvertmasked(int x, int yb, unsigned char mask); void grayinvertmasked(int x, int yb, unsigned char mask);
/** implementation **/ /** implementation **/
/* timer interrupt handler: display next bitplane */ /* timer interrupt handler: display next bitplane */
void timer4_isr(void) /* IMIA4 */ void timer_isr(void)
{ {
rb->lcd_blit(graybuf->data + (graybuf->plane_size * graybuf->cur_plane), rb->lcd_blit(graybuf->data + (graybuf->plane_size * graybuf->cur_plane),
graybuf->x, graybuf->by, graybuf->width, graybuf->bheight, graybuf->x, graybuf->by, graybuf->width, graybuf->bheight,
@ -107,24 +104,24 @@ void timer4_isr(void) /* IMIA4 */
if (graybuf->flags & GRAY_DEFERRED_UPDATE) /* lcd_update() requested? */ if (graybuf->flags & GRAY_DEFERRED_UPDATE) /* lcd_update() requested? */
{ {
int x1 = MAX(graybuf->x, 0); int x1 = MAX(graybuf->x, 0);
int x2 = MIN(graybuf->x + graybuf->width, LCD_WIDTH); int x2 = MIN(graybuf->x + graybuf->width, LCD_WIDTH);
int y1 = MAX(graybuf->by << 3, 0); int y1 = MAX(graybuf->by << 3, 0);
int y2 = MIN((graybuf->by + graybuf->bheight) << 3, LCD_HEIGHT); int y2 = MIN((graybuf->by + graybuf->bheight) << 3, LCD_HEIGHT);
if(y1 > 0) /* refresh part above overlay, full width */ if (y1 > 0) /* refresh part above overlay, full width */
rb->lcd_update_rect(0, 0, LCD_WIDTH, y1); rb->lcd_update_rect(0, 0, LCD_WIDTH, y1);
if(y2 < LCD_HEIGHT) /* refresh part below overlay, full width */ if (y2 < LCD_HEIGHT) /* refresh part below overlay, full width */
rb->lcd_update_rect(0, y2, LCD_WIDTH, LCD_HEIGHT - y2); rb->lcd_update_rect(0, y2, LCD_WIDTH, LCD_HEIGHT - y2);
if(x1 > 0) /* refresh part to the left of overlay */ if (x1 > 0) /* refresh part to the left of overlay */
rb->lcd_update_rect(0, y1, x1, y2 - y1); rb->lcd_update_rect(0, y1, x1, y2 - y1);
if(x2 < LCD_WIDTH) /* refresh part to the right of overlay */ if (x2 < LCD_WIDTH) /* refresh part to the right of overlay */
rb->lcd_update_rect(x2, y1, LCD_WIDTH - x2, y2 - y1); rb->lcd_update_rect(x2, y1, LCD_WIDTH - x2, y2 - y1);
graybuf->flags &= ~GRAY_DEFERRED_UPDATE; /* clear request */ graybuf->flags &= ~GRAY_DEFERRED_UPDATE; /* clear request */
} }
} }
@ -135,14 +132,11 @@ void graypixel(int x, int y, unsigned long pattern)
static short random_buffer; static short random_buffer;
register long address, mask, random; register long address, mask, random;
/* Some (pseudo-)random function must be used here to shift /* Some (pseudo-)random function must be used here to shift the bit
* the bit pattern randomly, otherwise you would get flicker * pattern randomly, otherwise you would get flicker and/or moire.
* and/or moire. * Since rand() is relatively slow, I've implemented a simple, but very
* Since rand() is relatively slow, I've implemented a simple, * fast pseudo-random generator based on linear congruency in assembler.
* but very fast pseudo-random generator based on linear * It delivers 16 pseudo-random bits in each iteration. */
* congruency in assembler. It delivers 16 pseudo-random bits
* in each iteration.
*/
/* simple but fast pseudo-random generator */ /* simple but fast pseudo-random generator */
asm( asm(
@ -192,7 +186,7 @@ void graypixel(int x, int y, unsigned long pattern)
".pp_end: \n" ".pp_end: \n"
: /* outputs */ : /* outputs */
/* %0 */ "=&r"(address), /* %0 */ "=&r"(address),
/* %1 */ "=&r"(mask) /* %1 */ "=&r"(mask)
: /* inputs */ : /* inputs */
/* %2 */ "r"(graybuf->width), /* %2 */ "r"(graybuf->width),
@ -268,7 +262,7 @@ void graypixel(int x, int y, unsigned long pattern)
} }
/* Invert the bits for 1-8 pixels within the buffer */ /* Invert the bits for 1-8 pixels within the buffer */
void grayinvertmasked(int x, int yb, unsigned char mask) void grayinvertmasked(int x, int by, unsigned char mask)
{ {
asm( asm(
"mulu %4,%5 \n" /* width * by (offset of row) */ "mulu %4,%5 \n" /* width * by (offset of row) */
@ -291,7 +285,7 @@ void grayinvertmasked(int x, int yb, unsigned char mask)
/* %2 */ "r"(mask), /* %2 */ "r"(mask),
/* %3 */ "r"(graybuf->plane_size), /* %3 */ "r"(graybuf->plane_size),
/* %4 */ "r"(graybuf->width), /* %4 */ "r"(graybuf->width),
/* %5 */ "r"(yb) /* %5 */ "r"(by)
: /* clobbers */ : /* clobbers */
"r1", "r2", "macl" "r1", "r2", "macl"
); );
@ -316,12 +310,12 @@ void gray_show_display(bool enable);
* gbuf_size = max usable size of the buffer * gbuf_size = max usable size of the buffer
* width = width in pixels (1..112) * width = width in pixels (1..112)
* bheight = height in 8-pixel units (1..8) * bheight = height in 8-pixel units (1..8)
* depth = desired number of grayscales - 1 (1..32) * depth = desired number of shades - 1 (1..32)
* *
* result: * result:
* = depth if there was enough memory * = depth if there was enough memory
* < depth if there wasn't enough memory. The number of displayable * < depth if there wasn't enough memory. The number of displayable
* grayscales is smaller than desired, but it still works * shades is smaller than desired, but it still works
* = 0 if there wasn't even enough memory for 1 bitplane (black & white) * = 0 if there wasn't even enough memory for 1 bitplane (black & white)
* *
* You can request any depth from 1 to 32, not just powers of 2. The routine * You can request any depth from 1 to 32, not just powers of 2. The routine
@ -335,17 +329,23 @@ void gray_show_display(bool enable);
* sizeof(tGraymap) (= 48 bytes currently) * sizeof(tGraymap) (= 48 bytes currently)
* + sizeof(long) (= 4 bytes) * + sizeof(long) (= 4 bytes)
* + (width * bheight + sizeof(long)) * depth * + (width * bheight + sizeof(long)) * depth
* + 0..3 (longword alignment of grayscale display buffer)
*/ */
int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width,
int bheight, int depth) int bheight, int depth)
{ {
int plane_size; int possible_depth, plane_size;
int possible_depth;
int i, j; int i, j;
if (width > LCD_WIDTH || bheight > (LCD_HEIGHT >> 3) || depth < 1) if (width > LCD_WIDTH || bheight > (LCD_HEIGHT >> 3) || depth < 1)
return 0; return 0;
while ((unsigned long)gbuf & 3) /* the buffer has to be long aligned */
{
gbuf++;
gbuf_size--;
}
plane_size = width * bheight; plane_size = width * bheight;
possible_depth = (gbuf_size - sizeof(tGraybuf) - sizeof(unsigned long)) possible_depth = (gbuf_size - sizeof(tGraybuf) - sizeof(unsigned long))
/ (plane_size + sizeof(unsigned long)); / (plane_size + sizeof(unsigned long));
@ -375,8 +375,8 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width,
j = 8; j = 8;
while (i != 0) while (i != 0)
{ {
i >>= 1; i >>= 1;
j--; j--;
} }
graybuf->randmask = 0xFF >> j; graybuf->randmask = 0xFF >> j;
@ -386,11 +386,11 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width,
/* Precalculate the bit patterns for all possible pixel values */ /* Precalculate the bit patterns for all possible pixel values */
for (i = 0; i <= depth; i++) for (i = 0; i <= depth; i++)
{ {
unsigned long pattern = 0; unsigned long pattern = 0;
int value = 0; int value = 0;
for (j = 0; j < depth; j++) for (j = 0; j < depth; j++)
{ {
pattern <<= 1; pattern <<= 1;
value += i; value += i;
@ -398,10 +398,10 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width,
value -= depth; /* "white" bit */ value -= depth; /* "white" bit */
else else
pattern |= 1; /* "black" bit */ pattern |= 1; /* "black" bit */
} }
/* now the lower <depth> bits contain the pattern */ /* now the lower <depth> bits contain the pattern */
graybuf->bitpattern[i] = pattern; graybuf->bitpattern[i] = pattern;
} }
return depth; return depth;
@ -474,7 +474,7 @@ void gray_show_display(bool enable)
if (enable) if (enable)
{ {
graybuf->flags |= GRAY_RUNNING; graybuf->flags |= GRAY_RUNNING;
rb->plugin_register_timer(FREQ / 67, 1, timer4_isr); rb->plugin_register_timer(FREQ / 67, 1, timer_isr);
} }
else else
{ {
@ -504,7 +504,7 @@ void gray_clear_display(void);
//void gray_scroll_down8(bool black_border); //void gray_scroll_down8(bool black_border);
//void gray_scroll_up1(bool black_border); //void gray_scroll_up1(bool black_border);
//void gray_scroll_down1(bool black_border); //void gray_scroll_down1(bool black_border);
//
/* pixel functions */ /* pixel functions */
void gray_drawpixel(int x, int y, int brightness); void gray_drawpixel(int x, int y, int brightness);
//void gray_invertpixel(int x, int y); //void gray_invertpixel(int x, int y);
@ -519,9 +519,11 @@ void gray_drawpixel(int x, int y, int brightness);
//void gray_invertrect(int x1, int y1, int x2, int y2); //void gray_invertrect(int x1, int y1, int x2, int y2);
/* bitmap functions */ /* bitmap functions */
//void gray_drawgraymap(unsigned char *src, int x, int y, int nx, int ny); //void gray_drawgraymap(unsigned char *src, int x, int y, int nx, int ny,
// int stride);
//void gray_drawbitmap(unsigned char *src, int x, int y, int nx, int ny, //void gray_drawbitmap(unsigned char *src, int x, int y, int nx, int ny,
// bool draw_bg, int fg_brightness, int bg_brightness); // int stride, bool draw_bg, int fg_brightness,
// int bg_brightness);
/** implementation **/ /** implementation **/
@ -535,31 +537,6 @@ void gray_clear_display(void)
rb->memset(graybuf->data, 0, graybuf->depth * graybuf->plane_size); rb->memset(graybuf->data, 0, graybuf->depth * graybuf->plane_size);
} }
/* Set the grayscale display to all black
*/
void gray_black_display(void)
{
if (graybuf == NULL)
return;
rb->memset(graybuf->data, 0xFF, graybuf->depth * graybuf->plane_size);
}
/* Do a lcd_update() to show changes done by rb->lcd_xxx() functions (in areas
* of the screen not covered by the grayscale overlay). If the grayscale
* overlay is running, the update will be done in the next call of the
* interrupt routine, otherwise it will be performed right away. See also
* comment for the gray_show_display() function.
*/
void gray_deferred_update(void)
{
if (graybuf != NULL && (graybuf->flags & GRAY_RUNNING))
graybuf->flags |= GRAY_DEFERRED_UPDATE;
else
rb->lcd_update();
}
/* Set a pixel to a specific gray value /* Set a pixel to a specific gray value
* *
* brightness is 0..255 (black to white) regardless of real bit depth * brightness is 0..255 (black to white) regardless of real bit depth
@ -574,24 +551,8 @@ void gray_drawpixel(int x, int y, int brightness)
* (graybuf->depth + 1)) >> 8]); * (graybuf->depth + 1)) >> 8]);
} }
/* Invert a pixel
*
* The bit pattern for that pixel in the buffer is inverted, so white
* becomes black, light gray becomes dark gray etc.
*/
void gray_invertpixel(int x, int y)
{
if (graybuf == NULL || x >= graybuf->width || y >= graybuf->height)
return;
grayinvertmasked(x, (y >> 3), 1 << (y & 7)); /*********************** end grayscale framework ***************************/
}
/**************** end grayscale framework ********************/
@ -630,7 +591,7 @@ void calc_mandelbrot_set(void){
x = 0; x = 0;
y = 0; y = 0;
n_iter = 0; n_iter = 0;
while (++n_iter<=max_iter) { while (++n_iter<=max_iter) {
x >>= 13; x >>= 13;
y >>= 13; y >>= 13;