]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf.c
Create the event_window at the right size using the same logic as in
[~andy/gtk] / gdk-pixbuf / gdk-pixbuf.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2 /* GdkPixbuf library - Basic memory management
3  *
4  * Copyright (C) 1999 The Free Software Foundation
5  *
6  * Authors: Mark Crichton <crichton@gimp.org>
7  *          Miguel de Icaza <miguel@gnu.org>
8  *          Federico Mena-Quintero <federico@gimp.org>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */
25
26 #include <config.h>
27 #include <math.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include "gdk-pixbuf.h"
31 #include "gdk-pixbuf-private.h"
32
33 static void gdk_pixbuf_class_init   (GdkPixbufClass *klass);
34 static void gdk_pixbuf_finalize     (GObject        *object);
35 static void gdk_pixbuf_set_property (GObject        *object,
36                                      guint           prop_id,
37                                      const GValue   *value,
38                                      GParamSpec     *pspec);
39 static void gdk_pixbuf_get_property (GObject        *object,
40                                      guint           prop_id,
41                                      GValue         *value,
42                                      GParamSpec     *pspec);
43
44 \f
45 enum 
46 {
47   PROP_0,
48   PROP_COLORSPACE,
49   PROP_N_CHANNELS,
50   PROP_HAS_ALPHA,
51   PROP_BITS_PER_SAMPLE,
52   PROP_WIDTH,
53   PROP_HEIGHT,
54   PROP_ROWSTRIDE,
55   PROP_PIXELS
56 };
57
58 static gpointer parent_class;
59
60 GType
61 gdk_pixbuf_get_type (void)
62 {
63         static GType object_type = 0;
64
65         if (!object_type) {
66                 static const GTypeInfo object_info = {
67                         sizeof (GdkPixbufClass),
68                         (GBaseInitFunc) NULL,
69                         (GBaseFinalizeFunc) NULL,
70                         (GClassInitFunc) gdk_pixbuf_class_init,
71                         NULL,           /* class_finalize */
72                         NULL,           /* class_data */
73                         sizeof (GdkPixbuf),
74                         0,              /* n_preallocs */
75                         (GInstanceInitFunc) NULL,
76                 };
77                 
78                 object_type = g_type_register_static (G_TYPE_OBJECT,
79                                                       "GdkPixbuf",
80                                                       &object_info, 0);
81         }
82   
83         return object_type;
84 }
85
86 static void
87 gdk_pixbuf_class_init (GdkPixbufClass *klass)
88 {
89         GObjectClass *object_class = G_OBJECT_CLASS (klass);
90         
91         parent_class = g_type_class_peek_parent (klass);
92         
93         object_class->finalize = gdk_pixbuf_finalize;
94         object_class->set_property = gdk_pixbuf_set_property;
95         object_class->get_property = gdk_pixbuf_get_property;
96         
97         g_object_class_install_property (object_class,
98                                          PROP_N_CHANNELS,
99                                          g_param_spec_int ("n_channels",
100                                                            P_("Number of Channels"),
101                                                            P_("The number of samples per pixel"),
102                                                            0,
103                                                            G_MAXINT,
104                                                            3,
105                                                            G_PARAM_READWRITE |
106                                                            G_PARAM_CONSTRUCT_ONLY));
107
108         g_object_class_install_property (object_class,
109                                          PROP_COLORSPACE,
110                                          g_param_spec_enum ("colorspace",
111                                                             P_("Colorspace"),
112                                                             P_("The colorspace in which the samples are interpreted"),
113                                                             GDK_TYPE_COLORSPACE,
114                                                             GDK_COLORSPACE_RGB,
115                                                             
116                                                             G_PARAM_READWRITE |
117                                                             G_PARAM_CONSTRUCT_ONLY));
118
119         g_object_class_install_property (object_class,
120                                          PROP_HAS_ALPHA,
121                                          g_param_spec_boolean ("has_alpha",
122                                                                P_("Has Alpha"),
123                                                                P_("Whether the pixbuf has an alpha channel"),
124                                                                FALSE,
125                                                                G_PARAM_READWRITE |
126                                                                G_PARAM_CONSTRUCT_ONLY));
127
128         g_object_class_install_property (object_class,
129                                          PROP_BITS_PER_SAMPLE,
130                                          g_param_spec_int ("bits_per_sample",
131                                                            P_("Bits per Sample"),
132                                                            P_("The number of bits per sample"),
133                                                            1,
134                                                            16,
135                                                            8,
136                                                            G_PARAM_READWRITE |
137                                                            G_PARAM_CONSTRUCT_ONLY));
138
139         g_object_class_install_property (object_class,
140                                          PROP_WIDTH,
141                                          g_param_spec_int ("width",
142                                                            P_("Width"),
143                                                            P_("The number of columns of the pixbuf"),
144                                                            1,
145                                                            G_MAXINT,
146                                                            1,
147                                                            G_PARAM_READWRITE |
148                                                            G_PARAM_CONSTRUCT_ONLY));
149
150         g_object_class_install_property (object_class,
151                                          PROP_HEIGHT,
152                                          g_param_spec_int ("height",
153                                                            P_("Height"),
154                                                            P_("The number of rows of the pixbuf"),
155                                                            1,
156                                                            G_MAXINT,
157                                                            1,
158                                                            G_PARAM_READWRITE |
159                                                            G_PARAM_CONSTRUCT_ONLY));
160
161         g_object_class_install_property (object_class,
162                                          PROP_ROWSTRIDE,
163                                          g_param_spec_int ("rowstride",
164                                                            P_("Rowstride"),
165                                                            P_("The number of bytes between the start of a row and the start of the next row"),
166                                                            1,
167                                                            G_MAXINT,
168                                                            1,
169                                                            G_PARAM_READWRITE |
170                                                            G_PARAM_CONSTRUCT_ONLY));
171
172         g_object_class_install_property (object_class,
173                                          PROP_PIXELS,
174                                          g_param_spec_pointer ("pixels",
175                                                                P_("Pixels"),
176                                                                P_("A pointer to the pixel data of the pixbuf"),
177                                                                G_PARAM_READWRITE |
178                                                                G_PARAM_CONSTRUCT_ONLY));
179 }
180
181 static void
182 gdk_pixbuf_finalize (GObject *object)
183 {
184         GdkPixbuf *pixbuf = GDK_PIXBUF (object);
185         
186         if (pixbuf->destroy_fn)
187                 (* pixbuf->destroy_fn) (pixbuf->pixels, pixbuf->destroy_fn_data);
188         
189         G_OBJECT_CLASS (parent_class)->finalize (object);
190 }
191 \f
192
193 /**
194  * gdk_pixbuf_ref:
195  * @pixbuf: A pixbuf.
196  *
197  * Adds a reference to a pixbuf. 
198  *
199  * Return value: The same as the @pixbuf argument.
200  *
201  * Deprecated: Use g_object_ref().
202  **/
203 GdkPixbuf *
204 gdk_pixbuf_ref (GdkPixbuf *pixbuf)
205 {
206         return (GdkPixbuf *) g_object_ref (pixbuf);
207 }
208
209 /**
210  * gdk_pixbuf_unref:
211  * @pixbuf: A pixbuf.
212  *
213  * Removes a reference from a pixbuf. 
214  *
215  * Deprecated: Use g_object_unref().
216  **/
217 void
218 gdk_pixbuf_unref (GdkPixbuf *pixbuf)
219 {
220         g_object_unref (pixbuf);
221 }
222
223 \f
224
225 /* Used as the destroy notification function for gdk_pixbuf_new() */
226 static void
227 free_buffer (guchar *pixels, gpointer data)
228 {
229         g_free (pixels);
230 }
231
232 /**
233  * gdk_pixbuf_new:
234  * @colorspace: Color space for image.
235  * @has_alpha: Whether the image should have transparency information.
236  * @bits_per_sample: Number of bits per color sample.
237  * @width: Width of image in pixels.
238  * @height: Height of image in pixels.
239  *
240  * Creates a new #GdkPixbuf structure and allocates a buffer for it.  The 
241  * buffer has an optimal rowstride.  Note that the buffer is not cleared;
242  * you will have to fill it completely yourself.
243  *
244  * Return value: A newly-created #GdkPixbuf with a reference count of 1, or 
245  * %NULL if not enough memory could be allocated for the image buffer.
246  **/
247 GdkPixbuf *
248 gdk_pixbuf_new (GdkColorspace colorspace, 
249                 gboolean      has_alpha,
250                 int           bits_per_sample,
251                 int           width,
252                 int           height)
253 {
254         guchar *buf;
255         int channels;
256         int rowstride;
257         gsize bytes;
258
259         g_return_val_if_fail (colorspace == GDK_COLORSPACE_RGB, NULL);
260         g_return_val_if_fail (bits_per_sample == 8, NULL);
261         g_return_val_if_fail (width > 0, NULL);
262         g_return_val_if_fail (height > 0, NULL);
263
264         if (width <= 0 || height <= 0)
265                 return NULL;
266
267         channels = has_alpha ? 4 : 3;
268         rowstride = width * channels;
269         if (rowstride / channels != width || rowstride + 3 < 0) /* overflow */
270                 return NULL;
271         
272         /* Always align rows to 32-bit boundaries */
273         rowstride = (rowstride + 3) & ~3;
274
275         bytes = height * rowstride;
276         if (bytes / rowstride !=  height) /* overflow */
277                 return NULL;
278             
279         buf = g_try_malloc (bytes);
280         if (!buf)
281                 return NULL;
282
283         return gdk_pixbuf_new_from_data (buf, colorspace, has_alpha, bits_per_sample,
284                                          width, height, rowstride,
285                                          free_buffer, NULL);
286 }
287
288 /**
289  * gdk_pixbuf_copy:
290  * @pixbuf: A pixbuf.
291  * 
292  * Creates a new #GdkPixbuf with a copy of the information in the specified
293  * @pixbuf.
294  * 
295  * Return value: A newly-created pixbuf with a reference count of 1, or %NULL if
296  * not enough memory could be allocated.
297  **/
298 GdkPixbuf *
299 gdk_pixbuf_copy (const GdkPixbuf *pixbuf)
300 {
301         guchar *buf;
302         int size;
303
304         g_return_val_if_fail (pixbuf != NULL, NULL);
305
306         /* Calculate a semi-exact size.  Here we copy with full rowstrides;
307          * maybe we should copy each row individually with the minimum
308          * rowstride?
309          */
310
311         size = ((pixbuf->height - 1) * pixbuf->rowstride +
312                 pixbuf->width * ((pixbuf->n_channels * pixbuf->bits_per_sample + 7) / 8));
313
314         buf = g_try_malloc (size * sizeof (guchar));
315         if (!buf)
316                 return NULL;
317
318         memcpy (buf, pixbuf->pixels, size);
319
320         return gdk_pixbuf_new_from_data (buf,
321                                          pixbuf->colorspace, pixbuf->has_alpha,
322                                          pixbuf->bits_per_sample,
323                                          pixbuf->width, pixbuf->height,
324                                          pixbuf->rowstride,
325                                          free_buffer,
326                                          NULL);
327 }
328
329 /**
330  * gdk_pixbuf_new_subpixbuf:
331  * @src_pixbuf: a #GdkPixbuf
332  * @src_x: X coord in @src_pixbuf
333  * @src_y: Y coord in @src_pixbuf
334  * @width: width of region in @src_pixbuf
335  * @height: height of region in @src_pixbuf
336  * 
337  * Creates a new pixbuf which represents a sub-region of
338  * @src_pixbuf. The new pixbuf shares its pixels with the
339  * original pixbuf, so writing to one affects both.
340  * The new pixbuf holds a reference to @src_pixbuf, so
341  * @src_pixbuf will not be finalized until the new pixbuf
342  * is finalized.
343  * 
344  * Return value: a new pixbuf 
345  **/
346 GdkPixbuf*
347 gdk_pixbuf_new_subpixbuf (GdkPixbuf *src_pixbuf,
348                           int        src_x,
349                           int        src_y,
350                           int        width,
351                           int        height)
352 {
353         guchar *pixels;
354         GdkPixbuf *sub;
355
356         g_return_val_if_fail (GDK_IS_PIXBUF (src_pixbuf), NULL);
357         g_return_val_if_fail (src_x >= 0 && src_x + width <= src_pixbuf->width, NULL);
358         g_return_val_if_fail (src_y >= 0 && src_y + height <= src_pixbuf->height, NULL);
359
360         pixels = (gdk_pixbuf_get_pixels (src_pixbuf)
361                   + src_y * src_pixbuf->rowstride
362                   + src_x * src_pixbuf->n_channels);
363
364         sub = gdk_pixbuf_new_from_data (pixels,
365                                         src_pixbuf->colorspace,
366                                         src_pixbuf->has_alpha,
367                                         src_pixbuf->bits_per_sample,
368                                         width, height,
369                                         src_pixbuf->rowstride,
370                                         NULL, NULL);
371
372         /* Keep a reference to src_pixbuf */
373         g_object_ref (src_pixbuf);
374   
375         g_object_set_qdata_full (G_OBJECT (sub),
376                                  g_quark_from_static_string ("gdk-pixbuf-subpixbuf-src"),
377                                  src_pixbuf,
378                                  (GDestroyNotify) g_object_unref);
379
380         return sub;
381 }
382
383 \f
384
385 /* Accessors */
386
387 /**
388  * gdk_pixbuf_get_colorspace:
389  * @pixbuf: A pixbuf.
390  *
391  * Queries the color space of a pixbuf.
392  *
393  * Return value: Color space.
394  **/
395 GdkColorspace
396 gdk_pixbuf_get_colorspace (const GdkPixbuf *pixbuf)
397 {
398         g_return_val_if_fail (pixbuf != NULL, GDK_COLORSPACE_RGB);
399
400         return pixbuf->colorspace;
401 }
402
403 /**
404  * gdk_pixbuf_get_n_channels:
405  * @pixbuf: A pixbuf.
406  *
407  * Queries the number of channels of a pixbuf.
408  *
409  * Return value: Number of channels.
410  **/
411 int
412 gdk_pixbuf_get_n_channels (const GdkPixbuf *pixbuf)
413 {
414         g_return_val_if_fail (pixbuf != NULL, -1);
415
416         return pixbuf->n_channels;
417 }
418
419 /**
420  * gdk_pixbuf_get_has_alpha:
421  * @pixbuf: A pixbuf.
422  *
423  * Queries whether a pixbuf has an alpha channel (opacity information).
424  *
425  * Return value: %TRUE if it has an alpha channel, %FALSE otherwise.
426  **/
427 gboolean
428 gdk_pixbuf_get_has_alpha (const GdkPixbuf *pixbuf)
429 {
430         g_return_val_if_fail (pixbuf != NULL, FALSE);
431
432         return pixbuf->has_alpha ? TRUE : FALSE;
433 }
434
435 /**
436  * gdk_pixbuf_get_bits_per_sample:
437  * @pixbuf: A pixbuf.
438  *
439  * Queries the number of bits per color sample in a pixbuf.
440  *
441  * Return value: Number of bits per color sample.
442  **/
443 int
444 gdk_pixbuf_get_bits_per_sample (const GdkPixbuf *pixbuf)
445 {
446         g_return_val_if_fail (pixbuf != NULL, -1);
447
448         return pixbuf->bits_per_sample;
449 }
450
451 /**
452  * gdk_pixbuf_get_pixels:
453  * @pixbuf: A pixbuf.
454  *
455  * Queries a pointer to the pixel data of a pixbuf.
456  *
457  * Return value: A pointer to the pixbuf's pixel data.  Please see <xref linkend="image-data"/>
458  * for information about how the pixel data is stored in
459  * memory.
460  **/
461 guchar *
462 gdk_pixbuf_get_pixels (const GdkPixbuf *pixbuf)
463 {
464         g_return_val_if_fail (pixbuf != NULL, NULL);
465
466         return pixbuf->pixels;
467 }
468
469 /**
470  * gdk_pixbuf_get_width:
471  * @pixbuf: A pixbuf.
472  *
473  * Queries the width of a pixbuf.
474  *
475  * Return value: Width in pixels.
476  **/
477 int
478 gdk_pixbuf_get_width (const GdkPixbuf *pixbuf)
479 {
480         g_return_val_if_fail (pixbuf != NULL, -1);
481
482         return pixbuf->width;
483 }
484
485 /**
486  * gdk_pixbuf_get_height:
487  * @pixbuf: A pixbuf.
488  *
489  * Queries the height of a pixbuf.
490  *
491  * Return value: Height in pixels.
492  **/
493 int
494 gdk_pixbuf_get_height (const GdkPixbuf *pixbuf)
495 {
496         g_return_val_if_fail (pixbuf != NULL, -1);
497
498         return pixbuf->height;
499 }
500
501 /**
502  * gdk_pixbuf_get_rowstride:
503  * @pixbuf: A pixbuf.
504  *
505  * Queries the rowstride of a pixbuf, which is the number of bytes between the start of a row
506  * and the start of the next row.
507  *
508  * Return value: Distance between row starts.
509  **/
510 int
511 gdk_pixbuf_get_rowstride (const GdkPixbuf *pixbuf)
512 {
513         g_return_val_if_fail (pixbuf != NULL, -1);
514
515         return pixbuf->rowstride;
516 }
517
518 \f
519
520 /* General initialization hooks */
521 const guint gdk_pixbuf_major_version = GDK_PIXBUF_MAJOR;
522 const guint gdk_pixbuf_minor_version = GDK_PIXBUF_MINOR;
523 const guint gdk_pixbuf_micro_version = GDK_PIXBUF_MICRO;
524
525 const char *gdk_pixbuf_version = GDK_PIXBUF_VERSION;
526
527 /* Error quark */
528 GQuark
529 gdk_pixbuf_error_quark (void)
530 {
531   static GQuark q = 0;
532   if (q == 0)
533     q = g_quark_from_static_string ("gdk-pixbuf-error-quark");
534
535   return q;
536 }
537
538 /**
539  * gdk_pixbuf_fill:
540  * @pixbuf: a #GdkPixbuf
541  * @pixel: RGBA pixel to clear to
542  *         (0xffffffff is opaque white, 0x00000000 transparent black)
543  *
544  * Clears a pixbuf to the given RGBA value, converting the RGBA value into
545  * the pixbuf's pixel format. The alpha will be ignored if the pixbuf
546  * doesn't have an alpha channel.
547  * 
548  **/
549 void
550 gdk_pixbuf_fill (GdkPixbuf *pixbuf,
551                  guint32    pixel)
552 {
553         guchar *pixels;
554         guint r, g, b, a;
555         guchar *p;
556         guint w, h;
557
558         g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
559
560         if (pixbuf->width == 0 || pixbuf->height == 0)
561                 return;
562
563         pixels = pixbuf->pixels;
564
565         r = (pixel & 0xff000000) >> 24;
566         g = (pixel & 0x00ff0000) >> 16;
567         b = (pixel & 0x0000ff00) >> 8;
568         a = (pixel & 0x000000ff);
569
570         h = pixbuf->height;
571         
572         while (h--) {
573                 w = pixbuf->width;
574                 p = pixels;
575
576                 switch (pixbuf->n_channels) {
577                 case 3:
578                         while (w--) {
579                                 p[0] = r;
580                                 p[1] = g;
581                                 p[2] = b;
582                                 p += 3;
583                         }
584                         break;
585                 case 4:
586                         while (w--) {
587                                 p[0] = r;
588                                 p[1] = g;
589                                 p[2] = b;
590                                 p[3] = a;
591                                 p += 4;
592                         }
593                         break;
594                 default:
595                         break;
596                 }
597                 
598                 pixels += pixbuf->rowstride;
599         }
600 }
601
602 \f
603
604 /**
605  * gdk_pixbuf_get_option:
606  * @pixbuf: a #GdkPixbuf
607  * @key: a nul-terminated string.
608  * 
609  * Looks up @key in the list of options that may have been attached to the
610  * @pixbuf when it was loaded. 
611  * 
612  * Return value: the value associated with @key. This is a nul-terminated 
613  * string that should not be freed or %NULL if @key was not found.
614  **/
615 G_CONST_RETURN gchar *
616 gdk_pixbuf_get_option (GdkPixbuf   *pixbuf,
617                        const gchar *key)
618 {
619         gchar **options;
620         gint i;
621
622         g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
623         g_return_val_if_fail (key != NULL, NULL);
624   
625         options = g_object_get_qdata (G_OBJECT (pixbuf), 
626                                       g_quark_from_static_string ("gdk_pixbuf_options"));
627         if (options) {
628                 for (i = 0; options[2*i]; i++) {
629                         if (strcmp (options[2*i], key) == 0)
630                                 return options[2*i+1];
631                 }
632         }
633         
634         return NULL;
635 }
636
637 /**
638  * gdk_pixbuf_set_option:
639  * @pixbuf: a #GdkPixbuf
640  * @key: a nul-terminated string.
641  * @value: a nul-terminated string.
642  * 
643  * Attaches a key/value pair as an option to a #GdkPixbuf. If %key already
644  * exists in the list of options attached to @pixbuf, the new value is 
645  * ignored and %FALSE is returned.
646  *
647  * Return value: %TRUE on success.
648  *
649  * Since: 2.2
650  **/
651 gboolean
652 gdk_pixbuf_set_option (GdkPixbuf   *pixbuf,
653                        const gchar *key,
654                        const gchar *value)
655 {
656         GQuark  quark;
657         gchar **options;
658         gint n = 0;
659  
660         g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
661         g_return_val_if_fail (key != NULL, FALSE);
662         g_return_val_if_fail (value != NULL, FALSE);
663
664         quark = g_quark_from_static_string ("gdk_pixbuf_options");
665
666         options = g_object_get_qdata (G_OBJECT (pixbuf), quark);
667
668         if (options) {
669                 for (n = 0; options[2*n]; n++) {
670                         if (strcmp (options[2*n], key) == 0)
671                                 return FALSE;
672                 }
673
674                 g_object_steal_qdata (G_OBJECT (pixbuf), quark);
675                 options = g_renew (gchar *, options, 2*(n+1) + 1);
676         } else {
677                 options = g_new (gchar *, 3);
678         }
679         
680         options[2*n]   = g_strdup (key);
681         options[2*n+1] = g_strdup (value);
682         options[2*n+2] = NULL;
683
684         g_object_set_qdata_full (G_OBJECT (pixbuf), quark,
685                                  options, (GDestroyNotify) g_strfreev);
686         
687         return TRUE;
688 }
689
690 static void
691 gdk_pixbuf_set_property (GObject         *object,
692                          guint            prop_id,
693                          const GValue    *value,
694                          GParamSpec      *pspec)
695 {
696   GdkPixbuf *pixbuf = GDK_PIXBUF (object);
697
698   switch (prop_id)
699           {
700           case PROP_COLORSPACE:
701                   pixbuf->colorspace = g_value_get_enum (value);
702                   break;
703           case PROP_N_CHANNELS:
704                   pixbuf->n_channels = g_value_get_int (value);
705                   break;
706           case PROP_HAS_ALPHA:
707                   pixbuf->has_alpha = g_value_get_boolean (value);
708                   break;
709           case PROP_BITS_PER_SAMPLE:
710                   pixbuf->bits_per_sample = g_value_get_int (value);
711                   break;
712           case PROP_WIDTH:
713                   pixbuf->width = g_value_get_int (value);
714                   break;
715           case PROP_HEIGHT:
716                   pixbuf->height = g_value_get_int (value);
717                   break;
718           case PROP_ROWSTRIDE:
719                   pixbuf->rowstride = g_value_get_int (value);
720                   break;
721           case PROP_PIXELS:
722                   pixbuf->pixels = (guchar *) g_value_get_pointer (value);
723                   break;
724           default:
725                   G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
726                   break;
727           }
728 }
729
730 static void
731 gdk_pixbuf_get_property (GObject         *object,
732                          guint            prop_id,
733                          GValue          *value,
734                          GParamSpec      *pspec)
735 {
736   GdkPixbuf *pixbuf = GDK_PIXBUF (object);
737   
738   switch (prop_id)
739           {
740           case PROP_COLORSPACE:
741                   g_value_set_enum (value, gdk_pixbuf_get_colorspace (pixbuf));
742                   break;
743           case PROP_N_CHANNELS:
744                   g_value_set_int (value, gdk_pixbuf_get_n_channels (pixbuf));
745                   break;
746           case PROP_HAS_ALPHA:
747                   g_value_set_boolean (value, gdk_pixbuf_get_has_alpha (pixbuf));
748                   break;
749           case PROP_BITS_PER_SAMPLE:
750                   g_value_set_int (value, gdk_pixbuf_get_bits_per_sample (pixbuf));
751                   break;
752           case PROP_WIDTH:
753                   g_value_set_int (value, gdk_pixbuf_get_width (pixbuf));
754                   break;
755           case PROP_HEIGHT:
756                   g_value_set_int (value, gdk_pixbuf_get_height (pixbuf));
757                   break;
758           case PROP_ROWSTRIDE:
759                   g_value_set_int (value, gdk_pixbuf_get_rowstride (pixbuf));
760                   break;
761           case PROP_PIXELS:
762                   g_value_set_pointer (value, gdk_pixbuf_get_pixels (pixbuf));
763                   break;
764           default:
765                   G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
766                   break;
767           }
768 }
769
770 \f
771
772 /* Include the marshallers */
773 #include <glib-object.h>
774 #include "gdk-pixbuf-marshal.c"