+
+#ifdef G_OS_WIN32
+
+#undef gdk_pixbuf_savev
+
+gboolean
+gdk_pixbuf_savev (GdkPixbuf *pixbuf,
+ const char *filename,
+ const char *type,
+ char **option_keys,
+ char **option_values,
+ GError **error)
+{
+ char *utf8_filename;
+ gboolean retval;
+
+ g_return_val_if_fail (filename != NULL, FALSE);
+
+ utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, error);
+
+ if (utf8_filename == NULL)
+ return FALSE;
+
+ retval = gdk_pixbuf_savev_utf8 (pixbuf, utf8_filename, type,
+ option_keys, option_values, error);
+
+ g_free (utf8_filename);
+
+ return retval;
+}
+
+#endif
+
+/**
+ * gdk_pixbuf_save_to_callback:
+ * @pixbuf: a #GdkPixbuf.
+ * @save_func: a function that is called to save each block of data that
+ * the save routine generates.
+ * @user_data: user data to pass to the save function.
+ * @type: name of file format.
+ * @error: return location for error, or %NULL
+ * @Varargs: list of key-value save options
+ *
+ * Saves pixbuf in format @type by feeding the produced data to a
+ * callback. Can be used when you want to store the image to something
+ * other than a file, such as an in-memory buffer or a socket.
+ * If @error is set, %FALSE will be returned. Possible errors
+ * include those in the #GDK_PIXBUF_ERROR domain and whatever the save
+ * function generates.
+ *
+ * See gdk_pixbuf_save() for more details.
+ *
+ * Return value: whether an error was set
+ *
+ * Since: 2.4
+ **/
+gboolean
+gdk_pixbuf_save_to_callback (GdkPixbuf *pixbuf,
+ GdkPixbufSaveFunc save_func,
+ gpointer user_data,
+ const char *type,
+ GError **error,
+ ...)
+{
+ gchar **keys = NULL;
+ gchar **values = NULL;
+ va_list args;
+ gboolean result;
+
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ va_start (args, error);
+
+ collect_save_options (args, &keys, &values);
+
+ va_end (args);
+
+ result = gdk_pixbuf_save_to_callbackv (pixbuf, save_func, user_data,
+ type, keys, values,
+ error);
+
+ g_strfreev (keys);
+ g_strfreev (values);
+
+ return result;
+}
+
+/**
+ * gdk_pixbuf_save_to_callbackv:
+ * @pixbuf: a #GdkPixbuf.
+ * @save_func: a function that is called to save each block of data that
+ * the save routine generates.
+ * @user_data: user data to pass to the save function.
+ * @type: name of file format.
+ * @option_keys: name of options to set, %NULL-terminated
+ * @option_values: values for named options
+ * @error: return location for error, or %NULL
+ *
+ * Saves pixbuf to a callback in format @type, which is currently "jpeg",
+ * "png", "tiff", "ico" or "bmp". If @error is set, %FALSE will be returned. See
+ * gdk_pixbuf_save_to_callback () for more details.
+ *
+ * Return value: whether an error was set
+ *
+ * Since: 2.4
+ **/
+gboolean
+gdk_pixbuf_save_to_callbackv (GdkPixbuf *pixbuf,
+ GdkPixbufSaveFunc save_func,
+ gpointer user_data,
+ const char *type,
+ char **option_keys,
+ char **option_values,
+ GError **error)
+{
+ gboolean result;
+
+
+ g_return_val_if_fail (save_func != NULL, FALSE);
+ g_return_val_if_fail (type != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ result = gdk_pixbuf_real_save_to_callback (pixbuf,
+ save_func, user_data, type,
+ option_keys, option_values,
+ error);
+
+ if (!result) {
+ g_return_val_if_fail (error == NULL || *error != NULL, FALSE);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ * gdk_pixbuf_save_to_buffer:
+ * @pixbuf: a #GdkPixbuf.
+ * @buffer: location to receive a pointer to the new buffer.
+ * @buffer_size: location to receive the size of the new buffer.
+ * @type: name of file format.
+ * @error: return location for error, or %NULL
+ * @Varargs: list of key-value save options
+ *
+ * Saves pixbuf to a new buffer in format @type, which is currently "jpeg",
+ * "png", "tiff", "ico" or "bmp". This is a convenience function that uses
+ * gdk_pixbuf_save_to_callback() to do the real work. Note that the buffer
+ * is not nul-terminated and may contain embedded nuls.
+ * If @error is set, %FALSE will be returned and @buffer will be set to
+ * %NULL. Possible errors include those in the #GDK_PIXBUF_ERROR
+ * domain.
+ *
+ * See gdk_pixbuf_save() for more details.
+ *
+ * Return value: whether an error was set
+ *
+ * Since: 2.4
+ **/
+gboolean
+gdk_pixbuf_save_to_buffer (GdkPixbuf *pixbuf,
+ gchar **buffer,
+ gsize *buffer_size,
+ const char *type,
+ GError **error,
+ ...)
+{
+ gchar **keys = NULL;
+ gchar **values = NULL;
+ va_list args;
+ gboolean result;
+
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ va_start (args, error);
+
+ collect_save_options (args, &keys, &values);
+
+ va_end (args);
+
+ result = gdk_pixbuf_save_to_bufferv (pixbuf, buffer, buffer_size,
+ type, keys, values,
+ error);
+
+ g_strfreev (keys);
+ g_strfreev (values);
+
+ return result;
+}
+
+struct SaveToBufferData {
+ gchar *buffer;
+ gsize len, max;
+};
+
+static gboolean
+save_to_buffer_callback (const gchar *data,
+ gsize count,
+ GError **error,
+ gpointer user_data)
+{
+ struct SaveToBufferData *sdata = user_data;
+ gchar *new_buffer;
+ gsize new_max;
+
+ if (sdata->len + count > sdata->max) {
+ new_max = MAX (sdata->max*2, sdata->len + count);
+ new_buffer = g_try_realloc (sdata->buffer, new_max);
+ if (!new_buffer) {
+ g_set_error_literal (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+ _("Insufficient memory to save image into a buffer"));
+ return FALSE;
+ }
+ sdata->buffer = new_buffer;
+ sdata->max = new_max;
+ }
+ memcpy (sdata->buffer + sdata->len, data, count);
+ sdata->len += count;
+ return TRUE;
+}
+
+/**
+ * gdk_pixbuf_save_to_bufferv:
+ * @pixbuf: a #GdkPixbuf.
+ * @buffer: location to receive a pointer to the new buffer.
+ * @buffer_size: location to receive the size of the new buffer.
+ * @type: name of file format.
+ * @option_keys: name of options to set, %NULL-terminated
+ * @option_values: values for named options
+ * @error: return location for error, or %NULL
+ *
+ * Saves pixbuf to a new buffer in format @type, which is currently "jpeg",
+ * "tiff", "png", "ico" or "bmp". See gdk_pixbuf_save_to_buffer()
+ * for more details.
+ *
+ * Return value: whether an error was set
+ *
+ * Since: 2.4
+ **/
+gboolean
+gdk_pixbuf_save_to_bufferv (GdkPixbuf *pixbuf,
+ gchar **buffer,
+ gsize *buffer_size,
+ const char *type,
+ char **option_keys,
+ char **option_values,
+ GError **error)
+{
+ static const gint initial_max = 1024;
+ struct SaveToBufferData sdata;
+
+ *buffer = NULL;
+ *buffer_size = 0;
+
+ sdata.buffer = g_try_malloc (initial_max);
+ sdata.max = initial_max;
+ sdata.len = 0;
+ if (!sdata.buffer) {
+ g_set_error_literal (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+ _("Insufficient memory to save image into a buffer"));
+ return FALSE;
+ }
+
+ if (!gdk_pixbuf_save_to_callbackv (pixbuf,
+ save_to_buffer_callback, &sdata,
+ type, option_keys, option_values,
+ error)) {
+ g_free (sdata.buffer);
+ return FALSE;
+ }
+
+ *buffer = sdata.buffer;
+ *buffer_size = sdata.len;
+ return TRUE;
+}
+
+typedef struct {
+ GOutputStream *stream;
+ GCancellable *cancellable;
+} SaveToStreamData;
+
+static gboolean
+save_to_stream (const gchar *buffer,
+ gsize count,
+ GError **error,
+ gpointer data)
+{
+ SaveToStreamData *sdata = (SaveToStreamData *)data;
+ gsize remaining;
+ gssize written;
+ GError *my_error = NULL;
+
+ remaining = count;
+ written = 0;
+ while (remaining > 0) {
+ buffer += written;
+ remaining -= written;
+ written = g_output_stream_write (sdata->stream,
+ buffer, remaining,
+ sdata->cancellable,
+ &my_error);
+ if (written < 0) {
+ if (!my_error) {
+ g_set_error_literal (error,
+ G_IO_ERROR, 0,
+ _("Error writing to image stream"));
+ }
+ else {
+ g_propagate_error (error, my_error);
+ }
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/**
+ * gdk_pixbuf_save_to_stream:
+ * @pixbuf: a #GdkPixbuf
+ * @stream: a #GOutputStream to save the pixbuf to
+ * @type: name of file format
+ * @cancellable: optional #GCancellable object, %NULL to ignore
+ * @error: return location for error, or %NULL
+ * @Varargs: list of key-value save options
+ *
+ * Saves @pixbuf to an output stream.
+ *
+ * Supported file formats are currently "jpeg", "tiff", "png", "ico" or
+ * "bmp". See gdk_pixbuf_save_to_buffer() for more details.
+ *
+ * The @cancellable can be used to abort the operation from another
+ * thread. If the operation was cancelled, the error %GIO_ERROR_CANCELLED
+ * will be returned. Other possible errors are in the #GDK_PIXBUF_ERROR
+ * and %G_IO_ERROR domains.
+ *
+ * The stream is not closed.
+ *
+ * Returns: %TRUE if the pixbuf was saved successfully, %FALSE if an
+ * error was set.
+ *
+ * Since: 2.14
+ */
+gboolean
+gdk_pixbuf_save_to_stream (GdkPixbuf *pixbuf,
+ GOutputStream *stream,
+ const char *type,
+ GCancellable *cancellable,
+ GError **error,
+ ...)
+{
+ gboolean res;
+ gchar **keys = NULL;
+ gchar **values = NULL;
+ va_list args;
+ SaveToStreamData data;
+
+ va_start (args, error);
+ collect_save_options (args, &keys, &values);
+ va_end (args);
+
+ data.stream = stream;
+ data.cancellable = cancellable;
+
+ res = gdk_pixbuf_save_to_callbackv (pixbuf, save_to_stream,
+ &data, type,
+ keys, values,
+ error);
+
+ g_strfreev (keys);
+ g_strfreev (values);
+
+ return res;
+}
+
+/**
+ * gdk_pixbuf_format_get_name:
+ * @format: a #GdkPixbufFormat
+ *
+ * Returns the name of the format.
+ *
+ * Return value: the name of the format.
+ *
+ * Since: 2.2
+ */
+gchar *
+gdk_pixbuf_format_get_name (GdkPixbufFormat *format)
+{
+ g_return_val_if_fail (format != NULL, NULL);
+
+ return g_strdup (format->name);
+}
+
+/**
+ * gdk_pixbuf_format_get_description:
+ * @format: a #GdkPixbufFormat
+ *
+ * Returns a description of the format.
+ *
+ * Return value: a description of the format.
+ *
+ * Since: 2.2
+ */
+gchar *
+gdk_pixbuf_format_get_description (GdkPixbufFormat *format)
+{
+ gchar *domain;
+ const gchar *description;
+ g_return_val_if_fail (format != NULL, NULL);
+
+ if (format->domain != NULL)
+ domain = format->domain;
+ else
+ domain = GETTEXT_PACKAGE;
+ description = g_dgettext (domain, format->description);
+
+ return g_strdup (description);
+}
+
+/**
+ * gdk_pixbuf_format_get_mime_types:
+ * @format: a #GdkPixbufFormat
+ *
+ * Returns the mime types supported by the format.
+ *
+ * Return value: a %NULL-terminated array of mime types which must be freed with
+ * g_strfreev() when it is no longer needed.
+ *
+ * Since: 2.2
+ */
+gchar **
+gdk_pixbuf_format_get_mime_types (GdkPixbufFormat *format)
+{
+ g_return_val_if_fail (format != NULL, NULL);
+
+ return g_strdupv (format->mime_types);
+}
+
+/**
+ * gdk_pixbuf_format_get_extensions:
+ * @format: a #GdkPixbufFormat
+ *
+ * Returns the filename extensions typically used for files in the
+ * given format.
+ *
+ * Return value: a %NULL-terminated array of filename extensions which must be
+ * freed with g_strfreev() when it is no longer needed.
+ *
+ * Since: 2.2
+ */
+gchar **
+gdk_pixbuf_format_get_extensions (GdkPixbufFormat *format)
+{
+ g_return_val_if_fail (format != NULL, NULL);
+
+ return g_strdupv (format->extensions);
+}
+
+/**
+ * gdk_pixbuf_format_is_writable:
+ * @format: a #GdkPixbufFormat
+ *
+ * Returns whether pixbufs can be saved in the given format.
+ *
+ * Return value: whether pixbufs can be saved in the given format.
+ *
+ * Since: 2.2
+ */
+gboolean
+gdk_pixbuf_format_is_writable (GdkPixbufFormat *format)
+{
+ g_return_val_if_fail (format != NULL, FALSE);
+
+ return (format->flags & GDK_PIXBUF_FORMAT_WRITABLE) != 0;
+}
+
+/**
+ * gdk_pixbuf_format_is_scalable:
+ * @format: a #GdkPixbufFormat
+ *
+ * Returns whether this image format is scalable. If a file is in a
+ * scalable format, it is preferable to load it at the desired size,
+ * rather than loading it at the default size and scaling the
+ * resulting pixbuf to the desired size.
+ *
+ * Return value: whether this image format is scalable.
+ *
+ * Since: 2.6
+ */
+gboolean
+gdk_pixbuf_format_is_scalable (GdkPixbufFormat *format)
+{
+ g_return_val_if_fail (format != NULL, FALSE);
+
+ return (format->flags & GDK_PIXBUF_FORMAT_SCALABLE) != 0;
+}
+
+/**
+ * gdk_pixbuf_format_is_disabled:
+ * @format: a #GdkPixbufFormat
+ *
+ * Returns whether this image format is disabled. See
+ * gdk_pixbuf_format_set_disabled().
+ *
+ * Return value: whether this image format is disabled.
+ *
+ * Since: 2.6
+ */
+gboolean
+gdk_pixbuf_format_is_disabled (GdkPixbufFormat *format)
+{
+ g_return_val_if_fail (format != NULL, FALSE);
+
+ return format->disabled;
+}
+
+/**
+ * gdk_pixbuf_format_set_disabled:
+ * @format: a #GdkPixbufFormat
+ * @disabled: %TRUE to disable the format @format
+ *
+ * Disables or enables an image format. If a format is disabled,
+ * gdk-pixbuf won't use the image loader for this format to load
+ * images. Applications can use this to avoid using image loaders
+ * with an inappropriate license, see gdk_pixbuf_format_get_license().
+ *
+ * Since: 2.6
+ */
+void
+gdk_pixbuf_format_set_disabled (GdkPixbufFormat *format,
+ gboolean disabled)
+{
+ g_return_if_fail (format != NULL);
+
+ format->disabled = disabled != FALSE;
+}
+
+/**
+ * gdk_pixbuf_format_get_license:
+ * @format: a #GdkPixbufFormat
+ *
+ * Returns information about the license of the image loader for the format. The
+ * returned string should be a shorthand for a wellknown license, e.g. "LGPL",
+ * "GPL", "QPL", "GPL/QPL", or "other" to indicate some other license. This
+ * string should be freed with g_free() when it's no longer needed.
+ *
+ * Returns: a string describing the license of @format.
+ *
+ * Since: 2.6
+ */
+gchar*
+gdk_pixbuf_format_get_license (GdkPixbufFormat *format)
+{
+ g_return_val_if_fail (format != NULL, NULL);
+
+ return g_strdup (format->license);
+}
+
+GdkPixbufFormat *
+_gdk_pixbuf_get_format (GdkPixbufModule *module)
+{
+ g_return_val_if_fail (module != NULL, NULL);
+
+ return module->info;
+}
+
+/**
+ * gdk_pixbuf_get_formats:
+ *
+ * Obtains the available information about the image formats supported
+ * by GdkPixbuf.
+ *
+ * Returns: A list of #GdkPixbufFormat<!-- -->s describing the supported
+ * image formats. The list should be freed when it is no longer needed,
+ * but the structures themselves are owned by #GdkPixbuf and should not be
+ * freed.
+ *
+ * Since: 2.2
+ */
+GSList *
+gdk_pixbuf_get_formats (void)
+{
+ GSList *result = NULL;
+ GSList *modules;
+
+ for (modules = get_file_formats (); modules; modules = g_slist_next (modules)) {
+ GdkPixbufModule *module = (GdkPixbufModule *)modules->data;
+ GdkPixbufFormat *info = _gdk_pixbuf_get_format (module);
+ result = g_slist_prepend (result, info);
+ }
+
+ return result;
+}
+
+
+#define __GDK_PIXBUF_IO_C__
+#include "gdk-pixbuf-aliasdef.c"