Package: gdk-pixbuf

Class gdk-pixbuf

Superclasses

g-object, common-lisp:standard-object, common-lisp:t

Documented Subclasses

None

Direct Slots

bits-per-sample
The "bits-per-sample" property of type gint (Read / Write / Construct Only)
The number of bits per sample. Currently only 8 bit per sample are supported.
Allowed values: [1,16]
Default value: 8
colorspace
The "colorspace" property of type gdk-colorspace (Read / Write / Construct Only)
The colorspace in which the samples are interpreted.
Default value: :rgb
has-alpha
The "has-alpha" property of type gboolean (Read / Write / Construct Only)
Whether the pixbuf has an alpha channel.
Default value: nil
height
The "height" property of type gint (Read / Write / Construct Only)
The number of rows of the pixbuf.
Allowed values: >= 1
Default value: 1
n-channels
The "n-channels" property of type gint (Read / Write / Construct Only)
The number of samples per pixel. Currently, only 3 or 4 samples per pixel are supported.
Allowed values: >= 0
Default value: 3
pixels
The "pixels" property of type gpointer (Read / Write / Construct Only)
A pointer to the pixel data of the pixbuf.
rowstride
The "rowstride" property of type gint (Read / Write / Construct Only)
The number of bytes between the start of a row and the start of the next row. This number must (obviously) be at least as large as the width of the pixbuf.
Allowed values: >= 1
Default value: 1
width
The "width" property of type gint (Read / Write / Construct Only)
The number of columns of the pixbuf.
Allowed values: >= 1
Default value: 1

Details

This is the main structure in the gdk-pixbuf library. It is used to represent images. It contains information about the image's pixel data, its color space, bits per sample, width and height, and the rowstride (the number of bytes between the start of one row and the start of the next).

Image Data

Image data in a pixbuf is stored in memory in uncompressed, packed format. Rows in the image are stored top to bottom, and in each row pixels are stored from left to right. There may be padding at the end of a row. The "rowstride" value of a pixbuf, as returned by gdk-pixbuf-get-rowstride, indicates the number of bytes between rows.

Example 1. put_pixel() example
The following code illustrates a simple put_pixel() function for RGB pixbufs with 8 bits per channel with an alpha channel. It is not included in the gdk-pixbuf library for performance reasons; rather than making several function calls for each pixel, your own code can take shortcuts.
 static void
 put_pixel (GdkPixbuf *pixbuf, int x, int y, guchar red, guchar green,
                                             guchar blue, guchar alpha)
 {
   int width, height, rowstride, n_channels;
   guchar *pixels, *p;

n_channels = gdk_pixbuf_get_n_channels (pixbuf);

g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB); g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); g_assert (gdk_pixbuf_get_has_alpha (pixbuf)); g_assert (n_channels == 4);

width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf);

g_assert (x >= 0 && x < width); g_assert (y >= 0 && y < height);

rowstride = gdk_pixbuf_get_rowstride (pixbuf); pixels = gdk_pixbuf_get_pixels (pixbuf);

p = pixels + y * rowstride + x * n_channels; p[0] = red; p[1] = green; p[2] = blue; p[3] = alpha; }
This function will not work for pixbufs with images that are other than 8 bits per sample or channel, but it will work for most of the pixbufs that GTK+ uses.

Note

If you are doing memcpy() of raw pixbuf data, note that the last row in the pixbuf may not be as wide as the full rowstride, but rather just as wide as the pixel data needs to be. That is, it is unsafe to do memcpy (dest, pixels, rowstride * height) to copy a whole pixbuf. Use gdk-pixbuf-copy instead, or compute the width in bytes of the last row as width * ((n_channels * bits_per_sample + 7) / 8).
 

Slot Access Functions

Inherited Slot Access Functions

2013-2-8