diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/lib/gray.c | 36 | ||||
-rw-r--r-- | 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) | |||
423 | * | 423 | * |
424 | * The total memory needed can be calculated as follows: | 424 | * The total memory needed can be calculated as follows: |
425 | * total_mem = | 425 | * total_mem = |
426 | * sizeof(tGraymap) (= 48 bytes currently) | 426 | * sizeof(tGraybuf) (= 48 bytes currently) |
427 | * + sizeof(long) (= 4 bytes) | 427 | * + sizeof(long) (= 4 bytes) |
428 | * + (width * bheight + sizeof(long)) * depth | 428 | * + (width * bheight + sizeof(long)) * depth |
429 | * + 0..3 (longword alignment of grayscale display buffer) | 429 | * + 0..3 (longword alignment of grayscale display buffer) |
430 | */ | 430 | */ |
431 | int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, | 431 | int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, |
432 | int bheight, int depth) | 432 | int bheight, int depth, int *buf_taken) |
433 | { | 433 | { |
434 | int possible_depth, plane_size; | 434 | int possible_depth, plane_size; |
435 | int i, j; | 435 | int i, j, align; |
436 | 436 | ||
437 | if (rb == NULL || (unsigned) width > LCD_WIDTH | 437 | if (rb == NULL |
438 | || (unsigned) width > LCD_WIDTH | ||
438 | || (unsigned) bheight > (LCD_HEIGHT/8) | 439 | || (unsigned) bheight > (LCD_HEIGHT/8) |
439 | || depth < 1) | 440 | || depth < 1) |
440 | return 0; | 441 | return 0; |
441 | 442 | ||
442 | while ((unsigned long)gbuf & 3) /* the buffer has to be long aligned */ | 443 | /* the buffer has to be long aligned */ |
443 | { | 444 | align = 3 - (((unsigned long)gbuf + 3) & 3); |
444 | gbuf++; | 445 | gbuf += align; |
445 | gbuf_size--; | 446 | gbuf_size -= align; |
446 | } | ||
447 | 447 | ||
448 | plane_size = width * bheight; | 448 | plane_size = width * bheight; |
449 | possible_depth = (gbuf_size - sizeof(tGraybuf) - sizeof(unsigned long)) | 449 | possible_depth = (gbuf_size - sizeof(tGraybuf) - sizeof(long)) |
450 | / (plane_size + sizeof(unsigned long)); | 450 | / (plane_size + sizeof(long)); |
451 | 451 | ||
452 | if (possible_depth < 1) | 452 | if (possible_depth < 1) |
453 | return 0; | 453 | return 0; |
@@ -455,8 +455,8 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, | |||
455 | depth = MIN(depth, 32); | 455 | depth = MIN(depth, 32); |
456 | depth = MIN(depth, possible_depth); | 456 | depth = MIN(depth, possible_depth); |
457 | 457 | ||
458 | graybuf = (tGraybuf *) gbuf; /* global pointer to buffer structure */ | 458 | graybuf = (tGraybuf *) gbuf; /* global pointer to buffer structure */ |
459 | 459 | ||
460 | graybuf->x = 0; | 460 | graybuf->x = 0; |
461 | graybuf->by = 0; | 461 | graybuf->by = 0; |
462 | graybuf->width = width; | 462 | graybuf->width = width; |
@@ -467,9 +467,9 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, | |||
467 | graybuf->cur_plane = 0; | 467 | graybuf->cur_plane = 0; |
468 | graybuf->flags = 0; | 468 | graybuf->flags = 0; |
469 | graybuf->data = gbuf + sizeof(tGraybuf); | 469 | graybuf->data = gbuf + sizeof(tGraybuf); |
470 | graybuf->bitpattern = (unsigned long *) (graybuf->data | 470 | graybuf->bitpattern = (unsigned long *) (graybuf->data |
471 | + depth * plane_size); | 471 | + depth * plane_size); |
472 | 472 | ||
473 | i = depth; | 473 | i = depth; |
474 | j = 8; | 474 | j = 8; |
475 | while (i != 0) | 475 | while (i != 0) |
@@ -503,6 +503,12 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, | |||
503 | graybuf->bitpattern[i] = pattern; | 503 | graybuf->bitpattern[i] = pattern; |
504 | } | 504 | } |
505 | 505 | ||
506 | if (buf_taken) /* caller requested info about space taken */ | ||
507 | { | ||
508 | *buf_taken = sizeof(tGraybuf) + sizeof(long) | ||
509 | + (plane_size + sizeof(long)) * depth + align; | ||
510 | } | ||
511 | |||
506 | return depth; | 512 | return depth; |
507 | } | 513 | } |
508 | 514 | ||
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); | |||
37 | 37 | ||
38 | /* general functions */ | 38 | /* general functions */ |
39 | int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, | 39 | int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, |
40 | int bheight, int depth); | 40 | int bheight, int depth, int *buf_taken); |
41 | void gray_release_buffer(void); | 41 | void gray_release_buffer(void); |
42 | void gray_position_display(int x, int by); | 42 | void gray_position_display(int x, int by); |
43 | void gray_show_display(bool enable); | 43 | void gray_show_display(bool enable); |