Rendering

Name

Rendering -- Rendering a pixbuf to a GDK drawable.

Synopsis


#include <gdk-pixbuf/gdk-pixbuf.h>


enum        GdkPixbufAlphaMode;
void        gdk_pixbuf_render_to_drawable_alpha
                                            (GdkPixbuf *pixbuf,
                                             GdkDrawable *drawable,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             GdkPixbufAlphaMode alpha_mode,
                                             int alpha_threshold,
                                             GdkRgbDither dither,
                                             int x_dither,
                                             int y_dither);
void        gdk_pixbuf_render_to_drawable   (GdkPixbuf *pixbuf,
                                             GdkDrawable *drawable,
                                             GdkGC *gc,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             GdkRgbDither dither,
                                             int x_dither,
                                             int y_dither);
void        gdk_pixbuf_render_threshold_alpha
                                            (GdkPixbuf *pixbuf,
                                             GdkBitmap *bitmap,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             int alpha_threshold);
void        gdk_pixbuf_render_pixmap_and_mask
                                            (GdkPixbuf *pixbuf,
                                             GdkPixmap **pixmap_return,
                                             GdkBitmap **mask_return,
                                             int alpha_threshold);

Description

The gdk-pixbuf library provides several convenience functions to render pixbufs to GDK drawables. It uses the GdkRGB to render the image data.

At this point there is not a standard alpha channel extension for the X Window System, so it is not possible to use full opacity information when painting images to arbitrary drawables. The gdk-pixbuf convenience functions will threshold the opacity information to create a bi-level clipping mask (black and white), and use that to draw the image onto a drawable.

Important: Since these functions use GdkRGB for rendering, you must initialize GdkRGB before using any of them. You can do this by calling gdk_rgb_init() near the beginning of your program.

Details

enum GdkPixbufAlphaMode

typedef enum {
	GDK_PIXBUF_ALPHA_BILEVEL,
	GDK_PIXBUF_ALPHA_FULL
} GdkPixbufAlphaMode;

These values can be passed to gdk_pixbuf_render_to_drawable_alpha() to control how the alpha chanel of an image should be handled. This function can create a bilevel clipping mask (black and white) and use it while painting the image. In the future, when the X Window System gets an alpha channel extension, it will be possible to do full alpha compositing onto arbitrary drawables. For now both cases fall back to a bilevel clipping mask.


gdk_pixbuf_render_to_drawable_alpha ()

void        gdk_pixbuf_render_to_drawable_alpha
                                            (GdkPixbuf *pixbuf,
                                             GdkDrawable *drawable,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             GdkPixbufAlphaMode alpha_mode,
                                             int alpha_threshold,
                                             GdkRgbDither dither,
                                             int x_dither,
                                             int y_dither);

Renders a rectangular portion of a pixbuf to a drawable. This is done using GdkRGB, so the specified drawable must have the GdkRGB visual and colormap.

When used with GDK_PIXBUF_ALPHA_BILEVEL, this function has to create a bitmap out of the thresholded alpha channel of the image and, it has to set this bitmap as the clipping mask for the GC used for drawing. This can be a significant performance penalty depending on the size and the complexity of the alpha channel of the image. If performance is crucial, consider handling the alpha channel yourself (possibly by caching it in your application) and using gdk_pixbuf_render_to_drawable() or GdkRGB directly instead.


gdk_pixbuf_render_to_drawable ()

void        gdk_pixbuf_render_to_drawable   (GdkPixbuf *pixbuf,
                                             GdkDrawable *drawable,
                                             GdkGC *gc,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             GdkRgbDither dither,
                                             int x_dither,
                                             int y_dither);

Renders a rectangular portion of a pixbuf to a drawable while using the specified GC. This is done using GdkRGB, so the specified drawable must have the GdkRGB visual and colormap. Note that this function will ignore the opacity information for images with an alpha channel; the GC must already have the clipping mask set if you want transparent regions to show through.

For an explanation of dither offsets, see the GdkRGB documentation. In brief, the dither offset is important when re-rendering partial regions of an image to a rendered version of the full image, or for when the offsets to a base position change, as in scrolling. The dither matrix has to be shifted for consistent visual results. If you do not have any of these cases, the dither offsets can be both zero.


gdk_pixbuf_render_threshold_alpha ()

void        gdk_pixbuf_render_threshold_alpha
                                            (GdkPixbuf *pixbuf,
                                             GdkBitmap *bitmap,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             int alpha_threshold);

Takes the opacity values in a rectangular portion of a pixbuf and thresholds them to produce a bi-level alpha mask that can be used as a clipping mask for a drawable.


gdk_pixbuf_render_pixmap_and_mask ()

void        gdk_pixbuf_render_pixmap_and_mask
                                            (GdkPixbuf *pixbuf,
                                             GdkPixmap **pixmap_return,
                                             GdkBitmap **mask_return,
                                             int alpha_threshold);

Creates a pixmap and a mask bitmap which are returned in the pixmap_return and mask_return arguments, respectively, and renders a pixbuf and its corresponding tresholded alpha mask to them. This is merely a convenience function; applications that need to render pixbufs with dither offsets or to given drawables should use gdk_pixbuf_render_to_drawable_alpha() or gdk_pixbuf_render_to_drawable(), and gdk_pixbuf_render_threshold_alpha().

If the pixbuf does not have an alpha channel, then *mask_return will be set to NULL.

See Also

GdkRGB