Tk Source Code

View Ticket
Login
Ticket UUID: 809157
Title: partially transparent images don't display correctly.
Type: Bug Version: obsolete: 8.4.4
Submitter: mistachkin Created on: 2003-09-19 08:57:30
Subsystem: 41. Photo Images Assigned To: hobbs
Priority: 4 Severity:
Status: Closed Last Modified: 2026-10-22 17:22:37
Resolution: Fixed Closed By: serhiy.storchaka
    Closed on: 2026-09-24 19:17:27
Description:
When using "partial transparency of images with non-
trivial alpha channels", the renderer always assumes a 
grey background. This means that if the image has any 
areas that are partially transparent instead of fully 
transparent they will be rendered as grey pixels. This 
precludes using any shape such as a rounded edge, 
circles, ovals, triangles, polygons, etc (anything other 
than a normalized, non-rotated rectangle) that require 
anti-aliasing in an image as the edges will appear jagged 
with grey pixels instead of smooth and blended with the 
background pixels. The correct behaviour is to instead 
sample the underlying background pixel and combine it 
with the partially transparent pixel of the foreground 
image to create a new "result" pixel. According to dkf 
the issue appears to be a bug in the renderer code 
in "tkImgPhoto.c".
User Comments: serhiy.storchaka added on 2026-09-24 19:17:27:

Fixed in 8.4.5 by [48047b21ab] (and on macOS by [9cff21180c]); partially transparent pixels are blended with the background in 8.6 and 9.x. Canvas PostScript output still ignores partial alpha (a known limitation), and the "ghosting" mentioned below was never reproduced. The alpha set by transparency set ... -alpha (9.0) was not blended, that is [54c2ca0e94]. Closing.


mistachkin added on 2004-06-22 18:01:26:
Logged In: YES 
user_id=113501

There seems to be a slight ghosting effect for partially 
transparent images in HEAD.  More testing is definately 
required, especially on different flavors of unix (both 32 and 
64 bit).

dkf added on 2004-02-23 20:35:14:
Logged In: YES 
user_id=79902

I've no idea how to do that level of sophistication of PS
magic.  I suggest we just leave it broken for now and let
someone contribute code to make it happen if they know how
and it bugs them.  ;)

das added on 2004-02-23 18:48:57:
Logged In: YES 
user_id=90580

Noticed that partial photo transparency doesn't work for 
postscript output.
I don't remember enough postscript to debug this, the alpha 
data certainly gets written out to ps, but the TkPhoto ps function 
doesn't seem to deal with partial transparency.
see
http://rutherglen.ics.mq.edu.au/~steffen/tcltk/
tk_bug_809157/alpha-test3/out_aqua.ps
for ps output of the attached alpha-test3 suite.

das added on 2004-02-23 17:49:53:

File Added - 77635: XGetPutImage-HEAD.patch

das added on 2004-02-23 17:49:18:

File Deleted - 77633: 



File Added - 77634: XGetPutImage-core-8-4-branch.patch

das added on 2004-02-23 17:48:08:

File Added - 77633: XGetPutImage-HEAD.patch

das added on 2004-02-23 17:48:07:
Logged In: YES 
user_id=90580

attached patches that fix this on MacOSX.
checked in to HEAD and core-8-4-branch.

hobbs added on 2003-11-12 01:37:42:
Logged In: YES 
user_id=72656

fixed for 15bpp+ on Windows/Unix, but not OS X.

dkf added on 2003-11-03 23:47:09:
Logged In: YES 
user_id=79902

Assigning to Jeff as he seems to be taking more of a lead in 
this one.

hobbs added on 2003-10-31 06:53:49:

File Added - 66008: alpha-hobbs7.patch

Logged In: YES 
user_id=72656

7 is the lucky number.  Attached is a patch that should work 
for 15bpp+ screens across the board.  Needs OS X testing, 
and of course more testing everywhere else.

hobbs added on 2003-10-30 06:08:46:

File Added - 65875: alpha-hobbs6.patch

Logged In: YES 
user_id=72656

variant #6 that has somewhat working 16bpp code for unix.  I 
don't think this is 100% for 16bpp.  It also simplifies the 
ALPHA_BLEND macro.

dkf added on 2003-10-29 23:02:58:
Logged In: YES 
user_id=79902

Here's a helpful script (customize to suit!):

package require Img
set i 0
image create photo foo -file yourSampleImage.png
foreach visual [winfo visualsavailable .] {
   set f [frame .f$i -visual $visual]
   pack $f
   label $f.l -text $visual -image foo -compound right
   pack $f.l
}

dkf added on 2003-10-29 22:33:36:
Logged In: YES 
user_id=79902

Hmm. Trying out a bit further, I find that you've got 16bpp
as the split-point between the two renderers.  Wouldn't it
be better to use 15 but then only if the visual isn't
pseudocolor (or some other colormapped visual type?)  And we
can of course support greyscale visuals completely even if
they are only 8 bits deep...

dkf added on 2003-10-29 18:38:26:
Logged In: YES 
user_id=79902

Aside from that, it looks good.  Especially when I run two
identical tests side-by-side where one is in an 8-bit window
and the other is in a 24-bit window (one of the few things
that an SGI is really good at!)  I shan't post the code I'm
using to do the test here, since it depends on a lot of
extra instrumentation code that I'm still thinking about.

dkf added on 2003-10-29 18:35:00:
Logged In: YES 
user_id=79902

Need to call ToggleComplexAlphaIfNeeded() (or otherwise
toggle the COMPLEX_ALPHA bit) from inside Tk_PhotoPutBlock
and Tk_PhotoPutZoomedBlock, but might it be sufficient to
postpone computing that until idle?

hobbs added on 2003-10-29 10:43:24:

File Added - 65763: alpha-test3.tar.gz

hobbs added on 2003-10-29 10:43:21:
Logged In: YES 
user_id=72656

added new test files that have more clear images on what 
one should see.

hobbs added on 2003-10-29 10:39:15:

File Added - 65762: alpha-hobbs3.patch

Logged In: YES 
user_id=72656

3rd gen patch that uses shift/mask info from the visual.  This 
should work across LE and BE machines and X server 
variations.  It's more compute intensive for unix.

hobbs added on 2003-10-29 05:22:56:

File Added - 65731: alpha-hobbs2.patch

Logged In: YES 
user_id=72656

minor correction in patch for XGetImageZPixmap to handle 
odd width images by letting XCreateImage calc the line width 
from the bitmap_pad.  This makes 16bpp work right on 
Windows.

hobbs added on 2003-10-29 04:06:35:

File Added - 65716: alpha-test.tar.gz

hobbs added on 2003-10-29 04:06:34:
Logged In: YES 
user_id=72656

attached is a modification of GPS's tests that display several 
alpha transparent images.  test against 16bpp and 24+bpp 
(and 8bpp - you should see no use of blending).

hobbs added on 2003-10-29 03:56:10:
Logged In: YES 
user_id=72656

I should note that the one oddity I see with this is for 
Windows 16bpp displays, when the x and/or width to display 
is at the edge (clipped) and odd, the image can get slanted.

hobbs added on 2003-10-29 03:54:44:

File Added - 65712: alpha-hobbs.patch

hobbs added on 2003-10-29 03:54:43:
Logged In: YES 
user_id=72656

attaching new patch which rewrites GPS's stuff to scale back 
the a much simpler alpha blend.  It always blends against the 
original image and works correctly for 16bpp (with 
tkWinImage.c patch also attached).  Needs to be tested on 
OS X, especially with 16bpp.

dkf added on 2003-09-29 19:02:39:
Logged In: YES 
user_id=79902

GPStaplin is working on a fix for this in selected visual
types (those without palettes!)

Attachments: