fixed working strechblt for all dibxx now. do not say it does not take offset of...
[reactos.git] / reactos / subsys / win32k / dib / dib4bpp.c
index 78ba101..d3afbd3 100644 (file)
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 /* $Id$ */
+
 #include <w32k.h>
 
+#define NDEBUG
+#include <debug.h>
+
 VOID
 DIB_4BPP_PutPixel(SURFOBJ *SurfObj, LONG x, LONG y, ULONG c)
 {
-   PBYTE addr = SurfObj->pvScan0 + (x>>1) + y * SurfObj->lDelta;
+   PBYTE addr = (PBYTE)SurfObj->pvScan0 + (x>>1) + y * SurfObj->lDelta;
    *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
 }
 
 ULONG
 DIB_4BPP_GetPixel(SURFOBJ *SurfObj, LONG x, LONG y)
 {
-   PBYTE addr = SurfObj->pvScan0 + (x>>1) + y * SurfObj->lDelta;
+   PBYTE addr = (PBYTE)SurfObj->pvScan0 + (x>>1) + y * SurfObj->lDelta;
    return (*addr >> ((1-(x&1))<<2)) & 0x0f;
 }
 
 VOID
 DIB_4BPP_HLine(SURFOBJ *SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
 {
-  PBYTE  addr = SurfObj->pvScan0 + (x1>>1) + y * SurfObj->lDelta;
+  PBYTE  addr = (PBYTE)SurfObj->pvScan0 + (x1>>1) + y * SurfObj->lDelta;
   LONG  cx = x1;
 
   while(cx < x2) {
@@ -68,7 +72,7 @@ DIB_4BPP_BitBltSrcCopy(PBLTINFO BltInfo)
   PBYTE    DestBits, DestLine, SourceBits_8BPP, SourceLine_8BPP;
   PBYTE    SourceBits, SourceLine;
 
-  DestBits = BltInfo->DestSurface->pvScan0 +
+  DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 +
              (BltInfo->DestRect.left >> 1) +
              BltInfo->DestRect.top * BltInfo->DestSurface->lDelta;
 
@@ -119,7 +123,7 @@ DIB_4BPP_BitBltSrcCopy(PBLTINFO BltInfo)
       break;
 
     case BMF_8BPP:
-      SourceBits_8BPP = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
+      SourceBits_8BPP = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
 
       for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
       {
@@ -141,7 +145,7 @@ DIB_4BPP_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++)
@@ -165,7 +169,7 @@ DIB_4BPP_BitBltSrcCopy(PBLTINFO BltInfo)
       break;
 
     case BMF_24BPP:
-      SourceBits_24BPP = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x * 3;
+      SourceBits_24BPP = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x * 3;
 
       for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
       {
@@ -190,7 +194,7 @@ DIB_4BPP_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++)
@@ -274,7 +278,7 @@ DIB_4BPP_BitBlt(PBLTINFO BltInfo)
    for (DestY = BltInfo->DestRect.top; DestY < BltInfo->DestRect.bottom; DestY++)
    {
       DestBits = (PULONG)(
-         BltInfo->DestSurface->pvScan0 +
+         (PBYTE)BltInfo->DestSurface->pvScan0 +
          (BltInfo->DestRect.left >> 1) +
          DestY * BltInfo->DestSurface->lDelta);
       SourceX = BltInfo->SourcePoint.x;
@@ -377,803 +381,138 @@ BOOLEAN DIB_4BPP_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;
   
-
-   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;
-
-    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_4BPP_HLine(DestSurf, DesX, saveX, count, 0);
-                                               else
-                                                       for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_HLine(DestSurf, DesX, saveX, count, 1);
-                                                                                                                                                                                               
-                                         }                                                                             
-                                 }
-                           }
-                        else
-                        {
-                          /* Draw one Hline on X - Led to the Des Zoom Out*/
+   DesSizeY = DestRect->bottom - DestRect->top;
+   DesSizeX = DestRect->right - DestRect->left;
 
-               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_4BPP_HLine(DestSurf, DesX, saveX, count, 0);
-                                               else
-                                                       for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_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_4BPP_PutPixel(DestSurf, DesX, count, 0);                                                                            
-                                               else
-                                                       for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_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_4BPP_PutPixel(DestSurf, DesX, count, 0);                                                                            
-                                               else
-                                                       for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_PutPixel(DestSurf, DesX, count, 1);                                                                            
-                                                                                                       
-                                        }
-                         }
-                       }
-                  }
-               break;
+   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_4BPP_PutPixel(DestSurf, DesX, DesY, XLATEOBJ_iXlate(ColorTranslation, 0));
+                  } 
+                                 else 
+                                 {
+                    DIB_4BPP_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 =  DIB_4BPP_GetPixel(SourceSurf, sx, sy);
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_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 =  DIB_4BPP_GetPixel(SourceSurf, sx, sy);
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_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 =  DIB_4BPP_GetPixel(SourceSurf, sx, sy);
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_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 =  DIB_4BPP_GetPixel(SourceSurf, sx, sy);
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_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_4BPP_PutPixel(DestSurf, DesX, DesY, XLATEOBJ_iXlate(ColorTranslation, color));
+            }
+       }                  
+      break;
 
       case BMF_8BPP:           
-                  /* 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_8BPP_GetPixel(SourceSurf, sx, sy));
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_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_8BPP_GetPixel(SourceSurf, sx, sy));
-                                                                                               
-                                               saveX = DesX + zoomX;
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_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_8BPP_GetPixel(SourceSurf, sx, sy));
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_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_8BPP_GetPixel(SourceSurf, sx, sy));
-                                                           
-                                               for (count=DesY;count<saveY;count++)
-                                                       DIB_4BPP_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_8BPP_GetPixel(SourceSurf, sx, sy);
+                 DIB_4BPP_PutPixel(DestSurf, DesX, DesY, XLATEOBJ_iXlate(ColorTranslation, color));
+            }
+       }                  
+      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_4BPP_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_4BPP_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_4BPP_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_4BPP_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_4BPP_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 */
-           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_4BPP_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_4BPP_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_4BPP_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_4BPP_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_24BPP_GetPixel(SourceSurf, sx, sy);
+                 DIB_4BPP_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 */
-           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_4BPP_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_4BPP_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_4BPP_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_4BPP_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_32BPP_GetPixel(SourceSurf, sx, sy);
+                 DIB_4BPP_PutPixel(DestSurf, DesX, DesY, XLATEOBJ_iXlate(ColorTranslation, color));
+            }
+       }                  
+      break;
 
       default:
       //DPRINT1("DIB_4BPP_StretchBlt: Unhandled Source BPP: %u\n", BitsPerFormat(SourceSurf->iBitmapFormat));
       return FALSE;
-    }
+   }
   
   return TRUE;
 }
@@ -1186,4 +525,13 @@ DIB_4BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
   return FALSE;
 }
 
+BOOLEAN
+DIB_4BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
+                    RECTL* SourceRect, CLIPOBJ* ClipRegion,
+                    XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
+{
+  UNIMPLEMENTED;
+  return FALSE;
+}
+
 /* EOF */