Tk Source Code

View Ticket
Login
Ticket UUID: 32f2e19de82946d0277b72dcb840b4753d6e643e
Title: Windows: photo -gamma and -palette are ignored since RGBA rendering
Type: Bug Version: 9.1b1
Submitter: serhiy.storchaka Created on: 2026-09-24 13:53:02
Subsystem: 41. Photo Images Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-09-29 19:32:13
Resolution: Fixed Closed By: oehhar
    Closed on: 2026-09-29 19:32:13
Description:

Since [3bbe54bc74] (merge of [7caf9e9e]) win/tkWinPort.h defines TK_CAN_RENDER_RGBA. With it, TkImgPhotoDisplay draws the model's RGBA pixels directly with TkpPutRGBAImage, and the photo instance, where -gamma correction and -palette reduction are applied, is not used for drawing. So on Windows these options no longer have any visible effect.

-gamma:

foreach {img opts} {plain {} gamma {-gamma 2}} {
    image create photo $img -width 60 -height 60 {*}$opts
    $img put #ffa500 -to 0 0 60 60
    pack [label .$img -image $img] -side left
}

In 8.6 and 9.0 the right image is lighter than the left one, (255,205,0) instead of (255,165,0); in 9.1b1 both are the same orange.

-palette:

foreach {img opts} {plain {} gray2 {-palette 2} rgb3 {-palette 3/3/3}} {
    image create photo $img -width 120 -height 120 {*}$opts
    for {set x 0} {$x < 120} {incr x} {
        $img put [format #%02x%02x00 [expr {$x * 255 / 119}] [expr {$x * 165 / 119}]] \
                -to $x 0 [expr {$x + 1}] 120
    }
    pack [label .$img -image $img] -side left
}

In 8.6 and 9.0 the second and third images are dithered with 2 shades of gray and 3 levels per color; in 9.1b1 all three show the same smooth gradient. (The black and white dither of -palette 2 is inverted on Windows, which is [481255ffff].)

On X11 both options work as expected in 8.6, 9.0 and 9.1. macOS has always ignored them ([de6ef8276c]).

User Comments: oehhar added on 2026-09-29 19:32:13:

Thanks ! Fix is effective.

Merged to main by [05a0704a].

Mason, could you comment on this fix?

Bug closed.

Thanks for all, Harald


serhiy.storchaka added on 2026-09-24 19:20:11:

Correction: this can be tested. tktest has testpixel, which reads back rendered pixels. Tests imgPhInstance-7.1 and 7.2 were added in win-photo-gamma-palette; they fail on Windows without the fix.


serhiy.storchaka added on 2026-09-24 13:55:27:

Fixed in branch win-photo-gamma-palette ([c892f77266]). When the instance has a non-default -gamma or -palette, Windows again draws the instance pixmap, as in 9.0. With the examples above it now looks the same as in 8.6 and 9.0.

Images with partially transparent pixels are still drawn from the model's RGBA data, so these options still have no effect on them, as on macOS.

There is no automatic test: Tk cannot read pixels back from the screen, so the examples above have to be checked visually.