<refentry id="gdk-pixbuf-rendering">
<refmeta>
<refentrytitle>Rendering</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GDK-PIXBUF Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>Rendering</refname><refpurpose>Rendering a pixbuf to a GDK drawable.</refpurpose>
</refnamediv>

<refsynopsisdiv><title>Synopsis</title>
<synopsis>

#include &lt;gdk-pixbuf/gdk-pixbuf.h&gt;


enum        <link linkend="GdkPixbufAlphaMode">GdkPixbufAlphaMode</link>;
void        <link linkend="gdk-pixbuf-render-to-drawable-alpha">gdk_pixbuf_render_to_drawable_alpha</link>
                                            (<link linkend="GdkPixbuf">GdkPixbuf</link> *pixbuf,
                                             <link linkend="GdkDrawable">GdkDrawable</link> *drawable,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             <link linkend="GdkPixbufAlphaMode">GdkPixbufAlphaMode</link> alpha_mode,
                                             int alpha_threshold,
                                             <link linkend="GdkRgbDither">GdkRgbDither</link> dither,
                                             int x_dither,
                                             int y_dither);
void        <link linkend="gdk-pixbuf-render-to-drawable">gdk_pixbuf_render_to_drawable</link>   (<link linkend="GdkPixbuf">GdkPixbuf</link> *pixbuf,
                                             <link linkend="GdkDrawable">GdkDrawable</link> *drawable,
                                             <link linkend="GdkGC">GdkGC</link> *gc,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             <link linkend="GdkRgbDither">GdkRgbDither</link> dither,
                                             int x_dither,
                                             int y_dither);
void        <link linkend="gdk-pixbuf-render-threshold-alpha">gdk_pixbuf_render_threshold_alpha</link>
                                            (<link linkend="GdkPixbuf">GdkPixbuf</link> *pixbuf,
                                             <link linkend="GdkBitmap">GdkBitmap</link> *bitmap,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             int alpha_threshold);
void        <link linkend="gdk-pixbuf-render-pixmap-and-mask">gdk_pixbuf_render_pixmap_and_mask</link>
                                            (<link linkend="GdkPixbuf">GdkPixbuf</link> *pixbuf,
                                             <link linkend="GdkPixmap">GdkPixmap</link> **pixmap_return,
                                             <link linkend="GdkBitmap">GdkBitmap</link> **mask_return,
                                             int alpha_threshold);
</synopsis>
</refsynopsisdiv>





<refsect1>
<title>Description</title>
  <para>
    The &gdk-pixbuf; library provides several convenience functions to
    render pixbufs to GDK drawables.  It uses the GdkRGB to render the
    image data.
  </para>

  <para>
    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.
  </para>

  <important>
    <para>
      Since these functions use GdkRGB for rendering, you must
      initialize GdkRGB before using any of them.  You can do this by
      calling <link linkend="gdk-rgb-init">gdk_rgb_init</link>() near the beginning of your program.
    </para>
  </important>
</refsect1>

<refsect1>
<title>Details</title>
<refsect2>
<title><anchor id="GdkPixbufAlphaMode">enum GdkPixbufAlphaMode</title>
<programlisting>typedef enum {
	GDK_PIXBUF_ALPHA_BILEVEL,
	GDK_PIXBUF_ALPHA_FULL
} GdkPixbufAlphaMode;
</programlisting>
  <para>
    These values can be passed to
    <link linkend="gdk-pixbuf-render-to-drawable-alpha">gdk_pixbuf_render_to_drawable_alpha</link>() 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.
  </para><informaltable pgwide="1" frame="none" role="enum">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row>
<entry><literal>GDK_PIXBUF_ALPHA_BILEVEL</literal></entry>
<entry>A bilevel clipping mask (black and white)
will be created and used to draw the image.  Pixels below 0.5 opacity
will be considered fully transparent, and all others will be
considered fully opaque.
</entry>
</row>
<row>
<entry><literal>GDK_PIXBUF_ALPHA_FULL</literal></entry>
<entry>For now falls back to <link linkend="GDK-PIXBUF-ALPHA-BILEVEL-CAPS">GDK_PIXBUF_ALPHA_BILEVEL</link>.
In the future it will do full alpha compositing.

</entry>
</row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-pixbuf-render-to-drawable-alpha">gdk_pixbuf_render_to_drawable_alpha ()</title>
<programlisting>void        gdk_pixbuf_render_to_drawable_alpha
                                            (<link linkend="GdkPixbuf">GdkPixbuf</link> *pixbuf,
                                             <link linkend="GdkDrawable">GdkDrawable</link> *drawable,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             <link linkend="GdkPixbufAlphaMode">GdkPixbufAlphaMode</link> alpha_mode,
                                             int alpha_threshold,
                                             <link linkend="GdkRgbDither">GdkRgbDither</link> dither,
                                             int x_dither,
                                             int y_dither);</programlisting>
<para>
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.
</para>
<para>
When used with <link linkend="GDK-PIXBUF-ALPHA-BILEVEL-CAPS">GDK_PIXBUF_ALPHA_BILEVEL</link>, 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 <link linkend="gdk-pixbuf-render-to-drawable">gdk_pixbuf_render_to_drawable</link>() or GdkRGB directly instead.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>pixbuf</parameter>&nbsp;:</entry>
<entry> A pixbuf.
</entry></row>
<row><entry align="right"><parameter>drawable</parameter>&nbsp;:</entry>
<entry> Destination drawable.
</entry></row>
<row><entry align="right"><parameter>src_x</parameter>&nbsp;:</entry>
<entry> Source X coordinate within pixbuf.
</entry></row>
<row><entry align="right"><parameter>src_y</parameter>&nbsp;:</entry>
<entry> Source Y coordinates within pixbuf.
</entry></row>
<row><entry align="right"><parameter>dest_x</parameter>&nbsp;:</entry>
<entry> Destination X coordinate within drawable.
</entry></row>
<row><entry align="right"><parameter>dest_y</parameter>&nbsp;:</entry>
<entry> Destination Y coordinate within drawable.
</entry></row>
<row><entry align="right"><parameter>width</parameter>&nbsp;:</entry>
<entry> Width of region to render, in pixels.
</entry></row>
<row><entry align="right"><parameter>height</parameter>&nbsp;:</entry>
<entry> Height of region to render, in pixels.
</entry></row>
<row><entry align="right"><parameter>alpha_mode</parameter>&nbsp;:</entry>
<entry> If the image does not have opacity information, this is ignored.
Otherwise, specifies how to handle transparency when rendering.
</entry></row>
<row><entry align="right"><parameter>alpha_threshold</parameter>&nbsp;:</entry>
<entry> If the image does have opacity information and <parameter>alpha_mode</parameter>
is GDK_PIXBUF_ALPHA_BILEVEL, specifies the threshold value for opacity
values.
</entry></row>
<row><entry align="right"><parameter>dither</parameter>&nbsp;:</entry>
<entry> Dithering mode for GdkRGB.
</entry></row>
<row><entry align="right"><parameter>x_dither</parameter>&nbsp;:</entry>
<entry> X offset for dither.
</entry></row>
<row><entry align="right"><parameter>y_dither</parameter>&nbsp;:</entry>
<entry> Y offset for dither.
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-pixbuf-render-to-drawable">gdk_pixbuf_render_to_drawable ()</title>
<programlisting>void        gdk_pixbuf_render_to_drawable   (<link linkend="GdkPixbuf">GdkPixbuf</link> *pixbuf,
                                             <link linkend="GdkDrawable">GdkDrawable</link> *drawable,
                                             <link linkend="GdkGC">GdkGC</link> *gc,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             <link linkend="GdkRgbDither">GdkRgbDither</link> dither,
                                             int x_dither,
                                             int y_dither);</programlisting>
<para>
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.
</para>
<para>
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.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>pixbuf</parameter>&nbsp;:</entry>
<entry> A pixbuf.
</entry></row>
<row><entry align="right"><parameter>drawable</parameter>&nbsp;:</entry>
<entry> Destination drawable.
</entry></row>
<row><entry align="right"><parameter>gc</parameter>&nbsp;:</entry>
<entry> GC used for rendering.
</entry></row>
<row><entry align="right"><parameter>src_x</parameter>&nbsp;:</entry>
<entry> Source X coordinate within pixbuf.
</entry></row>
<row><entry align="right"><parameter>src_y</parameter>&nbsp;:</entry>
<entry> Source Y coordinate within pixbuf.
</entry></row>
<row><entry align="right"><parameter>dest_x</parameter>&nbsp;:</entry>
<entry> Destination X coordinate within drawable.
</entry></row>
<row><entry align="right"><parameter>dest_y</parameter>&nbsp;:</entry>
<entry> Destination Y coordinate within drawable.
</entry></row>
<row><entry align="right"><parameter>width</parameter>&nbsp;:</entry>
<entry> Width of region to render, in pixels.
</entry></row>
<row><entry align="right"><parameter>height</parameter>&nbsp;:</entry>
<entry> Height of region to render, in pixels.
</entry></row>
<row><entry align="right"><parameter>dither</parameter>&nbsp;:</entry>
<entry> Dithering mode for GdkRGB.
</entry></row>
<row><entry align="right"><parameter>x_dither</parameter>&nbsp;:</entry>
<entry> X offset for dither.
</entry></row>
<row><entry align="right"><parameter>y_dither</parameter>&nbsp;:</entry>
<entry> Y offset for dither.
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-pixbuf-render-threshold-alpha">gdk_pixbuf_render_threshold_alpha ()</title>
<programlisting>void        gdk_pixbuf_render_threshold_alpha
                                            (<link linkend="GdkPixbuf">GdkPixbuf</link> *pixbuf,
                                             <link linkend="GdkBitmap">GdkBitmap</link> *bitmap,
                                             int src_x,
                                             int src_y,
                                             int dest_x,
                                             int dest_y,
                                             int width,
                                             int height,
                                             int alpha_threshold);</programlisting>
<para>
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.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>pixbuf</parameter>&nbsp;:</entry>
<entry> A pixbuf.
</entry></row>
<row><entry align="right"><parameter>bitmap</parameter>&nbsp;:</entry>
<entry> Bitmap where the bilevel mask will be painted to.
</entry></row>
<row><entry align="right"><parameter>src_x</parameter>&nbsp;:</entry>
<entry> Source X coordinate.
</entry></row>
<row><entry align="right"><parameter>src_y</parameter>&nbsp;:</entry>
<entry> source Y coordinate.
</entry></row>
<row><entry align="right"><parameter>dest_x</parameter>&nbsp;:</entry>
<entry> Destination X coordinate.
</entry></row>
<row><entry align="right"><parameter>dest_y</parameter>&nbsp;:</entry>
<entry> Destination Y coordinate.
</entry></row>
<row><entry align="right"><parameter>width</parameter>&nbsp;:</entry>
<entry> Width of region to threshold.
</entry></row>
<row><entry align="right"><parameter>height</parameter>&nbsp;:</entry>
<entry> Height of region to threshold.
</entry></row>
<row><entry align="right"><parameter>alpha_threshold</parameter>&nbsp;:</entry>
<entry> Opacity values below this will be painted as zero; all
other values will be painted as one.
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-pixbuf-render-pixmap-and-mask">gdk_pixbuf_render_pixmap_and_mask ()</title>
<programlisting>void        gdk_pixbuf_render_pixmap_and_mask
                                            (<link linkend="GdkPixbuf">GdkPixbuf</link> *pixbuf,
                                             <link linkend="GdkPixmap">GdkPixmap</link> **pixmap_return,
                                             <link linkend="GdkBitmap">GdkBitmap</link> **mask_return,
                                             int alpha_threshold);</programlisting>
<para>
Creates a pixmap and a mask bitmap which are returned in the <parameter>pixmap_return</parameter>
and <parameter>mask_return</parameter> 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 <link linkend="gdk-pixbuf-render-to-drawable-alpha">gdk_pixbuf_render_to_drawable_alpha</link>() or
<link linkend="gdk-pixbuf-render-to-drawable">gdk_pixbuf_render_to_drawable</link>(), and <link linkend="gdk-pixbuf-render-threshold-alpha">gdk_pixbuf_render_threshold_alpha</link>().
</para>
<para>
If the pixbuf does not have an alpha channel, then *<parameter>mask_return</parameter> will be set
to <literal>NULL</literal>.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>pixbuf</parameter>&nbsp;:</entry>
<entry> A pixbuf.
</entry></row>
<row><entry align="right"><parameter>pixmap_return</parameter>&nbsp;:</entry>
<entry> Return value for the created pixmap.
</entry></row>
<row><entry align="right"><parameter>mask_return</parameter>&nbsp;:</entry>
<entry> Return value for the created mask.
</entry></row>
<row><entry align="right"><parameter>alpha_threshold</parameter>&nbsp;:</entry>
<entry> Threshold value for opacity values.
</entry></row>
</tbody></tgroup></informaltable></refsect2>

</refsect1>



<refsect1>
<title>See Also</title>
  <para>
    GdkRGB
  </para>
</refsect1>

</refentry>
