Commit 04412f7a authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

gdiplus: Avoid accessing dib bits directly in GdipCreateBitmapFromHBITMAP.

parent c98767a4
...@@ -4694,62 +4694,50 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBi ...@@ -4694,62 +4694,50 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBi
format, &lockeddata); format, &lockeddata);
if (retval == Ok) if (retval == Ok)
{ {
if (bm.bmBits) HDC hdc;
{ HBITMAP oldhbm;
for (y=0; y<bm.bmHeight; y++) BITMAPINFO *pbmi;
{ INT src_height, dst_stride;
memcpy((BYTE*)lockeddata.Scan0+lockeddata.Stride*y, BYTE *dst_bits;
(BYTE*)bm.bmBits+bm.bmWidthBytes*(bm.bmHeight-1-y),
bm.bmWidthBytes);
}
}
else
{
HDC hdc;
HBITMAP oldhbm;
BITMAPINFO *pbmi;
INT src_height, dst_stride;
BYTE *dst_bits;
hdc = CreateCompatibleDC(NULL); hdc = CreateCompatibleDC(NULL);
oldhbm = SelectObject(hdc, hbm); oldhbm = SelectObject(hdc, hbm);
pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
if (pbmi) if (pbmi)
{ {
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biBitCount = 0; pbmi->bmiHeader.biBitCount = 0;
GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
src_height = abs(pbmi->bmiHeader.biHeight);
if (pbmi->bmiHeader.biHeight > 0) GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
{
dst_bits = (BYTE*)lockeddata.Scan0+lockeddata.Stride*(src_height-1);
dst_stride = -lockeddata.Stride;
}
else
{
dst_bits = lockeddata.Scan0;
dst_stride = lockeddata.Stride;
}
for (y=0; y<src_height; y++) src_height = abs(pbmi->bmiHeader.biHeight);
{
GetDIBits(hdc, hbm, y, 1, dst_bits+dst_stride*y,
pbmi, DIB_RGB_COLORS);
}
GdipFree(pbmi); if (pbmi->bmiHeader.biHeight > 0)
{
dst_bits = (BYTE*)lockeddata.Scan0+lockeddata.Stride*(src_height-1);
dst_stride = -lockeddata.Stride;
} }
else else
retval = OutOfMemory; {
dst_bits = lockeddata.Scan0;
dst_stride = lockeddata.Stride;
}
for (y=0; y<src_height; y++)
{
GetDIBits(hdc, hbm, y, 1, dst_bits+dst_stride*y,
pbmi, DIB_RGB_COLORS);
}
SelectObject(hdc, oldhbm); GdipFree(pbmi);
DeleteDC(hdc);
} }
else
retval = OutOfMemory;
SelectObject(hdc, oldhbm);
DeleteDC(hdc);
GdipBitmapUnlockBits(*bitmap, &lockeddata); GdipBitmapUnlockBits(*bitmap, &lockeddata);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment