Transparent Color in blitting with X11

Glynn Clements glynn at gclements.plus.com
Thu Jul 29 03:42:22 PDT 2010


Peter Harris wrote:

> > but xlib doesnt support an alpha channel (and the freerunner has only 16
> > bits per pixel). is there an easy way to do transparency (one
> > transparent color is enough) with xlib or a toolkit which builds on it?
> 
> If you can easily extract that color into a 1-bit bitmap, you can use
> XSetClipMask.

Alternatively, you can do it in two steps:

	XSetFunction(dpy, gc, GXandInverted);
	XSetBackground(dpy, gc, 0UL);
	XSetForeground(dpy, gc, ~0UL);
	XCopyPlane(dpy, mask, win, gc, ..., 1UL);
	
	XSetFunction(dpy, gc, GXor);
	XCopyArea(dpy, image, win, gc, ...);

The image must have all background (transparent) pixels set to zero.

Also, you can use XPutImage() instead of XCopyPlane() and XCopyArea().

-- 
Glynn Clements <glynn at gclements.plus.com>



More information about the xorg mailing list