diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/mpegplayer/mpegplayer.c | 174 | ||||
-rw-r--r-- | apps/plugins/rockpaint.c | 182 |
2 files changed, 352 insertions, 4 deletions
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c index 2361ba0fbd..22136d8393 100644 --- a/apps/plugins/mpegplayer/mpegplayer.c +++ b/apps/plugins/mpegplayer/mpegplayer.c | |||
@@ -663,6 +663,172 @@ static void draw_oriented_mono_bitmap_part(const unsigned char *src, | |||
663 | while (src < src_end); | 663 | while (src < src_end); |
664 | } | 664 | } |
665 | 665 | ||
666 | /* draw alpha bitmap for anti-alias font */ | ||
667 | #define ALPHA_COLOR_FONT_DEPTH 2 | ||
668 | #define ALPHA_COLOR_LOOKUP_SHIFT (1 << ALPHA_COLOR_FONT_DEPTH) | ||
669 | #define ALPHA_COLOR_LOOKUP_SIZE ((1 << ALPHA_COLOR_LOOKUP_SHIFT) - 1) | ||
670 | #define ALPHA_COLOR_PIXEL_PER_BYTE (8 >> ALPHA_COLOR_FONT_DEPTH) | ||
671 | #define ALPHA_COLOR_PIXEL_PER_WORD (32 >> ALPHA_COLOR_FONT_DEPTH) | ||
672 | #ifdef CPU_ARM | ||
673 | #define BLEND_INIT do {} while (0) | ||
674 | #define BLEND_START(acc, color, alpha) \ | ||
675 | asm volatile("mul %0, %1, %2" : "=&r" (acc) : "r" (color), "r" (alpha)) | ||
676 | #define BLEND_CONT(acc, color, alpha) \ | ||
677 | asm volatile("mla %0, %1, %2, %0" : "+&r" (acc) : "r" (color), "r" (alpha)) | ||
678 | #define BLEND_OUT(acc) do {} while (0) | ||
679 | #elif defined(CPU_COLDFIRE) | ||
680 | #define ALPHA_BITMAP_READ_WORDS | ||
681 | #define BLEND_INIT coldfire_set_macsr(EMAC_UNSIGNED) | ||
682 | #define BLEND_START(acc, color, alpha) \ | ||
683 | asm volatile("mac.l %0, %1, %%acc0" :: "%d" (color), "d" (alpha)) | ||
684 | #define BLEND_CONT BLEND_START | ||
685 | #define BLEND_OUT(acc) asm volatile("movclr.l %%acc0, %0" : "=d" (acc)) | ||
686 | #else | ||
687 | #define BLEND_INIT do {} while (0) | ||
688 | #define BLEND_START(acc, color, alpha) ((acc) = (color) * (alpha)) | ||
689 | #define BLEND_CONT(acc, color, alpha) ((acc) += (color) * (alpha)) | ||
690 | #define BLEND_OUT(acc) do {} while (0) | ||
691 | #endif | ||
692 | |||
693 | /* Blend the given two colors */ | ||
694 | static inline unsigned blend_two_colors(unsigned c1, unsigned c2, unsigned a) | ||
695 | { | ||
696 | a += a >> (ALPHA_COLOR_LOOKUP_SHIFT - 1); | ||
697 | #if (LCD_PIXELFORMAT == RGB565SWAPPED) | ||
698 | c1 = swap16(c1); | ||
699 | c2 = swap16(c2); | ||
700 | #endif | ||
701 | unsigned c1l = (c1 | (c1 << 16)) & 0x07e0f81f; | ||
702 | unsigned c2l = (c2 | (c2 << 16)) & 0x07e0f81f; | ||
703 | unsigned p; | ||
704 | BLEND_START(p, c1l, a); | ||
705 | BLEND_CONT(p, c2l, ALPHA_COLOR_LOOKUP_SIZE + 1 - a); | ||
706 | BLEND_OUT(p); | ||
707 | p = (p >> ALPHA_COLOR_LOOKUP_SHIFT) & 0x07e0f81f; | ||
708 | p |= (p >> 16); | ||
709 | #if (LCD_PIXELFORMAT == RGB565SWAPPED) | ||
710 | return swap16(p); | ||
711 | #else | ||
712 | return p; | ||
713 | #endif | ||
714 | } | ||
715 | |||
716 | static void draw_oriented_alpha_bitmap_part(const unsigned char *src, | ||
717 | int src_x, int src_y, | ||
718 | int stride, int x, int y, | ||
719 | int width, int height) | ||
720 | { | ||
721 | fb_data *dst, *dst_start; | ||
722 | unsigned fg_pattern, bg_pattern; | ||
723 | |||
724 | if (x + width > SCREEN_WIDTH) | ||
725 | width = SCREEN_WIDTH - x; /* Clip right */ | ||
726 | if (x < 0) | ||
727 | width += x, x = 0; /* Clip left */ | ||
728 | if (width <= 0) | ||
729 | return; /* nothing left to do */ | ||
730 | |||
731 | if (y + height > SCREEN_HEIGHT) | ||
732 | height = SCREEN_HEIGHT - y; /* Clip bottom */ | ||
733 | if (y < 0) | ||
734 | height += y, y = 0; /* Clip top */ | ||
735 | if (height <= 0) | ||
736 | return; /* nothing left to do */ | ||
737 | |||
738 | /* initialize blending */ | ||
739 | BLEND_INIT; | ||
740 | |||
741 | fg_pattern = rb->lcd_get_foreground(); | ||
742 | bg_pattern = rb->lcd_get_background(); | ||
743 | |||
744 | dst_start = rb->lcd_framebuffer + (LCD_WIDTH - y - 1) + x*LCD_WIDTH; | ||
745 | int col, row = height; | ||
746 | unsigned data, pixels; | ||
747 | unsigned skip_end = (stride - width); | ||
748 | unsigned skip_start = src_y * stride + src_x; | ||
749 | |||
750 | #ifdef ALPHA_BITMAP_READ_WORDS | ||
751 | uint32_t *src_w = (uint32_t *)((uintptr_t)src & ~3); | ||
752 | skip_start += ALPHA_COLOR_PIXEL_PER_BYTE * ((uintptr_t)src & 3); | ||
753 | src_w += skip_start / ALPHA_COLOR_PIXEL_PER_WORD; | ||
754 | data = letoh32(*src_w++); | ||
755 | #else | ||
756 | src += skip_start / ALPHA_COLOR_PIXEL_PER_BYTE; | ||
757 | data = *src; | ||
758 | #endif | ||
759 | pixels = skip_start % ALPHA_COLOR_PIXEL_PER_WORD; | ||
760 | data >>= pixels * ALPHA_COLOR_LOOKUP_SHIFT; | ||
761 | #ifdef ALPHA_BITMAP_READ_WORDS | ||
762 | pixels = 8 - pixels; | ||
763 | #endif | ||
764 | |||
765 | do | ||
766 | { | ||
767 | col = width; | ||
768 | dst = dst_start--; | ||
769 | #ifdef ALPHA_BITMAP_READ_WORDS | ||
770 | #define UPDATE_SRC_ALPHA do { \ | ||
771 | if (--pixels) \ | ||
772 | data >>= ALPHA_COLOR_LOOKUP_SHIFT; \ | ||
773 | else \ | ||
774 | { \ | ||
775 | data = letoh32(*src_w++); \ | ||
776 | pixels = ALPHA_COLOR_PIXEL_PER_WORD; \ | ||
777 | } \ | ||
778 | } while (0) | ||
779 | #elif ALPHA_COLOR_PIXEL_PER_BYTE == 2 | ||
780 | #define UPDATE_SRC_ALPHA do { \ | ||
781 | if (pixels ^= 1) \ | ||
782 | data >>= ALPHA_COLOR_LOOKUP_SHIFT; \ | ||
783 | else \ | ||
784 | data = *(++src); \ | ||
785 | } while (0) | ||
786 | #else | ||
787 | #define UPDATE_SRC_ALPHA do { \ | ||
788 | if (pixels = (++pixels % ALPHA_COLOR_PIXEL_PER_BYTE)) \ | ||
789 | data >>= ALPHA_COLOR_LOOKUP_SHIFT; \ | ||
790 | else \ | ||
791 | data = *(++src); \ | ||
792 | } while (0) | ||
793 | #endif | ||
794 | do | ||
795 | { | ||
796 | *dst=blend_two_colors(*dst, fg_pattern, | ||
797 | data & ALPHA_COLOR_LOOKUP_SIZE ); | ||
798 | dst += LCD_WIDTH; | ||
799 | UPDATE_SRC_ALPHA; | ||
800 | } | ||
801 | while (--col); | ||
802 | #ifdef ALPHA_BITMAP_READ_WORDS | ||
803 | if (skip_end < pixels) | ||
804 | { | ||
805 | pixels -= skip_end; | ||
806 | data >>= skip_end * ALPHA_COLOR_LOOKUP_SHIFT; | ||
807 | } else { | ||
808 | pixels = skip_end - pixels; | ||
809 | src_w += pixels / ALPHA_COLOR_PIXEL_PER_WORD; | ||
810 | pixels %= ALPHA_COLOR_PIXEL_PER_WORD; | ||
811 | data = letoh32(*src_w++); | ||
812 | data >>= pixels * ALPHA_COLOR_LOOKUP_SHIFT; | ||
813 | pixels = 8 - pixels; | ||
814 | } | ||
815 | #else | ||
816 | if (skip_end) | ||
817 | { | ||
818 | pixels += skip_end; | ||
819 | if (pixels >= ALPHA_COLOR_PIXEL_PER_BYTE) | ||
820 | { | ||
821 | src += pixels / ALPHA_COLOR_PIXEL_PER_BYTE; | ||
822 | pixels %= ALPHA_COLOR_PIXEL_PER_BYTE; | ||
823 | data = *src; | ||
824 | data >>= pixels * ALPHA_COLOR_LOOKUP_SHIFT; | ||
825 | } else | ||
826 | data >>= skip_end * ALPHA_COLOR_LOOKUP_SHIFT; | ||
827 | } | ||
828 | #endif | ||
829 | } while (--row); | ||
830 | } | ||
831 | |||
666 | static void draw_putsxy_oriented(int x, int y, const char *str) | 832 | static void draw_putsxy_oriented(int x, int y, const char *str) |
667 | { | 833 | { |
668 | unsigned short ch; | 834 | unsigned short ch; |
@@ -690,8 +856,12 @@ static void draw_putsxy_oriented(int x, int y, const char *str) | |||
690 | 856 | ||
691 | bits = rb->font_get_bits(pf, ch); | 857 | bits = rb->font_get_bits(pf, ch); |
692 | 858 | ||
693 | draw_oriented_mono_bitmap_part(bits, ofs, 0, width, x, y, | 859 | if (pf->depth) |
694 | width - ofs, pf->height); | 860 | draw_oriented_alpha_bitmap_part(bits, ofs, 0, width, x, y, |
861 | width - ofs, pf->height); | ||
862 | else | ||
863 | draw_oriented_mono_bitmap_part(bits, ofs, 0, width, x, y, | ||
864 | width - ofs, pf->height); | ||
695 | 865 | ||
696 | x += width - ofs; | 866 | x += width - ofs; |
697 | ofs = 0; | 867 | ofs = 0; |
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c index 0acbe41aaf..1fef0e9f5f 100644 --- a/apps/plugins/rockpaint.c +++ b/apps/plugins/rockpaint.c | |||
@@ -562,6 +562,180 @@ static void buffer_mono_bitmap_part( | |||
562 | } while( src < src_end ); | 562 | } while( src < src_end ); |
563 | } | 563 | } |
564 | 564 | ||
565 | /* draw alpha bitmap for anti-alias font */ | ||
566 | #define ALPHA_COLOR_FONT_DEPTH 2 | ||
567 | #define ALPHA_COLOR_LOOKUP_SHIFT (1 << ALPHA_COLOR_FONT_DEPTH) | ||
568 | #define ALPHA_COLOR_LOOKUP_SIZE ((1 << ALPHA_COLOR_LOOKUP_SHIFT) - 1) | ||
569 | #define ALPHA_COLOR_PIXEL_PER_BYTE (8 >> ALPHA_COLOR_FONT_DEPTH) | ||
570 | #define ALPHA_COLOR_PIXEL_PER_WORD (32 >> ALPHA_COLOR_FONT_DEPTH) | ||
571 | #ifdef CPU_ARM | ||
572 | #define BLEND_INIT do {} while (0) | ||
573 | #define BLEND_START(acc, color, alpha) \ | ||
574 | asm volatile("mul %0, %1, %2" : "=&r" (acc) : "r" (color), "r" (alpha)) | ||
575 | #define BLEND_CONT(acc, color, alpha) \ | ||
576 | asm volatile("mla %0, %1, %2, %0" : "+&r" (acc) : "r" (color), "r" (alpha)) | ||
577 | #define BLEND_OUT(acc) do {} while (0) | ||
578 | #elif defined(CPU_COLDFIRE) | ||
579 | #define ALPHA_BITMAP_READ_WORDS | ||
580 | #define BLEND_INIT coldfire_set_macsr(EMAC_UNSIGNED) | ||
581 | #define BLEND_START(acc, color, alpha) \ | ||
582 | asm volatile("mac.l %0, %1, %%acc0" :: "%d" (color), "d" (alpha)) | ||
583 | #define BLEND_CONT BLEND_START | ||
584 | #define BLEND_OUT(acc) asm volatile("movclr.l %%acc0, %0" : "=d" (acc)) | ||
585 | #else | ||
586 | #define BLEND_INIT do {} while (0) | ||
587 | #define BLEND_START(acc, color, alpha) ((acc) = (color) * (alpha)) | ||
588 | #define BLEND_CONT(acc, color, alpha) ((acc) += (color) * (alpha)) | ||
589 | #define BLEND_OUT(acc) do {} while (0) | ||
590 | #endif | ||
591 | |||
592 | /* Blend the given two colors */ | ||
593 | static inline unsigned blend_two_colors(unsigned c1, unsigned c2, unsigned a) | ||
594 | { | ||
595 | a += a >> (ALPHA_COLOR_LOOKUP_SHIFT - 1); | ||
596 | #if (LCD_PIXELFORMAT == RGB565SWAPPED) | ||
597 | c1 = swap16(c1); | ||
598 | c2 = swap16(c2); | ||
599 | #endif | ||
600 | unsigned c1l = (c1 | (c1 << 16)) & 0x07e0f81f; | ||
601 | unsigned c2l = (c2 | (c2 << 16)) & 0x07e0f81f; | ||
602 | unsigned p; | ||
603 | BLEND_START(p, c1l, a); | ||
604 | BLEND_CONT(p, c2l, ALPHA_COLOR_LOOKUP_SIZE + 1 - a); | ||
605 | BLEND_OUT(p); | ||
606 | p = (p >> ALPHA_COLOR_LOOKUP_SHIFT) & 0x07e0f81f; | ||
607 | p |= (p >> 16); | ||
608 | #if (LCD_PIXELFORMAT == RGB565SWAPPED) | ||
609 | return swap16(p); | ||
610 | #else | ||
611 | return p; | ||
612 | #endif | ||
613 | } | ||
614 | |||
615 | static void buffer_alpha_bitmap_part( | ||
616 | fb_data *buf, int buf_width, int buf_height, | ||
617 | const unsigned char *src, int src_x, int src_y, | ||
618 | int stride, int x, int y, int width, int height ) | ||
619 | { | ||
620 | fb_data *dst; | ||
621 | unsigned fg_pattern = rb->lcd_get_foreground(); | ||
622 | |||
623 | /* nothing to draw? */ | ||
624 | if ((width <= 0) || (height <= 0) || (x >= buf_width) || | ||
625 | (y >= buf_height) || (x + width <= 0) || (y + height <= 0)) | ||
626 | return; | ||
627 | |||
628 | /* initialize blending */ | ||
629 | BLEND_INIT; | ||
630 | |||
631 | /* clipping */ | ||
632 | if (x < 0) | ||
633 | { | ||
634 | width += x; | ||
635 | src_x -= x; | ||
636 | x = 0; | ||
637 | } | ||
638 | if (y < 0) | ||
639 | { | ||
640 | height += y; | ||
641 | src_y -= y; | ||
642 | y = 0; | ||
643 | } | ||
644 | if (x + width > buf_width) | ||
645 | width = buf_width - x; | ||
646 | if (y + height > buf_height) | ||
647 | height = buf_height - y; | ||
648 | |||
649 | dst = buf + y*buf_width + x; | ||
650 | |||
651 | int col, row = height; | ||
652 | unsigned data, pixels; | ||
653 | unsigned skip_end = (stride - width); | ||
654 | unsigned skip_start = src_y * stride + src_x; | ||
655 | |||
656 | #ifdef ALPHA_BITMAP_READ_WORDS | ||
657 | uint32_t *src_w = (uint32_t *)((uintptr_t)src & ~3); | ||
658 | skip_start += ALPHA_COLOR_PIXEL_PER_BYTE * ((uintptr_t)src & 3); | ||
659 | src_w += skip_start / ALPHA_COLOR_PIXEL_PER_WORD; | ||
660 | data = letoh32(*src_w++); | ||
661 | #else | ||
662 | src += skip_start / ALPHA_COLOR_PIXEL_PER_BYTE; | ||
663 | data = *src; | ||
664 | #endif | ||
665 | pixels = skip_start % ALPHA_COLOR_PIXEL_PER_WORD; | ||
666 | data >>= pixels * ALPHA_COLOR_LOOKUP_SHIFT; | ||
667 | #ifdef ALPHA_BITMAP_READ_WORDS | ||
668 | pixels = 8 - pixels; | ||
669 | #endif | ||
670 | |||
671 | do | ||
672 | { | ||
673 | col = width; | ||
674 | #ifdef ALPHA_BITMAP_READ_WORDS | ||
675 | #define UPDATE_SRC_ALPHA do { \ | ||
676 | if (--pixels) \ | ||
677 | data >>= ALPHA_COLOR_LOOKUP_SHIFT; \ | ||
678 | else \ | ||
679 | { \ | ||
680 | data = letoh32(*src_w++); \ | ||
681 | pixels = ALPHA_COLOR_PIXEL_PER_WORD; \ | ||
682 | } \ | ||
683 | } while (0) | ||
684 | #elif ALPHA_COLOR_PIXEL_PER_BYTE == 2 | ||
685 | #define UPDATE_SRC_ALPHA do { \ | ||
686 | if (pixels ^= 1) \ | ||
687 | data >>= ALPHA_COLOR_LOOKUP_SHIFT; \ | ||
688 | else \ | ||
689 | data = *(++src); \ | ||
690 | } while (0) | ||
691 | #else | ||
692 | #define UPDATE_SRC_ALPHA do { \ | ||
693 | if (pixels = (++pixels % ALPHA_COLOR_PIXEL_PER_BYTE)) \ | ||
694 | data >>= ALPHA_COLOR_LOOKUP_SHIFT; \ | ||
695 | else \ | ||
696 | data = *(++src); \ | ||
697 | } while (0) | ||
698 | #endif | ||
699 | |||
700 | do | ||
701 | { | ||
702 | *dst=blend_two_colors(*dst, fg_pattern, | ||
703 | data & ALPHA_COLOR_LOOKUP_SIZE ); | ||
704 | dst++; | ||
705 | UPDATE_SRC_ALPHA; | ||
706 | } | ||
707 | while (--col); | ||
708 | #ifdef ALPHA_BITMAP_READ_WORDS | ||
709 | if (skip_end < pixels) | ||
710 | { | ||
711 | pixels -= skip_end; | ||
712 | data >>= skip_end * ALPHA_COLOR_LOOKUP_SHIFT; | ||
713 | } else { | ||
714 | pixels = skip_end - pixels; | ||
715 | src_w += pixels / ALPHA_COLOR_PIXEL_PER_WORD; | ||
716 | pixels %= ALPHA_COLOR_PIXEL_PER_WORD; | ||
717 | data = letoh32(*src_w++); | ||
718 | data >>= pixels * ALPHA_COLOR_LOOKUP_SHIFT; | ||
719 | pixels = 8 - pixels; | ||
720 | } | ||
721 | #else | ||
722 | if (skip_end) | ||
723 | { | ||
724 | pixels += skip_end; | ||
725 | if (pixels >= ALPHA_COLOR_PIXEL_PER_BYTE) | ||
726 | { | ||
727 | src += pixels / ALPHA_COLOR_PIXEL_PER_BYTE; | ||
728 | pixels %= ALPHA_COLOR_PIXEL_PER_BYTE; | ||
729 | data = *src; | ||
730 | data >>= pixels * ALPHA_COLOR_LOOKUP_SHIFT; | ||
731 | } else | ||
732 | data >>= skip_end * ALPHA_COLOR_LOOKUP_SHIFT; | ||
733 | } | ||
734 | #endif | ||
735 | dst += LCD_WIDTH - width; | ||
736 | } while (--row); | ||
737 | } | ||
738 | |||
565 | static void buffer_putsxyofs( fb_data *buf, int buf_width, int buf_height, | 739 | static void buffer_putsxyofs( fb_data *buf, int buf_width, int buf_height, |
566 | int x, int y, int ofs, const unsigned char *str ) | 740 | int x, int y, int ofs, const unsigned char *str ) |
567 | { | 741 | { |
@@ -589,8 +763,12 @@ static void buffer_putsxyofs( fb_data *buf, int buf_width, int buf_height, | |||
589 | 763 | ||
590 | bits = rb->font_get_bits( pf, ch ); | 764 | bits = rb->font_get_bits( pf, ch ); |
591 | 765 | ||
592 | buffer_mono_bitmap_part( buf, buf_width, buf_height, bits, ofs, 0, | 766 | if (pf->depth) |
593 | width, x, y, width - ofs, pf->height); | 767 | buffer_alpha_bitmap_part( buf, buf_width, buf_height, bits, ofs, 0, |
768 | width, x, y, width - ofs, pf->height); | ||
769 | else | ||
770 | buffer_mono_bitmap_part( buf, buf_width, buf_height, bits, ofs, 0, | ||
771 | width, x, y, width - ofs, pf->height); | ||
594 | 772 | ||
595 | x += width - ofs; | 773 | x += width - ofs; |
596 | ofs = 0; | 774 | ofs = 0; |