* Boston, MA 02111-1307, USA.
*/
-#include <config.h>
+#include "config.h"
#include <string.h>
#include "gdk-pixbuf-private.h"
#include "gdk-pixbuf-animation.h"
+#include "gdk-pixbuf-scaled-anim.h"
#include "gdk-pixbuf-io.h"
#include "gdk-pixbuf-loader.h"
#include "gdk-pixbuf-marshal.h"
};
-static void gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass);
-static void gdk_pixbuf_loader_init (GdkPixbufLoader *loader);
-static void gdk_pixbuf_loader_finalize (GObject *loader);
+static void gdk_pixbuf_loader_finalize (GObject *loader);
-static gpointer parent_class = NULL;
static guint pixbuf_loader_signals[LAST_SIGNAL] = { 0 };
/* Internal data */
gboolean needs_scale;
} GdkPixbufLoaderPrivate;
-
-/**
- * gdk_pixbuf_loader_get_type:
- *
- * Registers the #GdkPixbufLoader class if necessary, and returns the type ID
- * associated to it.
- *
- * Return value: The type ID of the #GdkPixbufLoader class.
- **/
-GType
-gdk_pixbuf_loader_get_type (void)
-{
- static GType loader_type = 0;
-
- if (!loader_type)
- {
- static const GTypeInfo loader_info = {
- sizeof (GdkPixbufLoaderClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gdk_pixbuf_loader_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GdkPixbufLoader),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gdk_pixbuf_loader_init
- };
-
- loader_type = g_type_register_static (G_TYPE_OBJECT,
- g_intern_static_string ("GdkPixbufLoader"),
- &loader_info,
- 0);
- }
-
- return loader_type;
-}
+G_DEFINE_TYPE (GdkPixbufLoader, gdk_pixbuf_loader, G_TYPE_OBJECT)
static void
gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *class)
object_class = (GObjectClass *) class;
- parent_class = g_type_class_peek_parent (class);
-
object_class->finalize = gdk_pixbuf_loader_finalize;
/**
* the desired size to which the image should be scaled.
*/
pixbuf_loader_signals[SIZE_PREPARED] =
- g_signal_new ("size_prepared",
+ g_signal_new ("size-prepared",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GdkPixbufLoaderClass, size_prepared),
* the partially-loaded pixbuf.
*/
pixbuf_loader_signals[AREA_PREPARED] =
- g_signal_new ("area_prepared",
+ g_signal_new ("area-prepared",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GdkPixbufLoaderClass, area_prepared),
* areas of an image that is being loaded.
*/
pixbuf_loader_signals[AREA_UPDATED] =
- g_signal_new ("area_updated",
+ g_signal_new ("area-updated",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GdkPixbufLoaderClass, area_updated),
g_free (priv);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (gdk_pixbuf_loader_parent_class)->finalize (object);
}
/**
* Causes the image to be scaled while it is loaded. The desired
* image size can be determined relative to the original size of
* the image by calling gdk_pixbuf_loader_set_size() from a
- * signal handler for the ::size_prepared signal.
+ * signal handler for the ::size-prepared signal.
*
* Attempts to set the desired image size are ignored after the
- * emission of the ::size_prepared signal.
+ * emission of the ::size-prepared signal.
*
* Since: 2.2
*/
else
anim = gdk_pixbuf_non_anim_new (pixbuf);
- priv->animation = anim;
+ if (priv->needs_scale) {
+ priv->animation = GDK_PIXBUF_ANIMATION (_gdk_pixbuf_scaled_anim_new (anim,
+ (double) priv->width / gdk_pixbuf_get_width (pixbuf),
+ (double) priv->height / gdk_pixbuf_get_height (pixbuf),
+ 1.0));
+ g_object_unref (anim);
+ }
+ else
+ priv->animation = anim;
if (!priv->needs_scale)
g_signal_emit (loader, pixbuf_loader_signals[AREA_PREPARED], 0);
MIN (height, gdk_pixbuf_animation_get_height (priv->animation)));
}
+/* Defense against broken loaders; DO NOT take this as a GError example! */
+static void
+gdk_pixbuf_loader_ensure_error (GdkPixbufLoader *loader,
+ GError **error)
+{
+ GdkPixbufLoaderPrivate *priv = loader->priv;
+
+ if (error == NULL || *error != NULL)
+ return;
+
+ g_warning ("Bug! loader '%s' didn't set an error on failure",
+ priv->image_module->module_name);
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_FAILED,
+ _("Internal error: Image loader module '%s' failed to"
+ " complete an operation, but didn't give a reason for"
+ " the failure"),
+ priv->image_module->module_name);
+}
+
static gint
gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader,
const char *image_type,
if (priv->image_module == NULL)
return 0;
- if (priv->image_module->module == NULL)
- if (!_gdk_pixbuf_load_module (priv->image_module, error))
- return 0;
+ if (!_gdk_pixbuf_load_module (priv->image_module, error))
+ return 0;
if (priv->image_module->module == NULL)
return 0;
if (priv->context == NULL)
{
- /* Defense against broken loaders; DO NOT take this as a GError
- * example
- */
- if (error && *error == NULL)
- {
- g_warning ("Bug! loader '%s' didn't set an error on failure",
- priv->image_module->module_name);
- g_set_error (error,
- GDK_PIXBUF_ERROR,
- GDK_PIXBUF_ERROR_FAILED,
- _("Internal error: Image loader module '%s'"
- " failed to begin loading an image, but didn't"
- " give a reason for the failure"),
- priv->image_module->module_name);
-
- }
-
+ gdk_pixbuf_loader_ensure_error (loader, error);
return 0;
}
{
GdkPixbufLoaderPrivate *priv;
- g_return_val_if_fail (loader != NULL, FALSE);
g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), FALSE);
g_return_val_if_fail (buf != NULL, FALSE);
- g_return_val_if_fail (count >= 0, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
priv = loader->priv;
eaten = gdk_pixbuf_loader_eat_header_write (loader, buf, count, error);
if (eaten <= 0)
- return FALSE;
+ goto fail;
count -= eaten;
buf += eaten;
if (count > 0 && priv->image_module->load_increment)
{
- gboolean retval;
- retval = priv->image_module->load_increment (priv->context, buf, count,
- error);
- if (!retval && error && *error == NULL)
- {
- /* Fix up busted image loader */
- g_warning ("Bug! loader '%s' didn't set an error on failure",
- priv->image_module->module_name);
- g_set_error (error,
- GDK_PIXBUF_ERROR,
- GDK_PIXBUF_ERROR_FAILED,
- _("Internal error: Image loader module '%s'"
- " failed to begin loading an image, but didn't"
- " give a reason for the failure"),
- priv->image_module->module_name);
- }
-
- return retval;
+ if (!priv->image_module->load_increment (priv->context, buf, count,
+ error))
+ goto fail;
}
return TRUE;
+
+ fail:
+ gdk_pixbuf_loader_ensure_error (loader, error);
+ gdk_pixbuf_loader_close (loader, NULL);
+
+ return FALSE;
}
/**
/**
* gdk_pixbuf_loader_new_with_type:
* @image_type: name of the image format to be loaded with the image
- * @error: return location for an allocated #GError, or %NULL to ignore errors
+ * @error: (allow-none): return location for an allocated #GError, or %NULL to ignore errors
*
* Creates a new pixbuf loader object that always attempts to parse
* image data as if it were an image of type @image_type, instead of
* that can't be reliably identified by looking at the data, or if
* the user manually forces a specific type.
*
+ * The list of supported image formats depends on what image loaders
+ * are installed, but typically "png", "jpeg", "gif", "tiff" and
+ * "xpm" are among the supported formats. To obtain the full list of
+ * supported image formats, call gdk_pixbuf_format_get_name() on each
+ * of the #GdkPixbufFormat structs returned by gdk_pixbuf_get_formats().
+ *
* Return value: A newly-created pixbuf loader.
**/
GdkPixbufLoader *
/**
* gdk_pixbuf_loader_new_with_mime_type:
* @mime_type: the mime type to be loaded
- * @error: return location for an allocated #GError, or %NULL to ignore errors
+ * @error: (allow-none): return location for an allocated #GError, or %NULL to ignore errors
*
* Creates a new pixbuf loader object that always attempts to parse
* image data as if it were an image of mime type @mime_type, instead of
* that can't be reliably identified by looking at the data, or if
* the user manually forces a specific mime type.
*
+ * The list of supported mime types depends on what image loaders
+ * are installed, but typically "image/png", "image/jpeg", "image/gif",
+ * "image/tiff" and "image/x-xpixmap" are among the supported mime types.
+ * To obtain the full list of supported mime types, call
+ * gdk_pixbuf_format_get_mime_types() on each of the #GdkPixbufFormat
+ * structs returned by gdk_pixbuf_get_formats().
+ *
* Return value: A newly-created pixbuf loader.
* Since: 2.4
**/
*
* Queries the #GdkPixbuf that a pixbuf loader is currently creating.
* In general it only makes sense to call this function after the
- * "area_prepared" signal has been emitted by the loader; this means
+ * "area-prepared" signal has been emitted by the loader; this means
* that enough data has been read to know the size of the image that
* will be allocated. If the loader has not received enough data via
* gdk_pixbuf_loader_write(), then this function returns %NULL. The
{
GdkPixbufLoaderPrivate *priv;
- g_return_val_if_fail (loader != NULL, NULL);
g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL);
priv = loader->priv;
* @loader: A pixbuf loader
*
* Queries the #GdkPixbufAnimation that a pixbuf loader is currently creating.
- * In general it only makes sense to call this function after the "area_prepared"
+ * In general it only makes sense to call this function after the "area-prepared"
* signal has been emitted by the loader. If the loader doesn't have enough
- * bytes yet (hasn't emitted the "area_prepared" signal) this function will
+ * bytes yet (hasn't emitted the "area-prepared" signal) this function will
* return %NULL.
*
* Return value: The #GdkPixbufAnimation that the loader is loading, or %NULL if
{
GdkPixbufLoaderPrivate *priv;
- g_return_val_if_fail (loader != NULL, NULL);
g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL);
priv = loader->priv;
/**
* gdk_pixbuf_loader_close:
* @loader: A pixbuf loader.
- * @error: return location for a #GError, or %NULL to ignore errors
+ * @error: (allow-none): return location for a #GError, or %NULL to ignore errors
*
* Informs a pixbuf loader that no further writes with
* gdk_pixbuf_loader_write() will occur, so that it can free its
GdkPixbufLoaderPrivate *priv;
gboolean retval = TRUE;
- g_return_val_if_fail (loader != NULL, TRUE);
g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), TRUE);
g_return_val_if_fail (error == NULL || *error == NULL, TRUE);
priv = loader->priv;
- /* we expect it's not closed */
- g_return_val_if_fail (priv->closed == FALSE, TRUE);
+ if (priv->closed)
+ return TRUE;
/* We have less the LOADER_HEADER_SIZE bytes in the image.
* Flush it, and keep going.
if (priv->image_module && priv->image_module->stop_load && priv->context)
{
- if (!priv->image_module->stop_load (priv->context, error))
- retval = FALSE;
+ GError *tmp = NULL;
+ if (!priv->image_module->stop_load (priv->context, &tmp) || tmp)
+ {
+ /* don't call gdk_pixbuf_loader_ensure_error()
+ * here, since we might not get an error in the
+ * gdk_pixbuf_get_file_info() case
+ */
+ if (tmp) {
+ if (error && *error == NULL)
+ g_propagate_error (error, tmp);
+ else
+ g_error_free (tmp);
+ }
+ retval = FALSE;
+ }
}
priv->closed = TRUE;
if (priv->needs_scale)
{
- GdkPixbuf *tmp, *pixbuf;
-
- tmp = gdk_pixbuf_animation_get_static_image (priv->animation);
- g_object_ref (tmp);
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, tmp->has_alpha, 8, priv->width, priv->height);
- g_object_unref (priv->animation);
- priv->animation = gdk_pixbuf_non_anim_new (pixbuf);
- g_object_unref (pixbuf);
+
g_signal_emit (loader, pixbuf_loader_signals[AREA_PREPARED], 0);
- gdk_pixbuf_scale (tmp, pixbuf, 0, 0, priv->width, priv->height, 0, 0,
- (double) priv->width / tmp->width,
- (double) priv->height / tmp->height,
- GDK_INTERP_BILINEAR);
- g_object_unref (tmp);
-
g_signal_emit (loader, pixbuf_loader_signals[AREA_UPDATED], 0,
0, 0, priv->width, priv->height);
}
{
GdkPixbufLoaderPrivate *priv;
- g_return_val_if_fail (loader != NULL, NULL);
g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), NULL);
priv = loader->priv;