Problem displaying image with alpha channel in a transparent window
- From: Yann Droneaud <ydroneaud mandriva com>
- To: gtk-app-devel-list gnome org, gtk-list gnome org
- Subject: Problem displaying image with alpha channel in a transparent window
- Date: Wed, 23 Jul 2008 10:38:51 +0200
Hi,
I'm trying to write a program to display a picture with full
transparency in its own window (without border), using Composite
extension (ARGB colormap and visual).
I've written a couple of programs doing this using Xlib alone or with
libXrender.
Using GTK+ to do the same seems easy since programs like cairo-clock [1]
are able to draw window with non rectangular shape and full
transparency.
But after many hours, and many version of my GTK+ demonstration program,
I'm still wandering how to display a GdkPixBuf with alpha layer in a
GtkWindow without any background or artefact.
So here are my little demonstration programs
- test-gdkpixbuf.c :
This program does the following:
- looks up the RGBA colormap with gdk_screen_get_rgba_colormap()
- installs the colormap with gtk_widget_set_default_colormap()
- creates a GdkPixbuf with gdk_pixbuf_new_from_file()
- creates a GtkWindow
- sets the widget as GTK_APP_PAINTABLE with
gtk_widget_set_app_paintable()
- disables double buffering with gtk_widget_set_double_buffered()
- in the realize signal handler, it removes any background pixmap
using gdk_window_set_back_pixmap()
- in the expose event handler, it draws the GdkPixBuf using
gdk_draw_pixbuf()
At first, it seems to work, but in fact, as soon as you move the
picture using CTRL+Button 1, you will realize the problem: the
window's background is a snapshot of the root window (see post from
Matt Hoosier [2]), and is fixed for the window's lifetime.
At least, the content of the picture is well composited with the
background, but it's not the full transparency I'm looking for.
See:
- test-gdkpixbuf.png
- test-gdkpixbuf-bg.patch:
Apply the patch on top of test-gdkpixbuf.c to create
test-gdkpixbuf-background.c
This patch set a pixmap as a background, and draw nothing on the
window. Only the realize signal and expose event handlers are
modified:
- realize signal handler creates a new pixmap with gdk_pixmap_new(),
writes the content of the GdkPixBuf with gdk_draw_pixbuf() and then
install the background with gdk_window_set_back_pixmap().
- expose event handler only call to gdk_window_clear()
With this version, the background is really transparent, but many
artefacts are visibles: the background is corrupted.
On some configuration, I'm even able to see some other pixmap content
as background, strange !
See:
- test-gdkpixbuf-background.png
Note: those were tested with Gtk+ 2.10 and Gtk+ 2.12.
So I'm stuck. Either I'm always getting a unwanted background (filled
with solid color or a root window snapshot) or I'm getting a corrupted
image.
I've tried to:
- use a GtkImage widget made from the GdkPixBuf
- use a GtkDrawingArea in the main window and draw into it
- use gdk_draw_rgb_32_image() instead of gdk_draw_pixbuf()
- paint with gdk_cairo_set_source_pixbuf()
I'm always getting an image composited with the window background.
Could someone provide me a link, a tips, or something to help me.
Thanks.
[1] http://macslow.thepimp.net/?page_id=23
[2] http://mail.gnome.org/archives/gtk-list/2006-October/msg00246.html
--
Yann Droneaud <ydroneaud mandriva com>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]