1
0
Fork 0
forked from len0rd/rockbox

Added return parameter for space taken by grayscale buffer to gray_init_buffer()

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4648 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2004-05-19 17:02:20 +00:00
parent 0e1faea5ac
commit 007e1d1af3
2 changed files with 22 additions and 16 deletions

View file

@ -423,31 +423,31 @@ void gray_init(struct plugin_api* newrb)
* *
* The total memory needed can be calculated as follows: * The total memory needed can be calculated as follows:
* total_mem = * total_mem =
* sizeof(tGraymap) (= 48 bytes currently) * sizeof(tGraybuf) (= 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) * + 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 *buf_taken)
{ {
int possible_depth, plane_size; int possible_depth, plane_size;
int i, j; int i, j, align;
if (rb == NULL || (unsigned) width > LCD_WIDTH if (rb == NULL
|| (unsigned) width > LCD_WIDTH
|| (unsigned) bheight > (LCD_HEIGHT/8) || (unsigned) bheight > (LCD_HEIGHT/8)
|| depth < 1) || depth < 1)
return 0; return 0;
while ((unsigned long)gbuf & 3) /* the buffer has to be long aligned */ /* the buffer has to be long aligned */
{ align = 3 - (((unsigned long)gbuf + 3) & 3);
gbuf++; gbuf += align;
gbuf_size--; gbuf_size -= align;
}
plane_size = width * bheight; plane_size = width * bheight;
possible_depth = (gbuf_size - sizeof(tGraybuf) - sizeof(unsigned long)) possible_depth = (gbuf_size - sizeof(tGraybuf) - sizeof(long))
/ (plane_size + sizeof(unsigned long)); / (plane_size + sizeof(long));
if (possible_depth < 1) if (possible_depth < 1)
return 0; return 0;
@ -503,6 +503,12 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width,
graybuf->bitpattern[i] = pattern; graybuf->bitpattern[i] = pattern;
} }
if (buf_taken) /* caller requested info about space taken */
{
*buf_taken = sizeof(tGraybuf) + sizeof(long)
+ (plane_size + sizeof(long)) * depth + align;
}
return depth; return depth;
} }

View file

@ -37,7 +37,7 @@ void gray_init(struct plugin_api* newrb);
/* general functions */ /* general functions */
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 *buf_taken);
void gray_release_buffer(void); void gray_release_buffer(void);
void gray_position_display(int x, int by); void gray_position_display(int x, int by);
void gray_show_display(bool enable); void gray_show_display(bool enable);