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 f19699f..dde6e9e 100644 (file)
@@ -26,7 +26,7 @@
 VOID
 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;
 }
@@ -34,7 +34,7 @@ DIB_8BPP_PutPixel(SURFOBJ *SurfObj, LONG x, LONG y, ULONG c)
 ULONG
 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);
 }
@@ -42,13 +42,13 @@ DIB_8BPP_GetPixel(SURFOBJ *SurfObj, LONG x, LONG y)
 VOID
 DIB_8BPP_HLine(SURFOBJ *SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
 {
-  memset(SurfObj->pvScan0 + y * SurfObj->lDelta + x1, (BYTE) c, x2 - x1);
+  memset((PBYTE)SurfObj->pvScan0 + y * SurfObj->lDelta + x1, (BYTE) c, x2 - x1);
 }
 
 VOID
 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;
 
@@ -67,7 +67,7 @@ DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
   PBYTE    SourceBits, DestBits, SourceLine, DestLine;
   PBYTE    SourceBits_4BPP, SourceLine_4BPP;
 
-  DestBits = BltInfo->DestSurface->pvScan0 + (BltInfo->DestRect.top * BltInfo->DestSurface->lDelta) + BltInfo->DestRect.left;
+  DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 + (BltInfo->DestRect.top * BltInfo->DestSurface->lDelta) + BltInfo->DestRect.left;
 
   switch(BltInfo->SourceSurface->iBitmapFormat)
   {
@@ -93,7 +93,7 @@ DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
       break;
 
     case BMF_4BPP:
-      SourceBits_4BPP = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + (BltInfo->SourcePoint.x >> 1);
+      SourceBits_4BPP = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + (BltInfo->SourcePoint.x >> 1);
 
       for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
       {
@@ -119,7 +119,7 @@ DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
       {
        if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
          {
-           SourceBits = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
+           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, BltInfo->DestRect.right - BltInfo->DestRect.left);
@@ -129,8 +129,8 @@ DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
          }
        else
          {
-           SourceBits = BltInfo->SourceSurface->pvScan0 + ((BltInfo->SourcePoint.y + BltInfo->DestRect.bottom - BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
-           DestBits = BltInfo->DestSurface->pvScan0 + ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta) + BltInfo->DestRect.left;
+           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, BltInfo->DestRect.right - BltInfo->DestRect.left);
@@ -143,7 +143,7 @@ DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
       {
        if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
          {
-           SourceLine = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
+           SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
            DestLine = DestBits;
            for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
              {
@@ -159,8 +159,8 @@ DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
          }
        else
          {
-           SourceLine = BltInfo->SourceSurface->pvScan0 + ((BltInfo->SourcePoint.y + BltInfo->DestRect.bottom - BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
-           DestLine = BltInfo->DestSurface->pvScan0 + ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta) + BltInfo->DestRect.left;
+           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;
@@ -177,7 +177,7 @@ DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
       break;
 
     case BMF_16BPP:
-      SourceLine = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 2 * BltInfo->SourcePoint.x;
+      SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 2 * BltInfo->SourcePoint.x;
       DestLine = DestBits;
 
       for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
@@ -199,7 +199,7 @@ DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
       break;
 
     case BMF_24BPP:
-      SourceLine = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 3 * BltInfo->SourcePoint.x;
+      SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 3 * BltInfo->SourcePoint.x;
       DestLine = DestBits;
 
       for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
@@ -223,7 +223,7 @@ DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
       break;
 
     case BMF_32BPP:
-      SourceLine = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
+      SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
       DestLine = DestBits;
 
       for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
@@ -252,114 +252,17 @@ DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
   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)(
-         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;
 }
 /*
 =======================================
@@ -373,7 +276,7 @@ DIB_8BPP_ColorFill(SURFOBJ* DestSurface, RECTL* DestRect, ULONG color)
 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
 }
@@ -461,8 +364,8 @@ BOOLEAN ScaleRectAvg8(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
   PIXEL *ScanLine, *ScanLineAhead;
   PIXEL *PrevSource = NULL;
   PIXEL *PrevSourceAhead = NULL;
-  PIXEL *Target = (PIXEL *) (DestSurf->pvScan0 + (DestRect->top * DestSurf->lDelta) + DestRect->left);
-  PIXEL *Source = (PIXEL *) (SourceSurf->pvScan0 + (SourceRect->top * SourceSurf->lDelta) + SourceRect->left);
+  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;
@@ -557,304 +460,69 @@ BOOLEAN DIB_8BPP_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
                             CLIPOBJ *ClipRegion, XLATEOBJ *ColorTranslation,
                             ULONG Mode)
 {
-   int SrcSizeY;
-   int SrcSizeX;
-   int DesSizeY;
-   int DesSizeX;      
-   int sx;
-   int sy;
-   int DesX;
-   int DesY;
-   int color;
-   int zoomX;
-   int zoomY;
-   int count;
-   int saveX;
-   int saveY;
-   BOOLEAN DesIsBiggerY=FALSE;
+   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);
 
-   SrcSizeY = SourceRect->bottom;
-   SrcSizeX = SourceRect->right;
+    SrcSizeY = SourceRect->bottom - SourceRect->top;
+    SrcSizeX = SourceRect->right - SourceRect->left;
   
-   DesSizeY = DestRect->bottom;
-   DesSizeX = DestRect->right;
-
-   zoomX = DesSizeX / SrcSizeX;
-   if (zoomX==0) zoomX=1;
-
-   zoomY = DesSizeY / SrcSizeY;
-   if (zoomY==0) zoomY=1;
-
-   if (DesSizeY>SrcSizeY)
-      DesIsBiggerY = TRUE;
+    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 */
-           if (zoomX>1)
-                  {
-                    /* Draw one Hline on X - Led to the Des Zoom In*/
-                    if (DesSizeX>SrcSizeX)
-                        {
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {                                               
-                                               sx = (int) ((ULONG) SrcSizeX * (ULONG) DesX) / ((ULONG) DesSizeX);
-                                               
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               saveX = DesX + zoomX;
-
-                                               if (DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0) 
-                                                  for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, 0);
-                                               else
-                                                       for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, 1);
-                                                                                                                                                                                               
-                                         }                                                                             
-                                 }
-                           }
-                        else
-                        {
-                          /* Draw one Hline on X - Led to the Des Zoom Out*/
-
-               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {
-                                               sx = (int) ((ULONG) DesSizeX * (ULONG) DesX) / ((ULONG) SrcSizeX);                                                                  
-                                       
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               saveX = DesX + zoomX;
-
-                                               if (DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0) 
-                                                  for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, 0);
-                                               else
-                                                       for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, 1);
-                                                                                                                                                                                               
-                                         }                                                                             
-                                 }
-                        }
-                  }                    
-                  else
-                  {
-                   
-                   if (DesSizeX>SrcSizeX)
-                       {
-                               /* Draw one pixel on X - Led to the Des Zoom In*/
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {                                               
-                                               sx = (int) ((ULONG) SrcSizeX * (ULONG) DesX) / ((ULONG) DesSizeX);
-                                               
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               if (DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0) 
-                                                  for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, 0);                                                                            
-                                               else
-                                                       for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, 1);                                                                            
-                                                           
-                                               
-                                        }
-                         }
-                        }
-                       else
-                       {
-                               /* Draw one pixel on X - Led to the Des Zoom Out*/
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {
-                                               sx = (int) ((ULONG) DesSizeX * (ULONG) DesX) / ((ULONG) SrcSizeX);                                                                  
-                                       
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               if (DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0) 
-                                                  for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, 0);                                                                            
-                                               else
-                                                       for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, 1);                                                                            
-                                                                                                       
-                                        }
-                         }
-                       }
-                  }
-               break;
+      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 */
-           if (zoomX>1)
-                  {
-                    /* Draw one Hline on X - Led to the Des Zoom In*/
-                    if (DesSizeX>SrcSizeX)
-                        {
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {                                               
-                                               sx = (int) ((ULONG) SrcSizeX * (ULONG) DesX) / ((ULONG) DesSizeX);
-                                               
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_4BPP_GetPixel(SourceSurf, sx, sy));
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, color);
-                                         }                                                                             
-                                 }
-                           }
-                        else
-                        {
-                          /* Draw one Hline on X - Led to the Des Zoom Out*/
-
-               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {
-                                               sx = (int) ((ULONG) DesSizeX * (ULONG) DesX) / ((ULONG) SrcSizeX);                                                                  
-                                       
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_4BPP_GetPixel(SourceSurf, sx, sy));
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, color);
-                                         }                                                                             
-                                 }
-                        }
-                  }
-                       
-                  else
-                  {
-                   
-                   if (DesSizeX>SrcSizeX)
-                       {
-                               /* Draw one pixel on X - Led to the Des Zoom In*/
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {                                               
-                                               sx = (int) ((ULONG) SrcSizeX * (ULONG) DesX) / ((ULONG) DesSizeX);
-                                               
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_4BPP_GetPixel(SourceSurf, sx, sy));
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, color);                                                                                
-                                        }
-                         }
-                        }
-                       else
-                       {
-                               /* Draw one pixel on X - Led to the Des Zoom Out*/
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {
-                                               sx = (int) ((ULONG) DesSizeX * (ULONG) DesX) / ((ULONG) SrcSizeX);                                                                  
-                                       
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_4BPP_GetPixel(SourceSurf, sx, sy));
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, color);                                                                                
-                                        }
-                         }
-                       }
-                  }
-               break;
+      /* 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 BMF_8BPP:
         return ScaleRectAvg8(DestSurf, SourceSurf, DestRect, SourceRect, MaskOrigin, BrushOrigin,
@@ -862,376 +530,56 @@ BOOLEAN DIB_8BPP_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
       break;
 
       case BMF_16BPP:          
-                  /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
-                  /* This is a reference implementation, it hasn't been optimized for speed */
-           if (zoomX>1)
-                  {
-                    /* Draw one Hline on X - Led to the Des Zoom In*/
-                    if (DesSizeX>SrcSizeX)
-                        {
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {                                               
-                                               sx = (int) ((ULONG) SrcSizeX * (ULONG) DesX) / ((ULONG) DesSizeX);
-                                               
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_16BPP_GetPixel(SourceSurf, sx, sy));
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, color);
-                                         }                                                                             
-                                 }
-                           }
-                        else
-                        {
-                          /* Draw one Hline on X - Led to the Des Zoom Out*/
-
-               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {
-                                               sx = (int) ((ULONG) DesSizeX * (ULONG) DesX) / ((ULONG) SrcSizeX);                                                                  
-                                       
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_16BPP_GetPixel(SourceSurf, sx, sy));
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, color);
-                                         }                                                                             
-                                 }
-                        }
-                  }
-                       
-                  else
-                  {
-                   
-                   if (DesSizeX>SrcSizeX)
-                       {
-                               /* Draw one pixel on X - Led to the Des Zoom In*/
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {                                               
-                                               sx = (int) ((ULONG) SrcSizeX * (ULONG) DesX) / ((ULONG) DesSizeX);
-                                               
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_16BPP_GetPixel(SourceSurf, sx, sy));
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, color);                                                                                
-                                        }
-                         }
-                        }
-                       else
-                       {
-                               /* Draw one pixel on X - Led to the Des Zoom Out*/
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {
-                                               sx = (int) ((ULONG) DesSizeX * (ULONG) DesX) / ((ULONG) SrcSizeX);                                                                  
-                                       
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_16BPP_GetPixel(SourceSurf, sx, sy));
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, color);                                                                                
-                                        }
-                         }
-                       }
-                  }
-               break;
-
-      case BMF_24BPP:          
-                  /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
-                  /* This is a reference implementation, it hasn't been optimized for speed */
-           if (zoomX>1)
-                  {
-                    /* Draw one Hline on X - Led to the Des Zoom In*/
-                    if (DesSizeX>SrcSizeX)
-                        {
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {                                               
-                                               sx = (int) ((ULONG) SrcSizeX * (ULONG) DesX) / ((ULONG) DesSizeX);
-                                               
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_24BPP_GetPixel(SourceSurf, sx, sy));
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, color);
-                                         }                                                                             
-                                 }
-                           }
-                        else
-                        {
-                          /* Draw one Hline on X - Led to the Des Zoom Out*/
-
-               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {
-                                               sx = (int) ((ULONG) DesSizeX * (ULONG) DesX) / ((ULONG) SrcSizeX);                                                                  
-                                       
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_24BPP_GetPixel(SourceSurf, sx, sy));
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, color);
-                                         }                                                                             
-                                 }
-                        }
-                  }
-                       
-                  else
-                  {
-                   
-                   if (DesSizeX>SrcSizeX)
-                       {
-                               /* Draw one pixel on X - Led to the Des Zoom In*/
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {                                               
-                                               sx = (int) ((ULONG) SrcSizeX * (ULONG) DesX) / ((ULONG) DesSizeX);
-                                               
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_24BPP_GetPixel(SourceSurf, sx, sy));
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, color);                                                                                
-                                        }
-                         }
-                        }
-                       else
-                       {
-                               /* Draw one pixel on X - Led to the Des Zoom Out*/
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {
-                                               sx = (int) ((ULONG) DesSizeX * (ULONG) DesX) / ((ULONG) SrcSizeX);                                                                  
-                                       
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_24BPP_GetPixel(SourceSurf, sx, sy));
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, color);                                                                                
-                                        }
-                         }
-                       }
-                  }
-               break;
-
-      case BMF_32BPP:          
-                  /* FIXME :  MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
-                  /* This is a reference implementation, it hasn't been optimized for speed */
-           if (zoomX>1)
-                  {
-                    /* Draw one Hline on X - Led to the Des Zoom In*/
-                    if (DesSizeX>SrcSizeX)
-                        {
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {                                               
-                                               sx = (int) ((ULONG) SrcSizeX * (ULONG) DesX) / ((ULONG) DesSizeX);
-                                               
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_32BPP_GetPixel(SourceSurf, sx, sy));
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, color);
-                                         }                                                                             
-                                 }
-                           }
-                        else
-                        {
-                          /* Draw one Hline on X - Led to the Des Zoom Out*/
-
-               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {
-                                               sx = (int) ((ULONG) DesSizeX * (ULONG) DesX) / ((ULONG) SrcSizeX);                                                                  
-                                       
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_32BPP_GetPixel(SourceSurf, sx, sy));
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_HLine(DestSurf, DesX, saveX, count, color);
-                                         }                                                                             
-                                 }
-                        }
-                  }
-                       
-                  else
-                  {
-                   
-                   if (DesSizeX>SrcSizeX)
-                       {
-                               /* Draw one pixel on X - Led to the Des Zoom In*/
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {                                               
-                                               sx = (int) ((ULONG) SrcSizeX * (ULONG) DesX) / ((ULONG) DesSizeX);
-                                               
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_32BPP_GetPixel(SourceSurf, sx, sy));
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, color);                                                                                
-                                        }
-                         }
-                        }
-                       else
-                       {
-                               /* Draw one pixel on X - Led to the Des Zoom Out*/
-                               for (DesY=DestRect->bottom-zoomY; DesY>=0; DesY-=zoomY)
-                               {
-                                       if (DesIsBiggerY)
-                                               sy = (int) ((ULONG) SrcSizeY * (ULONG) DesY) / ((ULONG) DesSizeY);
-                                       else
-                                               sy = (int) ((ULONG) DesSizeY * (ULONG) DesY) / ((ULONG) SrcSizeY); 
-                                               
-                                       if (sy > SourceRect->bottom) break;
-
-                                       saveY = DesY+zoomY;
-
-                                       for (DesX=DestRect->right-zoomX; DesX>=0; DesX-=zoomX)                          
-                                       {
-                                               sx = (int) ((ULONG) DesSizeX * (ULONG) DesX) / ((ULONG) SrcSizeX);                                                                  
-                                       
-                                               if (sx > SourceRect->right) break;
-                                       
-                                               color =  XLATEOBJ_iXlate(ColorTranslation, DIB_32BPP_GetPixel(SourceSurf, sx, sy));
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_8BPP_PutPixel(DestSurf, DesX, count, color);                                                                                
-                                        }
-                         }
-                       }
-                  }
-               break;
+      /* 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:
@@ -1252,13 +600,13 @@ DIB_8BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
 
   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++)
@@ -1314,4 +662,162 @@ DIB_8BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
   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 */