Commit d5fce697 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

When loading a bitmap we should stretch the image to the requested

size.
parent 6b1e80cb
...@@ -2059,15 +2059,22 @@ static void DIB_FixColorsToLoadflags(BITMAPINFO * bmi, UINT loadflags, BYTE pix) ...@@ -2059,15 +2059,22 @@ static void DIB_FixColorsToLoadflags(BITMAPINFO * bmi, UINT loadflags, BYTE pix)
/********************************************************************** /**********************************************************************
* BITMAP_Load * BITMAP_Load
*/ */
static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name, UINT loadflags ) static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name,
INT desiredx, INT desiredy, UINT loadflags )
{ {
HBITMAP hbitmap = 0; HBITMAP hbitmap = 0, orig_bm;
HRSRC hRsrc; HRSRC hRsrc;
HGLOBAL handle; HGLOBAL handle;
char *ptr = NULL; char *ptr = NULL;
BITMAPINFO *info, *fix_info=NULL; BITMAPINFO *info, *fix_info = NULL, *scaled_info = NULL;
HGLOBAL hFix;
int size; int size;
BYTE pix;
char *bits;
LONG width, height, new_width, new_height;
WORD bpp_dummy;
DWORD compr_dummy;
INT bm_type;
HDC screen_mem_dc = NULL;
if (!(loadflags & LR_LOADFROMFILE)) if (!(loadflags & LR_LOADFROMFILE))
{ {
...@@ -2090,62 +2097,68 @@ static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name, UINT loadflags ) ...@@ -2090,62 +2097,68 @@ static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name, UINT loadflags )
} }
size = bitmap_info_size(info, DIB_RGB_COLORS); size = bitmap_info_size(info, DIB_RGB_COLORS);
if ((hFix = GlobalAlloc(0, size))) fix_info=GlobalLock(hFix); fix_info = HeapAlloc(GetProcessHeap(), 0, size);
scaled_info = HeapAlloc(GetProcessHeap(), 0, size);
if (fix_info) { if (!fix_info || !scaled_info) goto end;
BYTE pix; memcpy(fix_info, info, size);
memcpy(fix_info, info, size); pix = *((LPBYTE)info + size);
pix = *((LPBYTE)info + size); DIB_FixColorsToLoadflags(fix_info, loadflags, pix);
DIB_FixColorsToLoadflags(fix_info, loadflags, pix);
if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
if (screen_dc) memcpy(scaled_info, fix_info, size);
{ bm_type = DIB_GetBitmapInfo( &fix_info->bmiHeader, &width, &height,
char *bits = (char *)info + size; &bpp_dummy, &compr_dummy);
if(desiredx != 0)
if (loadflags & LR_CREATEDIBSECTION) { new_width = desiredx;
DIBSECTION dib; else
fix_info->bmiHeader.biCompression = 0; /* DIBSection can't be compressed */ new_width = width;
hbitmap = CreateDIBSection(screen_dc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
GetObjectA(hbitmap, sizeof(DIBSECTION), &dib);
SetDIBits(screen_dc, hbitmap, 0, dib.dsBm.bmHeight, bits, info,
DIB_RGB_COLORS);
}
else {
/* If it's possible, create a monochrome bitmap */
LONG width; if(desiredy != 0)
LONG height; new_height = height > 0 ? desiredy : -desiredy;
WORD bpp; else
DWORD compr; new_height = height;
if (DIB_GetBitmapInfo( &fix_info->bmiHeader, &width, &height, &bpp, &compr ) != -1) if(bm_type == 0)
{ {
if (width < 0) BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)&scaled_info->bmiHeader;
TRACE("Bitmap has a negative width\n"); core->bcWidth = new_width;
else core->bcHeight = new_height;
{ }
/* Top-down DIBs have a negative height */ else
if (height < 0) height = -height; {
scaled_info->bmiHeader.biWidth = new_width;
TRACE("width=%ld, height=%ld, bpp=%u, compr=%lu\n", width, height, bpp, compr); scaled_info->bmiHeader.biHeight = new_height;
}
if (is_dib_monochrome(fix_info))
hbitmap = CreateBitmap(width, height, 1, 1, NULL); if (new_height < 0) new_height = -new_height;
else
hbitmap = CreateCompatibleBitmap(screen_dc, width, height); if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
if (!(screen_mem_dc = CreateCompatibleDC( screen_dc ))) goto end;
SetDIBits(screen_dc, hbitmap, 0, height, bits, fix_info, DIB_RGB_COLORS);
} bits = (char *)info + size;
}
}
}
GlobalUnlock(hFix); if (loadflags & LR_CREATEDIBSECTION)
GlobalFree(hFix); {
scaled_info->bmiHeader.biCompression = 0; /* DIBSection can't be compressed */
hbitmap = CreateDIBSection(screen_dc, scaled_info, DIB_RGB_COLORS, NULL, 0, 0);
}
else
{
if (is_dib_monochrome(fix_info))
hbitmap = CreateBitmap(new_width, new_height, 1, 1, NULL);
else
hbitmap = CreateCompatibleBitmap(screen_dc, new_width, new_height);
} }
orig_bm = SelectObject(screen_mem_dc, hbitmap);
StretchDIBits(screen_mem_dc, 0, 0, new_width, new_height, 0, 0, width, height, bits, fix_info, DIB_RGB_COLORS, SRCCOPY);
SelectObject(screen_mem_dc, orig_bm);
end:
if (screen_mem_dc) DeleteDC(screen_mem_dc);
HeapFree(GetProcessHeap(), 0, scaled_info);
HeapFree(GetProcessHeap(), 0, fix_info);
if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr ); if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
return hbitmap; return hbitmap;
...@@ -2231,7 +2244,7 @@ HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type, ...@@ -2231,7 +2244,7 @@ HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type,
if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED; if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED;
switch (type) { switch (type) {
case IMAGE_BITMAP: case IMAGE_BITMAP:
return BITMAP_Load( hinst, name, loadflags ); return BITMAP_Load( hinst, name, desiredx, desiredy, loadflags );
case IMAGE_ICON: case IMAGE_ICON:
if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL ); if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
......
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