diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-11-16 10:13:10 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-11-16 10:13:10 (GMT) |
commit | fa771129aae950bb9e9278cbeec1cbf084322a1b (patch) | |
tree | 233e241e13613577a7ec05ca779fb1bdc3cdb37e /win/tkWinWm.c | |
parent | 506d559afbf724b2943dca074e5622e8c4daba92 (diff) | |
download | tk-fa771129aae950bb9e9278cbeec1cbf084322a1b.zip tk-fa771129aae950bb9e9278cbeec1cbf084322a1b.tar.gz tk-fa771129aae950bb9e9278cbeec1cbf084322a1b.tar.bz2 |
Eric Boudaillier's latest patch (with a few tweaks, eliminating compiler warnings)
Diffstat (limited to 'win/tkWinWm.c')
-rw-r--r-- | win/tkWinWm.c | 90 |
1 files changed, 4 insertions, 86 deletions
diff --git a/win/tkWinWm.c b/win/tkWinWm.c index 352a941..20d68ea 100644 --- a/win/tkWinWm.c +++ b/win/tkWinWm.c @@ -4147,15 +4147,11 @@ WmIconphotoCmd( TkWindow *useWinPtr = winPtr; /* window to apply to (NULL if -default) */ Tk_PhotoHandle photo; Tk_PhotoImageBlock block; - int i, width, height, idx, bufferSize, startObj = 3; - union {unsigned char *ptr; void *voidPtr;} bgraPixel; - union {unsigned char *ptr; void *voidPtr;} bgraMask; + int i, width, height, startObj = 3; BlockOfIconImagesPtr lpIR; WinIconPtr titlebaricon = NULL; HICON hIcon; unsigned size; - BITMAPINFO bmInfo; - ICONINFO iconInfo; (void)tkwin; if (objc < 4) { @@ -4200,93 +4196,14 @@ WmIconphotoCmd( } ZeroMemory(lpIR, size); - lpIR->nNumImages = objc - startObj; - for (i = startObj; i < objc; i++) { photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i])); Tk_PhotoGetSize(photo, &width, &height); Tk_PhotoGetImage(photo, &block); - /* - * Don't use CreateIcon to create the icon, as it requires color - * bitmap data in device-dependent format. Instead we use - * CreateIconIndirect which takes device-independent bitmaps and - * converts them as required. Initialise icon info structure. - */ - - ZeroMemory(&iconInfo, sizeof(iconInfo)); - iconInfo.fIcon = TRUE; - - /* - * Create device-independent color bitmap. - */ - - ZeroMemory(&bmInfo, sizeof bmInfo); - bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmInfo.bmiHeader.biWidth = width; - bmInfo.bmiHeader.biHeight = -height; - bmInfo.bmiHeader.biPlanes = 1; - bmInfo.bmiHeader.biBitCount = 32; - bmInfo.bmiHeader.biCompression = BI_RGB; - - iconInfo.hbmColor = CreateDIBSection(NULL, &bmInfo, DIB_RGB_COLORS, - &bgraPixel.voidPtr, NULL, 0); - if (!iconInfo.hbmColor) { - ckfree(lpIR); - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "failed to create an iconphoto with image \"%s\"", - Tcl_GetString(objv[i]))); - Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "IMAGE", NULL); - return TCL_ERROR; - } - - /* - * Convert the photo image data into BGRA format (RGBQUAD). - */ - - bufferSize = height * width * 4; - for (idx = 0 ; idx < bufferSize ; idx += 4) { - bgraPixel.ptr[idx] = block.pixelPtr[idx+2]; - bgraPixel.ptr[idx+1] = block.pixelPtr[idx+1]; - bgraPixel.ptr[idx+2] = block.pixelPtr[idx+0]; - bgraPixel.ptr[idx+3] = block.pixelPtr[idx+3]; - } - - /* - * Create a dummy mask bitmap. The contents of this don't appear to - * matter, as CreateIconIndirect will setup the icon mask based on the - * alpha channel in our color bitmap. - */ - - bmInfo.bmiHeader.biBitCount = 1; - - iconInfo.hbmMask = CreateDIBSection(NULL, &bmInfo, DIB_RGB_COLORS, - &bgraMask.voidPtr, NULL, 0); - if (!iconInfo.hbmMask) { - DeleteObject(iconInfo.hbmColor); - ckfree(lpIR); - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "failed to create mask bitmap for \"%s\"", - Tcl_GetString(objv[i]))); - Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "MASK", NULL); - return TCL_ERROR; - } - - ZeroMemory(bgraMask.ptr, width*height/8); - - /* - * Create an icon from the bitmaps. - */ - - hIcon = CreateIconIndirect(&iconInfo); - DeleteObject(iconInfo.hbmColor); - DeleteObject(iconInfo.hbmMask); + hIcon = CreateIcoFromPhoto(width, height, block); if (hIcon == NULL) { - /* - * XXX should free up created icons. - */ - - ckfree(lpIR); + FreeIconBlock(lpIR); Tcl_SetObjResult(interp, Tcl_ObjPrintf( "failed to create icon for \"%s\"", Tcl_GetString(objv[i]))); @@ -4297,6 +4214,7 @@ WmIconphotoCmd( lpIR->IconImages[i-startObj].Height = height; lpIR->IconImages[i-startObj].Colors = 4; lpIR->IconImages[i-startObj].hIcon = hIcon; + lpIR->nNumImages++; } titlebaricon = (WinIconPtr)ckalloc(sizeof(WinIconInstance)); |