Add generation of 8bpp DIB code
Modified: trunk/reactos/subsys/win32k/dib/dib8bpp.c
Modified: trunk/reactos/subsys/win32k/win32k.xml
Modified: trunk/reactos/tools/gendib/gendib.c
Modified: trunk/reactos/tools/gendib/gendib.mak

Modified: trunk/reactos/subsys/win32k/dib/dib8bpp.c
--- trunk/reactos/subsys/win32k/dib/dib8bpp.c	2005-08-19 19:05:59 UTC (rev 17440)
+++ trunk/reactos/subsys/win32k/dib/dib8bpp.c	2005-08-19 20:56:01 UTC (rev 17441)
@@ -252,114 +252,17 @@
   return TRUE;
 }
 
-BOOLEAN
-DIB_8BPP_BitBlt(PBLTINFO BltInfo)
-{
-   ULONG DestX, DestY;
-   ULONG SourceX, SourceY;
-   ULONG PatternY = 0;
-   ULONG Dest, Source = 0, Pattern = 0;
-   BOOL UsesSource;
-   BOOL UsesPattern;
-   PULONG DestBits;
-   LONG RoundedRight;
-
-   UsesSource = ROP4_USES_SOURCE(BltInfo->Rop4);
-   UsesPattern = ROP4_USES_PATTERN(BltInfo->Rop4);
-
-   SourceY = BltInfo->SourcePoint.y;
-   RoundedRight = BltInfo->DestRect.right -
-                  ((BltInfo->DestRect.right - BltInfo->DestRect.left) & 0x7);
-
-   if (UsesPattern)
-   {
-      if (BltInfo->PatternSurface)
-      {
-         PatternY = (BltInfo->DestRect.top + BltInfo->BrushOrigin.y) %
-                    BltInfo->PatternSurface->sizlBitmap.cy;
-      }
-      else
-      {
-         Pattern = BltInfo->Brush->iSolidColor |
-                   (BltInfo->Brush->iSolidColor << 8) |
-                   (BltInfo->Brush->iSolidColor << 16) |
-                   (BltInfo->Brush->iSolidColor << 24);
-      }
-   }
-
-   for (DestY = BltInfo->DestRect.top; DestY < BltInfo->DestRect.bottom; DestY++)
-   {
-      SourceX = BltInfo->SourcePoint.x;
-      DestBits = (PULONG)(
-         (PBYTE)BltInfo->DestSurface->pvScan0 +
-         BltInfo->DestRect.left +
-         DestY * BltInfo->DestSurface->lDelta);
-
-      for (DestX = BltInfo->DestRect.left; DestX < RoundedRight; DestX += 4, DestBits++)
-      {
-         Dest = *DestBits;
-
-         if (UsesSource)
-         {
-            Source = DIB_GetSource(BltInfo->SourceSurface, SourceX + (DestX - BltInfo->DestRect.left), SourceY, BltInfo->XlateSourceToDest);
-            Source |= DIB_GetSource(BltInfo->SourceSurface, SourceX + (DestX - BltInfo->DestRect.left) + 1, SourceY, BltInfo->XlateSourceToDest) << 8;
-            Source |= DIB_GetSource(BltInfo->SourceSurface, SourceX + (DestX - BltInfo->DestRect.left) + 2, SourceY, BltInfo->XlateSourceToDest) << 16;
-            Source |= DIB_GetSource(BltInfo->SourceSurface, SourceX + (DestX - BltInfo->DestRect.left) + 3, SourceY, BltInfo->XlateSourceToDest) << 24;
-         }
-
-         if (BltInfo->PatternSurface)
-         {
-            Pattern = DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest);
-            Pattern |= DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 1) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest) << 8;
-            Pattern |= DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 2) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest) << 16;
-            Pattern |= DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 3) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest) << 24;
-         }
-
-         *DestBits = DIB_DoRop(BltInfo->Rop4, Dest, Source, Pattern);
-      }
-
-      if (DestX < BltInfo->DestRect.right)
-      {
-         for (; DestX < BltInfo->DestRect.right; DestX++)
-         {
-            Dest = DIB_8BPP_GetPixel(BltInfo->DestSurface, DestX, DestY);
-
-            if (UsesSource)
-	    {
-               Source = DIB_GetSource(BltInfo->SourceSurface, SourceX + (DestX - BltInfo->DestRect.left), SourceY, BltInfo->XlateSourceToDest);
-            }
-
-            if (BltInfo->PatternSurface)
-            {
-               Pattern = DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest);
-            }
-
-            DIB_8BPP_PutPixel(BltInfo->DestSurface, DestX, DestY, DIB_DoRop(BltInfo->Rop4, Dest, Source, Pattern) & 0xFFFF);
-         }
-      }
-
-      SourceY++;
-      if (BltInfo->PatternSurface)
-      {
-         PatternY++;
-         PatternY %= BltInfo->PatternSurface->sizlBitmap.cy;
-      }
-   }
-
-   return TRUE;
-}
-
 /* BitBlt Optimize */
 BOOLEAN 
 DIB_8BPP_ColorFill(SURFOBJ* DestSurface, RECTL* DestRect, ULONG color)
 {			 
   ULONG DestY;			
-	for (DestY = DestRect->top; DestY< DestRect->bottom; DestY++)
-  {
-    DIB_8BPP_HLine (DestSurface, DestRect->left, DestRect->right, DestY, color);
-  }
+  for (DestY = DestRect->top; DestY< DestRect->bottom; DestY++)
+    {
+      DIB_8BPP_HLine(DestSurface, DestRect->left, DestRect->right, DestY, color);
+    }
 	
-	return TRUE;
+  return TRUE;
 }
 /*
 =======================================

Modified: trunk/reactos/subsys/win32k/win32k.xml
--- trunk/reactos/subsys/win32k/win32k.xml	2005-08-19 19:05:59 UTC (rev 17440)
+++ trunk/reactos/subsys/win32k/win32k.xml	2005-08-19 20:56:01 UTC (rev 17441)
@@ -14,6 +14,7 @@
 		<file>dib1bpp.c</file>
 		<file>dib4bpp.c</file>
 		<file>dib8bpp.c</file>
+		<file>dib8gen.c</file>
 		<file>dib16bpp.c</file>
 		<file>dib16gen.c</file>
 		<file>dib24bpp.c</file>

Modified: trunk/reactos/tools/gendib/gendib.c
--- trunk/reactos/tools/gendib/gendib.c	2005-08-19 19:05:59 UTC (rev 17440)
+++ trunk/reactos/tools/gendib/gendib.c	2005-08-19 20:56:01 UTC (rev 17441)
@@ -263,11 +263,16 @@
       Cast = "";
       Dest = "*DestPtr";
     }
-  else
+  else if (16 == Bpp)
     {
       Cast = "(USHORT) ";
       Dest = "*((PUSHORT) DestPtr)";
     }
+  else
+    {
+      Cast = "(UCHAR) ";
+      Dest = "*((PUCHAR) DestPtr)";
+    }
   Output(Out, "%s = ", Dest);
   if (ROPCODE_GENERIC == RopInfo->RopCode)
     {
@@ -448,11 +453,24 @@
   MARK(Out);
   if (32 != Bpp)
     {
-      Output(Out, "LeftCount = ((ULONG_PTR) DestBase >> 1) & 0x01;\n");
+      if (8 < Bpp)
+        {
+          Output(Out, "LeftCount = ((ULONG_PTR) DestBase >> 1) & 0x01;\n");
+        }
+      else
+        {
+          Output(Out, "LeftCount = (ULONG_PTR) DestBase & 0x03;\n");
+          Output(Out, "if (BltInfo->DestRect.right - BltInfo->DestRect.left < "
+                      "LeftCount)\n");
+          Output(Out, "{\n");
+          Output(Out, "LeftCount = BltInfo->DestRect.right - "
+                      "BltInfo->DestRect.left;\n");
+          Output(Out, "}\n");
+        }
       Output(Out, "CenterCount = (BltInfo->DestRect.right - BltInfo->DestRect.left -\n");
-      Output(Out, "               LeftCount) / 2;\n");
+      Output(Out, "               LeftCount) / %u;\n", 32 / Bpp);
       Output(Out, "RightCount = (BltInfo->DestRect.right - BltInfo->DestRect.left -\n");
-      Output(Out, "              LeftCount - 2 * CenterCount);\n");
+      Output(Out, "              LeftCount - %u * CenterCount);\n", 32 / Bpp);
     }
   else
     {
@@ -461,6 +479,36 @@
 }
 
 static void
+CreateSetSinglePixel(FILE *Out, unsigned Bpp, PROPINFO RopInfo, int Flags,
+                     unsigned SourceBpp)
+{
+  if (RopInfo->UsesSource && 0 == (Flags & FLAG_FORCENOUSESSOURCE))
+    {
+      CreateGetSource(Out, Bpp, RopInfo, Flags, SourceBpp, 0);
+      MARK(Out);
+    }
+  if (RopInfo->UsesPattern && 0 != (Flags & FLAG_PATTERNSURFACE))
+    {
+      Output(Out, "Pattern = DIB_GetSource(BltInfo->PatternSurface, PatternX, PatternY, BltInfo->XlatePatternToDest);\n");
+      Output(Out, "if (BltInfo->PatternSurface->sizlBitmap.cx <= ++PatternX)\n");
+      Output(Out, "{\n");
+      Output(Out, "PatternX -= BltInfo->PatternSurface->sizlBitmap.cx;\n");
+      Output(Out, "}\n");
+    }
+  if ((RopInfo->UsesSource && 0 == (Flags & FLAG_FORCENOUSESSOURCE) &&
+       Bpp != SourceBpp) ||
+      (RopInfo->UsesPattern && 0 != (Flags & FLAG_PATTERNSURFACE)))
+    {
+      Output(Out, "\n");
+    }
+  CreateOperation(Out, Bpp, RopInfo, SourceBpp, 16);
+  Output(Out, ";\n");
+  MARK(Out);
+  Output(Out, "\n");
+  Output(Out, "DestPtr = (PULONG)((char *) DestPtr + %u);\n", Bpp / 8);
+}
+
+static void
 CreateBitCase(FILE *Out, unsigned Bpp, PROPINFO RopInfo, int Flags,
               unsigned SourceBpp)
 {
@@ -536,33 +584,19 @@
       Output(Out, "\n");
       if (32 != Bpp)
         {
-          Output(Out, "if (0 != LeftCount)\n");
-          Output(Out, "{\n");
-          if (RopInfo->UsesSource && 0 == (Flags & FLAG_FORCENOUSESSOURCE))
+          if (16 == Bpp)
             {
-              CreateGetSource(Out, Bpp, RopInfo, Flags | FLAG_FORCERAWSOURCEAVAIL,
-                              SourceBpp, 0);
-              MARK(Out);
+            Output(Out, "if (0 != LeftCount)\n");
             }
-          if (RopInfo->UsesPattern && 0 != (Flags & FLAG_PATTERNSURFACE))
+          else
             {
-              Output(Out, "Pattern = DIB_GetSource(BltInfo->PatternSurface, PatternX, PatternY, BltInfo->XlatePatternToDest);\n");
-              Output(Out, "if (BltInfo->PatternSurface->sizlBitmap.cx <= ++PatternX)\n");
-              Output(Out, "{\n");
-              Output(Out, "PatternX -= BltInfo->PatternSurface->sizlBitmap.cx;\n");
-              Output(Out, "}\n");
+            Output(Out, "for (i = 0; i < LeftCount; i++)\n");
             }
-          if ((RopInfo->UsesSource && 0 == (Flags & FLAG_FORCENOUSESSOURCE) &&
-               Bpp != SourceBpp) ||
-              (RopInfo->UsesPattern && 0 != (Flags & FLAG_PATTERNSURFACE)))
-            {
-              Output(Out, "\n");
-            }
-          CreateOperation(Out, Bpp, RopInfo, SourceBpp, 16);
-          Output(Out, ";\n");
+          Output(Out, "{\n");
+          CreateSetSinglePixel(Out, Bpp, RopInfo,
+                               (16 == Bpp ? Flags | FLAG_FORCERAWSOURCEAVAIL :
+                               Flags), SourceBpp);
           MARK(Out);
-          Output(Out, "\n");
-          Output(Out, "DestPtr = (PULONG)((char *) DestPtr + 2);\n");
           Output(Out, "}\n");
           Output(Out, "\n");
         }
@@ -606,24 +640,16 @@
       Output(Out, "\n");
       if (32 != Bpp)
         {
-          Output(Out, "if (0 != RightCount)\n");
-          Output(Out, "{\n");
-          if (RopInfo->UsesSource && 0 == (Flags & FLAG_FORCENOUSESSOURCE))
+          if (16 == Bpp)
             {
-              CreateGetSource(Out, Bpp, RopInfo, Flags, SourceBpp, 0);
-              MARK(Out);
+              Output(Out, "if (0 != RightCount)\n");
             }
-          if (RopInfo->UsesPattern && 0 != (Flags & FLAG_PATTERNSURFACE))
+          else
             {
-              Output(Out, "Pattern = DIB_GetSource(BltInfo->PatternSurface, PatternX, PatternY, BltInfo->XlatePatternToDest);\n");
+              Output(Out, "for (i = 0; i < RightCount; i++)\n");
             }
-          if ((RopInfo->UsesSource && 0 == (Flags & FLAG_FORCENOUSESSOURCE)) ||
-              (RopInfo->UsesPattern && 0 != (Flags & FLAG_PATTERNSURFACE)))
-            {
-              Output(Out, "\n");
-            }
-          CreateOperation(Out, Bpp, RopInfo, SourceBpp, 16);
-          Output(Out, ";\n");
+          Output(Out, "{\n");
+          CreateSetSinglePixel(Out, Bpp, RopInfo, Flags, SourceBpp);
           MARK(Out);
           Output(Out, "}\n");
           Output(Out, "\n");
@@ -998,7 +1024,7 @@
 {
   unsigned Index;
   static unsigned DestBpp[] =
-    { 16, 32 };
+    { 8, 16, 32 };
 
   for (Index = 0; Index < sizeof(DestBpp) / sizeof(DestBpp[0]); Index++)
     {

Modified: trunk/reactos/tools/gendib/gendib.mak
--- trunk/reactos/tools/gendib/gendib.mak	2005-08-19 19:05:59 UTC (rev 17440)
+++ trunk/reactos/tools/gendib/gendib.mak	2005-08-19 20:56:01 UTC (rev 17441)
@@ -44,8 +44,9 @@
 GENDIB_DIB_DIR = subsys$(SEP)win32k$(SEP)dib
 
 GENDIB_DIB_FILES = \
+	$(GENDIB_DIB_DIR)$(SEP)dib32gen.c \
 	$(GENDIB_DIB_DIR)$(SEP)dib16gen.c \
-	$(GENDIB_DIB_DIR)$(SEP)dib32gen.c
+	$(GENDIB_DIB_DIR)$(SEP)dib8gen.c
 
 $(GENDIB_DIB_FILES): $(GENDIB_TARGET)
 	$(ECHO_GENDIB)