From 007e1d1af37bd3412bab3c263cd1e5033c42b751 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Wed, 19 May 2004 17:02:20 +0000 Subject: [PATCH] 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 --- apps/plugins/lib/gray.c | 36 +++++++++++++++++++++--------------- apps/plugins/lib/gray.h | 2 +- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/apps/plugins/lib/gray.c b/apps/plugins/lib/gray.c index 6435f49007..f026ff7cd4 100644 --- a/apps/plugins/lib/gray.c +++ b/apps/plugins/lib/gray.c @@ -423,31 +423,31 @@ void gray_init(struct plugin_api* newrb) * * The total memory needed can be calculated as follows: * total_mem = - * sizeof(tGraymap) (= 48 bytes currently) + * sizeof(tGraybuf) (= 48 bytes currently) * + sizeof(long) (= 4 bytes) * + (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 bheight, int depth) + int bheight, int depth, int *buf_taken) { 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) || depth < 1) return 0; - while ((unsigned long)gbuf & 3) /* the buffer has to be long aligned */ - { - gbuf++; - gbuf_size--; - } + /* the buffer has to be long aligned */ + align = 3 - (((unsigned long)gbuf + 3) & 3); + gbuf += align; + gbuf_size -= align; plane_size = width * bheight; - possible_depth = (gbuf_size - sizeof(tGraybuf) - sizeof(unsigned long)) - / (plane_size + sizeof(unsigned long)); + possible_depth = (gbuf_size - sizeof(tGraybuf) - sizeof(long)) + / (plane_size + sizeof(long)); if (possible_depth < 1) return 0; @@ -455,8 +455,8 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, depth = MIN(depth, 32); depth = MIN(depth, possible_depth); - graybuf = (tGraybuf *) gbuf; /* global pointer to buffer structure */ - + graybuf = (tGraybuf *) gbuf; /* global pointer to buffer structure */ + graybuf->x = 0; graybuf->by = 0; graybuf->width = width; @@ -467,9 +467,9 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, graybuf->cur_plane = 0; graybuf->flags = 0; graybuf->data = gbuf + sizeof(tGraybuf); - graybuf->bitpattern = (unsigned long *) (graybuf->data + graybuf->bitpattern = (unsigned long *) (graybuf->data + depth * plane_size); - + i = depth; j = 8; while (i != 0) @@ -503,6 +503,12 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, 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; } diff --git a/apps/plugins/lib/gray.h b/apps/plugins/lib/gray.h index 64bc4dd8a5..62c3dd753f 100644 --- a/apps/plugins/lib/gray.h +++ b/apps/plugins/lib/gray.h @@ -37,7 +37,7 @@ void gray_init(struct plugin_api* newrb); /* general functions */ 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_position_display(int x, int by); void gray_show_display(bool enable);