#include "gdk-pixbuf-io.h"
#include "gdk-pixbuf-i18n.h"
#include "gdk-pixbuf-animation.h"
+#include "gdk-pixbuf-alias.h"
+
+#include <glib/gstdio.h>
typedef struct _GdkPixbufNonAnim GdkPixbufNonAnim;
typedef struct _GdkPixbufNonAnimClass GdkPixbufNonAnimClass;
};
object_type = g_type_register_static (G_TYPE_OBJECT,
- "GdkPixbufAnimation",
+ g_intern_static_string ("GdkPixbufAnimation"),
&object_info, 0);
}
/**
* gdk_pixbuf_animation_new_from_file:
- * @filename: Name of file to load.
+ * @filename: Name of file to load, in the GLib file name encoding
* @error: return location for error
*
* Creates a new animation by loading it from a file. The file format is
GdkPixbufAnimation *animation;
int size;
FILE *f;
- guchar buffer [128];
+ guchar buffer [1024];
GdkPixbufModule *image_module;
- gchar *utf8_filename;
+ gchar *display_name;
+ gboolean locked = FALSE;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- f = fopen (filename, "rb");
+ display_name = g_filename_display_name (filename);
+ f = g_fopen (filename, "rb");
if (!f) {
- utf8_filename = g_filename_to_utf8 (filename, -1,
- NULL, NULL, NULL);
+ gint save_errno = errno;
g_set_error (error,
G_FILE_ERROR,
- g_file_error_from_errno (errno),
+ g_file_error_from_errno (save_errno),
_("Failed to open file '%s': %s"),
- utf8_filename ? utf8_filename : "???",
- g_strerror (errno));
- g_free (utf8_filename);
+ display_name,
+ g_strerror (save_errno));
+ g_free (display_name);
return NULL;
}
size = fread (&buffer, 1, sizeof (buffer), f);
if (size == 0) {
- utf8_filename = g_filename_to_utf8 (filename, -1,
- NULL, NULL, NULL);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image file '%s' contains no data"),
- utf8_filename ? utf8_filename : "???");
- g_free (utf8_filename);
-
+ display_name);
+ g_free (display_name);
fclose (f);
return NULL;
}
image_module = _gdk_pixbuf_get_module (buffer, size, filename, error);
if (!image_module) {
+ g_free (display_name);
fclose (f);
return NULL;
}
if (image_module->module == NULL)
if (!_gdk_pixbuf_load_module (image_module, error)) {
+ g_free (display_name);
fclose (f);
return NULL;
}
g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
image_module->module_name);
- utf8_filename = g_filename_to_utf8 (filename, -1,
- NULL, NULL, NULL);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
_("Failed to load image '%s': reason not known, probably a corrupt image file"),
- utf8_filename ? utf8_filename : "???");
- g_free (utf8_filename);
+ display_name);
}
- if (pixbuf == NULL)
- return NULL;
+ if (pixbuf == NULL) {
+ g_free (display_name);
+ animation = NULL;
+ goto out_unlock;
+ }
animation = gdk_pixbuf_non_anim_new (pixbuf);
g_object_unref (pixbuf);
} else {
+ locked = _gdk_pixbuf_lock (image_module);
+
fseek (f, 0, SEEK_SET);
animation = (* image_module->load_animation) (f, error);
g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
image_module->module_name);
- utf8_filename = g_filename_to_utf8 (filename, -1,
- NULL, NULL, NULL);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
_("Failed to load animation '%s': reason not known, probably a corrupt animation file"),
- utf8_filename ? utf8_filename : "???");
- g_free (utf8_filename);
+ display_name);
}
fclose (f);
}
+ g_free (display_name);
+
+ out_unlock:
+ if (locked)
+ _gdk_pixbuf_unlock (image_module);
return animation;
}
+#ifdef G_OS_WIN32
+
+#undef gdk_pixbuf_animation_new_from_file
+
+GdkPixbufAnimation *
+gdk_pixbuf_animation_new_from_file (const char *filename,
+ GError **error)
+{
+ gchar *utf8_filename =
+ g_locale_to_utf8 (filename, -1, NULL, NULL, error);
+ GdkPixbufAnimation *retval;
+
+ if (utf8_filename == NULL)
+ return NULL;
+
+ retval = gdk_pixbuf_animation_new_from_file_utf8 (utf8_filename, error);
+
+ g_free (utf8_filename);
+
+ return retval;
+}
+
+#endif
+
/**
* gdk_pixbuf_animation_ref:
* @animation: An animation.
*
* Gets the current pixbuf which should be displayed; the pixbuf will
* be the same size as the animation itself
- * (gdk_pixbuf_animation_get_width(),
- * gdk_pixbuf_animation_get_height()). This pixbuf should be displayed
- * for gdk_pixbuf_animation_get_delay_time() milliseconds. The caller
+ * (gdk_pixbuf_animation_get_width(), gdk_pixbuf_animation_get_height()).
+ * This pixbuf should be displayed for
+ * gdk_pixbuf_animation_iter_get_delay_time() milliseconds. The caller
* of this function does not own a reference to the returned pixbuf;
* the returned pixbuf will become invalid when the iterator advances
* to the next frame, which may happen anytime you call
return FALSE;
}
+#define __GDK_PIXBUF_ANIMATION_C__
+#include "gdk-pixbuf-aliasdef.c"