gdiplus: Allocate enough space for BITMAPINFO in GdipLoadImageFromStream.
This commit is contained in:
parent
778ea2360e
commit
83d92f4195
|
@ -974,13 +974,19 @@ GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
|
||||||
IPicture_get_Type(pic, &type);
|
IPicture_get_Type(pic, &type);
|
||||||
|
|
||||||
if(type == PICTYPE_BITMAP){
|
if(type == PICTYPE_BITMAP){
|
||||||
BITMAPINFO bmi;
|
BITMAPINFO *pbmi;
|
||||||
BITMAPCOREHEADER* bmch;
|
BITMAPCOREHEADER* bmch;
|
||||||
OLE_HANDLE hbm;
|
OLE_HANDLE hbm;
|
||||||
HDC hdc;
|
HDC hdc;
|
||||||
|
|
||||||
|
pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
|
||||||
|
if (!pbmi)
|
||||||
|
return OutOfMemory;
|
||||||
*image = GdipAlloc(sizeof(GpBitmap));
|
*image = GdipAlloc(sizeof(GpBitmap));
|
||||||
if(!*image) return OutOfMemory;
|
if(!*image){
|
||||||
|
GdipFree(pbmi);
|
||||||
|
return OutOfMemory;
|
||||||
|
}
|
||||||
(*image)->type = ImageTypeBitmap;
|
(*image)->type = ImageTypeBitmap;
|
||||||
|
|
||||||
(*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
|
(*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
|
||||||
|
@ -990,22 +996,22 @@ GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
|
||||||
IPicture_get_Handle(pic, &hbm);
|
IPicture_get_Handle(pic, &hbm);
|
||||||
IPicture_get_CurDC(pic, &hdc);
|
IPicture_get_CurDC(pic, &hdc);
|
||||||
|
|
||||||
ZeroMemory(&bmi, sizeof(bmi));
|
bmch = (BITMAPCOREHEADER*) (&pbmi->bmiHeader);
|
||||||
bmch = (BITMAPCOREHEADER*) (&bmi.bmiHeader);
|
|
||||||
bmch->bcSize = sizeof(BITMAPCOREHEADER);
|
bmch->bcSize = sizeof(BITMAPCOREHEADER);
|
||||||
|
|
||||||
if(!hdc){
|
if(!hdc){
|
||||||
HBITMAP old;
|
HBITMAP old;
|
||||||
hdc = CreateCompatibleDC(0);
|
hdc = CreateCompatibleDC(0);
|
||||||
old = SelectObject(hdc, (HBITMAP)hbm);
|
old = SelectObject(hdc, (HBITMAP)hbm);
|
||||||
GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
|
GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
|
||||||
SelectObject(hdc, old);
|
SelectObject(hdc, old);
|
||||||
DeleteDC(hdc);
|
DeleteDC(hdc);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
|
GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
|
||||||
|
|
||||||
(*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
|
(*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
|
||||||
|
GdipFree(pbmi);
|
||||||
}
|
}
|
||||||
else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
|
else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
|
||||||
/* FIXME: missing initialization code */
|
/* FIXME: missing initialization code */
|
||||||
|
|
Loading…
Reference in New Issue