Tk Source Code

View Ticket
Login
Ticket UUID: 54c2ca0e94b925d5dfbbcad202c57678c70791b8
Title: photo: pixels made semi-transparent with "transparency set ... -alpha" are drawn opaque
Type: Bug Version: 9.0.5, 9.1b1
Submitter: serhiy.storchaka Created on: 2026-09-24 19:11:46
Subsystem: 41. Photo Images Assigned To: oehhar
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-20 20:40:13
Resolution: Fixed Closed By: oehhar
    Closed on: 2026-10-20 20:40:13
Description:

$img transparency set x y alpha -alpha (TIP 166, new in 9.0) sets the alpha value of the pixel, but does not mark the image as having partially transparent pixels (COMPLEX_ALPHA). So such pixels are drawn fully opaque instead of blended with the background, while the same alpha set with put is blended:

. configure -bg red
image create photo viaput -width 40 -height 40
viaput put #0000ff80 -to 0 0 40 40
image create photo viaset -width 40 -height 40
viaset put #0000ff -to 0 0 40 40
for {set y 0} {$y < 40} {incr y} {
    for {set x 0} {$x < 40} {incr x} {viaset transparency set $x $y 128 -alpha}
}
pack [label .a -image viaput -bg red -bd 0] [label .b -image viaset -bg red -bd 0] -side left

Both images report alpha 128 (transparency get 5 5 -alpha), but the right one is drawn opaque, pure blue (0,0,255) instead of (127,0,128): on X11 in 9.0.5 and 9.1b1, and on Windows in 9.0.5. Windows 9.1 is not affected, because since [3bbe54bc74] it draws the RGBA data directly; macOS presumably too.

PHOTO_TRANS_SET in ImgPhotoCmd() (generic/tkImgPhoto.c) changes the alpha byte without updating the COMPLEX_ALPHA flag. dkf noted the same requirement for Tk_PhotoPutBlock in [809157ffff] in 2003.

User Comments: oehhar added on 2026-10-20 20:40:13:

Also verified that tk9.1.0 release does not show the issue on MS-Win. Nevertheless, the image should be flagged as having transparent pixels.

Thanks for all, Harald


oehhar added on 2026-10-20 19:21:45:

Tried the example with 9.0 on MS-Win. Fix is effective.

So, committed to:

  • main: [59fba600]
  • core-9-0-branch: [33904f03] but the test is missing, as there is no file "tests/imgPhInstance.test".

Bug closed.

Thank you, Harald


serhiy.storchaka added on 2026-10-19 17:36:47:

Thank you, Harald. 9.1 is affected on X11 too (the ticket says: on X11 in 9.0.5 and 9.1b1, and on Windows in 9.0.5); only Windows 9.1 is not affected, because it draws the RGBA data directly. The branch photo-transparency-set-alpha is against main (rebased on 2026-10-15), and the fix also applies to 9.0.


oehhar added on 2026-10-19 17:32:21:

The ticket says, that 9.1 is not effected. But the patch is for 9.0.

Nevertheless, this looks reasonable for both.

May look-in again tomorrow.

Thanks, Harald


serhiy.storchaka added on 2026-09-24 19:16:25:

Proposed fix in branch photo-transparency-set-alpha ([3faec47822]): transparency set ... -alpha now sets COMPLEX_ALPHA for a partial alpha value, so such pixels are blended. Test imgPhInstance-6.1 checks the rendered pixel with testpixel; it fails without the fix.