XImage Transparency

Gheorghe, Gelu Gelu.Gheorghe at gdcanada.com
Fri Jul 27 08:18:59 PDT 2007


So the only way to get TRUE transparency (ie. I can see what's underneath it) is by pulling in this XRender library which may not necessarily work with Solaris / my version of the X server (which is 3.6 11)? 

>From what I understand, masking only 'masks' it (ie. matches that part you don't want to the background colour). 

I need it to be transparent and I need the mask to be dynamic as the XImage is 1000x1000 and constructed in real time, and there is a possibility it might be moving and I have to see the previous XImage through the current one. 

What about the following method ? 

      /*  Fill in the pixmap with our bg color: */ 
      XSetFunction(dpy, gc, GXcopy); 
      XSetForeground(dpy, gc, bg); 
      XFillRectangle(dpy, new, gc, 0, 0, width, height); 

      /*  Erase the parts not covered by the mask: */ 
      XSetFunction(dpy, gc, GXand); 
      XSetForeground(dpy, gc, 0); 
      XSetBackground(dpy, gc, ~0); 
      XCopyPlane(dpy, mask, new, gc, 0, 0, width, height, 0, 0, 1L); 

      /*  Copy in the "original" pixmap, but only those parts that 
       *  have a valid mask bit: 
       */ 
      XSetFunction(dpy, gc, GXor); 
      XCopyArea(dpy, image, new, gc, 0, 0, width, height, 0, 0); 

-----Original Message-----
From: Carsten Haitzler (The Rasterman) [mailto:raster at rasterman.com] 
Sent: July 26, 2007 7:20 PM
To: Juliusz Chroboczek
Cc: Glynn Clements; Gheorghe, Gelu; xorg at lists.freedesktop.org
Subject: Re: XImage Transparency

On Fri, 27 Jul 2007 00:21:18 +0200 Juliusz Chroboczek
<Juliusz.Chroboczek at pps.jussieu.fr> babbled:

> >> How can you make part of an XImage transparent (true transparency - as
> >> in I can see something under the transparent parts) ? 
> 
> > You can't.
> 
> > If you want to plot a "masked" image, you need a separate mask bitmap,
> > where 1 represents opaque and 0 represents transparent.
> >
> > First, the mask needs to exist as a 1-bit Pixmap. You can then set
> > this as the clip mask using XSetClipMask() and XSetClipOrigin(). When
> > you draw the image (XPutImage), it will be masked against the clip
> > mask.
> 
> And watch your X server collapse.
> 
> If you use XSetClipMask, the bitmap will be converted to a set of
> spans, which will kill performance.

that depends on the mask complexity. if its a simple-ish outline you are fine.
(i.e no more than 2 spans per image line on average for example).

> Instead, you should be using the Render extension together with RGBA
> images.

and watch performance collapse too. xrender isn't a perfromance beast. you pay
for a read/modify/write cycle PER PIXEL. xputimage with a mask is a write cycle
only with no read latency from the destination involved (and good luck if its
accelerated - properly). also this will limit you to SANE uses only being 24bpp
- down to 16bpp and 8bpp this will just fall over as xrender needs to
up-convert to 24bpp - do the blend, then down-convert to destination depth (or
use colorspace specific blend handling). also this won't work on old xservers -
so you need a fallback for when you run on that nice old NCD terminal anyway -
so back to ximage + mask :)

main point is - xrender is not a silver bullet. it's a bed of roses - lots of
thorns too. it mostly depends on what kind of input data you are looking at and
your desired results and support. xrender is an option - if alpha blending is
really what you want/need. if your masks will be complex it might be an option
too. in the end unless you are creating toolkits - you probably want to use
existing toolkits/libraries to worry about this for you as people have written
them to abstract this problem away from you.

-- 
------------- Codito, ergo sum - "I code, therefore I am" --------------
The Rasterman (Carsten Haitzler)    raster at rasterman.com
裸好多
Tokyo, Japan (東京 日本)

The information contained in this e-mail message is PRIVATE. It may contain confidential information and may be legally privileged. It is intended for the exclusive use of the addressee(s). If you are not the intended recipient, you are hereby notified that any dissemination, distribution or reproduction of this communication is strictly prohibited. If the intended recipient(s) cannot be reached or if a transmission problem has occurred, please notify the sender immediately by return e-mail and destroy all copies of this message. 
Thank you. 




More information about the xorg mailing list