summaryrefslogtreecommitdiff
path: root/apps/plugins/mpegplayer/mpegplayer.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mpegplayer/mpegplayer.c')
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c174
1 files changed, 172 insertions, 2 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 */
694static 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
716static 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
666static void draw_putsxy_oriented(int x, int y, const char *str) 832static 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;