Commit 1914f3ec authored by Alexandre Julliard's avatar Alexandre Julliard

gdi32: Copy a DIB section as a DIB section in BITMAP_CopyBitmap.

parent 91d91afb
......@@ -510,17 +510,41 @@ LONG WINAPI SetBitmapBits(
*/
HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
{
HBITMAP res = 0;
BITMAP bm;
HBITMAP res;
DIBSECTION dib;
DWORD size;
if (!(size = GetObjectW( hbitmap, sizeof(dib), &dib ))) return 0;
if (!GetObjectW( hbitmap, sizeof(bm), &bm )) return 0;
res = CreateBitmapIndirect(&bm);
if (size == sizeof(DIBSECTION))
{
void *bits;
BITMAPINFO *bi;
HDC dc = CreateCompatibleDC( NULL );
if (!dc) return 0;
if (!(bi = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ))))
{
DeleteDC( dc );
return 0;
}
bi->bmiHeader = dib.dsBmih;
/* Get the color table or the color masks */
GetDIBits( dc, hbitmap, 0, 0, NULL, bi, DIB_RGB_COLORS );
res = CreateDIBSection( dc, bi, DIB_RGB_COLORS, &bits, NULL, 0 );
if (res) SetDIBits( dc, res, 0, dib.dsBm.bmHeight, dib.dsBm.bmBits, bi, DIB_RGB_COLORS );
HeapFree( GetProcessHeap(), 0, bi );
DeleteDC( dc );
return res;
}
res = CreateBitmapIndirect( &dib.dsBm );
if(res) {
char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
bm.bmHeight );
GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
char *buf = HeapAlloc( GetProcessHeap(), 0, dib.dsBm.bmWidthBytes * dib.dsBm.bmHeight );
GetBitmapBits (hbitmap, dib.dsBm.bmWidthBytes * dib.dsBm.bmHeight, buf);
SetBitmapBits (res, dib.dsBm.bmWidthBytes * dib.dsBm.bmHeight, buf);
HeapFree( GetProcessHeap(), 0, buf );
}
return res;
......
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