From 36ee73af356527be46f688ea1915e65458812c39 Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Thu, 6 Feb 2025 04:33:49 +0100 Subject: [PATCH] Save 8 bytes --- ui/helper.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ui/helper.c b/ui/helper.c index d90d770..39d0e35 100644 --- a/ui/helper.c +++ b/ui/helper.c @@ -230,6 +230,7 @@ void UI_DrawPixelBuffer(uint8_t (*buffer)[128], uint8_t x, uint8_t y, bool black buffer[y/8][x] &= ~pattern; } +/* static void sort(int16_t *a, int16_t *b) { if(*a > *b) { @@ -238,6 +239,7 @@ static void sort(int16_t *a, int16_t *b) *b = t; } } +*/ #ifdef ENABLE_FEAT_F4HWN /* @@ -297,8 +299,17 @@ static void sort(int16_t *a, int16_t *b) void UI_DrawLineBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black) { - if(x2==x1) { - sort(&y1, &y2); + // Swap x1 and x2 if x1 > x2 + if (x1 > x2) { + int16_t tmp = x1; x1 = x2; x2 = tmp; + int16_t tmpY = y1; y1 = y2; y2 = tmpY; // Swap corresponding y-values as well + } + + if(x1==x2) { + // Ensure y1 <= y2 + if (y1 > y2) { + int16_t tmp = y1; y1 = y2; y2 = tmp; + } for(int16_t i = y1; i <= y2; i++) { UI_DrawPixelBuffer(buffer, x1, i, black); } @@ -307,7 +318,6 @@ void UI_DrawLineBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x int a = (y2-y1)*multipl / (x2-x1); int b = y1 - a * x1 / multipl; - sort(&x1, &x2); for(int i = x1; i<= x2; i++) { UI_DrawPixelBuffer(buffer, i, i*a/multipl +b, black);