diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-05-19 08:04:55 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-05-19 08:04:55 +0000 |
commit | a08fa7142a6654ca227ade464c7af61b521b791e (patch) | |
tree | 1375d58472b3191ff8c40bc58265ee75e38ce70d | |
parent | a9244032d2786997bf72a4b5f3f260579446df04 (diff) | |
download | rockbox-a08fa7142a6654ca227ade464c7af61b521b791e.tar.gz rockbox-a08fa7142a6654ca227ade464c7af61b521b791e.zip |
o killed trailing whitespace
o uses the new grayscale.h header
o #ifdef'ed out the code that builds a plugin, as this is now only part of the
libplugin. we should probably build a separate plugin instead.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4639 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/lib/grayscale.c | 211 |
1 files changed, 67 insertions, 144 deletions
diff --git a/apps/plugins/lib/grayscale.c b/apps/plugins/lib/grayscale.c index 55dd12aa3f..3b33b6e19c 100644 --- a/apps/plugins/lib/grayscale.c +++ b/apps/plugins/lib/grayscale.c | |||
@@ -23,13 +23,11 @@ | |||
23 | #include "plugin.h" | 23 | #include "plugin.h" |
24 | 24 | ||
25 | #ifdef HAVE_LCD_BITMAP /* and also not for the Player */ | 25 | #ifdef HAVE_LCD_BITMAP /* and also not for the Player */ |
26 | #include "grayscale.h" | ||
26 | 27 | ||
27 | /******************************* Globals ***********************************/ | 28 | /******************************* Globals ***********************************/ |
28 | 29 | ||
29 | static struct plugin_api* rb; /* global api struct pointer */ | 30 | static struct plugin_api* rb; /* global api struct pointer */ |
30 | static char pbuf[32]; /* global printf buffer */ | ||
31 | static unsigned char *gbuf; | ||
32 | static unsigned int gbuf_size = 0; | ||
33 | 31 | ||
34 | /*********************** Begin grayscale framework *************************/ | 32 | /*********************** Begin grayscale framework *************************/ |
35 | 33 | ||
@@ -55,43 +53,6 @@ static unsigned int gbuf_size = 0; | |||
55 | * order to not waste space. Don't forget to cut the prototype as well. | 53 | * order to not waste space. Don't forget to cut the prototype as well. |
56 | */ | 54 | */ |
57 | 55 | ||
58 | /**** internal core functions and definitions ****/ | ||
59 | |||
60 | /* You do not want to touch these if you don't know exactly what you're | ||
61 | * doing. */ | ||
62 | |||
63 | #define GRAY_RUNNING 0x0001 /* grayscale overlay is running */ | ||
64 | #define GRAY_DEFERRED_UPDATE 0x0002 /* lcd_update() requested */ | ||
65 | |||
66 | /* unsigned 16 bit multiplication (a single instruction on the SH) */ | ||
67 | #define MULU16(a, b) (((unsigned short) (a)) * ((unsigned short) (b))) | ||
68 | |||
69 | typedef struct | ||
70 | { | ||
71 | int x; | ||
72 | int by; /* 8-pixel units */ | ||
73 | int width; | ||
74 | int height; | ||
75 | int bheight; /* 8-pixel units */ | ||
76 | int plane_size; | ||
77 | int depth; /* number_of_bitplanes = (number_of_grayscales - 1) */ | ||
78 | int cur_plane; /* for the timer isr */ | ||
79 | unsigned long randmask; /* mask for random value in graypixel() */ | ||
80 | unsigned long flags; /* various flags, see #defines */ | ||
81 | unsigned char *data; /* pointer to start of bitplane data */ | ||
82 | unsigned long *bitpattern; /* pointer to start of pattern table */ | ||
83 | } tGraybuf; | ||
84 | |||
85 | static tGraybuf *graybuf = NULL; | ||
86 | static short gray_random_buffer; | ||
87 | |||
88 | /** prototypes **/ | ||
89 | |||
90 | void gray_timer_isr(void); | ||
91 | void graypixel(int x, int y, unsigned long pattern); | ||
92 | void grayblock(int x, int by, unsigned char* src, int stride); | ||
93 | void grayinvertmasked(int x, int by, unsigned char mask); | ||
94 | |||
95 | /** implementation **/ | 56 | /** implementation **/ |
96 | 57 | ||
97 | /* timer interrupt handler: display next bitplane */ | 58 | /* timer interrupt handler: display next bitplane */ |
@@ -173,7 +134,7 @@ void graypixel(int x, int y, unsigned long pattern) | |||
173 | "mova .pp_table,%3 \n" /* get address of mask table in r0 */ | 134 | "mova .pp_table,%3 \n" /* get address of mask table in r0 */ |
174 | "bra .pp_end \n" /* skip the table */ | 135 | "bra .pp_end \n" /* skip the table */ |
175 | "mov.b @(%3,%1),%1 \n" /* get entry from mask table */ | 136 | "mov.b @(%3,%1),%1 \n" /* get entry from mask table */ |
176 | 137 | ||
177 | ".align 2 \n" | 138 | ".align 2 \n" |
178 | ".pp_table: \n" /* mask table */ | 139 | ".pp_table: \n" /* mask table */ |
179 | ".byte 0x01 \n" | 140 | ".byte 0x01 \n" |
@@ -187,7 +148,7 @@ void graypixel(int x, int y, unsigned long pattern) | |||
187 | 148 | ||
188 | ".pp_end: \n" | 149 | ".pp_end: \n" |
189 | : /* outputs */ | 150 | : /* outputs */ |
190 | /* %0 */ "=&r"(address), | 151 | /* %0 */ "=&r"(address), |
191 | /* %1 */ "=&r"(mask) | 152 | /* %1 */ "=&r"(mask) |
192 | : /* inputs */ | 153 | : /* inputs */ |
193 | /* %2 */ "r"(graybuf->width), | 154 | /* %2 */ "r"(graybuf->width), |
@@ -205,7 +166,7 @@ void graypixel(int x, int y, unsigned long pattern) | |||
205 | /* it's sufficient to do this once, since the mask guarantees | 166 | /* it's sufficient to do this once, since the mask guarantees |
206 | * random < 2 * depth */ | 167 | * random < 2 * depth */ |
207 | ".p_ntrim: \n" | 168 | ".p_ntrim: \n" |
208 | 169 | ||
209 | /* calculate some addresses */ | 170 | /* calculate some addresses */ |
210 | "mulu %4,%1 \n" /* end address offset */ | 171 | "mulu %4,%1 \n" /* end address offset */ |
211 | "not %3,r1 \n" /* get inverse mask (for "and") */ | 172 | "not %3,r1 \n" /* get inverse mask (for "and") */ |
@@ -230,7 +191,7 @@ void graypixel(int x, int y, unsigned long pattern) | |||
230 | ".p_start1: \n" | 191 | ".p_start1: \n" |
231 | "cmp/hi r2,%1 \n" /* address < end address ? */ | 192 | "cmp/hi r2,%1 \n" /* address < end address ? */ |
232 | "bt .p_loop1 \n" | 193 | "bt .p_loop1 \n" |
233 | 194 | ||
234 | "bra .p_start2 \n" | 195 | "bra .p_start2 \n" |
235 | "nop \n" | 196 | "nop \n" |
236 | 197 | ||
@@ -268,7 +229,7 @@ void graypixel(int x, int y, unsigned long pattern) | |||
268 | void grayblock(int x, int by, unsigned char* src, int stride) | 229 | void grayblock(int x, int by, unsigned char* src, int stride) |
269 | { | 230 | { |
270 | /* precalculate the bit patterns with random shifts (same RNG as graypixel, | 231 | /* precalculate the bit patterns with random shifts (same RNG as graypixel, |
271 | * see there for an explanation) for all 8 pixels and put them on the | 232 | * see there for an explanation) for all 8 pixels and put them on the |
272 | * stack (!) */ | 233 | * stack (!) */ |
273 | asm( | 234 | asm( |
274 | "mova .gb_reload,r0 \n" /* set default loopback address */ | 235 | "mova .gb_reload,r0 \n" /* set default loopback address */ |
@@ -320,7 +281,7 @@ void grayblock(int x, int by, unsigned char* src, int stride) | |||
320 | 281 | ||
321 | "or r1,r0 \n" /* rotated_pattern = r0 | r1 */ | 282 | "or r1,r0 \n" /* rotated_pattern = r0 | r1 */ |
322 | "mov.l r0,@-r15 \n" /* push pattern */ | 283 | "mov.l r0,@-r15 \n" /* push pattern */ |
323 | 284 | ||
324 | "cmp/pl r3 \n" /* loop count > 0? */ | 285 | "cmp/pl r3 \n" /* loop count > 0? */ |
325 | "bf .gb_patdone \n" /* no: done */ | 286 | "bf .gb_patdone \n" /* no: done */ |
326 | 287 | ||
@@ -404,7 +365,7 @@ void grayinvertmasked(int x, int by, unsigned char mask) | |||
404 | "mov #0,r1 \n" /* current_plane = 0 */ | 365 | "mov #0,r1 \n" /* current_plane = 0 */ |
405 | "sts macl,r2 \n" /* get mulu result */ | 366 | "sts macl,r2 \n" /* get mulu result */ |
406 | "add r2,%1 \n" /* -> address in 1st bitplane */ | 367 | "add r2,%1 \n" /* -> address in 1st bitplane */ |
407 | 368 | ||
408 | ".i_loop: \n" | 369 | ".i_loop: \n" |
409 | "mov.b @%1,r2 \n" /* get data byte */ | 370 | "mov.b @%1,r2 \n" /* get data byte */ |
410 | "add #1,r1 \n" /* current_plane++; */ | 371 | "add #1,r1 \n" /* current_plane++; */ |
@@ -426,16 +387,6 @@ void grayinvertmasked(int x, int by, unsigned char mask) | |||
426 | ); | 387 | ); |
427 | } | 388 | } |
428 | 389 | ||
429 | /*** public core functions ***/ | ||
430 | |||
431 | /** prototypes **/ | ||
432 | |||
433 | int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, | ||
434 | int bheight, int depth); | ||
435 | void gray_release_buffer(void); | ||
436 | void gray_position_display(int x, int by); | ||
437 | void gray_show_display(bool enable); | ||
438 | |||
439 | /** implementation **/ | 390 | /** implementation **/ |
440 | 391 | ||
441 | /* Prepare the grayscale display buffer | 392 | /* Prepare the grayscale display buffer |
@@ -472,13 +423,13 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, | |||
472 | int possible_depth, plane_size; | 423 | int possible_depth, plane_size; |
473 | int i, j; | 424 | int i, j; |
474 | 425 | ||
475 | if ((unsigned) width > LCD_WIDTH | 426 | if ((unsigned) width > LCD_WIDTH |
476 | || (unsigned) bheight > (LCD_HEIGHT >> 3) | 427 | || (unsigned) bheight > (LCD_HEIGHT >> 3) |
477 | || depth < 1) | 428 | || depth < 1) |
478 | return 0; | 429 | return 0; |
479 | 430 | ||
480 | while ((unsigned long)gbuf & 3) /* the buffer has to be long aligned */ | 431 | while ((unsigned long)gbuf & 3) /* the buffer has to be long aligned */ |
481 | { | 432 | { |
482 | gbuf++; | 433 | gbuf++; |
483 | gbuf_size--; | 434 | gbuf_size--; |
484 | } | 435 | } |
@@ -505,9 +456,9 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, | |||
505 | graybuf->cur_plane = 0; | 456 | graybuf->cur_plane = 0; |
506 | graybuf->flags = 0; | 457 | graybuf->flags = 0; |
507 | graybuf->data = gbuf + sizeof(tGraybuf); | 458 | graybuf->data = gbuf + sizeof(tGraybuf); |
508 | graybuf->bitpattern = (unsigned long *) (graybuf->data | 459 | graybuf->bitpattern = (unsigned long *) (graybuf->data |
509 | + depth * plane_size); | 460 | + depth * plane_size); |
510 | 461 | ||
511 | i = depth; | 462 | i = depth; |
512 | j = 8; | 463 | j = 8; |
513 | while (i != 0) | 464 | while (i != 0) |
@@ -519,7 +470,7 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, | |||
519 | 470 | ||
520 | /* initial state is all white */ | 471 | /* initial state is all white */ |
521 | rb->memset(graybuf->data, 0, depth * plane_size); | 472 | rb->memset(graybuf->data, 0, depth * plane_size); |
522 | 473 | ||
523 | /* Precalculate the bit patterns for all possible pixel values */ | 474 | /* Precalculate the bit patterns for all possible pixel values */ |
524 | for (i = 0; i <= depth; i++) | 475 | for (i = 0; i <= depth; i++) |
525 | { | 476 | { |
@@ -535,12 +486,12 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, | |||
535 | value -= depth; /* "white" bit */ | 486 | value -= depth; /* "white" bit */ |
536 | else | 487 | else |
537 | pattern |= 1; /* "black" bit */ | 488 | pattern |= 1; /* "black" bit */ |
538 | } | 489 | } |
539 | /* now the lower <depth> bits contain the pattern */ | 490 | /* now the lower <depth> bits contain the pattern */ |
540 | 491 | ||
541 | graybuf->bitpattern[i] = pattern; | 492 | graybuf->bitpattern[i] = pattern; |
542 | } | 493 | } |
543 | 494 | ||
544 | return depth; | 495 | return depth; |
545 | } | 496 | } |
546 | 497 | ||
@@ -564,7 +515,7 @@ void gray_release_buffer(void) | |||
564 | * by = top margin in 8-pixel units | 515 | * by = top margin in 8-pixel units |
565 | * | 516 | * |
566 | * You may set this in a way that the overlay spills across the right or | 517 | * You may set this in a way that the overlay spills across the right or |
567 | * bottom display border. In this case it will simply be clipped by the | 518 | * bottom display border. In this case it will simply be clipped by the |
568 | * LCD controller. You can even set negative values, this will clip at the | 519 | * LCD controller. You can even set negative values, this will clip at the |
569 | * left or top border. I did not test it, but the limits may be +127 / -128 | 520 | * left or top border. I did not test it, but the limits may be +127 / -128 |
570 | * | 521 | * |
@@ -578,7 +529,7 @@ void gray_position_display(int x, int by) | |||
578 | 529 | ||
579 | graybuf->x = x; | 530 | graybuf->x = x; |
580 | graybuf->by = by; | 531 | graybuf->by = by; |
581 | 532 | ||
582 | if (graybuf->flags & GRAY_RUNNING) | 533 | if (graybuf->flags & GRAY_RUNNING) |
583 | graybuf->flags |= GRAY_DEFERRED_UPDATE; | 534 | graybuf->flags |= GRAY_DEFERRED_UPDATE; |
584 | } | 535 | } |
@@ -592,7 +543,7 @@ void gray_position_display(int x, int by) | |||
592 | * | 543 | * |
593 | * DO NOT call lcd_update() or any other api function that directly accesses | 544 | * DO NOT call lcd_update() or any other api function that directly accesses |
594 | * the lcd while the grayscale overlay is running! If you need to do | 545 | * the lcd while the grayscale overlay is running! If you need to do |
595 | * lcd_update() to update something outside the grayscale overlay area, use | 546 | * lcd_update() to update something outside the grayscale overlay area, use |
596 | * gray_deferred_update() instead. | 547 | * gray_deferred_update() instead. |
597 | * | 548 | * |
598 | * Other functions to avoid are: | 549 | * Other functions to avoid are: |
@@ -629,39 +580,6 @@ void gray_show_display(bool enable) | |||
629 | 580 | ||
630 | /** prototypes **/ | 581 | /** prototypes **/ |
631 | 582 | ||
632 | /* functions affecting the whole display */ | ||
633 | void gray_clear_display(void); | ||
634 | void gray_black_display(void); | ||
635 | void gray_deferred_update(void); | ||
636 | |||
637 | /* scrolling functions */ | ||
638 | void gray_scroll_left(int count, bool black_border); | ||
639 | void gray_scroll_right(int count, bool black_border); | ||
640 | void gray_scroll_up8(bool black_border); | ||
641 | void gray_scroll_down8(bool black_border); | ||
642 | void gray_scroll_up(int count, bool black_border); | ||
643 | void gray_scroll_down(int count, bool black_border); | ||
644 | |||
645 | /* pixel functions */ | ||
646 | void gray_drawpixel(int x, int y, int brightness); | ||
647 | void gray_invertpixel(int x, int y); | ||
648 | |||
649 | /* line functions */ | ||
650 | void gray_drawline(int x1, int y1, int x2, int y2, int brightness); | ||
651 | void gray_invertline(int x1, int y1, int x2, int y2); | ||
652 | |||
653 | /* rectangle functions */ | ||
654 | void gray_drawrect(int x1, int y1, int x2, int y2, int brightness); | ||
655 | void gray_fillrect(int x1, int y1, int x2, int y2, int brightness); | ||
656 | void gray_invertrect(int x1, int y1, int x2, int y2); | ||
657 | |||
658 | /* bitmap functions */ | ||
659 | void gray_drawgraymap(unsigned char *src, int x, int y, int nx, int ny, | ||
660 | int stride); | ||
661 | void gray_drawbitmap(unsigned char *src, int x, int y, int nx, int ny, | ||
662 | int stride, bool draw_bg, int fg_brightness, | ||
663 | int bg_brightness); | ||
664 | |||
665 | /** implementation **/ | 583 | /** implementation **/ |
666 | 584 | ||
667 | /* Clear the grayscale display (sets all pixels to white) | 585 | /* Clear the grayscale display (sets all pixels to white) |
@@ -685,7 +603,7 @@ void gray_black_display(void) | |||
685 | } | 603 | } |
686 | 604 | ||
687 | /* Do an lcd_update() to show changes done by rb->lcd_xxx() functions (in areas | 605 | /* Do an lcd_update() to show changes done by rb->lcd_xxx() functions (in areas |
688 | * of the screen not covered by the grayscale overlay). If the grayscale | 606 | * of the screen not covered by the grayscale overlay). If the grayscale |
689 | * overlay is running, the update will be done in the next call of the | 607 | * overlay is running, the update will be done in the next call of the |
690 | * interrupt routine, otherwise it will be performed right away. See also | 608 | * interrupt routine, otherwise it will be performed right away. See also |
691 | * comment for the gray_show_display() function. | 609 | * comment for the gray_show_display() function. |
@@ -701,7 +619,7 @@ void gray_deferred_update(void) | |||
701 | /* Scroll the whole grayscale buffer left by <count> pixels | 619 | /* Scroll the whole grayscale buffer left by <count> pixels |
702 | * | 620 | * |
703 | * black_border determines if the pixels scrolled in at the right are black | 621 | * black_border determines if the pixels scrolled in at the right are black |
704 | * or white | 622 | * or white |
705 | * | 623 | * |
706 | * Scrolling left/right by an even pixel count is almost twice as fast as | 624 | * Scrolling left/right by an even pixel count is almost twice as fast as |
707 | * scrolling by an odd pixel count. | 625 | * scrolling by an odd pixel count. |
@@ -714,7 +632,7 @@ void gray_scroll_left(int count, bool black_border) | |||
714 | 632 | ||
715 | if (graybuf == NULL || (unsigned) count >= (unsigned) graybuf->width) | 633 | if (graybuf == NULL || (unsigned) count >= (unsigned) graybuf->width) |
716 | return; | 634 | return; |
717 | 635 | ||
718 | if (black_border) | 636 | if (black_border) |
719 | filler = 0xFF; | 637 | filler = 0xFF; |
720 | else | 638 | else |
@@ -725,7 +643,7 @@ void gray_scroll_left(int count, bool black_border) | |||
725 | { | 643 | { |
726 | ptr = graybuf->data + MULU16(graybuf->width, by); | 644 | ptr = graybuf->data + MULU16(graybuf->width, by); |
727 | for (d = 0; d < graybuf->depth; d++) | 645 | for (d = 0; d < graybuf->depth; d++) |
728 | { | 646 | { |
729 | if (count & 1) /* odd count: scroll byte-wise */ | 647 | if (count & 1) /* odd count: scroll byte-wise */ |
730 | asm volatile ( | 648 | asm volatile ( |
731 | ".sl_loop1: \n" | 649 | ".sl_loop1: \n" |
@@ -843,7 +761,7 @@ void gray_scroll_up8(bool black_border) | |||
843 | 761 | ||
844 | if (graybuf == NULL) | 762 | if (graybuf == NULL) |
845 | return; | 763 | return; |
846 | 764 | ||
847 | if (black_border) | 765 | if (black_border) |
848 | filler = 0xFF; | 766 | filler = 0xFF; |
849 | else | 767 | else |
@@ -861,7 +779,7 @@ void gray_scroll_up8(bool black_border) | |||
861 | } | 779 | } |
862 | /* fill last row */ | 780 | /* fill last row */ |
863 | ptr = graybuf->data + graybuf->plane_size - graybuf->width; | 781 | ptr = graybuf->data + graybuf->plane_size - graybuf->width; |
864 | for (d = 0; d < graybuf->depth; d++) | 782 | for (d = 0; d < graybuf->depth; d++) |
865 | { | 783 | { |
866 | rb->memset(ptr, filler, graybuf->width); | 784 | rb->memset(ptr, filler, graybuf->width); |
867 | ptr += graybuf->plane_size; | 785 | ptr += graybuf->plane_size; |
@@ -883,7 +801,7 @@ void gray_scroll_down8(bool black_border) | |||
883 | 801 | ||
884 | if (graybuf == NULL) | 802 | if (graybuf == NULL) |
885 | return; | 803 | return; |
886 | 804 | ||
887 | if (black_border) | 805 | if (black_border) |
888 | filler = 0xFF; | 806 | filler = 0xFF; |
889 | else | 807 | else |
@@ -901,7 +819,7 @@ void gray_scroll_down8(bool black_border) | |||
901 | } | 819 | } |
902 | /* fill first row */ | 820 | /* fill first row */ |
903 | ptr = graybuf->data; | 821 | ptr = graybuf->data; |
904 | for (d = 0; d < graybuf->depth; d++) | 822 | for (d = 0; d < graybuf->depth; d++) |
905 | { | 823 | { |
906 | rb->memset(ptr, filler, graybuf->width); | 824 | rb->memset(ptr, filler, graybuf->width); |
907 | ptr += graybuf->plane_size; | 825 | ptr += graybuf->plane_size; |
@@ -928,7 +846,7 @@ void gray_scroll_up(int count, bool black_border) | |||
928 | filler = 0xFF; | 846 | filler = 0xFF; |
929 | else | 847 | else |
930 | filler = 0; | 848 | filler = 0; |
931 | 849 | ||
932 | /* scroll column by column to minimize flicker */ | 850 | /* scroll column by column to minimize flicker */ |
933 | asm( | 851 | asm( |
934 | "mov #0,r6 \n" /* x = 0 */ | 852 | "mov #0,r6 \n" /* x = 0 */ |
@@ -951,12 +869,12 @@ void gray_scroll_up(int count, bool black_border) | |||
951 | ".su_cloop: \n" /* repeat for every column */ | 869 | ".su_cloop: \n" /* repeat for every column */ |
952 | "mov %1,r2 \n" /* get start address */ | 870 | "mov %1,r2 \n" /* get start address */ |
953 | "mov #0,r3 \n" /* current_plane = 0 */ | 871 | "mov #0,r3 \n" /* current_plane = 0 */ |
954 | 872 | ||
955 | ".su_oloop: \n" /* repeat for every bitplane */ | 873 | ".su_oloop: \n" /* repeat for every bitplane */ |
956 | "mov r2,r4 \n" /* get start address */ | 874 | "mov r2,r4 \n" /* get start address */ |
957 | "mov #0,r5 \n" /* current_row = 0 */ | 875 | "mov #0,r5 \n" /* current_row = 0 */ |
958 | "mov %5,r1 \n" /* get filler bits */ | 876 | "mov %5,r1 \n" /* get filler bits */ |
959 | 877 | ||
960 | ".su_iloop: \n" /* repeat for all rows */ | 878 | ".su_iloop: \n" /* repeat for all rows */ |
961 | "sub %2,r4 \n" /* address -= width */ | 879 | "sub %2,r4 \n" /* address -= width */ |
962 | "mov.b @r4,r0 \n" /* get data byte */ | 880 | "mov.b @r4,r0 \n" /* get data byte */ |
@@ -965,7 +883,7 @@ void gray_scroll_up(int count, bool black_border) | |||
965 | "or r1,r0 \n" /* combine old data */ | 883 | "or r1,r0 \n" /* combine old data */ |
966 | "jmp @%6 \n" /* jump into shift "path" */ | 884 | "jmp @%6 \n" /* jump into shift "path" */ |
967 | "extu.b r0,r1 \n" /* store data for next round */ | 885 | "extu.b r0,r1 \n" /* store data for next round */ |
968 | 886 | ||
969 | ".su_shift6: \n" /* shift right by 0..7 bits */ | 887 | ".su_shift6: \n" /* shift right by 0..7 bits */ |
970 | "shlr2 r0 \n" | 888 | "shlr2 r0 \n" |
971 | ".su_shift4: \n" | 889 | ".su_shift4: \n" |
@@ -1031,7 +949,7 @@ void gray_scroll_down(int count, bool black_border) | |||
1031 | filler = 0xFF << count; /* calculate filler bits */ | 949 | filler = 0xFF << count; /* calculate filler bits */ |
1032 | else | 950 | else |
1033 | filler = 0; | 951 | filler = 0; |
1034 | 952 | ||
1035 | /* scroll column by column to minimize flicker */ | 953 | /* scroll column by column to minimize flicker */ |
1036 | asm( | 954 | asm( |
1037 | "mov #0,r6 \n" /* x = 0 */ | 955 | "mov #0,r6 \n" /* x = 0 */ |
@@ -1039,7 +957,7 @@ void gray_scroll_down(int count, bool black_border) | |||
1039 | "mov.b @(r0,%6),%6 \n" /* shift amount from table */ | 957 | "mov.b @(r0,%6),%6 \n" /* shift amount from table */ |
1040 | "bra .sd_cloop \n" /* skip table */ | 958 | "bra .sd_cloop \n" /* skip table */ |
1041 | "add r0,%6 \n" | 959 | "add r0,%6 \n" |
1042 | 960 | ||
1043 | ".align 2 \n" | 961 | ".align 2 \n" |
1044 | ".sd_shifttbl: \n" /* shift jump offset table */ | 962 | ".sd_shifttbl: \n" /* shift jump offset table */ |
1045 | ".byte .sd_shift0 - .sd_shifttbl \n" | 963 | ".byte .sd_shift0 - .sd_shifttbl \n" |
@@ -1054,18 +972,18 @@ void gray_scroll_down(int count, bool black_border) | |||
1054 | ".sd_cloop: \n" /* repeat for every column */ | 972 | ".sd_cloop: \n" /* repeat for every column */ |
1055 | "mov %1,r2 \n" /* get start address */ | 973 | "mov %1,r2 \n" /* get start address */ |
1056 | "mov #0,r3 \n" /* current_plane = 0 */ | 974 | "mov #0,r3 \n" /* current_plane = 0 */ |
1057 | 975 | ||
1058 | ".sd_oloop: \n" /* repeat for every bitplane */ | 976 | ".sd_oloop: \n" /* repeat for every bitplane */ |
1059 | "mov r2,r4 \n" /* get start address */ | 977 | "mov r2,r4 \n" /* get start address */ |
1060 | "mov #0,r5 \n" /* current_row = 0 */ | 978 | "mov #0,r5 \n" /* current_row = 0 */ |
1061 | "mov %5,r1 \n" /* get filler bits */ | 979 | "mov %5,r1 \n" /* get filler bits */ |
1062 | 980 | ||
1063 | ".sd_iloop: \n" /* repeat for all rows */ | 981 | ".sd_iloop: \n" /* repeat for all rows */ |
1064 | "shlr8 r1 \n" /* shift right to get residue */ | 982 | "shlr8 r1 \n" /* shift right to get residue */ |
1065 | "mov.b @r4,r0 \n" /* get data byte */ | 983 | "mov.b @r4,r0 \n" /* get data byte */ |
1066 | "jmp @%6 \n" /* jump into shift "path" */ | 984 | "jmp @%6 \n" /* jump into shift "path" */ |
1067 | "extu.b r0,r0 \n" /* extend unsigned */ | 985 | "extu.b r0,r0 \n" /* extend unsigned */ |
1068 | 986 | ||
1069 | ".sd_shift6: \n" /* shift left by 0..7 bits */ | 987 | ".sd_shift6: \n" /* shift left by 0..7 bits */ |
1070 | "shll2 r0 \n" | 988 | "shll2 r0 \n" |
1071 | ".sd_shift4: \n" | 989 | ".sd_shift4: \n" |
@@ -1119,7 +1037,7 @@ void gray_scroll_down(int count, bool black_border) | |||
1119 | */ | 1037 | */ |
1120 | void gray_drawpixel(int x, int y, int brightness) | 1038 | void gray_drawpixel(int x, int y, int brightness) |
1121 | { | 1039 | { |
1122 | if (graybuf == NULL | 1040 | if (graybuf == NULL |
1123 | || (unsigned) x >= (unsigned) graybuf->width | 1041 | || (unsigned) x >= (unsigned) graybuf->width |
1124 | || (unsigned) y >= (unsigned) graybuf->height | 1042 | || (unsigned) y >= (unsigned) graybuf->height |
1125 | || (unsigned) brightness > 255) | 1043 | || (unsigned) brightness > 255) |
@@ -1136,7 +1054,7 @@ void gray_drawpixel(int x, int y, int brightness) | |||
1136 | */ | 1054 | */ |
1137 | void gray_invertpixel(int x, int y) | 1055 | void gray_invertpixel(int x, int y) |
1138 | { | 1056 | { |
1139 | if (graybuf == NULL | 1057 | if (graybuf == NULL |
1140 | || (unsigned) x >= (unsigned) graybuf->width | 1058 | || (unsigned) x >= (unsigned) graybuf->width |
1141 | || (unsigned) y >= (unsigned) graybuf->height) | 1059 | || (unsigned) y >= (unsigned) graybuf->height) |
1142 | return; | 1060 | return; |
@@ -1158,7 +1076,7 @@ void gray_drawline(int x1, int y1, int x2, int y2, int brightness) | |||
1158 | int y, yinc1, yinc2; | 1076 | int y, yinc1, yinc2; |
1159 | unsigned long pattern; | 1077 | unsigned long pattern; |
1160 | 1078 | ||
1161 | if (graybuf == NULL | 1079 | if (graybuf == NULL |
1162 | || (unsigned) x1 >= (unsigned) graybuf->width | 1080 | || (unsigned) x1 >= (unsigned) graybuf->width |
1163 | || (unsigned) y1 >= (unsigned) graybuf->height | 1081 | || (unsigned) y1 >= (unsigned) graybuf->height |
1164 | || (unsigned) x2 >= (unsigned) graybuf->width | 1082 | || (unsigned) x2 >= (unsigned) graybuf->width |
@@ -1241,7 +1159,7 @@ void gray_invertline(int x1, int y1, int x2, int y2) | |||
1241 | int x, xinc1, xinc2; | 1159 | int x, xinc1, xinc2; |
1242 | int y, yinc1, yinc2; | 1160 | int y, yinc1, yinc2; |
1243 | 1161 | ||
1244 | if (graybuf == NULL | 1162 | if (graybuf == NULL |
1245 | || (unsigned) x1 >= (unsigned) graybuf->width | 1163 | || (unsigned) x1 >= (unsigned) graybuf->width |
1246 | || (unsigned) y1 >= (unsigned) graybuf->height | 1164 | || (unsigned) y1 >= (unsigned) graybuf->height |
1247 | || (unsigned) x2 >= (unsigned) graybuf->width | 1165 | || (unsigned) x2 >= (unsigned) graybuf->width |
@@ -1318,7 +1236,7 @@ void gray_drawrect(int x1, int y1, int x2, int y2, int brightness) | |||
1318 | unsigned long pattern; | 1236 | unsigned long pattern; |
1319 | unsigned char srcpixel; | 1237 | unsigned char srcpixel; |
1320 | 1238 | ||
1321 | if (graybuf == NULL | 1239 | if (graybuf == NULL |
1322 | || (unsigned) x1 >= (unsigned) graybuf->width | 1240 | || (unsigned) x1 >= (unsigned) graybuf->width |
1323 | || (unsigned) y1 >= (unsigned) graybuf->height | 1241 | || (unsigned) y1 >= (unsigned) graybuf->height |
1324 | || (unsigned) x2 >= (unsigned) graybuf->width | 1242 | || (unsigned) x2 >= (unsigned) graybuf->width |
@@ -1335,7 +1253,7 @@ void gray_drawrect(int x1, int y1, int x2, int y2, int brightness) | |||
1335 | if (x1 > x2) | 1253 | if (x1 > x2) |
1336 | { | 1254 | { |
1337 | x = x1; | 1255 | x = x1; |
1338 | x1 = x2; | 1256 | x1 = x2; |
1339 | x2 = x; | 1257 | x2 = x; |
1340 | } | 1258 | } |
1341 | 1259 | ||
@@ -1366,7 +1284,7 @@ void gray_drawrect(int x1, int y1, int x2, int y2, int brightness) | |||
1366 | } | 1284 | } |
1367 | } | 1285 | } |
1368 | 1286 | ||
1369 | /* Fill a rectangle with a specific gray value | 1287 | /* Fill a rectangle with a specific gray value |
1370 | * corners are (x1, y1) and (x2, y2) | 1288 | * corners are (x1, y1) and (x2, y2) |
1371 | * | 1289 | * |
1372 | * brightness is 0..255 (black to white) regardless of real bit depth | 1290 | * brightness is 0..255 (black to white) regardless of real bit depth |
@@ -1377,14 +1295,14 @@ void gray_fillrect(int x1, int y1, int x2, int y2, int brightness) | |||
1377 | unsigned long pattern; | 1295 | unsigned long pattern; |
1378 | unsigned char srcpixel; | 1296 | unsigned char srcpixel; |
1379 | 1297 | ||
1380 | if (graybuf == NULL | 1298 | if (graybuf == NULL |
1381 | || (unsigned) x1 >= (unsigned) graybuf->width | 1299 | || (unsigned) x1 >= (unsigned) graybuf->width |
1382 | || (unsigned) y1 >= (unsigned) graybuf->height | 1300 | || (unsigned) y1 >= (unsigned) graybuf->height |
1383 | || (unsigned) x2 >= (unsigned) graybuf->width | 1301 | || (unsigned) x2 >= (unsigned) graybuf->width |
1384 | || (unsigned) y2 >= (unsigned) graybuf->height | 1302 | || (unsigned) y2 >= (unsigned) graybuf->height |
1385 | || (unsigned) brightness > 255) | 1303 | || (unsigned) brightness > 255) |
1386 | return; | 1304 | return; |
1387 | 1305 | ||
1388 | if (y1 > y2) | 1306 | if (y1 > y2) |
1389 | { | 1307 | { |
1390 | y = y1; | 1308 | y = y1; |
@@ -1394,7 +1312,7 @@ void gray_fillrect(int x1, int y1, int x2, int y2, int brightness) | |||
1394 | if (x1 > x2) | 1312 | if (x1 > x2) |
1395 | { | 1313 | { |
1396 | x = x1; | 1314 | x = x1; |
1397 | x1 = x2; | 1315 | x1 = x2; |
1398 | x2 = x; | 1316 | x2 = x; |
1399 | } | 1317 | } |
1400 | 1318 | ||
@@ -1435,7 +1353,7 @@ void gray_invertrect(int x1, int y1, int x2, int y2) | |||
1435 | int x, yb, yb1, yb2; | 1353 | int x, yb, yb1, yb2; |
1436 | unsigned char mask; | 1354 | unsigned char mask; |
1437 | 1355 | ||
1438 | if (graybuf == NULL | 1356 | if (graybuf == NULL |
1439 | || (unsigned) x1 >= (unsigned) graybuf->width | 1357 | || (unsigned) x1 >= (unsigned) graybuf->width |
1440 | || (unsigned) y1 >= (unsigned) graybuf->height | 1358 | || (unsigned) y1 >= (unsigned) graybuf->height |
1441 | || (unsigned) x2 >= (unsigned) graybuf->width | 1359 | || (unsigned) x2 >= (unsigned) graybuf->width |
@@ -1451,10 +1369,10 @@ void gray_invertrect(int x1, int y1, int x2, int y2) | |||
1451 | if (x1 > x2) | 1369 | if (x1 > x2) |
1452 | { | 1370 | { |
1453 | x = x1; | 1371 | x = x1; |
1454 | x1 = x2; | 1372 | x1 = x2; |
1455 | x2 = x; | 1373 | x2 = x; |
1456 | } | 1374 | } |
1457 | 1375 | ||
1458 | yb1 = y1 >> 3; | 1376 | yb1 = y1 >> 3; |
1459 | yb2 = y2 >> 3; | 1377 | yb2 = y2 >> 3; |
1460 | 1378 | ||
@@ -1472,13 +1390,13 @@ void gray_invertrect(int x1, int y1, int x2, int y2) | |||
1472 | 1390 | ||
1473 | for (x = x1; x <= x2; x++) | 1391 | for (x = x1; x <= x2; x++) |
1474 | grayinvertmasked(x, yb1, mask); | 1392 | grayinvertmasked(x, yb1, mask); |
1475 | 1393 | ||
1476 | for (yb = yb1 + 1; yb < yb2; yb++) | 1394 | for (yb = yb1 + 1; yb < yb2; yb++) |
1477 | { | 1395 | { |
1478 | for (x = x1; x <= x2; x++) | 1396 | for (x = x1; x <= x2; x++) |
1479 | grayinvertmasked(x, yb, 0xFF); | 1397 | grayinvertmasked(x, yb, 0xFF); |
1480 | } | 1398 | } |
1481 | 1399 | ||
1482 | mask = 0xFF >> (7 - (y2 & 7)); | 1400 | mask = 0xFF >> (7 - (y2 & 7)); |
1483 | 1401 | ||
1484 | for (x = x1; x <= x2; x++) | 1402 | for (x = x1; x <= x2; x++) |
@@ -1487,7 +1405,7 @@ void gray_invertrect(int x1, int y1, int x2, int y2) | |||
1487 | } | 1405 | } |
1488 | 1406 | ||
1489 | /* Copy a grayscale bitmap into the display | 1407 | /* Copy a grayscale bitmap into the display |
1490 | * | 1408 | * |
1491 | * A grayscale bitmap contains one byte for every pixel that defines the | 1409 | * A grayscale bitmap contains one byte for every pixel that defines the |
1492 | * brightness of the pixel (0..255). Bytes are read in row-major order. | 1410 | * brightness of the pixel (0..255). Bytes are read in row-major order. |
1493 | * The <stride> parameter is useful if you want to show only a part of a | 1411 | * The <stride> parameter is useful if you want to show only a part of a |
@@ -1500,11 +1418,11 @@ void gray_drawgraymap(unsigned char *src, int x, int y, int nx, int ny, | |||
1500 | int xi, yi; | 1418 | int xi, yi; |
1501 | unsigned char *row; | 1419 | unsigned char *row; |
1502 | 1420 | ||
1503 | if (graybuf == NULL | 1421 | if (graybuf == NULL |
1504 | || (unsigned) x >= (unsigned) graybuf->width | 1422 | || (unsigned) x >= (unsigned) graybuf->width |
1505 | || (unsigned) y >= (unsigned) graybuf->height) | 1423 | || (unsigned) y >= (unsigned) graybuf->height) |
1506 | return; | 1424 | return; |
1507 | 1425 | ||
1508 | if ((y + ny) >= graybuf->height) /* clip bottom */ | 1426 | if ((y + ny) >= graybuf->height) /* clip bottom */ |
1509 | ny = graybuf->height - y; | 1427 | ny = graybuf->height - y; |
1510 | 1428 | ||
@@ -1610,6 +1528,11 @@ void gray_drawbitmap(unsigned char *src, int x, int y, int nx, int ny, | |||
1610 | 1528 | ||
1611 | /*********************** end grayscale framework ***************************/ | 1529 | /*********************** end grayscale framework ***************************/ |
1612 | 1530 | ||
1531 | #ifdef GRAYSCALE_PLUGIN | ||
1532 | static char pbuf[32]; /* global printf buffer */ | ||
1533 | static unsigned char *gbuf; | ||
1534 | static unsigned int gbuf_size = 0; | ||
1535 | |||
1613 | /**************************** main function ********************************/ | 1536 | /**************************** main function ********************************/ |
1614 | 1537 | ||
1615 | /* this is only a demo of what the framework can do */ | 1538 | /* this is only a demo of what the framework can do */ |
@@ -1636,7 +1559,7 @@ int main(void) | |||
1636 | 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08, | 1559 | 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08, |
1637 | 0x14, 0x22, 0x00 | 1560 | 0x14, 0x22, 0x00 |
1638 | }; | 1561 | }; |
1639 | 1562 | ||
1640 | static unsigned char showing[] = { | 1563 | static unsigned char showing[] = { |
1641 | /* ....................................... | 1564 | /* ....................................... |
1642 | * ..####.#...#..###..#...#.#.#...#..####. | 1565 | * ..####.#...#..###..#...#.#.#...#..####. |
@@ -1652,7 +1575,7 @@ int main(void) | |||
1652 | 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08, | 1575 | 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08, |
1653 | 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00 | 1576 | 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00 |
1654 | }; | 1577 | }; |
1655 | 1578 | ||
1656 | static unsigned char grayscale_gray[] = { | 1579 | static unsigned char grayscale_gray[] = { |
1657 | /* ....................................................... | 1580 | /* ....................................................... |
1658 | * ..####.####...###..#...#..####..###...###..#.....#####. | 1581 | * ..####.####...###..#...#..####..###...###..#.....#####. |
@@ -1732,7 +1655,7 @@ int main(void) | |||
1732 | gray_drawrect(0, 0, 111, 55, 0); /* black border */ | 1655 | gray_drawrect(0, 0, 111, 55, 0); /* black border */ |
1733 | 1656 | ||
1734 | /* draw gray tones */ | 1657 | /* draw gray tones */ |
1735 | for (i = 0; i < 86; i++) | 1658 | for (i = 0; i < 86; i++) |
1736 | { | 1659 | { |
1737 | x = 13 + i; | 1660 | x = 13 + i; |
1738 | gray_fillrect(x, 6, x, 49, 3 * i); /* gray rectangles */ | 1661 | gray_fillrect(x, 6, x, 49, 3 * i); /* gray rectangles */ |
@@ -1740,7 +1663,7 @@ int main(void) | |||
1740 | 1663 | ||
1741 | gray_invertrect(13, 29, 98, 49); /* invert rectangle (lower half) */ | 1664 | gray_invertrect(13, 29, 98, 49); /* invert rectangle (lower half) */ |
1742 | gray_invertline(13, 27, 98, 27); /* invert a line */ | 1665 | gray_invertline(13, 27, 98, 27); /* invert a line */ |
1743 | 1666 | ||
1744 | /* show bitmaps (1 bit and 8 bit) */ | 1667 | /* show bitmaps (1 bit and 8 bit) */ |
1745 | gray_drawbitmap(rockbox, 14, 13, 43, 7, 43, true, 255, 100); /* opaque */ | 1668 | gray_drawbitmap(rockbox, 14, 13, 43, 7, 43, true, 255, 100); /* opaque */ |
1746 | gray_drawbitmap(showing, 58, 13, 39, 7, 39, false, 0, 0); /* transparent */ | 1669 | gray_drawbitmap(showing, 58, 13, 39, 7, 39, false, 0, 0); /* transparent */ |
@@ -1753,7 +1676,7 @@ int main(void) | |||
1753 | rb->lcd_puts(0, 0, pbuf); | 1676 | rb->lcd_puts(0, 0, pbuf); |
1754 | gray_deferred_update(); /* schedule an lcd_update() */ | 1677 | gray_deferred_update(); /* schedule an lcd_update() */ |
1755 | 1678 | ||
1756 | /* drawing is now finished, play around with scrolling | 1679 | /* drawing is now finished, play around with scrolling |
1757 | * until you press OFF or connect USB | 1680 | * until you press OFF or connect USB |
1758 | */ | 1681 | */ |
1759 | while (true) | 1682 | while (true) |
@@ -1773,7 +1696,7 @@ int main(void) | |||
1773 | 1696 | ||
1774 | if (button & BUTTON_ON) | 1697 | if (button & BUTTON_ON) |
1775 | black_border = true; | 1698 | black_border = true; |
1776 | 1699 | ||
1777 | if (button & BUTTON_REPEAT) | 1700 | if (button & BUTTON_REPEAT) |
1778 | scroll_amount = 4; | 1701 | scroll_amount = 4; |
1779 | 1702 | ||
@@ -1810,7 +1733,6 @@ int main(void) | |||
1810 | } | 1733 | } |
1811 | 1734 | ||
1812 | /*************************** Plugin entry point ****************************/ | 1735 | /*************************** Plugin entry point ****************************/ |
1813 | |||
1814 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | 1736 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
1815 | { | 1737 | { |
1816 | int ret; | 1738 | int ret; |
@@ -1821,13 +1743,14 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
1821 | 1743 | ||
1822 | rb = api; // copy to global api pointer | 1744 | rb = api; // copy to global api pointer |
1823 | (void)parameter; | 1745 | (void)parameter; |
1824 | 1746 | ||
1825 | ret = main(); | 1747 | ret = main(); |
1826 | 1748 | ||
1827 | if (ret == PLUGIN_USB_CONNECTED) | 1749 | if (ret == PLUGIN_USB_CONNECTED) |
1828 | rb->usb_screen(); | 1750 | rb->usb_screen(); |
1829 | return ret; | 1751 | return ret; |
1830 | } | 1752 | } |
1753 | #endif /* GRAYSCALE_PLUGIN */ | ||
1831 | 1754 | ||
1832 | #endif // #ifdef HAVE_LCD_BITMAP | 1755 | #endif // #ifdef HAVE_LCD_BITMAP |
1833 | #endif // #ifndef SIMULATOR | 1756 | #endif // #ifndef SIMULATOR |