summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/lib/xlcd.c74
1 files changed, 73 insertions, 1 deletions
diff --git a/apps/plugins/lib/xlcd.c b/apps/plugins/lib/xlcd.c
index 8f26330470..9b03a16b6a 100644
--- a/apps/plugins/lib/xlcd.c
+++ b/apps/plugins/lib/xlcd.c
@@ -35,7 +35,78 @@ void xlcd_init(struct plugin_api* newrb)
35 local_rb = newrb; 35 local_rb = newrb;
36} 36}
37 37
38/* draw a filled triangle */ 38#if (LCD_DEPTH >= 8) || (LCD_PIXELFORMAT == HORIZONTAL_PACKING)
39/* draw a filled triangle, using horizontal lines for speed */
40void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3)
41{
42 int x, y;
43 long fp_x1, fp_x2, fp_dx1, fp_dx2;
44
45 /* sort vertices by increasing y value */
46 if (y1 > y3)
47 {
48 if (y2 < y3) /* y2 < y3 < y1 */
49 {
50 x = x1; x1 = x2; x2 = x3; x3 = x;
51 y = y1; y1 = y2; y2 = y3; y3 = y;
52 }
53 else if (y2 > y1) /* y3 < y1 < y2 */
54 {
55 x = x1; x1 = x3; x3 = x2; x2 = x;
56 y = y1; y1 = y3; y3 = y2; y2 = y;
57 }
58 else /* y3 <= y2 <= y1 */
59 {
60 x = x1; x1 = x3; x3 = x;
61 y = y1; y1 = y3; y3 = y;
62 }
63 }
64 else
65 {
66 if (y2 < y1) /* y2 < y1 <= y3 */
67 {
68 x = x1; x1 = x2; x2 = x;
69 y = y1; y1 = y2; y2 = y;
70 }
71 else if (y2 > y3) /* y1 <= y3 < y2 */
72 {
73 x = x2; x2 = x3; x3 = x;
74 y = y2; y2 = y3; y3 = y;
75 }
76 /* else already sorted */
77 }
78
79 if (y1 < y3) /* draw */
80 {
81 fp_dx1 = ((x3 - x1) << 16) / (y3 - y1);
82 fp_x1 = (x1 << 16) + (1<<15) + (fp_dx1 >> 1);
83
84 if (y1 < y2) /* first part */
85 {
86 fp_dx2 = ((x2 - x1) << 16) / (y2 - y1);
87 fp_x2 = (x1 << 16) + (1<<15) + (fp_dx2 >> 1);
88 for (y = y1; y < y2; y++)
89 {
90 local_rb->lcd_hline(fp_x1 >> 16, fp_x2 >> 16, y);
91 fp_x1 += fp_dx1;
92 fp_x2 += fp_dx2;
93 }
94 }
95 if (y2 < y3) /* second part */
96 {
97 fp_dx2 = ((x3 - x2) << 16) / (y3 - y2);
98 fp_x2 = (x2 << 16) + (1<<15) + (fp_dx2 >> 1);
99 for (y = y2; y < y3; y++)
100 {
101 local_rb->lcd_hline(fp_x1 >> 16, fp_x2 >> 16, y);
102 fp_x1 += fp_dx1;
103 fp_x2 += fp_dx2;
104 }
105 }
106 }
107}
108#else /* (LCD_DEPTH < 8) && (LCD_PIXELFORMAT == VERTICAL_PACKING) */
109/* draw a filled triangle, using vertical lines for speed */
39void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3) 110void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3)
40{ 111{
41 int x, y; 112 int x, y;
@@ -104,6 +175,7 @@ void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3)
104 } 175 }
105 } 176 }
106} 177}
178#endif /* LCD_DEPTH, LCD_PIXELFORMAT */
107 179
108#if LCD_DEPTH >= 8 180#if LCD_DEPTH >= 8
109 181