diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-09-26 09:23:18 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-10-09 22:07:46 +0100 |
commit | 4f9e4ddb9914ff73259f006a4cbcf520656f06e0 (patch) | |
tree | a2e9bc09589316ffe2f7a9748369dadbe15662fa /firmware/drivers/lcd-bitmap-common.c | |
parent | 4b8fe8acd1c079e75bb9229791170c549188fc08 (diff) | |
download | rockbox-4f9e4ddb9914ff73259f006a4cbcf520656f06e0.tar.gz rockbox-4f9e4ddb9914ff73259f006a4cbcf520656f06e0.zip |
lcd: Consolidate drawpixel, drawline, and drawrect functions
All three functions are nearly identical regardless of the
LCD pixel format. Consolidate them into a generic version in
lcd-bitmap-common.c.
Change-Id: Iab13429ea27ea2b0150b9004535bd27d4a4121a0
Diffstat (limited to 'firmware/drivers/lcd-bitmap-common.c')
-rw-r--r-- | firmware/drivers/lcd-bitmap-common.c | 128 |
1 files changed, 127 insertions, 1 deletions
diff --git a/firmware/drivers/lcd-bitmap-common.c b/firmware/drivers/lcd-bitmap-common.c index c867b214b5..bd6efa167c 100644 --- a/firmware/drivers/lcd-bitmap-common.c +++ b/firmware/drivers/lcd-bitmap-common.c | |||
@@ -67,7 +67,8 @@ static bool LCDFN(clip_viewport_pixel)(int *x, int *y) | |||
67 | { | 67 | { |
68 | struct viewport *vp = LCDFN(current_viewport); | 68 | struct viewport *vp = LCDFN(current_viewport); |
69 | 69 | ||
70 | if(*x >= vp->width || *y >= vp->height) | 70 | if (*x < 0 || *x >= vp->width || |
71 | *y < 0 || *y >= vp->height) | ||
71 | return false; | 72 | return false; |
72 | 73 | ||
73 | *x += vp->x; | 74 | *x += vp->x; |
@@ -805,3 +806,128 @@ void LCDFN(nine_segment_bmp)(const struct bitmap* bm, int x, int y, | |||
805 | LCDFN(bmp_part)(bm, bm->width - corner_w, bm->width - corner_h, | 806 | LCDFN(bmp_part)(bm, bm->width - corner_w, bm->width - corner_h, |
806 | width - corner_w, height - corner_h, corner_w, corner_h); | 807 | width - corner_w, height - corner_h, corner_w, corner_h); |
807 | } | 808 | } |
809 | |||
810 | void LCDFN(drawpixel)(int x, int y) | ||
811 | { | ||
812 | struct viewport *vp = LCDFN(current_viewport); | ||
813 | if (LCDFN(clip_viewport_pixel(&x, &y))) | ||
814 | { | ||
815 | #if LCDM(DEPTH) >= 8 | ||
816 | LCDFN(fastpixelfunc_type) *pfunc = LCDFN(fastpixelfuncs)[vp->drawmode]; | ||
817 | void *(*fbaddr)(int x, int y) = vp->buffer->get_address_fn; | ||
818 | pfunc(fbaddr(x, y)); | ||
819 | #else | ||
820 | LCDFN(pixelfunc_type) *pfunc = LCDFN(pixelfuncs)[vp->drawmode]; | ||
821 | pfunc(x, y); | ||
822 | #endif | ||
823 | } | ||
824 | } | ||
825 | |||
826 | void LCDFN(drawline)(int x1, int y1, int x2, int y2) | ||
827 | { | ||
828 | struct viewport *vp = LCDFN(current_viewport); | ||
829 | int numpixels; | ||
830 | int i; | ||
831 | int deltax, deltay; | ||
832 | int d, dinc1, dinc2; | ||
833 | int x, xinc1, xinc2; | ||
834 | int y, yinc1, yinc2; | ||
835 | |||
836 | deltay = abs(y2 - y1); | ||
837 | if (deltay == 0) | ||
838 | { | ||
839 | lcd_hline(x1, x2, y1); | ||
840 | return; | ||
841 | } | ||
842 | |||
843 | deltax = abs(x2 - x1); | ||
844 | if (deltax == 0) | ||
845 | { | ||
846 | lcd_vline(x1, y1, y2); | ||
847 | return; | ||
848 | } | ||
849 | |||
850 | xinc2 = 1; | ||
851 | yinc2 = 1; | ||
852 | |||
853 | if (deltax >= deltay) | ||
854 | { | ||
855 | numpixels = deltax; | ||
856 | d = 2 * deltay - deltax; | ||
857 | dinc1 = deltay * 2; | ||
858 | dinc2 = (deltay - deltax) * 2; | ||
859 | xinc1 = 1; | ||
860 | yinc1 = 0; | ||
861 | } | ||
862 | else | ||
863 | { | ||
864 | numpixels = deltay; | ||
865 | d = 2 * deltax - deltay; | ||
866 | dinc1 = deltax * 2; | ||
867 | dinc2 = (deltax - deltay) * 2; | ||
868 | xinc1 = 0; | ||
869 | yinc1 = 1; | ||
870 | } | ||
871 | numpixels++; /* include endpoints */ | ||
872 | |||
873 | if (x1 > x2) | ||
874 | { | ||
875 | xinc1 = -xinc1; | ||
876 | xinc2 = -xinc2; | ||
877 | } | ||
878 | |||
879 | if (y1 > y2) | ||
880 | { | ||
881 | yinc1 = -yinc1; | ||
882 | yinc2 = -yinc2; | ||
883 | } | ||
884 | |||
885 | x = x1; | ||
886 | y = y1; | ||
887 | |||
888 | #if LCDM(DEPTH) >= 8 | ||
889 | LCDFN(fastpixelfunc_type) *pfunc = LCDFN(fastpixelfuncs)[vp->drawmode]; | ||
890 | void *(*fbaddr)(int x, int y) = vp->buffer->get_address_fn; | ||
891 | #else | ||
892 | LCDFN(pixelfunc_type) *pfunc = LCDFN(pixelfuncs)[vp->drawmode]; | ||
893 | #endif | ||
894 | |||
895 | for (i = 0; i < numpixels; i++) | ||
896 | { | ||
897 | if (x >= 0 && y >= 0 && x < vp->width && y < vp->height) | ||
898 | { | ||
899 | #if LCDM(DEPTH) >= 8 | ||
900 | pfunc(fbaddr(x + vp->x, y + vp->y)); | ||
901 | #else | ||
902 | pfunc(x + vp->x, y + vp->y); | ||
903 | #endif | ||
904 | } | ||
905 | |||
906 | if (d < 0) | ||
907 | { | ||
908 | d += dinc1; | ||
909 | x += xinc1; | ||
910 | y += yinc1; | ||
911 | } | ||
912 | else | ||
913 | { | ||
914 | d += dinc2; | ||
915 | x += xinc2; | ||
916 | y += yinc2; | ||
917 | } | ||
918 | } | ||
919 | } | ||
920 | |||
921 | void LCDFN(drawrect)(int x, int y, int width, int height) | ||
922 | { | ||
923 | if ((width <= 0) || (height <= 0)) | ||
924 | return; | ||
925 | |||
926 | int x2 = x + width - 1; | ||
927 | int y2 = y + height - 1; | ||
928 | |||
929 | LCDFN(vline)(x, y, y2); | ||
930 | LCDFN(vline)(x2, y, y2); | ||
931 | LCDFN(hline)(x, x2, y); | ||
932 | LCDFN(hline)(x, x2, y2); | ||
933 | } | ||