1 <!-- ##### SECTION Title ##### -->
2 The GdkPixbuf Structure
4 <!-- ##### SECTION Short_Description ##### -->
5 Information that describes an image.
7 <!-- ##### SECTION Long_Description ##### -->
10 The <structname>GdkPixbuf</structname> structure contains
11 information that describes an image in memory.
14 <section id="image-data">
15 <title>Image Data</title>
18 Image data in a pixbuf is stored in memory in uncompressed,
19 packed format. Rows in the image are stored top to bottom, and
20 in each row pixels are stored from left to right. There may be
21 padding at the end of a row. The "rowstride" value of a pixbuf,
22 as returned by gdk_pixbuf_get_rowstride(), indicates the number
23 of bytes between rows.
26 <example id="put-pixel">
27 <title>put_pixel(<!-- -->) example</title>
30 The following code illustrates a simple put_pixel(<!-- -->)
31 function for RGB pixbufs with 8 bits per channel with an alpha
32 channel. It is not included in the gdk-pixbuf library for
33 performance reasons; rather than making several function calls
34 for each pixel, your own code can take shortcuts.
39 put_pixel (GdkPixbuf *pixbuf, int x, int y, guchar red, guchar green, guchar blue, guchar alpha)
41 int width, height, rowstride, n_channels;
44 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
46 g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
47 g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
48 g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
49 g_assert (n_channels == 4);
51 width = gdk_pixbuf_get_width (pixbuf);
52 height = gdk_pixbuf_get_height (pixbuf);
54 g_assert (x >= 0 && x < width);
55 g_assert (y >= 0 && y < height);
57 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
58 pixels = gdk_pixbuf_get_pixels (pixbuf);
60 p = pixels + y * rowstride + x * n_channels;
69 This function will not work for pixbufs with images that are
70 other than 8 bits per sample or channel, but it will work for
71 most of the pixbufs that GTK+ uses.
77 If you are doing memcpy() of raw pixbuf data, note that the
78 last row in the pixbuf may not be as wide as the full
79 rowstride, but rather just as wide as the pixel data needs to
80 be. That is, it is unsafe to do <literal>memcpy (dest,
81 pixels, rowstride * height)</literal> to copy a whole pixbuf.
82 Use gdk_pixbuf_copy() instead, or compute the width in bytes
83 of the last row as <literal>width * ((n_channels *
84 bits_per_sample + 7) / 8)</literal>.
89 <!-- ##### SECTION See_Also ##### -->
93 <!-- ##### SECTION Stability_Level ##### -->
96 <!-- ##### ENUM GdkPixbufError ##### -->
98 An error code in the #GDK_PIXBUF_ERROR domain. Many &gdk-pixbuf;
99 operations can cause errors in this domain, or in the #G_FILE_ERROR
103 @GDK_PIXBUF_ERROR_CORRUPT_IMAGE: An image file was broken somehow.
104 @GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY: Not enough memory.
105 @GDK_PIXBUF_ERROR_BAD_OPTION: A bad option was passed to a pixbuf save module.
106 @GDK_PIXBUF_ERROR_UNKNOWN_TYPE: Unknown image type.
107 @GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION: Don't know how to perform the
108 given operation on the type of image at hand.
109 @GDK_PIXBUF_ERROR_FAILED: Generic failure code, something went wrong.
111 <!-- ##### MACRO GDK_PIXBUF_ERROR ##### -->
113 Error domain used for pixbuf operations. Indicates that the error code
114 will be in the #GdkPixbufError enumeration. See #GError for
115 information on error domains and error codes.
120 <!-- ##### ENUM GdkColorspace ##### -->
122 This enumeration defines the color spaces that are supported by
123 the &gdk-pixbuf; library. Currently only RGB is supported.
126 @GDK_COLORSPACE_RGB: Indicates a red/green/blue additive color space.
128 <!-- ##### ENUM GdkPixbufAlphaMode ##### -->
130 This function can create a
131 bilevel clipping mask (black and white) and use it while painting
132 the image. In the future, when the X Window System gets an alpha
133 channel extension, it will be possible to do full alpha
134 compositing onto arbitrary drawables. For now both cases fall
135 back to a bilevel clipping mask.
138 @GDK_PIXBUF_ALPHA_BILEVEL: A bilevel clipping mask (black and white)
139 will be created and used to draw the image. Pixels below 0.5 opacity
140 will be considered fully transparent, and all others will be
141 considered fully opaque.
142 @GDK_PIXBUF_ALPHA_FULL: For now falls back to #GDK_PIXBUF_ALPHA_BILEVEL.
143 In the future it will do full alpha compositing.
145 <!-- ##### STRUCT GdkPixbuf ##### -->
147 This is the main structure in the &gdk-pixbuf; library. It is
148 used to represent images. It contains information about the
149 image's pixel data, its color space, bits per sample, width and
150 height, and the rowstride (the number of bytes between the start of
151 one row and the start of the next).
155 <!-- ##### ARG GdkPixbuf:bits-per-sample ##### -->
160 <!-- ##### ARG GdkPixbuf:colorspace ##### -->
165 <!-- ##### ARG GdkPixbuf:has-alpha ##### -->
170 <!-- ##### ARG GdkPixbuf:height ##### -->
175 <!-- ##### ARG GdkPixbuf:n-channels ##### -->
180 <!-- ##### ARG GdkPixbuf:pixels ##### -->
185 <!-- ##### ARG GdkPixbuf:rowstride ##### -->
190 <!-- ##### ARG GdkPixbuf:width ##### -->
195 <!-- ##### FUNCTION gdk_pixbuf_get_colorspace ##### -->
204 <!-- ##### FUNCTION gdk_pixbuf_get_n_channels ##### -->
213 <!-- ##### FUNCTION gdk_pixbuf_get_has_alpha ##### -->
222 <!-- ##### FUNCTION gdk_pixbuf_get_bits_per_sample ##### -->
231 <!-- ##### FUNCTION gdk_pixbuf_get_pixels ##### -->
240 <!-- ##### FUNCTION gdk_pixbuf_get_width ##### -->
249 <!-- ##### FUNCTION gdk_pixbuf_get_height ##### -->
258 <!-- ##### FUNCTION gdk_pixbuf_get_rowstride ##### -->
267 sgml-parent-document: ("../gdk-pixbuf.sgml" "book" "refsect2" "")
272 <!-- ##### FUNCTION gdk_pixbuf_get_option ##### -->
285 sgml-parent-document: ("../gdk-pixbuf.sgml" "book" "refsect2")