2023-07-04 20:05:46 -07:00
|
|
|
From a9cd52667f49a57900a08591cd66b40747a12db0 Mon Sep 17 00:00:00 2001
|
2016-04-22 01:15:52 -07:00
|
|
|
From: Dmitry Timoshkov <dmitry@baikal.ru>
|
|
|
|
Date: Thu, 21 Apr 2016 14:40:58 +0800
|
2023-07-04 20:05:46 -07:00
|
|
|
Subject: [PATCH] oleaut32: OleLoadPicture should create a DIB section for a
|
|
|
|
being loaded bitmap. (v3)
|
2016-04-22 01:15:52 -07:00
|
|
|
|
|
|
|
Application in the bug 39474 depends on this (GetObject/bmBits should not be
|
|
|
|
NULL, otherwise it crashes).
|
|
|
|
---
|
2023-07-04 20:05:46 -07:00
|
|
|
dlls/oleaut32/olepicture.c | 65 +++++++++++++-------------------
|
2016-04-22 01:15:52 -07:00
|
|
|
dlls/oleaut32/tests/olepicture.c | 2 +-
|
2016-12-31 07:28:23 -08:00
|
|
|
2 files changed, 27 insertions(+), 40 deletions(-)
|
2016-04-22 01:15:52 -07:00
|
|
|
|
|
|
|
diff --git a/dlls/oleaut32/olepicture.c b/dlls/oleaut32/olepicture.c
|
2023-07-04 20:05:46 -07:00
|
|
|
index 45baa74a439..22a34d6e380 100644
|
2016-04-22 01:15:52 -07:00
|
|
|
--- a/dlls/oleaut32/olepicture.c
|
|
|
|
+++ b/dlls/oleaut32/olepicture.c
|
2023-07-04 20:05:46 -07:00
|
|
|
@@ -983,23 +983,16 @@ static HRESULT OLEPictureImpl_LoadDIB(OLEPictureImpl *This, BYTE *xbuf, ULONG xr
|
2016-04-22 01:15:52 -07:00
|
|
|
{
|
|
|
|
BITMAPFILEHEADER *bfh = (BITMAPFILEHEADER*)xbuf;
|
|
|
|
BITMAPINFO *bi = (BITMAPINFO*)(bfh+1);
|
|
|
|
- HDC hdcref;
|
|
|
|
+ void *bits;
|
|
|
|
+ BITMAP bmp;
|
|
|
|
|
|
|
|
- /* Does not matter whether this is a coreheader or not, we only use
|
|
|
|
- * components which are in both
|
|
|
|
- */
|
|
|
|
- hdcref = GetDC(0);
|
2023-07-04 20:05:46 -07:00
|
|
|
- This->desc.bmp.hbitmap = CreateDIBitmap(
|
2016-04-22 01:15:52 -07:00
|
|
|
- hdcref,
|
|
|
|
- &(bi->bmiHeader),
|
|
|
|
- CBM_INIT,
|
|
|
|
- xbuf+bfh->bfOffBits,
|
|
|
|
- bi,
|
|
|
|
- DIB_RGB_COLORS
|
|
|
|
- );
|
|
|
|
- ReleaseDC(0, hdcref);
|
2023-07-04 20:05:46 -07:00
|
|
|
+ This->desc.bmp.hbitmap = CreateDIBSection(0, bi, DIB_RGB_COLORS, &bits, NULL, 0);
|
|
|
|
if (This->desc.bmp.hbitmap == 0)
|
2016-04-22 01:15:52 -07:00
|
|
|
return E_FAIL;
|
|
|
|
+
|
|
|
|
+ GetObjectA(This->desc.u.bmp.hbitmap, sizeof(bmp), &bmp);
|
|
|
|
+ memcpy(bits, xbuf + bfh->bfOffBits, bmp.bmHeight * bmp.bmWidthBytes);
|
|
|
|
+
|
|
|
|
This->desc.picType = PICTYPE_BITMAP;
|
|
|
|
OLEPictureImpl_SetBitmap(This);
|
|
|
|
return S_OK;
|
2023-07-04 20:05:46 -07:00
|
|
|
@@ -1009,10 +1002,9 @@ static HRESULT OLEPictureImpl_LoadWICSource(OLEPictureImpl *This, IWICBitmapSour
|
2016-04-22 01:15:52 -07:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
BITMAPINFOHEADER bih;
|
|
|
|
- HDC hdcref;
|
|
|
|
UINT width, height;
|
|
|
|
UINT stride, buffersize;
|
|
|
|
- LPBYTE bits=NULL;
|
2016-12-31 07:28:23 -08:00
|
|
|
+ BYTE *bits, *mask = NULL;
|
2016-04-22 01:15:52 -07:00
|
|
|
WICRect rc;
|
|
|
|
IWICBitmapSource *real_source;
|
|
|
|
UINT x, y;
|
2023-07-04 20:05:46 -07:00
|
|
|
@@ -1040,34 +1032,28 @@ static HRESULT OLEPictureImpl_LoadWICSource(OLEPictureImpl *This, IWICBitmapSour
|
2016-04-22 01:15:52 -07:00
|
|
|
stride = 4 * width;
|
|
|
|
buffersize = stride * height;
|
|
|
|
|
|
|
|
- bits = HeapAlloc(GetProcessHeap(), 0, buffersize);
|
|
|
|
- if (!bits)
|
2016-12-31 07:28:23 -08:00
|
|
|
+ mask = HeapAlloc(GetProcessHeap(), 0, buffersize);
|
|
|
|
+ if (!mask)
|
2016-04-22 01:15:52 -07:00
|
|
|
{
|
2016-12-31 07:28:23 -08:00
|
|
|
hr = E_OUTOFMEMORY;
|
2016-04-22 01:15:52 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2023-07-04 20:05:46 -07:00
|
|
|
+ This->desc.bmp.hbitmap = CreateDIBSection(0, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void **)&bits, NULL, 0);
|
|
|
|
+ if (This->desc.bmp.hbitmap == 0)
|
2016-12-31 07:28:23 -08:00
|
|
|
+ {
|
|
|
|
+ hr = E_FAIL;
|
|
|
|
+ goto end;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
rc.X = 0;
|
|
|
|
rc.Y = 0;
|
|
|
|
rc.Width = width;
|
2016-04-22 01:15:52 -07:00
|
|
|
rc.Height = height;
|
|
|
|
hr = IWICBitmapSource_CopyPixels(real_source, &rc, stride, buffersize, bits);
|
|
|
|
if (FAILED(hr))
|
|
|
|
- goto end;
|
|
|
|
-
|
|
|
|
- hdcref = GetDC(0);
|
2023-07-04 20:05:46 -07:00
|
|
|
- This->desc.bmp.hbitmap = CreateDIBitmap(
|
2016-04-22 01:15:52 -07:00
|
|
|
- hdcref,
|
|
|
|
- &bih,
|
|
|
|
- CBM_INIT,
|
|
|
|
- bits,
|
|
|
|
- (BITMAPINFO*)&bih,
|
|
|
|
- DIB_RGB_COLORS);
|
|
|
|
-
|
2023-07-04 20:05:46 -07:00
|
|
|
- if (This->desc.bmp.hbitmap == 0)
|
2016-04-22 01:15:52 -07:00
|
|
|
{
|
|
|
|
- hr = E_FAIL;
|
|
|
|
- ReleaseDC(0, hdcref);
|
2023-07-04 20:05:46 -07:00
|
|
|
+ DeleteObject(This->desc.bmp.hbitmap);
|
2016-04-22 01:15:52 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2023-07-04 20:05:46 -07:00
|
|
|
@@ -1081,23 +1067,25 @@ static HRESULT OLEPictureImpl_LoadWICSource(OLEPictureImpl *This, IWICBitmapSour
|
2016-12-31 07:28:23 -08:00
|
|
|
if((*pixel & 0x80000000) == 0)
|
|
|
|
{
|
|
|
|
has_alpha = TRUE;
|
|
|
|
- *pixel = black;
|
|
|
|
+ *(DWORD *)(mask + stride * y + 4 * x) = black;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
- *pixel = white;
|
|
|
|
+ *(DWORD *)(mask + stride * y + 4 * x) = white;
|
|
|
|
}
|
|
|
|
}
|
2016-04-22 01:15:52 -07:00
|
|
|
|
|
|
|
if (has_alpha)
|
|
|
|
{
|
|
|
|
- HDC hdcBmp, hdcXor, hdcMask;
|
|
|
|
+ HDC hdcref, hdcBmp, hdcXor, hdcMask;
|
|
|
|
HBITMAP hbmoldBmp, hbmoldXor, hbmoldMask;
|
|
|
|
|
|
|
|
+ hdcref = GetDC(0);
|
|
|
|
+
|
|
|
|
This->hbmXor = CreateDIBitmap(
|
|
|
|
hdcref,
|
|
|
|
&bih,
|
2016-12-31 07:28:23 -08:00
|
|
|
CBM_INIT,
|
|
|
|
- bits,
|
|
|
|
+ mask,
|
|
|
|
(BITMAPINFO*)&bih,
|
|
|
|
DIB_RGB_COLORS
|
|
|
|
);
|
2023-07-04 20:05:46 -07:00
|
|
|
@@ -1122,12 +1110,11 @@ static HRESULT OLEPictureImpl_LoadWICSource(OLEPictureImpl *This, IWICBitmapSour
|
2016-04-22 01:15:52 -07:00
|
|
|
DeleteDC(hdcBmp);
|
|
|
|
DeleteDC(hdcXor);
|
|
|
|
DeleteDC(hdcMask);
|
|
|
|
+ ReleaseDC(0, hdcref);
|
|
|
|
}
|
|
|
|
|
|
|
|
- ReleaseDC(0, hdcref);
|
|
|
|
-
|
|
|
|
end:
|
|
|
|
- HeapFree(GetProcessHeap(), 0, bits);
|
2016-12-31 07:28:23 -08:00
|
|
|
+ HeapFree(GetProcessHeap(), 0, mask);
|
2016-04-22 01:15:52 -07:00
|
|
|
IWICBitmapSource_Release(real_source);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
diff --git a/dlls/oleaut32/tests/olepicture.c b/dlls/oleaut32/tests/olepicture.c
|
2023-07-04 20:05:46 -07:00
|
|
|
index 7b45b690935..fa7e8009cbd 100644
|
2016-04-22 01:15:52 -07:00
|
|
|
--- a/dlls/oleaut32/tests/olepicture.c
|
|
|
|
+++ b/dlls/oleaut32/tests/olepicture.c
|
2023-07-04 20:05:46 -07:00
|
|
|
@@ -239,7 +239,7 @@ test_pic_with_stream(LPSTREAM stream, unsigned int imgsize)
|
2016-04-22 01:15:52 -07:00
|
|
|
{
|
|
|
|
BITMAP bmp;
|
|
|
|
GetObjectA(UlongToHandle(handle), sizeof(BITMAP), &bmp);
|
|
|
|
- todo_wine ok(bmp.bmBits != 0, "not a dib\n");
|
|
|
|
+ ok(bmp.bmBits != 0, "not a dib\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
width = 0;
|
|
|
|
--
|
2023-07-04 20:05:46 -07:00
|
|
|
2.40.1
|
2016-04-22 01:15:52 -07:00
|
|
|
|