[WIN32K]
[reactos.git] / subsystems / win32 / win32k / objects / dibobj.c
index 74931f8..8accc41 100644 (file)
@@ -265,10 +265,13 @@ IntSetDIBits(
     CONST BITMAPINFO  *bmi,
     UINT  ColorUse)
 {
-    HBITMAP     SourceBitmap, hOldSrcBmp = NULL, hOldDstBmp = NULL;
-       HDC                     hdcSrc, hdcDst;
+    HBITMAP     SourceBitmap;
+       PSURFACE    psurfDst, psurfSrc;
     INT         result = 0;
+       RECT            rcDst;
+       POINTL          ptSrc;
        PVOID           pvBits;
+       EXLATEOBJ       exlo;
 
     SourceBitmap = DIB_CreateDIBSection(DC, bmi, ColorUse, &pvBits, NULL, 0, 0);
        if (0 == SourceBitmap)
@@ -282,40 +285,45 @@ IntSetDIBits(
                                                                                                         bmi->bmiHeader.biHeight,
                                                                                                         bmi->bmiHeader.biBitCount));
 
-       hdcSrc = NtGdiCreateCompatibleDC(0);
-       hdcDst = NtGdiCreateCompatibleDC(0);
+       psurfDst = SURFACE_LockSurface(hBitmap);
+       psurfSrc = SURFACE_LockSurface(SourceBitmap);
 
-       if(!(hdcSrc && hdcDst))
+       if(!(psurfSrc && psurfDst))
        {
-               DPRINT1("Error, could not create memory DCs.\n");
+               DPRINT1("Error, could not lock surfaces.\n");
                goto cleanup;
        }
 
-       hOldSrcBmp = NtGdiSelectBitmap(hdcSrc, SourceBitmap);
-       hOldDstBmp = NtGdiSelectBitmap(hdcDst, hBitmap);
+       rcDst.top = bmi->bmiHeader.biHeight < 0 ?
+               abs(bmi->bmiHeader.biHeight) - (ScanLines + StartScan) : StartScan;
+       rcDst.left = 0;
+       rcDst.bottom = rcDst.top + ScanLines;
+       rcDst.right = psurfDst->SurfObj.sizlBitmap.cx;
 
-       if(!(hOldSrcBmp && hOldDstBmp))
-       {
-               DPRINT1("Error : Could not select bitmaps into DCs\n");
-               goto cleanup;
-       }
+       ptSrc.x = 0;
+       ptSrc.y = 0;
 
-       result = NtGdiBitBlt(hdcDst, 0, 0, bmi->bmiHeader.biWidth, ScanLines, hdcSrc, 0, StartScan,
-                                                       SRCCOPY, 0, 0);
+       EXLATEOBJ_vInitialize(&exlo, psurfSrc->ppal, psurfDst->ppal, 0, 0, 0);
 
+       result = IntEngCopyBits(&psurfDst->SurfObj,
+                                   &psurfSrc->SurfObj,
+                                                       NULL,
+                                                       &exlo.xlo,
+                                                       &rcDst,
+                                                       &ptSrc);
        if(result)
                result = ScanLines;
 
+       EXLATEOBJ_vCleanup(&exlo);
+
 cleanup:
-       if(hdcSrc)
+       if(psurfSrc)
        {
-               if(hOldSrcBmp) NtGdiSelectBitmap(hdcSrc, hOldSrcBmp);
-               NtGdiDeleteObjectApp(hdcSrc);
+               SURFACE_UnlockSurface(psurfSrc);
        }
-       if(hdcDst)
+       if(psurfDst)
        {
-               if(hOldDstBmp) NtGdiSelectBitmap(hdcDst, hOldDstBmp);
-               NtGdiDeleteObjectApp(hdcDst);
+               SURFACE_UnlockSurface(psurfDst);
        }
        GreDeleteObject(SourceBitmap);
 
@@ -695,8 +703,7 @@ NtGdiGetDIBitsInternal(
         Info->bmiHeader.biYPelsPerMeter = 0;
         Info->bmiHeader.biClrUsed = 0;
         Info->bmiHeader.biClrImportant = 0;
-               ScanLines = psurf->SurfObj.sizlBitmap.cy;
-               /* Get Complete info now */
+               ScanLines = abs(Info->bmiHeader.biHeight);
                goto done;
 
        case 1:
@@ -723,7 +730,12 @@ NtGdiGetDIBitsInternal(
                                        }
                                }
                                if(colors != 1 << bpp) Info->bmiHeader.biClrUsed = colors;
-                               RtlCopyMemory(rgbQuads, psurf->ppal->IndexedColors, colors * sizeof(RGBQUAD));
+                               for(i=0; i < colors; i++)
+                               {
+                                       rgbQuads[i].rgbRed = psurf->ppal->IndexedColors[i].peRed;
+                                       rgbQuads[i].rgbGreen = psurf->ppal->IndexedColors[i].peGreen;
+                                       rgbQuads[i].rgbBlue = psurf->ppal->IndexedColors[i].peBlue;
+                               }
                        }
                        else
                        {
@@ -897,8 +909,11 @@ NtGdiGetDIBitsInternal(
        {
                /* Create a DIBSECTION, blt it, profit */
                PVOID pDIBits ;
-               HBITMAP hBmpDest, hOldDest = NULL, hOldSrc = NULL;
-               HDC hdcDest = NULL, hdcSrc;
+               HBITMAP hBmpDest;
+               PSURFACE psurfDest;
+               EXLATEOBJ exlo;
+               RECT rcDest;
+               POINTL srcPoint;
                BOOL ret ;
 
                if (StartScan > psurf->SurfObj.sizlBitmap.cy)
@@ -911,7 +926,15 @@ NtGdiGetDIBitsInternal(
             ScanLines = min(ScanLines, psurf->SurfObj.sizlBitmap.cy - StartScan);
                }
 
+               /* Fixup values */
+               Info->bmiHeader.biWidth = psurf->SurfObj.sizlBitmap.cx;
+               Info->bmiHeader.biHeight = height < 0 ?
+                       -ScanLines : ScanLines;
+               /* Create the DIB */
                hBmpDest = DIB_CreateDIBSection(pDC, Info, Usage, &pDIBits, NULL, 0, 0);
+               /* Restore them */
+               Info->bmiHeader.biWidth = width;
+               Info->bmiHeader.biHeight = height;
                
                if(!hBmpDest)
                {
@@ -921,56 +944,25 @@ NtGdiGetDIBitsInternal(
                        goto done ;
                }
 
-               if(psurf->hdc)
-                       hdcSrc = psurf->hdc;
-               else
-               {
-                       hdcSrc = NtGdiCreateCompatibleDC(0);
-                       if(!hdcSrc)
-                       {
-                               DPRINT1("Error: could not create HDC!\n");
-                               ScanLines = 0;
-                               goto cleanup_blt;
-                       }
-                       hOldSrc = NtGdiSelectBitmap(hdcSrc, hBitmap);
-                       if(!hOldSrc)
-                       {
-                               DPRINT1("Error : Could not Select bitmap\n");
-                               ScanLines = 0;
-                               goto cleanup_blt;
-                       }
-               }
+               psurfDest = SURFACE_LockSurface(hBmpDest);
 
-               hdcDest = NtGdiCreateCompatibleDC(0);
-               if(!hdcDest)
-               {
-                       DPRINT1("Error: could not create HDC!\n");
-                       ScanLines = 0;
-                       goto cleanup_blt;
-               }
-               hOldDest = NtGdiSelectBitmap(hdcDest, hBmpDest);
-               if(!hOldDest)
-               {
-                       DPRINT1("Error : Could not Select bitmap\n");
-                       ScanLines = 0;
-                       goto cleanup_blt;
-               }
+               rcDest.left = 0;
+               rcDest.top = 0;
+               rcDest.bottom = ScanLines;
+               rcDest.right = psurf->SurfObj.sizlBitmap.cx;
+
+               srcPoint.x = 0;
+               srcPoint.y = height < 0 ?
+                       psurf->SurfObj.sizlBitmap.cy - (StartScan + ScanLines) : StartScan;
 
-               ret = GreStretchBltMask(hdcDest,
-                                                               0,
-                                                               0,
-                                                               width, 
-                                                               height,
-                                                               hdcSrc,
-                                                               0,
-                                                               StartScan,
-                                                               psurf->SurfObj.sizlBitmap.cx,
-                                                               ScanLines,
-                                                               SRCCOPY,
-                                                               0,
-                                                               NULL,
-                                                               0,
-                                                               0);
+               EXLATEOBJ_vInitialize(&exlo, psurf->ppal, psurfDest->ppal, 0, 0, 0);
+
+               ret = IntEngCopyBits(&psurfDest->SurfObj,
+                                                        &psurf->SurfObj,
+                                                        NULL,
+                                                        &exlo.xlo,
+                                                        &rcDest,
+                                                        &srcPoint);
 
                if(!ret)
                        ScanLines = 0;
@@ -994,19 +986,10 @@ NtGdiGetDIBitsInternal(
                        }
                }
 
-       cleanup_blt:
-               if(hdcSrc && (hdcSrc != psurf->hdc))
-               {
-                       if(hOldSrc) NtGdiSelectBitmap(hdcSrc, hOldSrc);
-                       NtGdiDeleteObjectApp(hdcSrc);
-               }
-               if(hdcSrc)
-               {
-                       if(hOldDest) NtGdiSelectBitmap(hdcDest, hOldDest);
-                       NtGdiDeleteObjectApp(hdcDest);
-               }
                GreDeleteObject(hBmpDest);
+               EXLATEOBJ_vCleanup(&exlo);
        }
+       else ScanLines = abs(height);
 
 done:
 
@@ -1067,6 +1050,7 @@ NtGdiStretchDIBitsInternal(
                return 0;
        }
 
+       /* Set bits */
        _SEH2_TRY
        {
                ProbeForRead(Bits, cjMaxBits, 1);