diff options
Diffstat (limited to 'apps/plugins/lib/grey_core.c')
-rw-r--r-- | apps/plugins/lib/grey_core.c | 133 |
1 files changed, 29 insertions, 104 deletions
diff --git a/apps/plugins/lib/grey_core.c b/apps/plugins/lib/grey_core.c index 395a1130d5..0e2408b107 100644 --- a/apps/plugins/lib/grey_core.c +++ b/apps/plugins/lib/grey_core.c | |||
@@ -214,7 +214,27 @@ static inline void _deferred_update(void) | |||
214 | _grey_info.rb->lcd_update_rect(x2, y1, LCD_WIDTH - x2, y2 - y1); | 214 | _grey_info.rb->lcd_update_rect(x2, y1, LCD_WIDTH - x2, y2 - y1); |
215 | } | 215 | } |
216 | 216 | ||
217 | #ifndef SIMULATOR | 217 | #ifdef SIMULATOR |
218 | |||
219 | /* Callback function for grey_ub_gray_bitmap_part() to read a pixel from the | ||
220 | * greybuffer. Note that x and y are in LCD coordinates, not greybuffer | ||
221 | * coordinates! */ | ||
222 | static unsigned long _grey_get_pixel(int x, int y) | ||
223 | { | ||
224 | int xg = x - _grey_info.x; | ||
225 | int yg = y - _grey_info.y; | ||
226 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING | ||
227 | int idx = _grey_info.width * yg + xg; | ||
228 | #else | ||
229 | int idx = _grey_info.width * (yg & ~_GREY_BMASK) | ||
230 | + (xg << _GREY_BSHIFT) + (~yg & _GREY_BMASK); | ||
231 | #endif | ||
232 | |||
233 | return _grey_info.values[idx] + (1 << LCD_DEPTH); | ||
234 | } | ||
235 | |||
236 | #else /* !SIMULATOR */ | ||
237 | |||
218 | /* Timer interrupt handler: display next frame */ | 238 | /* Timer interrupt handler: display next frame */ |
219 | static void _timer_isr(void) | 239 | static void _timer_isr(void) |
220 | { | 240 | { |
@@ -236,6 +256,7 @@ static void _timer_isr(void) | |||
236 | _grey_info.flags &= ~_GREY_DEFERRED_UPDATE; /* clear request */ | 256 | _grey_info.flags &= ~_GREY_DEFERRED_UPDATE; /* clear request */ |
237 | } | 257 | } |
238 | } | 258 | } |
259 | |||
239 | #endif /* !SIMULATOR */ | 260 | #endif /* !SIMULATOR */ |
240 | 261 | ||
241 | /* fixed point exp() */ | 262 | /* fixed point exp() */ |
@@ -357,22 +378,18 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, | |||
357 | gbuf += plane_size; | 378 | gbuf += plane_size; |
358 | buftaken += plane_size; | 379 | buftaken += plane_size; |
359 | } | 380 | } |
360 | #ifdef SIMULATOR | ||
361 | _grey_info.buffer = gbuf; | ||
362 | #else | ||
363 | _grey_info.values = gbuf; | 381 | _grey_info.values = gbuf; |
364 | gbuf += plane_size; | 382 | gbuf += plane_size; |
365 | _grey_info.phases = gbuf; | 383 | _grey_info.phases = gbuf; |
366 | #endif | ||
367 | buftaken += 2 * plane_size; | 384 | buftaken += 2 * plane_size; |
368 | 385 | ||
369 | if (buftaken > gbuf_size) | 386 | if (buftaken > gbuf_size) |
370 | return false; | 387 | return false; |
371 | 388 | ||
372 | #ifndef SIMULATOR | ||
373 | /* Init to white */ | 389 | /* Init to white */ |
374 | _grey_info.rb->memset(_grey_info.values, 0x80, plane_size); | 390 | _grey_info.rb->memset(_grey_info.values, 0x80, plane_size); |
375 | 391 | ||
392 | #ifndef SIMULATOR | ||
376 | /* Init phases with random bits */ | 393 | /* Init phases with random bits */ |
377 | dst = (unsigned*)(_grey_info.phases); | 394 | dst = (unsigned*)(_grey_info.phases); |
378 | end = (unsigned*)(_grey_info.phases + plane_size); | 395 | end = (unsigned*)(_grey_info.phases + plane_size); |
@@ -394,8 +411,6 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, | |||
394 | _grey_info.bheight = bdim; | 411 | _grey_info.bheight = bdim; |
395 | #endif | 412 | #endif |
396 | _grey_info.flags = 0; | 413 | _grey_info.flags = 0; |
397 | _grey_info.fg_val = 0; | ||
398 | _grey_info.bg_val = 128; | ||
399 | _grey_info.fg_brightness = 0; | 414 | _grey_info.fg_brightness = 0; |
400 | _grey_info.bg_brightness = 255; | 415 | _grey_info.bg_brightness = 255; |
401 | _grey_info.drawmode = DRMODE_SOLID; | 416 | _grey_info.drawmode = DRMODE_SOLID; |
@@ -442,7 +457,8 @@ void grey_show(bool enable) | |||
442 | _grey_info.flags |= _GREY_RUNNING; | 457 | _grey_info.flags |= _GREY_RUNNING; |
443 | #ifdef SIMULATOR | 458 | #ifdef SIMULATOR |
444 | _grey_info.rb->sim_lcd_ex_init(129, _grey_get_pixel); | 459 | _grey_info.rb->sim_lcd_ex_init(129, _grey_get_pixel); |
445 | grey_update(); | 460 | _grey_info.rb->sim_lcd_ex_update_rect(_grey_info.x, _grey_info.y, |
461 | _grey_info.width, _grey_info.height); | ||
446 | #else /* !SIMULATOR */ | 462 | #else /* !SIMULATOR */ |
447 | #ifdef NEED_BOOST | 463 | #ifdef NEED_BOOST |
448 | _grey_info.rb->cpu_boost(true); | 464 | _grey_info.rb->cpu_boost(true); |
@@ -484,91 +500,17 @@ void grey_show(bool enable) | |||
484 | } | 500 | } |
485 | } | 501 | } |
486 | 502 | ||
487 | #ifdef SIMULATOR | ||
488 | /* Callback function for grey_update_rect() to read a pixel from the greybuffer. | ||
489 | Note that x and y are in LCD coordinates, not greybuffer coordinates! */ | ||
490 | static unsigned long _grey_get_pixel(int x, int y) | ||
491 | { | ||
492 | return _grey_info.buffer[(y - _grey_info.y) * _grey_info.width | ||
493 | + x - _grey_info.x] + (1 << LCD_DEPTH); | ||
494 | } | ||
495 | |||
496 | /* Update a rectangular area of the greyscale overlay */ | ||
497 | void grey_update_rect(int x, int y, int width, int height) | ||
498 | { | ||
499 | if (x + width > _grey_info.width) | ||
500 | width = _grey_info.width - x; | ||
501 | if (y + height > _grey_info.height) | ||
502 | height = _grey_info.height - y; | ||
503 | |||
504 | x += _grey_info.x; | ||
505 | y += _grey_info.y; | ||
506 | |||
507 | if (x + width > LCD_WIDTH) | ||
508 | width = LCD_WIDTH - x; | ||
509 | if (y + height > LCD_HEIGHT) | ||
510 | height = LCD_HEIGHT - y; | ||
511 | |||
512 | _grey_info.rb->sim_lcd_ex_update_rect(x, y, width, height); | ||
513 | } | ||
514 | |||
515 | #else /* !SIMULATOR */ | ||
516 | |||
517 | void grey_update_rect(int x, int y, int width, int height) | 503 | void grey_update_rect(int x, int y, int width, int height) |
518 | { | 504 | { |
519 | unsigned char *src, *dst; | 505 | grey_ub_gray_bitmap_part(_grey_info.buffer, x, y, _grey_info.width, |
520 | 506 | x, y, width, height); | |
521 | if ((width <= 0) || (height <= 0)) | ||
522 | return; /* nothing to do */ | ||
523 | |||
524 | if (y + height > _grey_info.height) | ||
525 | height = _grey_info.height - y; | ||
526 | if (x + width > _grey_info.width) | ||
527 | width = _grey_info.width - x; | ||
528 | |||
529 | src = _grey_info.buffer + _GREY_MULUQ(_grey_info.width, y) + x; | ||
530 | |||
531 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING | ||
532 | dst = _grey_info.values + _GREY_MULUQ(_grey_info.width, y) + x; | ||
533 | |||
534 | do | ||
535 | { | ||
536 | _grey_info.rb->memcpy(dst, src, width); | ||
537 | dst += _grey_info.width; | ||
538 | src += _grey_info.width; | ||
539 | } | ||
540 | while (--height > 0); | ||
541 | |||
542 | #else /* LCD_PIXELFORMAT == VRTICAL_PACKING */ | ||
543 | do | ||
544 | { | ||
545 | unsigned char *src_row = src; | ||
546 | unsigned char *src_end = src + width; | ||
547 | |||
548 | dst = _grey_info.values | ||
549 | + _GREY_MULUQ(_grey_info.width, y & ~_GREY_BMASK) | ||
550 | + (x << _GREY_BSHIFT) + (~y & _GREY_BMASK); | ||
551 | do | ||
552 | { | ||
553 | *dst = *src_row++; | ||
554 | dst += _GREY_BSIZE; | ||
555 | } | ||
556 | while (src_row < src_end); | ||
557 | |||
558 | y++; | ||
559 | src += _grey_info.width; | ||
560 | } | ||
561 | while (--height > 0); | ||
562 | |||
563 | #endif /* LCD_PIXELFORMAT */ | ||
564 | } | 507 | } |
565 | 508 | ||
566 | #endif /* !SIMULATOR */ | ||
567 | |||
568 | /* Update the whole greyscale overlay */ | 509 | /* Update the whole greyscale overlay */ |
569 | void grey_update(void) | 510 | void grey_update(void) |
570 | { | 511 | { |
571 | grey_update_rect(0, 0, _grey_info.width, _grey_info.height); | 512 | grey_ub_gray_bitmap_part(_grey_info.buffer, 0, 0, _grey_info.width, |
513 | 0, 0, _grey_info.width, _grey_info.height); | ||
572 | } | 514 | } |
573 | 515 | ||
574 | /* Do an lcd_update() to show changes done by rb->lcd_xxx() functions | 516 | /* Do an lcd_update() to show changes done by rb->lcd_xxx() functions |
@@ -691,13 +633,8 @@ static void grey_screendump_hook(int fd) | |||
691 | if (((unsigned)gy < (unsigned)_grey_info.height) | 633 | if (((unsigned)gy < (unsigned)_grey_info.height) |
692 | && ((unsigned)gx < (unsigned)_grey_info.width)) | 634 | && ((unsigned)gx < (unsigned)_grey_info.width)) |
693 | { | 635 | { |
694 | #ifdef SIMULATOR | ||
695 | unsigned char *src = _grey_info.buffer | ||
696 | + _GREY_MULUQ(_grey_info.width, gy) + gx; | ||
697 | #else | ||
698 | unsigned char *src = _grey_info.values | 636 | unsigned char *src = _grey_info.values |
699 | + _GREY_MULUQ(_grey_info.width, gy) + gx; | 637 | + _GREY_MULUQ(_grey_info.width, gy) + gx; |
700 | #endif | ||
701 | for (i = 0; i < 4; i++) | 638 | for (i = 0; i < 4; i++) |
702 | linebuf[x + i] = BMP_FIXEDCOLORS + *src++; | 639 | linebuf[x + i] = BMP_FIXEDCOLORS + *src++; |
703 | } | 640 | } |
@@ -724,17 +661,11 @@ static void grey_screendump_hook(int fd) | |||
724 | if (((unsigned)gy < (unsigned)_grey_info.height) | 661 | if (((unsigned)gy < (unsigned)_grey_info.height) |
725 | && ((unsigned)gx < (unsigned)_grey_info.width)) | 662 | && ((unsigned)gx < (unsigned)_grey_info.width)) |
726 | { | 663 | { |
727 | #ifdef SIMULATOR | ||
728 | linebuf[x] = BMP_FIXEDCOLORS | ||
729 | + _grey_info.buffer[_GREY_MULUQ(_grey_info.width, | ||
730 | gy) + gx]; | ||
731 | #else | ||
732 | linebuf[x] = BMP_FIXEDCOLORS | 664 | linebuf[x] = BMP_FIXEDCOLORS |
733 | + _grey_info.values[_GREY_MULUQ(_grey_info.width, | 665 | + _grey_info.values[_GREY_MULUQ(_grey_info.width, |
734 | gy & ~_GREY_BMASK) | 666 | gy & ~_GREY_BMASK) |
735 | + (gx << _GREY_BSHIFT) | 667 | + (gx << _GREY_BSHIFT) |
736 | + (~gy & _GREY_BMASK)]; | 668 | + (~gy & _GREY_BMASK)]; |
737 | #endif | ||
738 | } | 669 | } |
739 | else | 670 | else |
740 | { | 671 | { |
@@ -753,17 +684,11 @@ static void grey_screendump_hook(int fd) | |||
753 | if (((unsigned)gy < (unsigned)_grey_info.height) | 684 | if (((unsigned)gy < (unsigned)_grey_info.height) |
754 | && ((unsigned)gx < (unsigned)_grey_info.width)) | 685 | && ((unsigned)gx < (unsigned)_grey_info.width)) |
755 | { | 686 | { |
756 | #ifdef SIMULATOR | ||
757 | linebuf[x] = BMP_FIXEDCOLORS | ||
758 | + _grey_info.buffer[_GREY_MULUQ(_grey_info.width, | ||
759 | gy) + gx]; | ||
760 | #else | ||
761 | linebuf[x] = BMP_FIXEDCOLORS | 687 | linebuf[x] = BMP_FIXEDCOLORS |
762 | + _grey_info.values[_GREY_MULUQ(_grey_info.width, | 688 | + _grey_info.values[_GREY_MULUQ(_grey_info.width, |
763 | gy & ~_GREY_BMASK) | 689 | gy & ~_GREY_BMASK) |
764 | + (gx << _GREY_BSHIFT) | 690 | + (gx << _GREY_BSHIFT) |
765 | + (~gy & _GREY_BMASK)]; | 691 | + (~gy & _GREY_BMASK)]; |
766 | #endif | ||
767 | } | 692 | } |
768 | else | 693 | else |
769 | { | 694 | { |