Improved HLine algorithm; improvement carried over to FillSolid
authorJason Filby <jason.filby@gmail.com>
Mon, 19 Aug 2002 22:01:12 +0000 (22:01 +0000)
committerJason Filby <jason.filby@gmail.com>
Mon, 19 Aug 2002 22:01:12 +0000 (22:01 +0000)
svn path=/trunk/; revision=3370

reactos/drivers/dd/vga/display/main/enable.c
reactos/drivers/dd/vga/display/objects/paint.c
reactos/drivers/dd/vga/display/vgavideo/vgavideo.c

index 57deba4..3bd357f 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * entry.c
  *
- * $Revision: 1.18 $
- * $Author: ekohl $
- * $Date: 2002/06/15 14:57:26 $
+ * $Revision: 1.19 $
+ * $Author: jfilby $
+ * $Date: 2002/08/19 22:01:11 $
  *
  */
 
@@ -202,13 +202,14 @@ DrvAssertMode(IN DHPDEV DPev,
     }
 
   }
+
 }
 
 
 VOID STDCALL
 DrvDisablePDEV(IN DHPDEV PDev)
 {
-  PPDEV ppdev = (PPDEV)PDev;
+  PPDEV ppdev = (PPDEV)PDev;\r
 
   // EngDeletePalette(devinfoVGA.hpalDefault);
   if (ppdev->pjPreallocSSBBuffer != NULL)
index 8193b49..f50ab17 100644 (file)
@@ -10,9 +10,11 @@ BOOL VGADDIFillSolid(SURFOBJ *Surface, RECTL Dimensions, ULONG iColor)
   int x, y, x2, y2, w, h;
   ULONG offset, i, j, pre1;
   ULONG orgpre1, orgx, midpre1, tmppre1;
-  ULONG long leftpixs, midpixs, rightpixs, temp;
+  ULONG ileftpix, imidpix, irightpix;
+  double leftpix, midpix, rightpix, temp;
   UCHAR a;
 
+  DPRINT("VGADDIFillSolid: x:%d, y:%d, w:%d, h:%d\n", x, y, w, h);
 
   // Swap dimensions so that x, y are at topmost left
   if(Dimensions.right < Dimensions.left) {
@@ -33,7 +35,6 @@ BOOL VGADDIFillSolid(SURFOBJ *Surface, RECTL Dimensions, ULONG iColor)
   // Calculate the width and height
   w = x2 - x;
   h = y2 - y;
-  DPRINT("VGADDIFillSolid: x:%d, y:%d, w:%d, h:%d, color: %d\n", x, y, w, h, iColor);
 
   // Calculate the starting offset
   offset = xconv[x]+y80[y];
@@ -50,33 +51,23 @@ BOOL VGADDIFillSolid(SURFOBJ *Surface, RECTL Dimensions, ULONG iColor)
   // Otherwise, use the optimized code
   } else {
 
-    leftpixs=x;
-    while(leftpixs>8) leftpixs-=8;
-    temp = w;
-    midpixs = 0;
+    // Calculate the left mask pixels, middle bytes and right mask pixel
+    leftpix = 8-mod(x, 8);
+    rightpix = mod(x+w, 8);
+    midpix = (w-leftpix-rightpix) / 8;
 
-    // Determine the number of bytes we can write (all 8 bits of the byte mask)
-    while(temp>7)
-    {
-      temp-=8;
-      midpixs++;
-    }
-    if((temp>=0) && (midpixs>0)) midpixs--;
+    ileftpix = leftpix;
+    irightpix = rightpix;
+    imidpix = midpix;
 
-    pre1=xconv[x]+y80[y];
+    pre1=xconv[x-(8-ileftpix)]+y80[y];
     orgpre1=pre1;
 
-    // Left
-    if(leftpixs==8) {
-      // Left edge should be an entire middle bar
-      x=orgx;
-      leftpixs=0;
-    }
-    else if(leftpixs>0)
+    if(ileftpix>0)
     {
       // Write left pixels
       WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08);     // set the mask
-      WRITE_PORT_UCHAR((PUCHAR)0x3cf,startmasks[leftpixs]);
+      WRITE_PORT_UCHAR((PUCHAR)0x3cf,startmasks[ileftpix]);
 
       tmppre1 = pre1;
       for (j=y; j<y+h; j++)
@@ -86,63 +77,38 @@ BOOL VGADDIFillSolid(SURFOBJ *Surface, RECTL Dimensions, ULONG iColor)
         tmppre1+=80;
       }
 
-      // Middle
-
-      x=orgx+(8-leftpixs)+leftpixs;
-
-    } else {
-      // leftpixs == 0
-      midpixs+=1;
+      // Prepare new x for the middle
+      x=orgx+8;
     }
 
-    if(midpixs>0)
+    if(imidpix>0)
     {
       midpre1=xconv[x]+y80[y];
 
       // Set mask to all pixels in byte
       WRITE_PORT_UCHAR((PUCHAR)0x3ce, 0x08);
+
       WRITE_PORT_UCHAR((PUCHAR)0x3cf, 0xff);
 
       for (j=y; j<y+h; j++)
       {
-        memset(vidmem+midpre1, iColor, midpixs); // write middle pixels, no need to read in latch because of the width
+        memset(vidmem+midpre1, iColor, imidpix); // write middle pixels, no need to read in latch because of the width
         midpre1+=80;
       }
     }
 
-    rightpixs = w - ((midpixs*8) + leftpixs);
-
-    if((rightpixs>0))
-    {
-      x=(orgx+w)-rightpixs;
-
-      // Go backwards till we reach the 8-byte boundary
-      while(mod(x, 8)!=0) { x--; rightpixs++; }
-
-      while(rightpixs>7)
-      {
-        // This is a BAD case as this should have been a midpixs
-
-        for (j=y; j<y+h; j++)
-        {
-          vgaPutByte(x, j, iColor);
-        }
-        rightpixs-=8;
-        x+=8;
-      }
-
-      pre1=xconv[x]+y80[y];
+    x=orgx+w-irightpix;
+    pre1=xconv[x]+y80[y];
 
-      // Write right pixels
-      WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08);     // set the mask bits
-      WRITE_PORT_UCHAR((PUCHAR)0x3cf,endmasks[rightpixs]);
+    // Write right pixels
+    WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08);     // set the mask bits
+    WRITE_PORT_UCHAR((PUCHAR)0x3cf,endmasks[irightpix]);
 
-      for (j=y; j<y+h; j++)
-      {
-        a = READ_REGISTER_UCHAR(vidmem + pre1);
-        WRITE_REGISTER_UCHAR(vidmem + pre1, iColor);
-        pre1+=80;
-      }
+    for (j=y; j<y+h; j++)
+    {
+      a = READ_REGISTER_UCHAR(vidmem + pre1);
+      WRITE_REGISTER_UCHAR(vidmem + pre1, iColor);
+      pre1+=80;
     }
   }
 
index a42d4d0..34c5090 100644 (file)
@@ -80,13 +80,14 @@ VOID vgaPreCalc()
 {
   ULONG j;
 
-  startmasks[1] = 127;
-  startmasks[2] = 63;
-  startmasks[3] = 31;
+  startmasks[0] = 255;
+  startmasks[1] = 1;
+  startmasks[2] = 3;
+  startmasks[3] = 7;
   startmasks[4] = 15;
-  startmasks[5] = 7;
-  startmasks[6] = 3;
-  startmasks[7] = 1;
+  startmasks[5] = 31;
+  startmasks[6] = 63;
+  startmasks[7] = 127;
   startmasks[8] = 255;
 
   endmasks[0] = 128;
@@ -226,7 +227,8 @@ BOOL vgaHLine(INT x, INT y, INT len, UCHAR c)
   UCHAR a;
   ULONG pre1, i;
   ULONG orgpre1, orgx, midpre1;
-  ULONG long leftpixs, midpixs, rightpixs, temp;
+  ULONG ileftpix, imidpix, irightpix;
+  double leftpix, midpix, rightpix, temp;
 
   orgx=x;
 
@@ -236,81 +238,51 @@ BOOL vgaHLine(INT x, INT y, INT len, UCHAR c)
       vgaPutPixel(i, y, c);
   } else {
 
-    leftpixs=x;
-    while(leftpixs>8) leftpixs-=8;
-    temp = len;
-    midpixs = 0;
+    // Calculate the left mask pixels, middle bytes and right mask pixel
+    leftpix = 8-mod(x, 8);
+    rightpix = mod(x+len, 8);
+    midpix = (len-leftpix-rightpix) / 8;
 
-    while(temp>7)
-    {
-      temp-=8;
-      midpixs++;
-    }
-    if((temp>=0) && (midpixs>0)) midpixs--;
+    ileftpix = leftpix;
+    irightpix = rightpix;
+    imidpix = midpix;
 
-    pre1=xconv[x]+y80[y];
+    pre1=xconv[x-(8-ileftpix)]+y80[y];
     orgpre1=pre1;
 
     // Left
-    if(leftpixs==8) {
-      // Left edge should be an entire middle bar
-      x=orgx;
-      leftpixs=0;
-    }
-    else if(leftpixs>0)
+    if(ileftpix>0)
     {
       // Write left pixels
       WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08);     // set the mask
-      WRITE_PORT_UCHAR((PUCHAR)0x3cf,startmasks[leftpixs]);
+      WRITE_PORT_UCHAR((PUCHAR)0x3cf,startmasks[ileftpix]);
 
       a = READ_REGISTER_UCHAR(vidmem + pre1);
       WRITE_REGISTER_UCHAR(vidmem + pre1, c);
 
-      // Middle
-      x=orgx+(8-leftpixs)+leftpixs;
-
-    } else {
-      // leftpixs == 0
-      midpixs+=1;
+      // Prepare new x for the middle
+      x=orgx+8;
     }
 
-    if(midpixs>0)
+    if(imidpix>0)
     {
       midpre1=xconv[x]+y80[y];
 
       // Set mask to all pixels in byte
       WRITE_PORT_UCHAR((PUCHAR)0x3ce, 0x08);
       WRITE_PORT_UCHAR((PUCHAR)0x3cf, 0xff);
-      memset(vidmem+midpre1, c, midpixs); // write middle pixels, no need to read in latch because of the width
+      memset(vidmem+midpre1, c, imidpix); // write middle pixels, no need to read in latch because of the width
     }
 
-    rightpixs = len - ((midpixs*8) + leftpixs);
-
-    if((rightpixs>0))
-    {
-      x=(orgx+len)-rightpixs;
-
-      // Go backwards till we reach the 8-byte boundary
-      while(mod(x, 8)!=0) { x--; rightpixs++; }
-
-      while(rightpixs>7)
-      {
-        // This is a BAD case as this should have been a midpixs
-
-        vgaPutByte(x, y, c);
-        rightpixs-=8;
-        x+=8;
-      }
-
-      pre1=xconv[x]+y80[y];
+    x=orgx+len-irightpix;
+    pre1=xconv[x]+y80[y];
 
-      // Write right pixels
-      WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08);     // set the mask bits
-      WRITE_PORT_UCHAR((PUCHAR)0x3cf,endmasks[rightpixs]);
+    // Write right pixels
+    WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08);     // set the mask bits
+    WRITE_PORT_UCHAR((PUCHAR)0x3cf, endmasks[irightpix]);
 
-      a = READ_REGISTER_UCHAR(vidmem + pre1);
-      WRITE_REGISTER_UCHAR(vidmem + pre1, c);
-    }
+    a = READ_REGISTER_UCHAR(vidmem + pre1);
+    WRITE_REGISTER_UCHAR(vidmem + pre1, c);
   }
 
   return TRUE;
@@ -439,6 +411,7 @@ void DIB_BltToVGA(int x, int y, int w, int h, void *b, int Source_lDelta)
     }
 
     opb += Source_lDelta;
+
     pb = opb;
 
   }
@@ -686,6 +659,7 @@ void DFB_BltToDIB(int x, int y, int w, int h, void *b, int bw, void *bdib, int d
   }
 }
 
+
 void DIB_BltToDFB(int x, int y, int w, int h, void *b, int bw, void *bdib, int dibw)
 
 // This algorithm converts a DIB into a DFB