]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf.c
Removed the unref_fn field. Now all memory management of the buffer is
[~andy/gtk] / gdk-pixbuf / gdk-pixbuf.c
1 /* GdkPixbuf library - Basic memory management
2  *
3  * Copyright (C) 1999 The Free Software Foundation
4  *
5  * Authors: Mark Crichton <crichton@gimp.org>
6  *          Miguel de Icaza <miguel@gnu.org>
7  *          Federico Mena-Quintero <federico@gimp.org>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #include <config.h>
26 #include <math.h>
27 #include <libart_lgpl/art_misc.h>
28 #include <libart_lgpl/art_affine.h>
29 #include <libart_lgpl/art_pixbuf.h>
30 #include <libart_lgpl/art_rgb_pixbuf_affine.h>
31 #include <libart_lgpl/art_alphagamma.h>
32 #include "gdk-pixbuf.h"
33
34 \f
35
36 /* Reference counting */
37
38 /**
39  * gdk_pixbuf_ref:
40  * @pixbuf: A pixbuf.
41  *
42  * Adds a reference to a pixbuf.  It must be released afterwards using
43  * gdk_pixbuf_unref().
44  **/
45 void
46 gdk_pixbuf_ref (GdkPixbuf *pixbuf)
47 {
48         g_return_if_fail (pixbuf != NULL);
49         g_return_if_fail (pixbuf->ref_count > 0);
50
51         pixbuf->ref_count++;
52 }
53
54 /**
55  * gdk_pixbuf_unref:
56  * @pixbuf: A pixbuf.
57  *
58  * Removes a reference from a pixbuf.  It will be destroyed when the reference
59  * count drops to zero.
60  **/
61 void
62 gdk_pixbuf_unref (GdkPixbuf *pixbuf)
63 {
64         g_return_if_fail (pixbuf != NULL);
65         g_return_if_fail (pixbuf->ref_count > 0);
66
67         pixbuf->ref_count--;
68
69         if (pixbuf->ref_count == 0) {
70                 art_pixbuf_free (pixbuf->art_pixbuf);
71                 pixbuf->art_pixbuf = NULL;
72                 g_free (pixbuf);
73         }
74 }
75
76 \f
77
78 /* Wrap a libart pixbuf */
79
80 /**
81  * gdk_pixbuf_new_from_art_pixbuf:
82  * @art_pixbuf: A libart pixbuf.
83  *
84  * Creates a &GdkPixbuf by wrapping a libart pixbuf.
85  *
86  * Return value: A newly-created &GdkPixbuf structure with a reference count of
87  * 1.
88  **/
89 GdkPixbuf *
90 gdk_pixbuf_new_from_art_pixbuf (ArtPixBuf *art_pixbuf)
91 {
92         GdkPixbuf *pixbuf;
93
94         g_return_val_if_fail (art_pixbuf != NULL, NULL);
95
96         pixbuf = g_new (GdkPixbuf, 1);
97         pixbuf->ref_count = 1;
98         pixbuf->art_pixbuf = art_pixbuf;
99
100         return pixbuf;
101 }