Tk Source Code

View Ticket
Login
Ticket UUID: fe942372aa0ce5389631842fe738ce55a2189faa
Title: Aqua: XPutImage() swaps red and blue channels
Type: Patch Version: 8.6.13
Submitter: chrstphrchvz Created on: 2023-11-20 17:43:18
Subsystem: 82. X11 Emulation Assigned To: fvogel
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2023-12-03 18:58:19
Resolution: Fixed Closed By: fvogel
    Closed on: 2023-12-03 18:58:19
Description:

The .pix32 photo image model data buffer is not meant to be used an XImage data buffer, since drawing is supposed to be done from photo instance pixmaps which have gamma (see [de6ef8276c]) and any dithering applied. But that is where Tk Aqua gets its current assumption that XImages use RGBA color channel byte order. The result is that usage of XPutImage() may draw with color channels swapped.

Example: the img::pixmap package in TkImg implements TIP 198-style XPM image support. It did not draw anything on Tk Aqua before this recent change: https://sourceforge.net/p/tkimg/patches/32/. It now draws something, but the red and blue channels are swapped. Script:

package require Tk
package require Img
package require img::pixmap
image create photo folder0 -file tests/folder.xpm image create pixmap folder1 -file tests/folder.xpm image create photo img0 -file tests/testimgs/img.xpm image create pixmap img1 -file tests/testimgs/img.xpm grid [label .l00 -text photo] -row 0 -column 0 grid [label .l02 -image img0] -row 0 -column 1 grid [label .l01 -image folder0] -row 0 -column 2 grid [label .l10 -text pixmap] -row 1 -column 0 grid [label .l12 -image img1] -row 1 -column 1 grid [label .l11 -image folder1] -row 1 -column 2

Screenshot comparing to TkImg’s photo image XPM support, and to X11:

(Ignore the gray area around the pixmap folder icon; that is caused by Aqua only implementing support for X GCs which clip to a region and not a pixmap.)

The attached patch could be considered the smallest possible fix for this specific example; I do not think it caused by something elsewhere, such as channels being swapped in pixel values from Tk_GetColor(). Screenshot:

User Comments: fvogel added on 2023-12-03 18:58:19:
Now merged. Thanks!

marc_culler (claiming to be Marc Culler) added on 2023-12-02 14:45:19:
No objections here.  Merge away!

fvogel added on 2023-12-02 12:10:31:
Yes thanks I can now reproduce on macOS aqua with only the core Tk. And yes, splitting into two patches helps understanding quite a lot, many thanks.

Unless someone objects (Marc? Kevin?) I will merge this tomorrow.

chrstphrchvz added on 2023-12-02 07:10:25:

Here is a way to trigger this issue in core Tk. The checkbutton appears blue rather than red.

package require Tk
ttk::style theme use alt
ttk::style configure TCheckbutton -indicatorcolor red
ttk::checkbutton .cb -variable x
set x 0
place .cb -x 0 -y 0

Screenshots of Aqua (before)/Aqua (after)/X11:

To make the proposed fix clearer, I have separated it into two patches. The first patch should behave no differently than the current behavior.

…I'm still unsure about channels swapping as a possible cause (we have the same issue in other areas of the code, e.g. [d66e6fabad]).

I think that is Windows-specific and unrelated to this issue.

Also I'm wondering: to what level would you evaluate the risk of breaking something with this patch applied?

I find myself unable to respond to this rationally.


fvogel added on 2023-11-25 15:40:14:

Thanks, patch now committed in [72cbe390c4].

I think I understand what the patch is doing, especially after reading this comment in the code.

That said I'm still unsure about channels swapping as a possible cause (we have the same issue in other areas of the code, e.g. [d66e6fabad]). Also I'm wondering: to what level would you evaluate the risk of breaking something with this patch applied?


Attachments: