Tk Source Code

View Ticket
Login
Ticket UUID: 1155596
Title: TkAqua: display issues for buttons with image with alpha
Type: Bug Version: obsolete: 8.4.13
Submitter: muonics Created on: 2005-03-03 05:33:54
Subsystem: 66. Aqua Window Operations Assigned To: aku
Priority: 4 Severity: Minor
Status: Open Last Modified: 2026-09-25 14:24:54
Resolution: Accepted Closed By: nobody
    Closed on:
Description:
set img [image create photo -file image-with-alpha.png]
pack [button .b -image $img]

The button is not displayed, and "OpenCPicture failed"
is printed to stderr.  Subsequently interacting with
the GUI results in a crash.  This happens both with
TkImg and with the PNG parser I'm implementing.  It
does not crash with labels.

0   com.apple.QD            0x9156d270 SetGWorld +
0x401   com.tcltk.tklibrary     0x0b079e68 TkPutImage +
0x300
2   com.tcltk.tklibrary     0x0b040950 ImgPhotoDisplay
+ 0x1043   com.tcltk.tklibrary     0x0b039700
Tk_RedrawImage + 0xb8
4   com.tcltk.tklibrary     0x0b075924 SetupBevelButton
+ 0x1385   com.tcltk.tklibrary     0x0b075694
TkMacOSXDrawControl + 0x29c
6   com.tcltk.tklibrary     0x0b074638 TkpDisplayButton
+ 0x1287   com.tcltk.tcllibrary    0x0a0678f8
TclServiceIdle + 0x68
8   com.tcltk.tcllibrary    0x0a056dac Tcl_DoOneEvent +
0x1809   com.tcltk.tklibrary     0x0b02bcf4 Tk_MainLoop
+ 0x18
10  com.tcltk.tklibrary     0x0b04936c Tk_MainEx +
0x33811  com.tcltk.wish          0x000163c4 0x1000 +
0x153c4
12  com.tcltk.wish          0x00015e80 0x1000 +
0x14e8013  dyld                    0x8fe1a558
_dyld_start + 0x64
User Comments: kevin_walzer added on 2026-09-25 14:24:54:
Can't test without an image that shows the problem - the images listed as attachments are not included - but this is a 20-year-old bug submitted against an obsolete implementation. I think it's safe to close this.

serhiy.storchaka added on 2026-09-25 11:54:01:

The QuickDraw code is gone since the Cocoa port, and since 8.6.12 photo images on macOS are drawn with TkpPutRGBAImage, which composites the alpha channel directly, without reading back the background with XGetImage. So a button with a partially transparent image should now be blended over the native button. Can someone on macOS confirm with 8.6.18 or 9.0?


das added on 2006-05-13 01:30:29:
Logged In: YES 
user_id=90580

committed fix for the incorrect positioning to HEAD and core-8-4-branch

However alpha-blending of an image with the native button background is 
still broken:
this is non-trivial to fix because the blending computation occurs in 
SetupBevelButton() before the native button is drawn, but the generic 
blending code assumes it can retrieve the background to blend into via 
XGetImage from the screen.

One possible (fairly expensive) solution might be to draw the undecorated 
widget into an offscreen buffer first and take the XGetImage bg from there; 
changes to generic code will be needed to add support for getting the 
background for blending from a different source than normal.

Please anybody feel free to have a go at this, it's not high on my list ATM...

muonics added on 2005-12-04 14:41:49:
Logged In: YES 
user_id=498198

Confirmed current core-8-4-branch doesn't crash but does
have drawing problems.  Seems like at least part of what's
going on here is it's offsetting the image by the distance
from the top-left corner of the window to the top-left
corner of the button.  Thus if the window is twice as wide
as the button, say, the left side of the image is right in
the middle (horizontally) in the button.

hobbs added on 2005-12-01 13:40:13:

File Added - 158214: osx-alphabtn.png

hobbs added on 2005-12-01 13:40:09:
Logged In: YES 
user_id=72656

Tk 8.4.12-rc (ActiveTcl) did not crash, but the button
certainly doesn't draw the image correctly, whereas the
label does appear to.  Attached is an image that underwent a
few resizings.

das added on 2005-03-25 00:42:26:
Logged In: YES 
user_id=90580

Jim,
you mentioned you were looking into nasties ;-), maybe you can help 
with this? I don't have time ATM...

muonics added on 2005-03-24 15:27:04:
Logged In: YES 
user_id=498198

Affects menubutton, too. I've pretty much run out of ideas.
 No matter what I try it will crash if Tk_RedrawImage() is
called any time between OpenCPicture() and ClosePicture(). 
I even tried creating a new pixmap and doing it into there
and it still crashed.

muonics added on 2005-03-04 12:53:00:

File Added - 124098: bbgwtf.png

Logged In: YES 
user_id=498198

If I comment out the ImgPhotoBlendComplexAlpha() call, so
that in theory it should display just the background image
that the actual image gets blended with, a rather odd thing
results, shown in the attached image.

Commenting out the XGetPixel/XPutPixel in IPBCA results in
the same.  It requires both the be commented out.  Either
one uncommented results in the button not being displayed at
all, and crashing after interacting with the GUI.  It seems
to really Not Like that background image generated by
XGetImage().

muonics added on 2005-03-04 10:25:04:
Logged In: YES 
user_id=498198

I've traced it down to the if
((instancePtr->masterPtr->flags & COMPLEX_ALPHA) ...) block
of ImgPhotoDisplay(), which generates an XImage from the
background and blends it with the image to be displayed.  If
the alternate path is used (the one used for images without
alpha) it displays the button normally with the image and
doesn't crash, but then of course no alpha blending is done
anywhere.

It seems rather wrong that it would be trying to blend with
a generated image from the background, however - the
background in this case is a button control that is in the
process of being drawn.

muonics added on 2005-03-03 12:51:04:
Logged In: YES 
user_id=498198

Actually it doesn't print "OpenCPicture failed" until I
resize the window.  It seems the crash is because it goes
ahead and continues despite the failure; tossing a "return"
in after the error message is printed seems to prevent the
crash, although the message is still printed with any
resizing or interaction and the button isn't displayed.

I notice tkMacOSXMenubutton.c also makes a call to
OpenCPicture which similarly continues after fail rather
than returning.

Attachments: