Alexandre Julliard : gdi32: Create a sanitized BITMAPINFO in StretchDIBits and pass that to the drivers .
Alexandre Julliard
julliard at winehq.org
Thu Aug 4 12:22:10 CDT 2011
Module: wine
Branch: master
Commit: d0d98046c61b5d97d0947179bfd3088f89095347
URL: http://source.winehq.org/git/wine.git/?a=commit;h=d0d98046c61b5d97d0947179bfd3088f89095347
Author: Alexandre Julliard <julliard at winehq.org>
Date: Thu Aug 4 13:09:34 2011 +0200
gdi32: Create a sanitized BITMAPINFO in StretchDIBits and pass that to the drivers.
---
dlls/gdi32/dib.c | 21 +++++++++----------
dlls/gdi32/enhmfdrv/bitblt.c | 9 +++----
dlls/gdi32/mfdrv/bitblt.c | 5 +--
dlls/wineps.drv/bitmap.c | 45 ++++-------------------------------------
4 files changed, 21 insertions(+), 59 deletions(-)
diff --git a/dlls/gdi32/dib.c b/dlls/gdi32/dib.c
index 3e23547..c05e8e3 100644
--- a/dlls/gdi32/dib.c
+++ b/dlls/gdi32/dib.c
@@ -389,9 +389,7 @@ INT nulldrv_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst, INT he
{
DC *dc = get_nulldrv_dc( dev );
INT ret;
- LONG width, height;
- WORD planes, bpp;
- DWORD compr, size;
+ LONG height;
HBITMAP hBitmap;
HDC hdcMem;
@@ -399,10 +397,8 @@ INT nulldrv_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst, INT he
if (GET_DC_PHYSDEV( dc, pStretchBlt ) == dev || GET_DC_PHYSDEV( dc, pPutImage ) == dev)
return 0;
- if (DIB_GetBitmapInfo( &info->bmiHeader, &width, &height, &planes, &bpp, &compr, &size ) == -1)
- return 0;
-
- if (width < 0) return 0;
+ if (info->bmiHeader.biWidth < 0) return 0;
+ height = info->bmiHeader.biHeight;
if (xSrc == 0 && ySrc == 0 && widthDst == widthSrc && heightDst == heightSrc &&
info->bmiHeader.biCompression == BI_RGB)
@@ -417,7 +413,7 @@ INT nulldrv_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst, INT he
hBitmap = GetCurrentObject( dev->hdc, OBJ_BITMAP );
if (GetObjectW( hBitmap, sizeof(bm), &bm ) &&
bm.bmWidth == widthSrc && bm.bmHeight == heightSrc &&
- bm.bmBitsPixel == bpp && bm.bmPlanes == planes)
+ bm.bmBitsPixel == info->bmiHeader.biBitCount && bm.bmPlanes == 1)
{
/* fast path */
return SetDIBits( dev->hdc, hBitmap, 0, abs( height ), bits, info, coloruse );
@@ -426,7 +422,7 @@ INT nulldrv_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst, INT he
}
hdcMem = CreateCompatibleDC( dev->hdc );
- hBitmap = CreateCompatibleBitmap( dev->hdc, width, height );
+ hBitmap = CreateCompatibleBitmap( dev->hdc, info->bmiHeader.biWidth, height );
SelectObject( hdcMem, hBitmap );
if (coloruse == DIB_PAL_COLORS)
SelectPalette( hdcMem, GetCurrentObject( dev->hdc, OBJ_PAL ), FALSE );
@@ -457,12 +453,15 @@ INT nulldrv_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst, INT he
*/
INT WINAPI StretchDIBits(HDC hdc, INT xDst, INT yDst, INT widthDst, INT heightDst,
INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, const void *bits,
- const BITMAPINFO *info, UINT coloruse, DWORD rop )
+ const BITMAPINFO *bmi, UINT coloruse, DWORD rop )
{
+ char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
+ BITMAPINFO *info = (BITMAPINFO *)buffer;
DC *dc;
INT ret = 0;
- if (!bits || !info) return 0;
+ if (!bits) return 0;
+ if (!bitmapinfo_from_user_bitmapinfo( info, bmi, coloruse )) return 0;
if ((dc = get_dc_ptr( hdc )))
{
diff --git a/dlls/gdi32/enhmfdrv/bitblt.c b/dlls/gdi32/enhmfdrv/bitblt.c
index 6d88a3c..feb1016 100644
--- a/dlls/gdi32/enhmfdrv/bitblt.c
+++ b/dlls/gdi32/enhmfdrv/bitblt.c
@@ -175,13 +175,12 @@ INT EMFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst, INT hei
{
EMRSTRETCHDIBITS *emr;
BOOL ret;
- UINT bmi_size=0, emr_size;
- UINT bits_size = get_dib_image_size(info);
+ UINT bmi_size, emr_size;
/* calculate the size of the colour table */
bmi_size = bitmap_info_size(info, wUsage);
- emr_size = sizeof (EMRSTRETCHDIBITS) + bmi_size + bits_size;
+ emr_size = sizeof (EMRSTRETCHDIBITS) + bmi_size + info->bmiHeader.biSizeImage;
emr = HeapAlloc(GetProcessHeap(), 0, emr_size );
if (!emr) return 0;
@@ -189,7 +188,7 @@ INT EMFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst, INT hei
memcpy( &emr[1], info, bmi_size);
/* write bitmap bits to the record */
- memcpy ( ( (BYTE *) (&emr[1]) ) + bmi_size, bits, bits_size);
+ memcpy ( ( (BYTE *) (&emr[1]) ) + bmi_size, bits, info->bmiHeader.biSizeImage);
/* fill in the EMR header at the front of our piece of memory */
emr->emr.iType = EMR_STRETCHDIBITS;
@@ -207,7 +206,7 @@ INT EMFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst, INT hei
emr->offBmiSrc = sizeof (EMRSTRETCHDIBITS);
emr->cbBmiSrc = bmi_size;
emr->offBitsSrc = emr->offBmiSrc + bmi_size;
- emr->cbBitsSrc = bits_size;
+ emr->cbBitsSrc = info->bmiHeader.biSizeImage;
emr->cxSrc = widthSrc;
emr->cySrc = heightSrc;
diff --git a/dlls/gdi32/mfdrv/bitblt.c b/dlls/gdi32/mfdrv/bitblt.c
index bd589de..aabf9f5 100644
--- a/dlls/gdi32/mfdrv/bitblt.c
+++ b/dlls/gdi32/mfdrv/bitblt.c
@@ -136,8 +136,7 @@ INT MFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
{
DWORD infosize = bitmap_info_size(info, wUsage);
- DWORD imagesize = get_dib_image_size( info );
- DWORD len = sizeof(METARECORD) + 10 * sizeof(WORD) + infosize + imagesize;
+ DWORD len = sizeof(METARECORD) + 10 * sizeof(WORD) + infosize + info->bmiHeader.biSizeImage;
METARECORD *mr = HeapAlloc( GetProcessHeap(), 0, len );
if(!mr) return 0;
@@ -155,7 +154,7 @@ INT MFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
mr->rdParm[9] = (INT16)yDst;
mr->rdParm[10] = (INT16)xDst;
memcpy(mr->rdParm + 11, info, infosize);
- memcpy(mr->rdParm + 11 + infosize / 2, bits, imagesize);
+ memcpy(mr->rdParm + 11 + infosize / 2, bits, info->bmiHeader.biSizeImage);
MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
HeapFree( GetProcessHeap(), 0, mr );
return heightSrc;
diff --git a/dlls/wineps.drv/bitmap.c b/dlls/wineps.drv/bitmap.c
index 4897b4e..7f2d507 100644
--- a/dlls/wineps.drv/bitmap.c
+++ b/dlls/wineps.drv/bitmap.c
@@ -49,37 +49,6 @@ static inline int get_dib_width_bytes( int width, int depth )
return 4 * words;
}
-/* get the bitmap info from either an INFOHEADER or COREHEADER bitmap */
-static BOOL get_bitmap_info( const void *ptr, LONG *width, LONG *height, WORD *bpp, WORD *compr )
-{
- const BITMAPINFOHEADER *header = ptr;
-
- switch(header->biSize)
- {
- case sizeof(BITMAPCOREHEADER):
- {
- const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)header;
- *width = core->bcWidth;
- *height = core->bcHeight;
- *bpp = core->bcBitCount;
- *compr = 0;
- }
- return TRUE;
- case sizeof(BITMAPINFOHEADER):
- case sizeof(BITMAPV4HEADER):
- case sizeof(BITMAPV5HEADER):
- /* V4 and V5 structures are a superset of the INFOHEADER structure */
- *width = header->biWidth;
- *height = header->biHeight;
- *bpp = header->biBitCount;
- *compr = header->biCompression;
- return TRUE;
- default:
- ERR("(%d): unknown/wrong size for header\n", header->biSize );
- return FALSE;
- }
-}
-
/***************************************************************************
* PSDRV_WriteImageHeader
@@ -336,9 +305,7 @@ INT PSDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
INT heightDst, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, const void *bits,
const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
{
- LONG fullSrcWidth, fullSrcHeight;
INT stride;
- WORD bpp, compression;
INT line;
POINT pt[2];
const BYTE *src_ptr;
@@ -348,15 +315,13 @@ INT PSDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
TRACE("%p (%d,%d %dx%d) -> (%d,%d %dx%d)\n", dev->hdc,
xSrc, ySrc, widthSrc, heightSrc, xDst, yDst, widthDst, heightDst);
- if (!get_bitmap_info( info, &fullSrcWidth, &fullSrcHeight, &bpp, &compression )) return FALSE;
-
- stride = get_dib_width_bytes(fullSrcWidth, bpp);
+ stride = get_dib_width_bytes( info->bmiHeader.biWidth, info->bmiHeader.biBitCount );
- TRACE("full size=%dx%d bpp=%d compression=%d rop=%08x\n", fullSrcWidth,
- fullSrcHeight, bpp, compression, dwRop);
+ TRACE("full size=%dx%d bpp=%d compression=%d rop=%08x\n", info->bmiHeader.biWidth,
+ info->bmiHeader.biHeight, info->bmiHeader.biBitCount, info->bmiHeader.biCompression, dwRop);
- if(compression != BI_RGB) {
+ if(info->bmiHeader.biCompression != BI_RGB) {
FIXME("Compression not supported\n");
return FALSE;
}
@@ -371,7 +336,7 @@ INT PSDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
widthDst = pt[1].x - pt[0].x;
heightDst = pt[1].y - pt[0].y;
- switch(bpp) {
+ switch (info->bmiHeader.biBitCount) {
case 1:
src_ptr = bits;
More information about the wine-cvs
mailing list