1 /* GdkPixbuf library - Main header file
3 * Copyright (C) 1999 The Free Software Foundation
5 * Authors: Mark Crichton <crichton@gimp.org>
6 * Miguel de Icaza <miguel@gnu.org>
7 * Federico Mena-Quintero <federico@gimp.org>
8 * Jonathan Blandford <jrb@redhat.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library 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.
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 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library 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.
26 #include "gdk-pixbuf-loader.h"
29 static GtkObjectClass *parent_class;
31 static void gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass);
32 static void gdk_pixbuf_loader_init (GdkPixbufLoader *loader);
33 static void gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader);
34 static void gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader);
37 typedef struct _GdkPixbufLoaderPrivate GdkPixbufLoaderPrivate;
38 struct _GdkPixbufLoaderPrivate
45 gdk_pixbuf_loader_get_type (void)
47 static GtkType loader_type = 0;
50 static const GtkTypeInfo loader_info = {
52 sizeof (GdkPixbufLoader),
53 sizeof (GdkPixbufLoaderClass),
54 (GtkClassInitFunc) gdk_pixbuf_loader_class_init,
55 (GtkObjectInitFunc) gdk_pixbuf_loader_init,
56 /* reserved_1 */ NULL,
57 /* reserved_2 */ NULL,
58 (GtkClassInitFunc) NULL,
61 loader_type = gtk_type_unique (GTK_TYPE_OBJECT, &loader_info);
68 gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass)
70 parent_class = GTK_OBJECT_CLASS (klass);
72 parent_class->destroy = gdk_pixbuf_loader_destroy;
73 parent_class->finalize = gdk_pixbuf_loader_finalize;
77 gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
80 loader->private = g_new (GdkPixbufLoaderPrivate, 1);
82 loader->pixbuf = NULL;
83 loader->closed = FALSE;
87 gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader)
89 GdkPixbufLoaderPrivate *priv;
91 priv = loader->private;
92 gdk_pixbuf_unref (priv->pixbuf);
96 gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader)
98 GdkPixbufLoaderPrivate *priv;
100 priv = loader->private;
104 /* Public functions */
106 gdk_pixbuf_loader_new (void)
108 GdkPixbufLoader *loader;
110 loader = gtk_type_new (gdk_pixbuf_loader_get_type ());
112 return GTK_OBJECT (loader);
116 * gdk_pixbuf_loader_write:
118 * @buf: The image data.
119 * @count: The length of @buf in bytes.
121 * This will load the next @size bytes of the image. It will return TRUE if the
122 * data was loaded successfully, and FALSE if an error occurred. In this case,
123 * the loader will be closed, and will not accept further writes.
125 * Return value: Returns TRUE if the write was successful -- FALSE if the loader
126 * cannot parse the buf.
129 gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, size_t count)
131 GdkPixbufLoaderPrivate *priv;
133 g_return_val_if_fail (loader != NULL, FALSE);
134 g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), FALSE);
136 priv = loader->private;
138 /* we expect it's not to be closed */
139 g_return_val_if_fail (priv->closed == FALSE, FALSE);
145 * gdk_pixbuf_loader_get_pixbuf:
148 * Gets the GdkPixbuf that the loader is currently loading. If the loader
149 * hasn't been enough data via gdk_pixbuf_loader_write, then NULL is returned.
150 * Any application using this function should check for this value when it is
151 * used. The pixbuf returned will be the same in all future calls to the
152 * loader, so simply calling a gdk_pixbuf_ref() should be sufficient to continue
155 * Return value: The GdkPixbuf that the loader is loading.
158 gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader)
160 GdkPixbufLoaderPrivate *priv;
162 g_return_val_if_fail (loader != NULL, NULL);
163 g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL);
164 priv = loader->private;
170 * gdk_pixbuf_loader_close:
173 * Tells the loader to stop accepting writes
177 gdk_pixbuf_loader_close (GdkPixbufLoader *loader)
179 GdkPixbufLoaderPrivate *priv;
181 g_return_if_fail (loader != NULL);
182 g_return_if_fail (GDK_IS_PIXBUF_LOADER (loader));
184 priv = loader->private;
186 /* we expect it's not closed */
187 g_return_if_fail (priv->closed == FALSE);