CreateBitmap fails
Jerry Jenkins
Jerry_J_Jenkins at hotmail.com
Sat Sep 20 06:46:48 CDT 2003
Patch for loading bitmaps.
ChangeLog:
* dlls/comctl32/toolar.c
- Create a compatible bitmap of the display, which can be selected into
a device context.
* windows/cursoricon.c
- Loading bitmaps with specified size works now.
-------------- next part --------------
Index: dlls/comctl32/toolbar.c
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/toolbar.c,v
retrieving revision 1.139
diff -u -r1.139 toolbar.c
--- dlls/comctl32/toolbar.c 17 Sep 2003 20:15:21 -0000 1.139
+++ dlls/comctl32/toolbar.c 20 Sep 2003 10:40:03 -0000
@@ -2215,7 +2215,7 @@
/* create new default image list */
TRACE ("creating default image list!\n");
- himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
+ himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
ILC_COLOR | ILC_MASK, nButtons, 2);
TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
infoPtr->himlInt = himlDef;
@@ -2236,7 +2236,7 @@
{
BITMAP bmp;
HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
- HDC hdcImage, hdcBitmap;
+ HDC hdcImage, hdcBitmap, hdcScreen;
/* copy the bitmap before adding it so that the user's bitmap
* doesn't get modified.
@@ -2245,11 +2245,12 @@
hdcImage = CreateCompatibleDC(0);
hdcBitmap = CreateCompatibleDC(0);
+ hdcScreen = GetDC(NULL);
/* create new bitmap */
- hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
- hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
- hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
+ hbmLoad = CreateCompatibleBitmap (hdcScreen, bmp.bmWidth, bmp.bmHeight);
+ hOldBitmapBitmap = SelectObject (hdcBitmap, (HBITMAP)lpAddBmp->nID);
+ hOldBitmapLoad = SelectObject (hdcImage, hbmLoad);
/* Copy the user's image */
BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
@@ -2259,6 +2260,7 @@
SelectObject (hdcBitmap, hOldBitmapBitmap);
DeleteDC (hdcImage);
DeleteDC (hdcBitmap);
+ ReleaseDC (NULL, hdcScreen);
nIndex = ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT);
DeleteObject (hbmLoad);
@@ -3845,7 +3847,7 @@
{
BITMAP bmp;
HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
- HDC hdcImage, hdcBitmap;
+ HDC hdcImage, hdcBitmap, hdcScreen;
/* copy the bitmap before adding it so that the user's bitmap
* doesn't get modified.
@@ -3854,11 +3856,12 @@
hdcImage = CreateCompatibleDC(0);
hdcBitmap = CreateCompatibleDC(0);
+ hdcScreen = GetDC(NULL);
/* create new bitmap */
- hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
- hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
- hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
+ hbmLoad = CreateCompatibleBitmap (hdcScreen, bmp.bmWidth, bmp.bmHeight);
+ hOldBitmapBitmap = SelectObject (hdcBitmap, hBitmap);
+ hOldBitmapLoad = SelectObject (hdcImage, hbmLoad);
/* Copy the user's image */
BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
@@ -3868,6 +3871,7 @@
SelectObject (hdcBitmap, hOldBitmapBitmap);
DeleteDC (hdcImage);
DeleteDC (hdcBitmap);
+ ReleaseDC (NULL, hdcScreen);
ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT);
DeleteObject (hbmLoad);
Index: windows/cursoricon.c
===================================================================
RCS file: /home/wine/wine/windows/cursoricon.c,v
retrieving revision 1.68
diff -u -r1.68 cursoricon.c
--- windows/cursoricon.c 10 Sep 2003 03:56:47 -0000 1.68
+++ windows/cursoricon.c 20 Sep 2003 10:40:32 -0000
@@ -1925,7 +1925,8 @@
/**********************************************************************
* BITMAP_Load
*/
-static HBITMAP BITMAP_Load( HINSTANCE instance,LPCWSTR name, UINT loadflags )
+static HBITMAP BITMAP_Load( HINSTANCE instance,LPCWSTR name,
+ INT width, INT height, UINT loadflags )
{
HBITMAP hbitmap = 0;
HRSRC hRsrc;
@@ -1934,6 +1935,8 @@
BITMAPINFO *info, *fix_info=NULL;
HGLOBAL hFix;
int size;
+ BOOL fStretch = FALSE;
+ HDC hdcMem =NULL;
if (!(loadflags & LR_LOADFROMFILE))
{
@@ -1953,6 +1956,12 @@
if (!(ptr = map_fileW( name ))) return 0;
info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
}
+
+ if (!width) width = info->bmiHeader.biWidth;
+ if (!height) height = info->bmiHeader.biHeight;
+ fStretch = (info->bmiHeader.biHeight != height) ||
+ (info->bmiHeader.biWidth != width);
+
size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
if ((hFix = GlobalAlloc(0, size))) fix_info=GlobalLock(hFix);
if (fix_info) {
@@ -1965,7 +1974,42 @@
if (screen_dc)
{
char *bits = (char *)info + size;
- if (loadflags & LR_CREATEDIBSECTION) {
+ if (fStretch) {
+ if (loadflags & LR_CREATEDIBSECTION) {
+ /* avoid GlobalAlloc & memcpy, but we have to save and then restore the value */
+ BITMAPINFOHEADER tSave = fix_info->bmiHeader;
+ fix_info->bmiHeader.biWidth = width;
+ fix_info->bmiHeader.biHeight = height;
+ fix_info->bmiHeader.biCompression = BI_RGB;
+ fix_info->bmiHeader.biSizeImage = 0;
+
+ hbitmap = CreateDIBSection(screen_dc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
+
+ fix_info->bmiHeader = tSave;
+ }
+ else {
+ if (fix_info->bmiHeader.biBitCount != 1 ) {
+ hbitmap = CreateCompatibleBitmap(screen_dc, width, height);
+ }
+ else hbitmap = CreateBitmap(width, height, 1, 1, NULL);
+ }
+ if(hbitmap) {
+ HBITMAP hOld;
+ BOOL res = FALSE;
+ hdcMem = CreateCompatibleDC(screen_dc);
+ if (hdcMem) {
+ hOld = SelectObject(hdcMem, hbitmap);
+ res = StretchDIBits(hdcMem, 0, 0, width, height, 0, 0,
+ fix_info->bmiHeader.biWidth,
+ fix_info->bmiHeader.biHeight,
+ bits, fix_info, DIB_RGB_COLORS, SRCCOPY);
+ SelectObject(hdcMem, hOld);
+ DeleteDC(hdcMem), hdcMem = NULL;
+ }
+ if (!res) { DeleteObject(hbitmap); hbitmap = NULL; }
+ }
+ }
+ else if (loadflags & LR_CREATEDIBSECTION) {
DIBSECTION dib;
hbitmap = CreateDIBSection(screen_dc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
GetObjectA(hbitmap, sizeof(DIBSECTION), &dib);
@@ -2064,7 +2108,7 @@
if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED;
switch (type) {
case IMAGE_BITMAP:
- return BITMAP_Load( hinst, name, loadflags );
+ return BITMAP_Load( hinst, name, desiredx, desiredy, loadflags );
case IMAGE_ICON:
if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
More information about the wine-patches
mailing list