Tk Source Code

View Ticket
Login
2026-10-17
10:12 • Ticket [de6ef827] imageName configure -gamma - has no effect on macOS status still Open with 3 other changes artifact: c7e29925 user: chrstphrchvz
2023-12-03
18:58 • Closed ticket [fe942372]: Aqua: XPutImage() swaps red and blue channels plus 6 other changes artifact: 6c802b63 user: fvogel
18:49
Fix [fe942372aa]: Aqua: XPutImage() swaps red and blue channels. Patch from Christopher Chavez. check-in: bf041dbc user: fvogel tags: trunk, main
18:49
Fix [fe942372aa]: Aqua: XPutImage() swaps red and blue channels. Patch from Christopher Chavez. check-in: 1877c045 user: fvogel tags: core-8-6-branch
2023-12-02
14:45 • Ticket [fe942372] Aqua: XPutImage() swaps red and blue channels status still Open with 4 other changes artifact: 2e55ede5 user: marc_culler
12:10 • Ticket [fe942372]: 3 changes artifact: 4b44e2db user: fvogel
07:10 • Ticket [fe942372]: 3 changes artifact: c0f9a2e4 user: chrstphrchvz
07:06 • Add attachment 0002-fe942372aa0c-fix.diff to ticket [fe942372] artifact: a8da706e user: chrstphrchvz
07:06 • Add attachment 0001-fe942372aa0c-reorganize.diff to ticket [fe942372] artifact: 7b44e358 user: chrstphrchvz
07:05 • Delete attachment "fe942372aa0c.diff" from ticket [fe942372] artifact: ef5c1062 user: chrstphrchvz
2023-11-25
15:40 • Ticket [fe942372] Aqua: XPutImage() swaps red and blue channels status still Open with 4 other changes artifact: 81c2c29c user: fvogel
15:20
Fix [fe942372aa]: Aqua: XPutImage() swaps red and blue channels. Patch from Christopher Chavez. check-in: 72cbe390 user: fvogel tags: bug-fe942372aa
2023-11-20
17:45 • Add attachment fe942372aa0c.diff to ticket [fe942372] artifact: b2318027 user: chrstphrchvz
17:43 • New ticket [fe942372] Aqua: XPutImage() swaps red and blue channels. artifact: 2da4af8a user: chrstphrchvz

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: