gdiplus: CreateDIBSection doesn't need a DC for the DIB_RGB_COLORS case.

This commit is contained in:
Alexandre Julliard 2012-05-02 12:02:17 +02:00
parent d2e8d44811
commit 039c85346c
3 changed files with 4 additions and 30 deletions

View File

@ -265,7 +265,6 @@ COLORREF ARGB2COLORREF(ARGB color)
HBITMAP ARGB2BMP(ARGB color) HBITMAP ARGB2BMP(ARGB color)
{ {
HDC hdc;
BITMAPINFO bi; BITMAPINFO bi;
HBITMAP result; HBITMAP result;
RGBQUAD *bits; RGBQUAD *bits;
@ -273,8 +272,6 @@ HBITMAP ARGB2BMP(ARGB color)
if ((color & 0xff000000) == 0xff000000) return 0; if ((color & 0xff000000) == 0xff000000) return 0;
hdc = CreateCompatibleDC(NULL);
bi.bmiHeader.biSize = sizeof(bi.bmiHeader); bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
bi.bmiHeader.biWidth = 1; bi.bmiHeader.biWidth = 1;
bi.bmiHeader.biHeight = 1; bi.bmiHeader.biHeight = 1;
@ -287,15 +284,13 @@ HBITMAP ARGB2BMP(ARGB color)
bi.bmiHeader.biClrUsed = 0; bi.bmiHeader.biClrUsed = 0;
bi.bmiHeader.biClrImportant = 0; bi.bmiHeader.biClrImportant = 0;
result = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, (void*)&bits, NULL, 0); result = CreateDIBSection(0, &bi, DIB_RGB_COLORS, (void*)&bits, NULL, 0);
bits[0].rgbReserved = alpha = (color>>24)&0xff; bits[0].rgbReserved = alpha = (color>>24)&0xff;
bits[0].rgbRed = ((color>>16)&0xff)*alpha/255; bits[0].rgbRed = ((color>>16)&0xff)*alpha/255;
bits[0].rgbGreen = ((color>>8)&0xff)*alpha/255; bits[0].rgbGreen = ((color>>8)&0xff)*alpha/255;
bits[0].rgbBlue = (color&0xff)*alpha/255; bits[0].rgbBlue = (color&0xff)*alpha/255;
DeleteDC(hdc);
return result; return result;
} }

View File

@ -131,15 +131,10 @@ static COLORREF get_gdi_brush_color(const GpBrush *brush)
static HBITMAP create_hatch_bitmap(const GpHatch *hatch) static HBITMAP create_hatch_bitmap(const GpHatch *hatch)
{ {
HBITMAP hbmp; HBITMAP hbmp;
HDC hdc;
BITMAPINFOHEADER bmih; BITMAPINFOHEADER bmih;
DWORD *bits; DWORD *bits;
int x, y; int x, y;
hdc = CreateCompatibleDC(0);
if (!hdc) return 0;
bmih.biSize = sizeof(bmih); bmih.biSize = sizeof(bmih);
bmih.biWidth = 8; bmih.biWidth = 8;
bmih.biHeight = 8; bmih.biHeight = 8;
@ -148,7 +143,7 @@ static HBITMAP create_hatch_bitmap(const GpHatch *hatch)
bmih.biCompression = BI_RGB; bmih.biCompression = BI_RGB;
bmih.biSizeImage = 0; bmih.biSizeImage = 0;
hbmp = CreateDIBSection(hdc, (BITMAPINFO *)&bmih, DIB_RGB_COLORS, (void **)&bits, NULL, 0); hbmp = CreateDIBSection(0, (BITMAPINFO *)&bmih, DIB_RGB_COLORS, (void **)&bits, NULL, 0);
if (hbmp) if (hbmp)
{ {
const char *hatch_data; const char *hatch_data;
@ -175,7 +170,6 @@ static HBITMAP create_hatch_bitmap(const GpHatch *hatch)
} }
} }
DeleteDC(hdc);
return hbmp; return hbmp;
} }

View File

@ -1372,7 +1372,6 @@ GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
GpStatus stat; GpStatus stat;
HBITMAP result; HBITMAP result;
UINT width, height; UINT width, height;
HDC hdc;
BITMAPINFOHEADER bih; BITMAPINFOHEADER bih;
LPBYTE bits; LPBYTE bits;
BitmapData lockeddata; BitmapData lockeddata;
@ -1395,11 +1394,7 @@ GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
bih.biClrUsed = 0; bih.biClrUsed = 0;
bih.biClrImportant = 0; bih.biClrImportant = 0;
hdc = CreateCompatibleDC(NULL); result = CreateDIBSection(0, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
if (!hdc) return GenericError;
result = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)&bits,
NULL, 0);
if (result) if (result)
{ {
@ -1415,8 +1410,6 @@ GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
else else
stat = GenericError; stat = GenericError;
DeleteDC(hdc);
if (stat != Ok && result) if (stat != Ok && result)
{ {
DeleteObject(result); DeleteObject(result);
@ -1694,7 +1687,6 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
BITMAPINFO* pbmi; BITMAPINFO* pbmi;
HBITMAP hbitmap=NULL; HBITMAP hbitmap=NULL;
INT row_size, dib_stride; INT row_size, dib_stride;
HDC hdc;
BYTE *bits=NULL, *own_bits=NULL; BYTE *bits=NULL, *own_bits=NULL;
REAL xres, yres; REAL xres, yres;
GpStatus stat; GpStatus stat;
@ -1739,15 +1731,8 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
pbmi->bmiHeader.biClrUsed = 0; pbmi->bmiHeader.biClrUsed = 0;
pbmi->bmiHeader.biClrImportant = 0; pbmi->bmiHeader.biClrImportant = 0;
hdc = CreateCompatibleDC(NULL); hbitmap = CreateDIBSection(0, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
if (!hdc) {
GdipFree(pbmi);
return GenericError;
}
hbitmap = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
DeleteDC(hdc);
GdipFree(pbmi); GdipFree(pbmi);
if (!hbitmap) return GenericError; if (!hbitmap) return GenericError;