GTK2 missing transparency (with patch for common cases)
Original Reporter info from Mantis: Bad Sector @badsectoracula
-
Reporter name: Kostas Michalopoulos
Original Reporter info from Mantis: Bad Sector @badsectoracula
- Reporter name: Kostas Michalopoulos
Description:
The GTK2 widgetset doesn't support drawing bitmaps with full transparency (alpha channel). While the bitmaps themselves can be stored as 32bit, it is impossible to use them on the GUI - everywhere a bitmap with an alpha channel is used (toolbars, icons, images, etc), the bitmap is drawn with jaggies because the widgetset only support 1bit transparency.
The reason for that is that the graphics contexts are implemented using GDK pixmaps which themselves do not support alpha channels, but it is possible to use a bitmask (hence the ability for 1bit transparency). When a graphics context is created for a bitmap with an alpha channel (stored as a GDK pixbuf, which however isn't a drawable and so it cant be used directly), the GTK2 backend generates a 24bit pixmap from the RGB data and a pixmap using an alpha threshold. Then the 32bit pixbuf is destroyed.
The only way to avoid the above is to rewrite the GTK2 graphics context functionality to use Cairo (which supports full alpha blending operations). However with the ongoing work on GTK3 and the impact that would have on the stability of existing applications (bugs from the new interface) this might not be a good idea at the moment.
As an intermediate solution, i have attached a patch that fixes the most common cases where a bitmap is drawn to widgets or other bitmaps (which are used, among others, for toolbars, images, icon views, lists, etc). This patch keeps the original pixbuf in the graphics context alongside with the generated pixmap and uses it instead of the pixmap when a SRCCOPY draw is requested (the patch works with or without scaling and with or without flipping). The pixbuf is destroyed when the graphics context is destroyed or when any drawing operation
on the graphics context is performed (f.e. drawing a line, arc or anything else on the bitmap). The latter is necessary since GDK does not provide functionality for those functions on pixbufs (which would allow a full 32bit aware implementation of graphics contexts under GTK2).
Attached i have the patch, a test program and an image that shows the problem with before and after the patch has been applied. The program tests toolbars, an image with an icon and a generated bitmap via TLazIntfImage drawn on a paintbox normally, flipped, scaled and both scaled and flipped.
Steps to reproduce:
Download, compile and run the test program under GTK2.
Mantis conversion info:
- Mantis ID: 25491
- OS: Linux
- Platform: GTK2
- Version: 1.3 (SVN)
- Fixed in revision: r43644 (#a76c5900)
- Monitored by: » heliosroots (heliosroots), » @m-fuchs (Michael Fuchs), » @badsectoracula (Kostas Michalopoulos)