fixed working strechblt for all dibxx now. do not say it does not take offset of...
[reactos.git] / reactos / subsys / win32k / dib / dib8bpp.c
index ed7042b..dde6e9e 100644 (file)
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: dib8bpp.c,v 1.21 2004/04/07 15:37:50 weiden Exp $ */
-#undef WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <stdlib.h>
-#include <win32k/bitmaps.h>
-#include <win32k/brush.h>
-#include <win32k/debug.h>
+/* $Id$ */
+
+#include <w32k.h>
+
+#define NDEBUG
 #include <debug.h>
-#include <include/object.h>
-#include <ddk/winddi.h>
-#include "../eng/objects.h"
-#include "dib.h"
 
 VOID
-DIB_8BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c)
+DIB_8BPP_PutPixel(SURFOBJ *SurfObj, LONG x, LONG y, ULONG c)
 {
-  PBYTE byteaddr = SurfObj->pvScan0 + y * SurfObj->lDelta + x;
+  PBYTE byteaddr = (PBYTE)SurfObj->pvScan0 + y * SurfObj->lDelta + x;
 
   *byteaddr = c;
 }
 
 ULONG
-DIB_8BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y)
+DIB_8BPP_GetPixel(SURFOBJ *SurfObj, LONG x, LONG y)
 {
-  PBYTE byteaddr = SurfObj->pvScan0 + y * SurfObj->lDelta + x;
+  PBYTE byteaddr = (PBYTE)SurfObj->pvScan0 + y * SurfObj->lDelta + x;
 
   return (ULONG)(*byteaddr);
 }
 
 VOID
-DIB_8BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
+DIB_8BPP_HLine(SURFOBJ *SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
 {
-  PBYTE byteaddr = SurfObj->pvScan0 + y * SurfObj->lDelta;
-  PBYTE addr = byteaddr + x1;
-  LONG cx = x1;
-
-  while(cx < x2) {
-    *addr = c;
-    ++addr;
-    ++cx;
-  }
+  memset((PBYTE)SurfObj->pvScan0 + y * SurfObj->lDelta + x1, (BYTE) c, x2 - x1);
 }
 
 VOID
-DIB_8BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
+DIB_8BPP_VLine(SURFOBJ *SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
 {
-  PBYTE byteaddr = SurfObj->pvScan0 + y1 * SurfObj->lDelta;
+  PBYTE byteaddr = (PBYTE)SurfObj->pvScan0 + y1 * SurfObj->lDelta;
   PBYTE addr = byteaddr + x;
   LONG lDelta = SurfObj->lDelta;
 
@@ -75,33 +61,30 @@ DIB_8BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
 }
 
 BOOLEAN
-DIB_8BPP_BitBltSrcCopy(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
-                      SURFGDI *DestGDI,  SURFGDI *SourceGDI,
-                      PRECTL  DestRect,  POINTL  *SourcePoint,
-                      XLATEOBJ *ColorTranslation)
+DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
 {
   LONG     i, j, sx, sy, xColor, f1;
   PBYTE    SourceBits, DestBits, SourceLine, DestLine;
   PBYTE    SourceBits_4BPP, SourceLine_4BPP;
 
-  DestBits = DestSurf->pvScan0 + (DestRect->top * DestSurf->lDelta) + DestRect->left;
+  DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 + (BltInfo->DestRect.top * BltInfo->DestSurface->lDelta) + BltInfo->DestRect.left;
 
-  switch(SourceGDI->BitsPerPixel)
+  switch(BltInfo->SourceSurface->iBitmapFormat)
   {
-    case 1:
-      sx = SourcePoint->x;
-      sy = SourcePoint->y;
+    case BMF_1BPP:
+      sx = BltInfo->SourcePoint.x;
+      sy = BltInfo->SourcePoint.y;
 
-      for (j=DestRect->top; j<DestRect->bottom; j++)
+      for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
       {
-        sx = SourcePoint->x;
-        for (i=DestRect->left; i<DestRect->right; i++)
+        sx = BltInfo->SourcePoint.x;
+        for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
         {
-          if(DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0)
+          if(DIB_1BPP_GetPixel(BltInfo->SourceSurface, sx, sy) == 0)
           {
-            DIB_8BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 0));
+            DIB_8BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 0));
           } else {
-            DIB_8BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 1));
+            DIB_8BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 1));
           }
           sx++;
         }
@@ -109,292 +92,178 @@ DIB_8BPP_BitBltSrcCopy(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
       }
       break;
 
-    case 4:
-      SourceBits_4BPP = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + (SourcePoint->x >> 1);
+    case BMF_4BPP:
+      SourceBits_4BPP = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + (BltInfo->SourcePoint.x >> 1);
 
-      for (j=DestRect->top; j<DestRect->bottom; j++)
+      for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
       {
         SourceLine_4BPP = SourceBits_4BPP;
-        sx = SourcePoint->x;
+        sx = BltInfo->SourcePoint.x;
         f1 = sx & 1;
 
-        for (i=DestRect->left; i<DestRect->right; i++)
+        for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
         {
-          xColor = XLATEOBJ_iXlate(ColorTranslation,
+          xColor = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest,
               (*SourceLine_4BPP & altnotmask[f1]) >> (4 * (1 - f1)));
-          DIB_8BPP_PutPixel(DestSurf, i, j, xColor);
+          DIB_8BPP_PutPixel(BltInfo->DestSurface, i, j, xColor);
           if(f1 == 1) { SourceLine_4BPP++; f1 = 0; } else { f1 = 1; }
           sx++;
         }
 
-        SourceBits_4BPP += SourceSurf->lDelta;
+        SourceBits_4BPP += BltInfo->SourceSurface->lDelta;
       }
       break;
 
-    case 8:
-      if (NULL == ColorTranslation || 0 != (ColorTranslation->flXlate & XO_TRIVIAL))
+    case BMF_8BPP:
+      if (NULL == BltInfo->XlateSourceToDest || 0 != (BltInfo->XlateSourceToDest->flXlate & XO_TRIVIAL))
       {
-       if (DestRect->top < SourcePoint->y)
+       if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
          {
-           SourceBits = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x;
-           for (j = DestRect->top; j < DestRect->bottom; j++)
+           SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
+           for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
              {
-               RtlMoveMemory(DestBits, SourceBits, DestRect->right - DestRect->left);
-               SourceBits += SourceSurf->lDelta;
-               DestBits += DestSurf->lDelta;
+               RtlMoveMemory(DestBits, SourceBits, BltInfo->DestRect.right - BltInfo->DestRect.left);
+               SourceBits += BltInfo->SourceSurface->lDelta;
+               DestBits += BltInfo->DestSurface->lDelta;
              }
          }
        else
          {
-           SourceBits = SourceSurf->pvScan0 + ((SourcePoint->y + DestRect->bottom - DestRect->top - 1) * SourceSurf->lDelta) + SourcePoint->x;
-           DestBits = DestSurf->pvScan0 + ((DestRect->bottom - 1) * DestSurf->lDelta) + DestRect->left;
-           for (j = DestRect->bottom - 1; DestRect->top <= j; j--)
+           SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0 + ((BltInfo->SourcePoint.y + BltInfo->DestRect.bottom - BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
+           DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 + ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta) + BltInfo->DestRect.left;
+           for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--)
              {
-               RtlMoveMemory(DestBits, SourceBits, DestRect->right - DestRect->left);
-               SourceBits -= SourceSurf->lDelta;
-               DestBits -= DestSurf->lDelta;
+               RtlMoveMemory(DestBits, SourceBits, BltInfo->DestRect.right - BltInfo->DestRect.left);
+               SourceBits -= BltInfo->SourceSurface->lDelta;
+               DestBits -= BltInfo->DestSurface->lDelta;
              }
          }
       }
       else
       {
-       if (DestRect->top < SourcePoint->y)
+       if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
          {
-           SourceLine = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x;
+           SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
            DestLine = DestBits;
-           for (j = DestRect->top; j < DestRect->bottom; j++)
+           for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
              {
                SourceBits = SourceLine;
                DestBits = DestLine;
-               for (i=DestRect->left; i<DestRect->right; i++)
+               for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
                  {
-                   *DestBits++ = XLATEOBJ_iXlate(ColorTranslation, *SourceBits++);
+                   *DestBits++ = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *SourceBits++);
                  }
-               SourceLine += SourceSurf->lDelta;
-               DestLine += DestSurf->lDelta;
+               SourceLine += BltInfo->SourceSurface->lDelta;
+               DestLine += BltInfo->DestSurface->lDelta;
              }
          }
        else
          {
-           SourceLine = SourceSurf->pvScan0 + ((SourcePoint->y + DestRect->bottom - DestRect->top - 1) * SourceSurf->lDelta) + SourcePoint->x;
-           DestLine = DestSurf->pvScan0 + ((DestRect->bottom - 1) * DestSurf->lDelta) + DestRect->left;
-           for (j = DestRect->bottom - 1; DestRect->top <= j; j--)
+           SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + ((BltInfo->SourcePoint.y + BltInfo->DestRect.bottom - BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
+           DestLine = (PBYTE)BltInfo->DestSurface->pvScan0 + ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta) + BltInfo->DestRect.left;
+           for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--)
              {
                SourceBits = SourceLine;
                DestBits = DestLine;
-               for (i=DestRect->left; i<DestRect->right; i++)
+               for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
                  {
-                   *DestBits++ = XLATEOBJ_iXlate(ColorTranslation, *SourceBits++);
+                   *DestBits++ = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *SourceBits++);
                  }
-               SourceLine -= SourceSurf->lDelta;
-               DestLine -= DestSurf->lDelta;
+               SourceLine -= BltInfo->SourceSurface->lDelta;
+               DestLine -= BltInfo->DestSurface->lDelta;
              }
          }
       }
       break;
 
-    case 16:
-      SourceLine = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + 2 * SourcePoint->x;
+    case BMF_16BPP:
+      SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 2 * BltInfo->SourcePoint.x;
       DestLine = DestBits;
 
-      for (j = DestRect->top; j < DestRect->bottom; j++)
+      for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
       {
         SourceBits = SourceLine;
         DestBits = DestLine;
 
-        for (i = DestRect->left; i < DestRect->right; i++)
+        for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
         {
           xColor = *((PWORD) SourceBits);
-          *DestBits = XLATEOBJ_iXlate(ColorTranslation, xColor);
+          *DestBits = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor);
           SourceBits += 2;
          DestBits += 1;
         }
 
-        SourceLine += SourceSurf->lDelta;
-        DestLine += DestSurf->lDelta;
+        SourceLine += BltInfo->SourceSurface->lDelta;
+        DestLine += BltInfo->DestSurface->lDelta;
       }
       break;
 
-    case 24:
-      SourceLine = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + 3 * SourcePoint->x;
+    case BMF_24BPP:
+      SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 3 * BltInfo->SourcePoint.x;
       DestLine = DestBits;
 
-      for (j = DestRect->top; j < DestRect->bottom; j++)
+      for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
       {
         SourceBits = SourceLine;
         DestBits = DestLine;
 
-        for (i = DestRect->left; i < DestRect->right; i++)
+        for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
         {
           xColor = (*(SourceBits + 2) << 0x10) +
              (*(SourceBits + 1) << 0x08) +
              (*(SourceBits));
-          *DestBits = XLATEOBJ_iXlate(ColorTranslation, xColor);
+          *DestBits = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor);
           SourceBits += 3;
          DestBits += 1;
         }
 
-        SourceLine += SourceSurf->lDelta;
-        DestLine += DestSurf->lDelta;
+        SourceLine += BltInfo->SourceSurface->lDelta;
+        DestLine += BltInfo->DestSurface->lDelta;
       }
       break;
 
-    case 32:
-      SourceLine = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + 4 * SourcePoint->x;
+    case BMF_32BPP:
+      SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
       DestLine = DestBits;
 
-      for (j = DestRect->top; j < DestRect->bottom; j++)
+      for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
       {
         SourceBits = SourceLine;
         DestBits = DestLine;
 
-        for (i = DestRect->left; i < DestRect->right; i++)
+        for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
         {
           xColor = *((PDWORD) SourceBits);
-          *DestBits = XLATEOBJ_iXlate(ColorTranslation, xColor);
+          *DestBits = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor);
           SourceBits += 4;
          DestBits += 1;
         }
 
-        SourceLine += SourceSurf->lDelta;
-        DestLine += DestSurf->lDelta;
+        SourceLine += BltInfo->SourceSurface->lDelta;
+        DestLine += BltInfo->DestSurface->lDelta;
       }
       break;
 
     default:
-      DbgPrint("DIB_8BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
+      DPRINT1("DIB_8BPP_Bitblt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo->SourceSurface->iBitmapFormat));
       return FALSE;
   }
 
   return TRUE;
 }
 
-BOOLEAN
-DIB_8BPP_BitBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
-                SURFGDI *DestGDI,  SURFGDI *SourceGDI,
-                PRECTL  DestRect,  POINTL  *SourcePoint,
-                PBRUSHOBJ Brush, PPOINTL BrushOrigin,
-                XLATEOBJ *ColorTranslation, ULONG Rop4)
-{
-   LONG i, j, k, sx, sy;
-   ULONG Dest, Source, Pattern = 0, PatternY;
-   PULONG DestBits;
-   BOOL UsesSource;
-   BOOL UsesPattern;
-   LONG RoundedRight;
-   /* Pattern brushes */
-   PGDIBRUSHOBJ GdiBrush;
-   HBITMAP PatternSurface = NULL;
-   PSURFOBJ PatternObj;
-   ULONG PatternWidth, PatternHeight;
-
-   if (Rop4 == SRCCOPY)
-   {
-      return DIB_8BPP_BitBltSrcCopy(
-         DestSurf,
-         SourceSurf,
-         DestGDI,
-         SourceGDI,
-         DestRect,
-         SourcePoint,
-         ColorTranslation);
-   }
-
-   UsesSource = ((Rop4 & 0xCC0000) >> 2) != (Rop4 & 0x330000);
-   UsesPattern = (((Rop4 & 0xF00000) >> 4) != (Rop4 & 0x0F0000)) && Brush;  
-
-   if (UsesPattern)
-   {
-      if (Brush->iSolidColor == 0xFFFFFFFF)
-      {
-         PBITMAPOBJ PatternBitmap;
-
-         GdiBrush = CONTAINING_RECORD(
-            Brush,
-            GDIBRUSHOBJ,
-            BrushObject);
-
-         PatternBitmap = BITMAPOBJ_LockBitmap(GdiBrush->hbmPattern);
-         PatternSurface = BitmapToSurf(PatternBitmap, NULL);
-         BITMAPOBJ_UnlockBitmap(GdiBrush->hbmPattern);
-
-         PatternObj = (PSURFOBJ)AccessUserObject((ULONG)PatternSurface);
-         PatternWidth = PatternObj->sizlBitmap.cx;
-         PatternHeight = PatternObj->sizlBitmap.cy;
-         
-         UsesPattern = TRUE;
-      }
-      else
-      {
-         UsesPattern = FALSE;
-         Pattern = (Brush->iSolidColor & 0xFF) |
-                    ((Brush->iSolidColor & 0xFF) << 8) |
-                    ((Brush->iSolidColor & 0xFF) << 16) |
-                    ((Brush->iSolidColor & 0xFF) << 24);
-      }
-   }
-   
-   RoundedRight = DestRect->right - ((DestRect->right - DestRect->left) & 0x3);
-   sy = SourcePoint->y;
-
-   for (j = DestRect->top; j < DestRect->bottom; j++)
-   {
-      sx = SourcePoint->x;
-      DestBits = (PULONG)(DestSurf->pvScan0 + DestRect->left + j * DestSurf->lDelta);
-
-      if(UsesPattern)
-        PatternY = j % PatternHeight;
-
-      for (i = DestRect->left; i < RoundedRight; i += 4, DestBits++)
-      {
-         Dest = *DestBits;
-
-         if (UsesSource)
-         {
-            Source = 0;
-            for (k = 0; k < 4; k++)
-               Source |= (DIB_GetSource(SourceSurf, SourceGDI, sx + (i - DestRect->left) + k, sy, ColorTranslation) << (k * 8));
-         }
-
-         if (UsesPattern)
-         {
-            Pattern = DIB_1BPP_GetPixel(PatternObj, i % PatternWidth, PatternY) ? GdiBrush->crFore : GdiBrush->crBack;
-            Pattern |= (DIB_1BPP_GetPixel(PatternObj, (i + 1) % PatternWidth, PatternY) ? GdiBrush->crFore : GdiBrush->crBack) << 8;
-            Pattern |= (DIB_1BPP_GetPixel(PatternObj, (i + 2) % PatternWidth, PatternY) ? GdiBrush->crFore : GdiBrush->crBack) << 16;
-            Pattern |= (DIB_1BPP_GetPixel(PatternObj, (i + 3) % PatternWidth, PatternY) ? GdiBrush->crFore : GdiBrush->crBack) << 24;
-         }
-         *DestBits = DIB_DoRop(Rop4, Dest, Source, Pattern);       
-      }
-
-      if (i < DestRect->right)
-      {
-         Dest = *DestBits;
-         for (; i < DestRect->right; i++)
-         {
-            if (UsesSource)
-           {
-               Source = DIB_GetSource(SourceSurf, SourceGDI, sx + (i - DestRect->left), sy, ColorTranslation);
-            }
-
-            if (UsesPattern)
-            {
-               Pattern = DIB_1BPP_GetPixel(PatternObj, i % PatternWidth,PatternY) ? GdiBrush->crFore : GdiBrush->crBack;
-            }
-
-            DIB_8BPP_PutPixel(DestSurf, i, j, DIB_DoRop(Rop4, Dest, Source, Pattern) & 0xFFFF);
-            Dest >>= 8;
-         }
-      }
-
-      sy++;
-   }
-
-   if (PatternSurface != NULL)
-      EngDeleteSurface(PatternSurface);
-
-   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);
+    }
+       
+  return TRUE;
 }
-
 /*
 =======================================
  Stretching functions goes below
@@ -407,7 +276,7 @@ DIB_8BPP_BitBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
 typedef unsigned char PIXEL;
 
 /* 16-bit HiColor (565 format) */
-inline PIXEL average8(PIXEL a, PIXEL b)
+__inline PIXEL average8(PIXEL a, PIXEL b)
 {
   return a; // FIXME: Depend on SetStretchMode
 }
@@ -442,26 +311,84 @@ void ScaleLineAvg8(PIXEL *Target, PIXEL *Source, int SrcWidth, int TgtWidth)
     *Target++ = *Source;
 }
 
+static BOOLEAN
+FinalCopy8(PIXEL *Target, PIXEL *Source, PSPAN ClipSpans, UINT ClipSpansCount, UINT *SpanIndex,
+           UINT DestY, RECTL *DestRect)
+{
+  LONG Left, Right;
+
+  while (ClipSpans[*SpanIndex].Y < DestY
+         || (ClipSpans[*SpanIndex].Y == DestY
+             && ClipSpans[*SpanIndex].X + ClipSpans[*SpanIndex].Width < DestRect->left))
+    {
+      (*SpanIndex)++;
+      if (ClipSpansCount <= *SpanIndex)
+        {
+          /* No more spans, everything else is clipped away, we're done */
+          return FALSE;
+        }
+    }
+  while (ClipSpans[*SpanIndex].Y == DestY)
+    {
+      if (ClipSpans[*SpanIndex].X < DestRect->right)
+        {
+          Left = max(ClipSpans[*SpanIndex].X, DestRect->left);
+          Right = min(ClipSpans[*SpanIndex].X + ClipSpans[*SpanIndex].Width, DestRect->right);
+          memcpy(Target + Left - DestRect->left, Source + Left - DestRect->left,
+                 (Right - Left) * sizeof(PIXEL));
+        }
+      (*SpanIndex)++;
+      if (ClipSpansCount <= *SpanIndex)
+        {
+          /* No more spans, everything else is clipped away, we're done */
+          return FALSE;
+        }
+    }
+
+  return TRUE;
+}
+
 //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
-void ScaleRectAvg8(PIXEL *Target, PIXEL *Source, int SrcWidth, int SrcHeight,
-                  int TgtWidth, int TgtHeight, int srcPitch, int dstPitch)
+BOOLEAN ScaleRectAvg8(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
+                      RECTL* DestRect, RECTL *SourceRect,
+                      POINTL* MaskOrigin, POINTL BrushOrigin,
+                      CLIPOBJ *ClipRegion, XLATEOBJ *ColorTranslation,
+                      ULONG Mode)
 {
-  int NumPixels = TgtHeight;
-  int IntPart = ((SrcHeight / TgtHeight) * srcPitch); //(SrcHeight / TgtHeight) * SrcWidth;
-  int FractPart = SrcHeight % TgtHeight;
-  int Mid = TgtHeight >> 1;
+  int NumPixels = DestRect->bottom - DestRect->top;
+  int IntPart = (((SourceRect->bottom - SourceRect->top) / (DestRect->bottom - DestRect->top)) * SourceSurf->lDelta); //((SourceRect->bottom - SourceRect->top) / (DestRect->bottom - DestRect->top)) * (SourceRect->right - SourceRect->left);
+  int FractPart = (SourceRect->bottom - SourceRect->top) % (DestRect->bottom - DestRect->top);
+  int Mid = (DestRect->bottom - DestRect->top) >> 1;
   int E = 0;
   int skip;
   PIXEL *ScanLine, *ScanLineAhead;
   PIXEL *PrevSource = NULL;
   PIXEL *PrevSourceAhead = NULL;
-
-  skip = (TgtHeight < SrcHeight) ? 0 : (TgtHeight / (2*SrcHeight) + 1);
+  PIXEL *Target = (PIXEL *) ((PBYTE)DestSurf->pvScan0 + (DestRect->top * DestSurf->lDelta) + DestRect->left);
+  PIXEL *Source = (PIXEL *) ((PBYTE)SourceSurf->pvScan0 + (SourceRect->top * SourceSurf->lDelta) + SourceRect->left);
+  PSPAN ClipSpans;
+  UINT ClipSpansCount;
+  UINT SpanIndex;
+  LONG DestY;
+
+  if (! ClipobjToSpans(&ClipSpans, &ClipSpansCount, ClipRegion, DestRect))
+    {
+      return FALSE;
+    }
+  if (0 == ClipSpansCount)
+    {
+      /* No clip spans == empty clipping region, everything clipped away */
+      ASSERT(NULL == ClipSpans);
+      return TRUE;
+    }
+  skip = (DestRect->bottom - DestRect->top < SourceRect->bottom - SourceRect->top) ? 0 : ((DestRect->bottom - DestRect->top) / (2 * (SourceRect->bottom - SourceRect->top)) + 1);
   NumPixels -= skip;
 
-  ScanLine = (PIXEL*)ExAllocatePool(NonPagedPool, TgtWidth*sizeof(PIXEL)); // FIXME: Should we use PagedPool here?
-  ScanLineAhead = (PIXEL *)ExAllocatePool(NonPagedPool, TgtWidth*sizeof(PIXEL));
+  ScanLine = (PIXEL*)ExAllocatePool(PagedPool, (DestRect->right - DestRect->left) * sizeof(PIXEL));
+  ScanLineAhead = (PIXEL *)ExAllocatePool(PagedPool, (DestRect->right - DestRect->left) * sizeof(PIXEL));
 
+  DestY = DestRect->top;
+  SpanIndex = 0;
   while (NumPixels-- > 0) {
     if (Source != PrevSource) {
       if (Source == PrevSourceAhead) {
@@ -473,137 +400,241 @@ void ScaleRectAvg8(PIXEL *Target, PIXEL *Source, int SrcWidth, int SrcHeight,
         ScanLine = ScanLineAhead;
         ScanLineAhead = tmp;
       } else {
-        ScaleLineAvg8(ScanLine, Source, SrcWidth, TgtWidth);
+        ScaleLineAvg8(ScanLine, Source, SourceRect->right - SourceRect->left, DestRect->right - DestRect->left);
       } /* if */
       PrevSource = Source;
     } /* if */
-    
-    if (E >= Mid && PrevSourceAhead != (PIXEL *)((BYTE *)Source + srcPitch)) {
+
+    if (E >= Mid && PrevSourceAhead != (PIXEL *)((BYTE *)Source + SourceSurf->lDelta)) {
       int x;
-      ScaleLineAvg8(ScanLineAhead, (PIXEL *)((BYTE *)Source + srcPitch), SrcWidth, TgtWidth);
-      for (x = 0; x < TgtWidth; x++)
+      ScaleLineAvg8(ScanLineAhead, (PIXEL *)((BYTE *)Source + SourceSurf->lDelta), SourceRect->right - SourceRect->left, DestRect->right - DestRect->left);
+      for (x = 0; x < DestRect->right - DestRect->left; x++)
         ScanLine[x] = average8(ScanLine[x], ScanLineAhead[x]);
-      PrevSourceAhead = (PIXEL *)((BYTE *)Source + srcPitch);
+      PrevSourceAhead = (PIXEL *)((BYTE *)Source + SourceSurf->lDelta);
     } /* if */
-    
-    memcpy(Target, ScanLine, TgtWidth*sizeof(PIXEL));
-    Target = (PIXEL *)((BYTE *)Target + dstPitch);
+
+    if (! FinalCopy8(Target, ScanLine, ClipSpans, ClipSpansCount, &SpanIndex, DestY, DestRect))
+      {
+        /* No more spans, everything else is clipped away, we're done */
+        ExFreePool(ClipSpans);
+        ExFreePool(ScanLine);
+        ExFreePool(ScanLineAhead);
+        return TRUE;
+      }
+    DestY++;
+    Target = (PIXEL *)((BYTE *)Target + DestSurf->lDelta);
     Source += IntPart;
     E += FractPart;
-    if (E >= TgtHeight) {
-      E -= TgtHeight;
-      Source = (PIXEL *)((BYTE *)Source + srcPitch);
+    if (E >= DestRect->bottom - DestRect->top) {
+      E -= DestRect->bottom - DestRect->top;
+      Source = (PIXEL *)((BYTE *)Source + SourceSurf->lDelta);
     } /* if */
   } /* while */
 
   if (skip > 0 && Source != PrevSource)
-    ScaleLineAvg8(ScanLine, Source, SrcWidth, TgtWidth);
+    ScaleLineAvg8(ScanLine, Source, SourceRect->right - SourceRect->left, DestRect->right - DestRect->left);
   while (skip-- > 0) {
-    memcpy(Target, ScanLine, TgtWidth*sizeof(PIXEL));
-    Target = (PIXEL *)((BYTE *)Target + dstPitch);
+    if (! FinalCopy8(Target, ScanLine, ClipSpans, ClipSpansCount, &SpanIndex, DestY, DestRect))
+      {
+        /* No more spans, everything else is clipped away, we're done */
+        ExFreePool(ClipSpans);
+        ExFreePool(ScanLine);
+        ExFreePool(ScanLineAhead);
+        return TRUE;
+      }
+    DestY++;
+    Target = (PIXEL *)((BYTE *)Target + DestSurf->lDelta);
   } /* while */
 
+  ExFreePool(ClipSpans);
   ExFreePool(ScanLine);
   ExFreePool(ScanLineAhead);
+
+  return TRUE;
 }
 
+//NOTE: If you change something here, please do the same in other dibXXbpp.c files!
 BOOLEAN DIB_8BPP_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
-                            SURFGDI *DestGDI, SURFGDI *SourceGDI,
                             RECTL* DestRect, RECTL *SourceRect,
-                            POINTL* MaskOrigin, POINTL* BrushOrigin,
-                                       XLATEOBJ *ColorTranslation, ULONG Mode)
+                            POINTL* MaskOrigin, POINTL BrushOrigin,
+                            CLIPOBJ *ClipRegion, XLATEOBJ *ColorTranslation,
+                            ULONG Mode)
 {
-  BYTE *SourceLine, *DestLine;
-  
-  DbgPrint("DIB_8BPP_StretchBlt: Source BPP: %u, srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
-     SourceGDI->BitsPerPixel, SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
+   LONG SrcSizeY;
+   LONG SrcSizeX;
+   LONG DesSizeY;
+   LONG DesSizeX;      
+   LONG sx;
+   LONG sy;
+   LONG DesX;
+   LONG DesY;
+   LONG color;
+
+  DPRINT("DIB_8BPP_StretchBlt: Source BPP: %u, srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
+     BitsPerFormat(SourceSurf->iBitmapFormat), SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
      DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
 
-    switch(SourceGDI->BitsPerPixel)
-    {
-      case 1:
-         return FALSE;      
-      break;
+    SrcSizeY = SourceRect->bottom - SourceRect->top;
+    SrcSizeX = SourceRect->right - SourceRect->left;
   
-      case 4:
-         return FALSE;
+    DesSizeY = DestRect->bottom - DestRect->top;
+    DesSizeX = DestRect->right - DestRect->left;
+
+    switch(SourceSurf->iBitmapFormat)
+    {     
+      case BMF_1BPP:
+         /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
+      /* This is a reference implementation, it hasn't been optimized for speed */
+                      
+       for (DesY=DestRect->top; DesY<DestRect->bottom; DesY++)
+       {                        
+           sy = (((DesY - DestRect->top) * SrcSizeY) / DesSizeY) + SourceRect->top;
+                     
+            for (DesX=DestRect->left; DesX<DestRect->right; DesX++)
+            {                  
+                  sx = (((DesX - DestRect->left) * SrcSizeX) / DesSizeX) + SourceRect->left;
+                               
+                  if(DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0)
+                                 {
+                                       DIB_8BPP_PutPixel(DestSurf, DesX, DesY, XLATEOBJ_iXlate(ColorTranslation, 0));
+                  } 
+                                 else 
+                                 {
+                    DIB_8BPP_PutPixel(DestSurf, DesX, DesY, XLATEOBJ_iXlate(ColorTranslation, 1));
+                  }
+            }
+       }               
+
+         break;
+
+      case BMF_4BPP:           
+      /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
+      /* This is a reference implementation, it hasn't been optimized for speed */
+                      
+       for (DesY=DestRect->top; DesY<DestRect->bottom; DesY++)
+       {                        
+           sy = (((DesY - DestRect->top) * SrcSizeY) / DesSizeY) + SourceRect->top;
+                     
+            for (DesX=DestRect->left; DesX<DestRect->right; DesX++)
+            {                  
+                 sx = (((DesX - DestRect->left) * SrcSizeX) / DesSizeX) + SourceRect->left;            
+                 color = DIB_4BPP_GetPixel(SourceSurf, sx, sy);
+                 DIB_8BPP_PutPixel(DestSurf, DesX, DesY, XLATEOBJ_iXlate(ColorTranslation, color));
+            }
+       }                  
       break;
-  
-      case 8:
-           SourceLine = SourceSurf->pvScan0 + (SourceRect->top * SourceSurf->lDelta) + SourceRect->left;
-           DestLine = DestSurf->pvScan0 + (DestRect->top * DestSurf->lDelta) + DestRect->left;
 
-        ScaleRectAvg8((PIXEL *)DestLine, (PIXEL *)SourceLine,
-           SourceRect->right-SourceRect->left, SourceRect->bottom-SourceRect->top, 
-           DestRect->right-DestRect->left, DestRect->bottom-DestRect->top, SourceSurf->lDelta, DestSurf->lDelta);
+      case BMF_8BPP:
+        return ScaleRectAvg8(DestSurf, SourceSurf, DestRect, SourceRect, MaskOrigin, BrushOrigin,
+                             ClipRegion, ColorTranslation, Mode);
       break;
 
-      case 16:
-         return FALSE;
-      break;
-    
-      case 24:
-         return FALSE;
-      break;
-      
-      case 32:
-         return FALSE;
-      break;
-      
+      case BMF_16BPP:          
+      /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
+      /* This is a reference implementation, it hasn't been optimized for speed */
+                      
+       for (DesY=DestRect->top; DesY<DestRect->bottom; DesY++)
+       {                        
+           sy = (((DesY - DestRect->top) * SrcSizeY) / DesSizeY) + SourceRect->top;
+                     
+            for (DesX=DestRect->left; DesX<DestRect->right; DesX++)
+            {                  
+                 sx = (((DesX - DestRect->left) * SrcSizeX) / DesSizeX) + SourceRect->left;            
+                 color = DIB_16BPP_GetPixel(SourceSurf, sx, sy);
+                 DIB_8BPP_PutPixel(DestSurf, DesX, DesY, XLATEOBJ_iXlate(ColorTranslation, color));
+            }
+       }                  
+         break;
+
+      case BMF_24BPP:
+      /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
+      /* This is a reference implementation, it hasn't been optimized for speed */
+                      
+       for (DesY=DestRect->top; DesY<DestRect->bottom; DesY++)
+       {                        
+           sy = (((DesY - DestRect->top) * SrcSizeY) / DesSizeY) + SourceRect->top;
+                     
+            for (DesX=DestRect->left; DesX<DestRect->right; DesX++)
+            {                  
+                 sx = (((DesX - DestRect->left) * SrcSizeX) / DesSizeX) + SourceRect->left;            
+                 color = DIB_24BPP_GetPixel(SourceSurf, sx, sy);
+                 DIB_8BPP_PutPixel(DestSurf, DesX, DesY, XLATEOBJ_iXlate(ColorTranslation, color));
+            }
+       }                               
+         break;
+
+      case BMF_32BPP:
+      /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
+      /* This is a reference implementation, it hasn't been optimized for speed */
+                      
+       for (DesY=DestRect->top; DesY<DestRect->bottom; DesY++)
+       {                        
+           sy = (((DesY - DestRect->top) * SrcSizeY) / DesSizeY) + SourceRect->top;
+                     
+            for (DesX=DestRect->left; DesX<DestRect->right; DesX++)
+            {                  
+                 sx = (((DesX - DestRect->left) * SrcSizeX) / DesSizeX) + SourceRect->left;            
+                 color = DIB_32BPP_GetPixel(SourceSurf, sx, sy);
+                 DIB_8BPP_PutPixel(DestSurf, DesX, DesY, XLATEOBJ_iXlate(ColorTranslation, color));
+            }
+       }                               
+         break;
+
+
+
       default:
-         DbgPrint("DIB_8BPP_StretchBlt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
+         DPRINT1("DIB_8BPP_StretchBlt: Unhandled Source BPP: %u\n", BitsPerFormat(SourceSurf->iBitmapFormat));
       return FALSE;
     }
-    
+
   return TRUE;
 }
 
-BOOLEAN 
+BOOLEAN
 DIB_8BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
-                        PSURFGDI DestGDI,  PSURFGDI SourceGDI,
                         RECTL*  DestRect,  POINTL  *SourcePoint,
                         XLATEOBJ *ColorTranslation, ULONG iTransColor)
 {
   ULONG RoundedRight, X, Y, SourceX, SourceY, Source, wd, Dest;
   ULONG *DestBits;
-  
+
   RoundedRight = DestRect->right - ((DestRect->right - DestRect->left) & 0x3);
   SourceY = SourcePoint->y;
-  DestBits = (ULONG*)(DestSurf->pvScan0 + DestRect->left +
+  DestBits = (ULONG*)((PBYTE)DestSurf->pvScan0 + DestRect->left +
                       (DestRect->top * DestSurf->lDelta));
   wd = DestSurf->lDelta - (DestRect->right - DestRect->left);
-  
+
   for(Y = DestRect->top; Y < DestRect->bottom; Y++)
   {
-    DestBits = (ULONG*)(DestSurf->pvScan0 + DestRect->left +
+    DestBits = (ULONG*)((PBYTE)DestSurf->pvScan0 + DestRect->left +
                         (Y * DestSurf->lDelta));
     SourceX = SourcePoint->x;
     for (X = DestRect->left; X < RoundedRight; X += 4, DestBits++)
     {
       Dest = *DestBits;
-      
-      Source = DIB_GetSourceIndex(SourceSurf, SourceGDI, SourceX++, SourceY);
+
+      Source = DIB_GetSourceIndex(SourceSurf, SourceX++, SourceY);
       if(Source != iTransColor)
       {
         Dest &= 0xFFFFFF00;
         Dest |= (XLATEOBJ_iXlate(ColorTranslation, Source) & 0xFF);
       }
 
-      Source = DIB_GetSourceIndex(SourceSurf, SourceGDI, SourceX++, SourceY);
+      Source = DIB_GetSourceIndex(SourceSurf, SourceX++, SourceY);
       if(Source != iTransColor)
       {
         Dest &= 0xFFFF00FF;
         Dest |= ((XLATEOBJ_iXlate(ColorTranslation, Source) << 8) & 0xFF00);
       }
-      
-      Source = DIB_GetSourceIndex(SourceSurf, SourceGDI, SourceX++, SourceY);
+
+      Source = DIB_GetSourceIndex(SourceSurf, SourceX++, SourceY);
       if(Source != iTransColor)
       {
         Dest &= 0xFF00FFFF;
         Dest |= ((XLATEOBJ_iXlate(ColorTranslation, Source) << 16) & 0xFF0000);
       }
-      
-      Source = DIB_GetSourceIndex(SourceSurf, SourceGDI, SourceX++, SourceY);
+
+      Source = DIB_GetSourceIndex(SourceSurf, SourceX++, SourceY);
       if(Source != iTransColor)
       {
         Dest &= 0x00FFFFFF;
@@ -612,12 +643,12 @@ DIB_8BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
 
       *DestBits = Dest;
     }
-    
+
     if(X < DestRect->right)
     {
       for (; X < DestRect->right; X++)
       {
-        Source = DIB_GetSourceIndex(SourceSurf, SourceGDI, SourceX++, SourceY);
+        Source = DIB_GetSourceIndex(SourceSurf, SourceX++, SourceY);
         if(Source != iTransColor)
         {
           *((BYTE*)DestBits) = (BYTE)(XLATEOBJ_iXlate(ColorTranslation, Source) & 0xFF);
@@ -627,8 +658,166 @@ DIB_8BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
     }
     SourceY++;
   }
-  
+
   return TRUE;
 }
 
+typedef union {
+   ULONG ul;
+   struct {
+      UCHAR red;
+      UCHAR green;
+      UCHAR blue;
+      UCHAR alpha;
+   } col;
+} NICEPIXEL32;
+
+typedef union {
+   USHORT us;
+   struct {
+      USHORT red:5,
+             green:6,
+             blue:5;
+   } col;
+} NICEPIXEL16;
+
+STATIC inline UCHAR
+Clamp8(ULONG val)
+{
+   return (val > 255) ? 255 : val;
+}
+
+BOOLEAN
+DIB_8BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
+                    RECTL* SourceRect, CLIPOBJ* ClipRegion,
+                    XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
+{
+   INT Rows, Cols, SrcX, SrcY;
+   register PUCHAR Dst;
+   ULONG DstDelta;
+   BLENDFUNCTION BlendFunc;
+   register NICEPIXEL32 DstPixel;
+   register NICEPIXEL32 SrcPixel;
+   register NICEPIXEL16 SrcPixel16;
+   UCHAR Alpha, SrcBpp;
+   HPALETTE SrcPalette, DstPalette;
+   XLATEOBJ *SrcTo32Xlate, *DstTo32Xlate, *DstFrom32Xlate;
+
+   DPRINT("DIB_8BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
+          SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
+          DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
+
+   ASSERT(DestRect->bottom - DestRect->top == SourceRect->bottom - SourceRect->top &&
+          DestRect->right - DestRect->left == SourceRect->right - SourceRect->left);
+
+   BlendFunc = BlendObj->BlendFunction;
+   if (BlendFunc.BlendOp != AC_SRC_OVER)
+   {
+      DPRINT1("BlendOp != AC_SRC_OVER\n");
+      return FALSE;
+   }
+   if (BlendFunc.BlendFlags != 0)
+   {
+      DPRINT1("BlendFlags != 0\n");
+      return FALSE;
+   }
+   if ((BlendFunc.AlphaFormat & ~AC_SRC_ALPHA) != 0)
+   {
+      DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc.AlphaFormat);
+      return FALSE;
+   }
+   if ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0 &&
+       BitsPerFormat(Source->iBitmapFormat) != 32)
+   {
+      DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
+      return FALSE;
+   }
+
+   SrcBpp = BitsPerFormat(Source->iBitmapFormat);
+   SrcPalette = IntEngGetXlatePalette(ColorTranslation, XO_SRCPALETTE);
+   if (SrcPalette != 0)
+   {
+      SrcTo32Xlate = IntEngCreateXlate(PAL_RGB, 0, NULL, SrcPalette);
+      if (SrcTo32Xlate == NULL)
+      {
+         DPRINT1("IntEngCreateXlate failed\n");
+         return FALSE;
+      }
+   }
+   else
+   {
+      SrcTo32Xlate = NULL;
+      ASSERT(SrcBpp >= 16);
+   }
+
+   DstPalette = IntEngGetXlatePalette(ColorTranslation, XO_DESTPALETTE);
+   DstTo32Xlate = IntEngCreateXlate(PAL_RGB, 0, NULL, DstPalette);
+   DstFrom32Xlate = IntEngCreateXlate(0, PAL_RGB, DstPalette, NULL);
+   if (DstTo32Xlate == NULL || DstFrom32Xlate == NULL)
+   {
+      if (SrcTo32Xlate != NULL)
+         EngDeleteXlate(SrcTo32Xlate);
+      if (DstTo32Xlate != NULL)
+         EngDeleteXlate(DstTo32Xlate);
+      if (DstFrom32Xlate != NULL)
+         EngDeleteXlate(DstFrom32Xlate);
+      DPRINT1("IntEngCreateXlate failed\n");
+      return FALSE;
+   }
+
+   Dst = (PUCHAR)((ULONG_PTR)Dest->pvScan0 + (DestRect->top * Dest->lDelta) +
+                             DestRect->left);
+   DstDelta = Dest->lDelta - (DestRect->right - DestRect->left);
+
+   Rows = DestRect->bottom - DestRect->top;
+   SrcY = SourceRect->top;
+   while (--Rows >= 0)
+   {
+      Cols = DestRect->right - DestRect->left;
+      SrcX = SourceRect->left;
+      while (--Cols >= 0)
+      {
+         if (SrcTo32Xlate != NULL)
+         {
+            SrcPixel.ul = DIB_GetSource(Source, SrcX++, SrcY, SrcTo32Xlate);
+         }
+         else if (SrcBpp <= 16)
+         {
+            SrcPixel16.us = DIB_GetSource(Source, SrcX++, SrcY, ColorTranslation);
+            SrcPixel.col.red = (SrcPixel16.col.red << 3) | (SrcPixel16.col.red >> 2);
+            SrcPixel.col.green = (SrcPixel16.col.green << 2) | (SrcPixel16.col.green >> 4);
+            SrcPixel.col.blue = (SrcPixel16.col.blue << 3) | (SrcPixel16.col.blue >> 2);
+         }
+         else
+         {
+            SrcPixel.ul = DIB_GetSourceIndex(Source, SrcX++, SrcY);
+         }
+         SrcPixel.col.red = SrcPixel.col.red * BlendFunc.SourceConstantAlpha / 255;
+         SrcPixel.col.green = SrcPixel.col.green * BlendFunc.SourceConstantAlpha / 255;
+         SrcPixel.col.blue = SrcPixel.col.blue * BlendFunc.SourceConstantAlpha / 255;
+         SrcPixel.col.alpha = (SrcBpp == 32) ? (SrcPixel.col.alpha * BlendFunc.SourceConstantAlpha / 255) : BlendFunc.SourceConstantAlpha;
+
+         Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
+                 SrcPixel.col.alpha : BlendFunc.SourceConstantAlpha;
+
+         DstPixel.ul = XLATEOBJ_iXlate(DstTo32Xlate, *Dst);
+         DstPixel.col.red = Clamp8(DstPixel.col.red * (255 - Alpha) / 255 + SrcPixel.col.red);
+         DstPixel.col.green = Clamp8(DstPixel.col.green * (255 - Alpha) / 255 + SrcPixel.col.green);
+         DstPixel.col.blue = Clamp8(DstPixel.col.blue * (255 - Alpha) / 255 + SrcPixel.col.blue);
+         *Dst++ = XLATEOBJ_iXlate(DstFrom32Xlate, DstPixel.ul);
+      }
+      Dst = (PUCHAR)((ULONG_PTR)Dst + DstDelta);
+      SrcY++;
+   }
+
+   if (SrcTo32Xlate != NULL)
+      EngDeleteXlate(SrcTo32Xlate);
+   if (DstTo32Xlate != NULL)
+      EngDeleteXlate(DstTo32Xlate);
+   if (DstFrom32Xlate != NULL)
+      EngDeleteXlate(DstFrom32Xlate);
+
+   return TRUE;
+}
+
 /* EOF */