FS#13970 - lcd_drawline() different depending on drawing direction try#2

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit dcdb539ca54e90700d4a6ce20350e34f700a96f7
Author: William Wilgus <[email protected]>
Date:   Wed Aug 5 11:40:02 2026 -0400

    FS#13970 - lcd_drawline() different depending on drawing direction try#2
    
    Last patch didn't swap both x and y so was wrong and messed up the coord pair
    I didn't want to add more swapping due to extra overhead
    
    ultimately the issue is that you have 1/2 pixel error (-1 0 1)
    and when doing the reverse line the error is on the wrong side
    so instead get the first point from the opposite dinc
    
    Change-Id: I141c4af36a601314f2b509a9ebfcfab3b5213bcd

diff --git a/firmware/drivers/lcd-bitmap-common.c b/firmware/drivers/lcd-bitmap-common.c
index c4009155fa..e1ebd7267b 100644
--- a/firmware/drivers/lcd-bitmap-common.c
+++ b/firmware/drivers/lcd-bitmap-common.c
@@ -911,6 +911,18 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2)
         dinc2 = (deltay - deltax) * 2;
         xinc1 = 1;
         yinc1 = 0;
+        if (x1 > x2)
+        {
+            xinc1 = -xinc1;
+            xinc2 = -xinc2;
+        }
+
+        if (y1 > y2)
+        {
+            d += dinc2;
+            yinc1 = -yinc1;
+            yinc2 = -yinc2;
+        }
     }
     else
     {
@@ -920,24 +932,20 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2)
         dinc2 = (deltax - deltay) * 2;
         xinc1 = 0;
         yinc1 = 1;
-    }
-    numpixels++; /* include endpoints */
-
-    if (x1 > x2)
-    {
-        /* swap their identities */
-        int x0 = x2;
-        x2 = x1;
-        x1 = x0;
-    }
+        if (x1 > x2)
+        {
+            d += dinc2;
+            xinc1 = -xinc1;
+            xinc2 = -xinc2;
+        }
 
-    if (y1 > y2)
-    {
-        /* swap their identities */
-        int y0 = y2;
-        y2 = y1;
-        y1 = y0;
+        if (y1 > y2)
+        {
+            yinc1 = -yinc1;
+            yinc2 = -yinc2;
+        }
     }
+    numpixels++; /* include endpoints */
 
     x = x1;
     y = y1;
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.