Initial support for 1BPP
authorJason Filby <jason.filby@gmail.com>
Fri, 13 Sep 2002 20:36:06 +0000 (20:36 +0000)
committerJason Filby <jason.filby@gmail.com>
Fri, 13 Sep 2002 20:36:06 +0000 (20:36 +0000)
svn path=/trunk/; revision=3500

reactos/subsys/win32k/dib/dib.h
reactos/subsys/win32k/dib/dib1bpp.c [new file with mode: 0644]
reactos/subsys/win32k/dib/dib24bpp.c
reactos/subsys/win32k/dib/dib4bpp.c
reactos/subsys/win32k/makefile
reactos/subsys/win32k/misc/math.c

index 72bdff1..cdc0323 100644 (file)
@@ -1,11 +1,21 @@
 static unsigned char notmask[2] = { 0x0f, 0xf0 };
 static unsigned char altnotmask[2] = { 0xf0, 0x0f };
+static unsigned char mask1Bpp[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
 
 typedef VOID  (*PFN_DIB_PutPixel)(PSURFOBJ, LONG, LONG, ULONG);
 typedef ULONG (*PFN_DIB_GetPixel)(PSURFOBJ, LONG, LONG);
 typedef VOID  (*PFN_DIB_HLine)   (PSURFOBJ, LONG, LONG, LONG, ULONG);
 typedef VOID  (*PFN_DIB_VLine)   (PSURFOBJ, LONG, LONG, LONG, ULONG);
 
+PFN_DIB_PutPixel DIB_1BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c);
+PFN_DIB_GetPixel DIB_1BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y);
+PFN_DIB_HLine DIB_1BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c);
+PFN_DIB_VLine DIB_1BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c);
+BOOLEAN DIB_To_1BPP_Bitblt(  SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
+        SURFGDI *DestGDI,  SURFGDI *SourceGDI,
+        PRECTL  DestRect,  POINTL  *SourcePoint,
+                            ULONG   Delta,     XLATEOBJ *ColorTranslation);
+
 PFN_DIB_PutPixel DIB_4BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c);
 PFN_DIB_GetPixel DIB_4BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y);
 PFN_DIB_HLine DIB_4BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c);
diff --git a/reactos/subsys/win32k/dib/dib1bpp.c b/reactos/subsys/win32k/dib/dib1bpp.c
new file mode 100644 (file)
index 0000000..eafc4e5
--- /dev/null
@@ -0,0 +1,122 @@
+#undef WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <stdlib.h>
+#include <win32k/bitmaps.h>
+#include <win32k/debug.h>
+#include <debug.h>
+#include <ddk/winddi.h>
+#include "../eng/objects.h"
+#include "dib.h"
+
+PFN_DIB_PutPixel DIB_1BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c)
+{
+  unsigned char *vp;
+  unsigned char mask;
+  PBYTE addr = SurfObj->pvBits;
+
+  addr += y * SurfObj->lDelta + (x >> 3);
+
+  if(c == 1)
+  {
+    *addr = (*addr | mask1Bpp[mod(x, 8)]);
+  }
+    else
+  {
+    *addr = (*addr ^ mask1Bpp[mod(x, 8)]);
+  }
+}
+
+PFN_DIB_GetPixel DIB_1BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y)
+{
+  PBYTE addr = SurfObj->pvBits + y * SurfObj->lDelta + (x >> 3);
+
+  if(*addr & mask1Bpp[mod(x, 8)]) return (PFN_DIB_GetPixel)(1);
+  return (PFN_DIB_GetPixel)(0);
+}
+
+PFN_DIB_HLine DIB_1BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
+{
+  LONG  cx = x1;
+
+  while(cx <= x2) {
+    DIB_1BPP_PutPixel(SurfObj, cx, y, c);
+  }
+}
+
+PFN_DIB_VLine DIB_1BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
+{
+  while(y1++ <= y2) {
+    DIB_1BPP_PutPixel(SurfObj, x, y1, c);
+  }
+}
+
+BOOLEAN DIB_To_1BPP_Bitblt(  SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
+        SURFGDI *DestGDI,  SURFGDI *SourceGDI,
+        PRECTL  DestRect,  POINTL  *SourcePoint,
+        ULONG   Delta,     XLATEOBJ *ColorTranslation)
+{
+  ULONG    i, j, sx, sy = SourcePoint->y;
+
+  switch(SourceGDI->BitsPerPixel)
+  {
+    case 1:
+      for (j=DestRect->top; j<DestRect->bottom; j++)
+      {
+        sx = SourcePoint->x;
+        for (i=DestRect->left; i<DestRect->right; i++)
+        {
+          if(DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0)
+          {
+            DIB_1BPP_PutPixel(DestSurf, i, j, 0);
+          } else {
+            DIB_1BPP_PutPixel(DestSurf, i, j, 1);
+          }
+          sx++;
+        }
+        sy++;
+      }
+      break;
+
+    case 4:
+      for (j=DestRect->top; j<DestRect->bottom; j++)
+      {
+        sx = SourcePoint->x;
+        for (i=DestRect->left; i<DestRect->right; i++)
+        {
+          if(XLATEOBJ_iXlate(ColorTranslation, DIB_4BPP_GetPixel(SourceSurf, sx, sy)) == 0)
+          {
+            DIB_1BPP_PutPixel(DestSurf, i, j, 0);
+          } else {
+            DIB_1BPP_PutPixel(DestSurf, i, j, 1);
+          }
+          sx++;
+        }
+        sy++;
+      }
+      break;
+
+    case 24:
+      for (j=DestRect->top; j<DestRect->bottom; j++)
+      {
+        sx = SourcePoint->x;
+        for (i=DestRect->left; i<DestRect->right; i++)
+        {
+          if(XLATEOBJ_iXlate(ColorTranslation, DIB_24BPP_GetPixel(SourceSurf, sx, sy)) == 0)
+          {
+            DIB_1BPP_PutPixel(DestSurf, i, j, 0);
+          } else {
+            DIB_1BPP_PutPixel(DestSurf, i, j, 1);
+          }
+          sx++;
+        }
+        sy++;
+      }
+      break;
+
+    default:
+      DbgPrint("DIB_1BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
+      return FALSE;
+  }
+
+  return TRUE;
+}
index e4f6ec1..f5bab13 100644 (file)
@@ -88,7 +88,7 @@ BOOLEAN DIB_To_24BPP_Bitblt(  SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
         PRECTL  DestRect,  POINTL  *SourcePoint,
         ULONG   Delta,     XLATEOBJ *ColorTranslation)
 {
-  ULONG    i, j, sx, xColor, f1;
+  ULONG    i, j, sx, sy, xColor, f1;
   PBYTE    DestBits, SourceBits_24BPP, DestLine, SourceLine_24BPP;
   PRGBTRIPLE  SPDestBits, SPSourceBits_24BPP, SPDestLine, SPSourceLine_24BPP; // specially for 24-to-24 blit
   PBYTE    SourceBits_4BPP, SourceBits_8BPP, SourceLine_4BPP, SourceLine_8BPP;
@@ -99,6 +99,27 @@ BOOLEAN DIB_To_24BPP_Bitblt(  SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
 
   switch(SourceGDI->BitsPerPixel)
   {
+    case 1:
+      sx = SourcePoint->x;
+      sy = SourcePoint->y;
+
+      for (j=DestRect->top; j<DestRect->bottom; j++)
+      {
+        sx = SourcePoint->x;
+        for (i=DestRect->left; i<DestRect->right; i++)
+        {
+          if(DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0)
+          {
+            DIB_24BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 0));
+          } else {
+            DIB_24BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 1));
+          }
+          sx++;
+        }
+        sy++;
+      }
+      break;
+
     case 4:
       SourceBits_4BPP = SourceSurf->pvBits + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x;
 
index 7b5f707..dc38a2f 100644 (file)
@@ -55,7 +55,7 @@ BOOLEAN DIB_To_4BPP_Bitblt(  SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
         PRECTL  DestRect,  POINTL  *SourcePoint,
         ULONG   Delta,     XLATEOBJ *ColorTranslation)
 {
-  ULONG    i, j, sx, f1, f2, xColor;
+  ULONG    i, j, sx, sy, f1, f2, xColor;
   PBYTE    SourceBits_24BPP, SourceLine_24BPP;
   PBYTE    DestBits, DestLine, SourceBits_4BPP, SourceBits_8BPP, SourceLine_4BPP, SourceLine_8BPP;
   PWORD    SourceBits_16BPP, SourceLine_16BPP;
@@ -65,6 +65,27 @@ BOOLEAN DIB_To_4BPP_Bitblt(  SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
 
   switch(SourceGDI->BitsPerPixel)
   {
+    case 1:
+      sx = SourcePoint->x;
+      sy = SourcePoint->y;
+
+      for (j=DestRect->top; j<DestRect->bottom; j++)
+      {
+        sx = SourcePoint->x;
+        for (i=DestRect->left; i<DestRect->right; i++)
+        {
+          if(DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0)
+          {
+            DIB_4BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 0));
+          } else {
+            DIB_4BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 1));
+          }
+          sx++;
+        }
+        sy++;
+      }
+      break;
+
     case 4:
       SourceBits_4BPP = SourceSurf->pvBits + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x;
 
index 58f3198..ad4fa09 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: makefile,v 1.51 2002/09/08 10:23:48 chorns Exp $
+# $Id: makefile,v 1.52 2002/09/13 20:36:05 jfilby Exp $
 
 PATH_TO_TOP = ../..
 
@@ -40,7 +40,7 @@ OBJECTS_OBJECTS = objects/bitmaps.o objects/brush.o objects/cliprgn.o  \
                   objects/region.o objects/text.o objects/wingl.o \
                   objects/bezier.o objects/objconv.o objects/dib.o \
                  objects/palette.o objects/rect.o
-DIB_OBJECTS = dib/dib4bpp.o dib/dib24bpp.o
+DIB_OBJECTS = dib/dib1bpp.o dib/dib4bpp.o dib/dib24bpp.o
 FREETYPE_OBJECTS = freetype/ctype.o freetype/grfont.o \
                freetype/src/base/ftsystem.o freetype/src/base/ftdebug.o \
                freetype/src/base/ftinit.o freetype/src/base/ftbase.o \
index e5e6f0b..ca4c659 100644 (file)
@@ -19,6 +19,7 @@
    Boston, MA 02111-1307, USA.  */
 
 #include <windows.h>
+#include <stdlib.h>
 
 double atan (double __x);
 double atan2 (double __y, double __x);
@@ -33,7 +34,8 @@ double pow (double __x, double __y);
 double sin (double __x);
 double sqrt (double __x);
 double tan (double __x);
-
+div_t div(int num, int denom);
+int mod(int num, int denom);
 
 double atan (double __x)
 {
@@ -209,6 +211,32 @@ double tan (double __x)
   return __value;
 }
 
+div_t div(int num, int denom)
+{
+  div_t r;
+  if (num > 0 && denom < 0) {
+    num = -num;
+    denom = -denom;
+  }
+  r.quot = num / denom;
+  r.rem = num % denom;
+  if (num < 0 && denom > 0)
+  {
+    if (r.rem > 0)
+    {
+      r.quot++;
+      r.rem -= denom;
+    }
+  }
+  return r;
+}
+
+int mod(int num, int denom)
+{
+  div_t dvt = div(num, denom);
+  return dvt.rem;
+}
+
 //FIXME! Is there a better algorithm. like FT_MulDiv
 INT STDCALL EngMulDiv(
             INT nMultiplicand,