summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/grey_core.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lib/grey_core.c')
-rw-r--r--apps/plugins/lib/grey_core.c153
1 files changed, 84 insertions, 69 deletions
diff --git a/apps/plugins/lib/grey_core.c b/apps/plugins/lib/grey_core.c
index c73f0cdf52..a7e8f2a08b 100644
--- a/apps/plugins/lib/grey_core.c
+++ b/apps/plugins/lib/grey_core.c
@@ -355,6 +355,7 @@ static inline void _deferred_update(void)
355 * coordinates! */ 355 * coordinates! */
356static unsigned long _grey_get_pixel(int x, int y) 356static unsigned long _grey_get_pixel(int x, int y)
357{ 357{
358 long val;
358 int xg = x - _grey_info.x; 359 int xg = x - _grey_info.x;
359 int yg = y - _grey_info.y; 360 int yg = y - _grey_info.y;
360#if LCD_PIXELFORMAT == HORIZONTAL_PACKING 361#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
@@ -364,7 +365,11 @@ static unsigned long _grey_get_pixel(int x, int y)
364 + (xg << _GREY_BSHIFT) + (~yg & _GREY_BMASK); 365 + (xg << _GREY_BSHIFT) + (~yg & _GREY_BMASK);
365#endif 366#endif
366 367
367 return _grey_info.values[idx] + (1 << LCD_DEPTH); 368 val = _grey_info.values[idx];
369#ifdef HAVE_LCD_SPLIT
370 val -= val >> 7;
371#endif
372 return val;
368} 373}
369 374
370#else /* !SIMULATOR */ 375#else /* !SIMULATOR */
@@ -634,9 +639,9 @@ void grey_show(bool enable)
634 { 639 {
635 _grey_info.flags |= _GREY_RUNNING; 640 _grey_info.flags |= _GREY_RUNNING;
636#ifdef SIMULATOR 641#ifdef SIMULATOR
637 rb->sim_lcd_ex_init(129, _grey_get_pixel); 642 rb->sim_lcd_ex_init(_grey_get_pixel);
638 rb->sim_lcd_ex_update_rect(_grey_info.x, _grey_info.y, 643 rb->sim_lcd_ex_update_rect(_grey_info.x, _grey_info.y,
639 _grey_info.width, _grey_info.height); 644 _grey_info.width, _grey_info.height);
640#else /* !SIMULATOR */ 645#else /* !SIMULATOR */
641#ifdef NEED_BOOST 646#ifdef NEED_BOOST
642 rb->cpu_boost(true); 647 rb->cpu_boost(true);
@@ -655,7 +660,7 @@ void grey_show(bool enable)
655 else if (!enable && (_grey_info.flags & _GREY_RUNNING)) 660 else if (!enable && (_grey_info.flags & _GREY_RUNNING))
656 { 661 {
657#ifdef SIMULATOR 662#ifdef SIMULATOR
658 rb->sim_lcd_ex_init(0, NULL); 663 rb->sim_lcd_ex_init(NULL);
659#else /* !SIMULATOR */ 664#else /* !SIMULATOR */
660 rb->timer_unregister(); 665 rb->timer_unregister();
661#if NUM_CORES > 1 /* Make sure the ISR has finished before calling lcd_update() */ 666#if NUM_CORES > 1 /* Make sure the ISR has finished before calling lcd_update() */
@@ -702,9 +707,14 @@ void grey_deferred_lcd_update(void)
702 707
703/*** Screenshot ***/ 708/*** Screenshot ***/
704 709
705#define BMP_FIXEDCOLORS (1 << LCD_DEPTH) 710#ifdef HAVE_LCD_SPLIT
706#define BMP_VARCOLORS 129 711#define GRADIENT_MAX 127
707#define BMP_NUMCOLORS (BMP_FIXEDCOLORS + BMP_VARCOLORS) 712#define BMP_NUMCOLORS 256
713#else
714#define GRADIENT_MAX 128
715#define BMP_NUMCOLORS 129
716#endif
717
708#define BMP_BPP 8 718#define BMP_BPP 8
709#define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3) 719#define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3)
710#define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS) 720#define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
@@ -723,7 +733,7 @@ static const unsigned char bmpheader[] =
723 733
724 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */ 734 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
725 LE32_CONST(LCD_WIDTH), /* Width in pixels */ 735 LE32_CONST(LCD_WIDTH), /* Width in pixels */
726 LE32_CONST(LCD_HEIGHT), /* Height in pixels */ 736 LE32_CONST(LCD_HEIGHT+LCD_SPLIT_LINES), /* Height in pixels */
727 0x01, 0x00, /* Number of planes (always 1) */ 737 0x01, 0x00, /* Number of planes (always 1) */
728 LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */ 738 LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */
729 0x00, 0x00, 0x00, 0x00, /* Compression mode, 0 = none */ 739 0x00, 0x00, 0x00, 0x00, /* Compression mode, 0 = none */
@@ -732,36 +742,11 @@ static const unsigned char bmpheader[] =
732 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */ 742 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
733 LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */ 743 LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */
734 LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */ 744 LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */
735
736 /* Fixed colours */
737#if LCD_DEPTH == 1
738 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
739 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
740#elif LCD_DEPTH == 2
741 0xe6, 0xd8, 0xad, 0x00, /* Colour #0 */
742 0x99, 0x90, 0x73, 0x00, /* Colour #1 */
743 0x4c, 0x48, 0x39, 0x00, /* Colour #2 */
744 0x00, 0x00, 0x00, 0x00 /* Colour #3 */
745#endif
746}; 745};
747 746
748#if LCD_DEPTH == 1 747#if LCD_DEPTH == 2
749#ifdef MROBE_100 748/* Only defined for positive, non-split LCD for now */
750#define BMP_RED 241 749static const unsigned char colorindex[4] = {128, 85, 43, 0};
751#define BMP_GREEN 6
752#define BMP_BLUE 3
753#define BMP_RED_BASE 94
754#define BMP_GREEN_BASE 2
755#define BMP_BLUE_BASE 2
756#else
757#define BMP_RED 0x90
758#define BMP_GREEN 0xee
759#define BMP_BLUE 0x90
760#endif
761#elif LCD_DEPTH == 2
762#define BMP_RED 0xad
763#define BMP_GREEN 0xd8
764#define BMP_BLUE 0xe6
765#endif 750#endif
766 751
767/* Hook function for core screen_dump() to save the current display 752/* Hook function for core screen_dump() to save the current display
@@ -772,6 +757,7 @@ static void grey_screendump_hook(int fd)
772 int x, y, gx, gy; 757 int x, y, gx, gy;
773#if LCD_PIXELFORMAT == VERTICAL_PACKING 758#if LCD_PIXELFORMAT == VERTICAL_PACKING
774#if LCD_DEPTH == 1 759#if LCD_DEPTH == 1
760 unsigned val;
775 unsigned mask; 761 unsigned mask;
776#elif LCD_DEPTH == 2 762#elif LCD_DEPTH == 2
777 int shift; 763 int shift;
@@ -782,37 +768,57 @@ static void grey_screendump_hook(int fd)
782#endif /* LCD_PIXELFORMAT */ 768#endif /* LCD_PIXELFORMAT */
783 fb_data *lcdptr; 769 fb_data *lcdptr;
784 unsigned char *clut_entry; 770 unsigned char *clut_entry;
785 unsigned char linebuf[MAX(4*BMP_VARCOLORS,BMP_LINESIZE)]; 771 unsigned char linebuf[MAX(4*BMP_NUMCOLORS,BMP_LINESIZE)];
786 772
787 rb->write(fd, bmpheader, sizeof(bmpheader)); /* write header */ 773 rb->write(fd, bmpheader, sizeof(bmpheader)); /* write header */
788 774
789 /* build clut */ 775 /* build clut */
790 rb->memset(linebuf, 0, 4*BMP_VARCOLORS); 776 rb->memset(linebuf, 0, 4*BMP_NUMCOLORS);
791 clut_entry = linebuf; 777 clut_entry = linebuf;
792 778
793 for (i = 0; i <= 128; i++) 779 for (i = 0; i <= GRADIENT_MAX; i++)
794 { 780 {
795#ifdef MROBE_100 781 *clut_entry++ = (_GREY_MULUQ(BLUE_CMP(LCD_BL_BRIGHTCOLOR)
796 *clut_entry++ = (_GREY_MULUQ(BMP_BLUE-BMP_BLUE_BASE, i) >> 7) + 782 -BLUE_CMP(LCD_BL_DARKCOLOR), i) >> 7)
797 BMP_BLUE_BASE; 783 + BLUE_CMP(LCD_BL_DARKCOLOR);
798 *clut_entry++ = (_GREY_MULUQ(BMP_GREEN-BMP_GREEN_BASE, i) >> 7) + 784 *clut_entry++ = (_GREY_MULUQ(GREEN_CMP(LCD_BL_BRIGHTCOLOR)
799 BMP_GREEN_BASE; 785 -GREEN_CMP(LCD_BL_DARKCOLOR), i) >> 7)
800 *clut_entry++ = (_GREY_MULUQ(BMP_RED-BMP_RED_BASE, i) >> 7) + 786 + GREEN_CMP(LCD_BL_DARKCOLOR);
801 BMP_RED_BASE; 787 *clut_entry++ = (_GREY_MULUQ(RED_CMP(LCD_BL_BRIGHTCOLOR)
802#else 788 -RED_CMP(LCD_BL_DARKCOLOR), i) >> 7)
803 *clut_entry++ = _GREY_MULUQ(BMP_BLUE, i) >> 7; 789 + RED_CMP(LCD_BL_DARKCOLOR);
804 *clut_entry++ = _GREY_MULUQ(BMP_GREEN, i) >> 7;
805 *clut_entry++ = _GREY_MULUQ(BMP_RED, i) >> 7;
806#endif
807 clut_entry++; 790 clut_entry++;
808 } 791 }
809 rb->write(fd, linebuf, 4*BMP_VARCOLORS); 792#ifdef HAVE_LCD_SPLIT
793 for (i = 0; i <= GRADIENT_MAX; i++)
794 {
795 *clut_entry++ = (_GREY_MULUQ(BLUE_CMP(LCD_BL_BRIGHTCOLOR_2)
796 -BLUE_CMP(LCD_BL_DARKCOLOR_2), i) >> 7)
797 + BLUE_CMP(LCD_BL_DARKCOLOR_2);
798 *clut_entry++ = (_GREY_MULUQ(GREEN_CMP(LCD_BL_BRIGHTCOLOR_2)
799 -GREEN_CMP(LCD_BL_DARKCOLOR_2), i) >> 7)
800 + GREEN_CMP(LCD_BL_DARKCOLOR_2);
801 *clut_entry++ = (_GREY_MULUQ(RED_CMP(LCD_BL_BRIGHTCOLOR_2)
802 -RED_CMP(LCD_BL_DARKCOLOR_2), i) >> 7)
803 + RED_CMP(LCD_BL_DARKCOLOR_2);
804 clut_entry++;
805 }
806#endif
807 rb->write(fd, linebuf, 4*BMP_NUMCOLORS);
810 808
811 /* BMP image goes bottom -> top */ 809 /* BMP image goes bottom -> top */
812 for (y = LCD_HEIGHT - 1; y >= 0; y--) 810 for (y = LCD_HEIGHT - 1; y >= 0; y--)
813 { 811 {
814 rb->memset(linebuf, 0, BMP_LINESIZE); 812 rb->memset(linebuf, 0, BMP_LINESIZE);
815 813
814#if defined(HAVE_LCD_SPLIT) && (LCD_SPLIT_LINES == 2)
815 if (y == LCD_SPLIT_POS - 1)
816 {
817 rb->write(fd, linebuf, BMP_LINESIZE);
818 rb->write(fd, linebuf, BMP_LINESIZE);
819 }
820#endif
821
816 gy = y - _grey_info.y; 822 gy = y - _grey_info.y;
817#if LCD_PIXELFORMAT == HORIZONTAL_PACKING 823#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
818#if LCD_DEPTH == 2 824#if LCD_DEPTH == 2
@@ -828,15 +834,15 @@ static void grey_screendump_hook(int fd)
828 unsigned char *src = _grey_info.values 834 unsigned char *src = _grey_info.values
829 + _GREY_MULUQ(_grey_info.width, gy) + gx; 835 + _GREY_MULUQ(_grey_info.width, gy) + gx;
830 for (i = 0; i < 4; i++) 836 for (i = 0; i < 4; i++)
831 linebuf[x + i] = BMP_FIXEDCOLORS + *src++; 837 linebuf[x + i] = *src++;
832 } 838 }
833 else 839 else
834 { 840 {
835 unsigned data = *lcdptr; 841 unsigned data = *lcdptr;
836 linebuf[x] = (data >> 6) & 3; 842 linebuf[x] = colorindex[(data >> 6) & 3];
837 linebuf[x + 1] = (data >> 4) & 3; 843 linebuf[x + 1] = colorindex[(data >> 4) & 3];
838 linebuf[x + 2] = (data >> 2) & 3; 844 linebuf[x + 2] = colorindex[(data >> 2) & 3];
839 linebuf[x + 3] = data & 3; 845 linebuf[x + 3] = colorindex[data & 3];
840 } 846 }
841 lcdptr++; 847 lcdptr++;
842 } 848 }
@@ -853,16 +859,27 @@ static void grey_screendump_hook(int fd)
853 if (((unsigned)gy < (unsigned)_grey_info.height) 859 if (((unsigned)gy < (unsigned)_grey_info.height)
854 && ((unsigned)gx < (unsigned)_grey_info.width)) 860 && ((unsigned)gx < (unsigned)_grey_info.width))
855 { 861 {
856 linebuf[x] = BMP_FIXEDCOLORS 862 val = _grey_info.values[_GREY_MULUQ(_grey_info.width,
857 + _grey_info.values[_GREY_MULUQ(_grey_info.width, 863 gy & ~_GREY_BMASK)
858 gy & ~_GREY_BMASK) 864 + (gx << _GREY_BSHIFT)
859 + (gx << _GREY_BSHIFT) 865 + (~gy & _GREY_BMASK)];
860 + (~gy & _GREY_BMASK)]; 866#ifdef HAVE_LCD_SPLIT
867 val -= val >> 7;
868#endif
861 } 869 }
862 else 870 else
863 { 871 {
864 linebuf[x] = (*lcdptr & mask) ? 1 : 0; 872#ifdef HAVE_NEGATIVE_LCD
873 val = (*lcdptr & mask) ? GRADIENT_MAX : 0;
874#else
875 val = (*lcdptr & mask) ? 0 : GRADIENT_MAX;
876#endif
865 } 877 }
878#ifdef HAVE_LCD_SPLIT
879 if (y < LCD_SPLIT_POS)
880 val |= 0x80;
881#endif
882 linebuf[x] = val;
866 lcdptr++; 883 lcdptr++;
867 } 884 }
868#elif LCD_DEPTH == 2 885#elif LCD_DEPTH == 2
@@ -876,15 +893,14 @@ static void grey_screendump_hook(int fd)
876 if (((unsigned)gy < (unsigned)_grey_info.height) 893 if (((unsigned)gy < (unsigned)_grey_info.height)
877 && ((unsigned)gx < (unsigned)_grey_info.width)) 894 && ((unsigned)gx < (unsigned)_grey_info.width))
878 { 895 {
879 linebuf[x] = BMP_FIXEDCOLORS 896 linebuf[x] = _grey_info.values[_GREY_MULUQ(_grey_info.width,
880 + _grey_info.values[_GREY_MULUQ(_grey_info.width,
881 gy & ~_GREY_BMASK) 897 gy & ~_GREY_BMASK)
882 + (gx << _GREY_BSHIFT) 898 + (gx << _GREY_BSHIFT)
883 + (~gy & _GREY_BMASK)]; 899 + (~gy & _GREY_BMASK)];
884 } 900 }
885 else 901 else
886 { 902 {
887 linebuf[x] = (*lcdptr >> shift) & 3; 903 linebuf[x] = colorindex[(*lcdptr >> shift) & 3];
888 } 904 }
889 lcdptr++; 905 lcdptr++;
890 } 906 }
@@ -901,8 +917,7 @@ static void grey_screendump_hook(int fd)
901 if (((unsigned)gy < (unsigned)_grey_info.height) 917 if (((unsigned)gy < (unsigned)_grey_info.height)
902 && ((unsigned)gx < (unsigned)_grey_info.width)) 918 && ((unsigned)gx < (unsigned)_grey_info.width))
903 { 919 {
904 linebuf[x] = BMP_FIXEDCOLORS 920 linebuf[x] = _grey_info.values[_GREY_MULUQ(_grey_info.width,
905 + _grey_info.values[_GREY_MULUQ(_grey_info.width,
906 gy & ~_GREY_BMASK) 921 gy & ~_GREY_BMASK)
907 + (gx << _GREY_BSHIFT) 922 + (gx << _GREY_BSHIFT)
908 + (~gy & _GREY_BMASK)]; 923 + (~gy & _GREY_BMASK)];
@@ -910,7 +925,7 @@ static void grey_screendump_hook(int fd)
910 else 925 else
911 { 926 {
912 data = (*lcdptr >> shift) & 0x0101; 927 data = (*lcdptr >> shift) & 0x0101;
913 linebuf[x] = ((data >> 7) | data) & 3; 928 linebuf[x] = colorindex[((data >> 7) | data) & 3];
914 } 929 }
915 lcdptr++; 930 lcdptr++;
916 } 931 }