Tk Source Code

View Ticket
Login
Ticket UUID: 99b84e49ffe486949ef08fd4b68feb29bb3e9002
Title: PhotoImages do not support alpha channel on OSX Mavericks
Type: Bug Version: 8.5.15.1, 8.6.1
Submitter: anonymous Created on: 2014-06-16 20:22:49
Subsystem: 41. Photo Images Assigned To: kevin_walzer
Priority: 5 Medium Severity: Critical
Status: Closed Last Modified: 2014-07-07 13:23:07
Resolution: Accepted Closed By: kevin_walzer
    Closed on: 2014-07-07 13:23:07
Description:
PhotoImages with alpha channel data do not work at all on OS X Mavericks.

This bug was discussed in this thread:
 http://sourceforge.net/p/tcl/mailman/message/31694269/
where the problem was correctly isolated in the XCopyArea function.  The implementation of XCopyArea uses NSCopyBits which requires as one of its arguments a GState.  However, in Mavericks Apple changed the allocateGState function to be a no-op, and this makes NSCopyBits unusable.

The function TkImgPhotoDisplay calls XGetImage which, in the macosx version, in turn calls XCopyArea.  Since XGetImage is unable to retrieve the background image to be blended with the PhotoImage, TkImagePhotoDisplay cannot support the alpha channel. 

I have written new implementations of XCopyArea and XGetImage.  Since I don't see any way of uploading a patch on this form, and since my patch is too long to paste here, I will send the patch directly to some of the developers.

Marc Culler
User Comments: kevin_walzer added on 2014-07-07 13:23:07:
Updated patch (see commits) addresses the reported bug without crashes.

kevin_walzer added on 2014-07-04 02:30:08:
Wish demo now launches, but I am still seeing a crash in a test app I am using, Scid (http://scid.sourceforge.net), which has dozens of images. Looks like the error involves a [retain] call somewhere:

Application Specific Information:
objc_msgSend() selector name: retain


Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib               	0x00007fff8ecc9097 objc_msgSend + 23
1   com.apple.CoreFoundation      	0x00007fff933f67c0 +[__NSArrayI __new:::] + 160
2   com.apple.CoreFoundation      	0x00007fff9345794a -[NSArray initWithObjects:] + 570
3   com.apple.AppKit              	0x00007fff8d8ee15a -[NSImage addRepresentation:] + 63
4   Tk                            	0x000000010bfdae84 XGetImage + 181
5   Tk                            	0x000000010bf7ae04 0x10bf12000 + 429572
6   Tk                            	0x000000010bf75b0a Tk_RedrawImage + 138
7   Tk                            	0x000000010bf63b0b 0x10bf12000 + 334603
8   Tk                            	0x000000010bf5cf55 0x10bf12000 + 307029
9   Tcl                           	0x00000001096fc70d TclServiceIdle + 87
10  Tcl                           	0x00000001096e3cee Tcl_DoOneEvent + 344

...ad nauseum. 

Hope this helps.

anonymous added on 2014-06-30 16:13:36:
Hi Kevin,

I have found the bug that was causing the crash.  The cause was that I sent an initWithCGImage message to an NSBitmapImageRep, and then called CGImageRelease on the CGImageRef which was passed in the message.  Evidently, when the Appkit cleaned up the NSBitmapImageRep it would try to free the CGImageRef which had already been freed because of my call to CGImageRelease.

I will upload a new patch which can now run the Canvas widget demos without any crashes.

- Marc

dkf added on 2014-06-23 08:37:28:

I've moved the related commits onto their own branches (bug-99b84e49ff-8.5 and bug-99b84e49ff-trunk) until we've got good fixes.


kevin_walzer added on 2014-06-23 02:20:38:
Re-opening because of newly discovered crashes in Tk.

kevin_walzer added on 2014-06-22 01:39:41:
Marc,

I tried again with a clean build of 8.5, as it is my own build and does not link to AS or anything else, and confirmed that it works. (My build of 8.6 is a bit wonky to avoid conflicts with 8.5, which is my production system, so perhaps there was some glitch that I can't account for there.) I've committed the patch for trunk  and core-8-5-branch. Thanks for the patch; it solves a gnarly problem that I didn't really understand how to approach. 

--Kevin

anonymous added on 2014-06-21 15:48:09:
Kevin,

I think there is something wrong with your test procedure or your build process.  On my Mavericks system, using my patched version of Tcl/Tk 8.6, your addressbook image displays correctly.  I will attach my screenshot.

When I was building Tcl and Tk from source I ran into a number of issues involving clang and OS X frameworks.  The -frameworks flag is not supported and produces warning messages.  Moreover, clang would choose to use the wrong framework paths.  I had to fix these with install_name_tool.  You might want to use otool -L to make sure that the version of wish8.6 you used for your test was really finding the patched framework.  I would not be surprised if clang managed to find the original Active State framework and install its path in your Wish.app executable.

- Marc

kevin_walzer added on 2014-06-20 23:23:44:
After reviewing and applying the patch, I do not see any difference in how transparency is rendered on 10.9.3. It still appears that Tk is not supporting alpha correctly here. I will attach a screenshot that displays the issue.

aku added on 2014-06-16 21:43:11:
Marc, thank you for the attachment.

I am now assigning this ticket to Kevin Walzer, our OSX expert, for review and such.

aku added on 2014-06-16 20:40:48:
Marc, now that you have created the ticket you can attach a patch.
Go to the ticket view, log in as anonymous (as you have done before, I believe), and then you should see an "Attach" button in the secondary navbar, just under the primary navbar at the top. It should be the leftmost button of the secondary navbar.

Attachments: