changeset 717:451fde45e116

Slightly optimize h/v-line routines.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 18 Apr 2013 00:01:50 +0300
parents 24096d1ef794
children 324374ced543 bb14d7907eb2
files dmgfx.c
diffstat 1 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/dmgfx.c	Wed Apr 17 21:54:34 2013 +0300
+++ b/dmgfx.c	Thu Apr 18 00:01:50 2013 +0300
@@ -14,7 +14,6 @@
 
 void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col)
 {
-    int x;
     const int bpp = screen->format->BytesPerPixel,
               cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y,
               cx1 = screen->clip_rect.x + screen->clip_rect.w - 1,
@@ -25,19 +24,20 @@
     if (x0 < cx0) x0 = cx0;
     if (x1 > cx1) x1 = cx1;
     
+    int x = x1 - x0 + 1;
     Uint8 *pix = screen->pixels + yc * screen->pitch + (x0 * bpp);
     switch (screen->format->BitsPerPixel)
     {
         case 8:
-            for (x = x0; x <= x1; x++)
+            while (x--)
                 *pix++ = col;
             break;
         
         case 32:
             {
-            Uint32 *p = (Uint32 *) pix;
-            for (x = x0; x <= x1; x++)
-                *p++ = col;
+                Uint32 *p = (Uint32 *) pix;
+                while (x--)
+                    *p++ = col;
             }
             break;
     }
@@ -46,7 +46,6 @@
 
 void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col)
 {
-    int y;
     const int bpp = screen->format->BytesPerPixel,
               pitch = screen->pitch / bpp,
               cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y,
@@ -58,19 +57,26 @@
     if (y0 < cy0) y0 = cy0;
     if (y1 > cy1) y1 = cy1;
 
+    int y = y1 - y0 + 1;
     Uint8 *pix = screen->pixels + y0 * screen->pitch + (xc * bpp);
     switch (screen->format->BitsPerPixel)
     {
         case 8:
-            for (y = y0; y <= y1; y++, pix += pitch)
+            while (y--)
+            {
                 *pix = col;
+                pix += pitch;
+            }
             break;
         
         case 32:
             {
-            Uint32 *p = (Uint32 *) pix;
-            for (y = y0; y <= y1; y++, p += pitch)
-                *p = col;
+                Uint32 *p = (Uint32 *) pix;
+                while (y--)
+                {
+                    *p = col;
+                    p += pitch;
+                }
             }
             break;
     }