Bladeren bron

proper pixel order

Thomas Buck 1 jaar geleden
bovenliggende
commit
ef0f492890
3 gewijzigde bestanden met toevoegingen van 19 en 19 verwijderingen
  1. 3
    3
      src/image.c
  2. 3
    3
      src/lcd.c
  3. 13
    13
      src/text.c

+ 3
- 3
src/image.c Bestand weergeven

@@ -34,13 +34,13 @@
34 34
 #define BATT_INTERVAL_MS 777
35 35
 
36 36
 void image_draw(const char *data, uint width, uint height) {
37
-    for (uint x = 0; x < width; x++) {
38
-        for (uint y = 0; y < height; y++) {
37
+    for (uint y = 0; y < height; y++) {
38
+        for (uint x = 0; x < width; x++) {
39 39
             uint32_t pixel[3];
40 40
             HEADER_PIXEL(data, pixel);
41 41
 
42 42
             uint32_t color = RGB_565(pixel[0], pixel[1], pixel[2]);
43
-            lcd_write_point(240 - x - 1, y, color);
43
+            lcd_write_point(x, y, color);
44 44
         }
45 45
     }
46 46
 }

+ 3
- 3
src/lcd.c Bestand weergeven

@@ -35,7 +35,7 @@
35 35
 #define LCD_PIN_BL 13
36 36
 
37 37
 #define ST7789_PICO_COLUMN                             240
38
-#define ST7789_PICO_ROW                                240
38
+#define ST7789_PICO_ROW                                ST7789_PICO_COLUMN
39 39
 
40 40
 #define ST7789_PICO_ACCESS                            (ST7789_ORDER_PAGE_TOP_TO_BOTTOM | \
41 41
                                                        ST7789_ORDER_COLUMN_LEFT_TO_RIGHT | \
@@ -269,11 +269,11 @@ void lcd_clear(void) {
269 269
 }
270 270
 
271 271
 void lcd_write_point(uint16_t x, uint16_t y, uint32_t color) {
272
-    st7789_draw_point(&gs_handle, x, y, color);
272
+    st7789_draw_point(&gs_handle, ST7789_PICO_COLUMN - y - 1, x, color);
273 273
 }
274 274
 
275 275
 void lcd_write_rect(uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t color) {
276
-    st7789_fill_rect(&gs_handle, left, top, right, bottom, color);
276
+    st7789_fill_rect(&gs_handle, 240 - bottom - 1, left, 240 - top - 1, right, color);
277 277
 }
278 278
 
279 279
 uint32_t from_hsv(float h, float s, float v) {

+ 13
- 13
src/text.c Bestand weergeven

@@ -54,7 +54,7 @@ static void pixel_callback(int16_t x, int16_t y, uint8_t count, uint8_t alpha,
54 54
     if (x < 0 || x + count >= s->options->width) return;
55 55
 
56 56
     while (count--) {
57
-        lcd_write_point(240 - y - 1, x,
57
+        lcd_write_point(x, y,
58 58
                         blend(s->options->fg, s->options->bg, alpha));
59 59
         x++;
60 60
     }
@@ -75,22 +75,22 @@ static bool line_callback(const char *line, uint16_t count, void *state) {
75 75
         int16_t line_height = s->options->font->font->line_height;
76 76
 
77 77
         if (s->options->alignment == MF_ALIGN_LEFT) {
78
-            lcd_write_rect(240 - s->options->y - 1 - line_height,
79
-                           s->options->x,
80
-                           240 - s->options->y - 1,
78
+            lcd_write_rect(s->options->x,
79
+                           s->options->y,
81 80
                            s->options->x + width,
81
+                           s->options->y + line_height,
82 82
                            s->options->bg);
83 83
         } else if (s->options->alignment == MF_ALIGN_CENTER) {
84
-            lcd_write_rect(240 - s->options->y - 1 - line_height,
85
-                           s->options->x + s->options->width / 2 - width / 2,
86
-                           240 - s->options->y - 1,
84
+            lcd_write_rect(s->options->x + s->options->width / 2 - width / 2,
85
+                           s->options->y,
87 86
                            s->options->x + s->options->width / 2 + width / 2,
87
+                           s->options->y + line_height,
88 88
                            s->options->bg);
89 89
         } else if (s->options->alignment == MF_ALIGN_RIGHT) {
90
-            lcd_write_rect(240 - s->options->y - 1 - line_height,
91
-                           s->options->x + s->options->width - width,
92
-                           240 - s->options->y - 1,
90
+            lcd_write_rect(s->options->x + s->options->width - width,
91
+                           s->options->y,
93 92
                            s->options->x + s->options->width,
93
+                           s->options->y + line_height,
94 94
                            s->options->bg);
95 95
         }
96 96
     }
@@ -181,10 +181,10 @@ void text_box(const char *s) {
181 181
         .font = &font,
182 182
     };
183 183
 
184
-    lcd_write_rect(240 - y - 1 - height,
185
-                   x,
186
-                   240 - y - 1,
184
+    lcd_write_rect(x,
185
+                   y,
187 186
                    x + width - 1,
187
+                   y + height - 1,
188 188
                    text.bg);
189 189
 
190 190
     text.text = s;

Laden…
Annuleren
Opslaan