Module: wine Branch: master Commit: 1837210159522a06aaad0c758a5d77bca319f262 URL: http://source.winehq.org/git/wine.git/?a=commit;h=1837210159522a06aaad0c758a...
Author: Ken Thomases ken@codeweavers.com Date: Sun Oct 23 13:03:27 2016 -0500
winemac: Use GetDIBits to retrieve the bitmap header when exporting a bitmap.
Signed-off-by: Ken Thomases ken@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/winemac.drv/clipboard.c | 87 ++++++++++---------------------------------- 1 file changed, 19 insertions(+), 68 deletions(-)
diff --git a/dlls/winemac.drv/clipboard.c b/dlls/winemac.drv/clipboard.c index 4c66b9f..75563ad 100644 --- a/dlls/winemac.drv/clipboard.c +++ b/dlls/winemac.drv/clipboard.c @@ -410,77 +410,28 @@ static int bitmap_info_size(const BITMAPINFO *info, WORD coloruse) * * Allocates a packed DIB and copies the bitmap data into it. */ -static HGLOBAL create_dib_from_bitmap(HBITMAP hBmp) +static HGLOBAL create_dib_from_bitmap(HBITMAP bitmap) { - BITMAP bmp; - HDC hdc; - HGLOBAL hPackedDIB; - LPBYTE pPackedDIB; - LPBITMAPINFOHEADER pbmiHeader; - unsigned int cDataSize, cPackedSize, OffsetBits; - int nLinesCopied; - - if (!GetObjectW(hBmp, sizeof(bmp), &bmp)) return 0; - - /* - * A packed DIB contains a BITMAPINFO structure followed immediately by - * an optional color palette and the pixel data. - */ - - /* Calculate the size of the packed DIB */ - cDataSize = abs(bmp.bmHeight) * (((bmp.bmWidth * bmp.bmBitsPixel + 31) / 8) & ~3); - cPackedSize = sizeof(BITMAPINFOHEADER) - + ((bmp.bmBitsPixel <= 8) ? (sizeof(RGBQUAD) * (1 << bmp.bmBitsPixel)) : 0) - + cDataSize; - /* Get the offset to the bits */ - OffsetBits = cPackedSize - cDataSize; - - /* Allocate the packed DIB */ - TRACE("\tAllocating packed DIB of size %d\n", cPackedSize); - hPackedDIB = GlobalAlloc(GMEM_FIXED, cPackedSize); - if (!hPackedDIB) - { - WARN("Could not allocate packed DIB!\n"); - return 0; - } + HANDLE ret = 0; + BITMAPINFOHEADER header; + HDC hdc = GetDC(0); + DWORD header_size; + BITMAPINFO *bmi;
- /* A packed DIB starts with a BITMAPINFOHEADER */ - pPackedDIB = GlobalLock(hPackedDIB); - pbmiHeader = (LPBITMAPINFOHEADER)pPackedDIB; - - /* Init the BITMAPINFOHEADER */ - pbmiHeader->biSize = sizeof(BITMAPINFOHEADER); - pbmiHeader->biWidth = bmp.bmWidth; - pbmiHeader->biHeight = bmp.bmHeight; - pbmiHeader->biPlanes = 1; - pbmiHeader->biBitCount = bmp.bmBitsPixel; - pbmiHeader->biCompression = BI_RGB; - pbmiHeader->biSizeImage = 0; - pbmiHeader->biXPelsPerMeter = pbmiHeader->biYPelsPerMeter = 0; - pbmiHeader->biClrUsed = 0; - pbmiHeader->biClrImportant = 0; - - /* Retrieve the DIB bits from the bitmap and fill in the - * DIB color table if present */ - hdc = GetDC(0); - nLinesCopied = GetDIBits(hdc, /* Handle to device context */ - hBmp, /* Handle to bitmap */ - 0, /* First scan line to set in dest bitmap */ - bmp.bmHeight, /* Number of scan lines to copy */ - pPackedDIB + OffsetBits, /* [out] Address of array for bitmap bits */ - (LPBITMAPINFO) pbmiHeader, /* [out] Address of BITMAPINFO structure */ - 0); /* RGB or palette index */ - GlobalUnlock(hPackedDIB); - ReleaseDC(0, hdc); + memset(&header, 0, sizeof(header)); + header.biSize = sizeof(header); + if (!GetDIBits(hdc, bitmap, 0, 0, NULL, (BITMAPINFO *)&header, DIB_RGB_COLORS)) goto done;
- /* Cleanup if GetDIBits failed */ - if (nLinesCopied != bmp.bmHeight) - { - TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied, bmp.bmHeight); - GlobalFree(hPackedDIB); - hPackedDIB = 0; - } - return hPackedDIB; + header_size = bitmap_info_size((BITMAPINFO *)&header, DIB_RGB_COLORS); + if (!(ret = GlobalAlloc(GMEM_FIXED, header_size + header.biSizeImage))) goto done; + bmi = (BITMAPINFO *)ret; + memset(bmi, 0, header_size); + memcpy(bmi, &header, header.biSize); + GetDIBits(hdc, bitmap, 0, abs(header.biHeight), (char *)bmi + header_size, bmi, DIB_RGB_COLORS); + +done: + ReleaseDC(0, hdc); + return ret; }