summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2012-08-30 15:48:25 -0400
committerCosimo Cecchi <cosimo@endlessm.com>2016-04-06 10:02:31 -0700
commitc53c4701ef185e95a4905926aa7b31b110a85b15 (patch)
tree6621a9e3957b12f277ff0818db709cd633c1cc45
parentcaa466616e65bd8a584c006f7b46ada505631786 (diff)
downloadgdk-pixbuf-c53c4701ef185e95a4905926aa7b31b110a85b15.tar.gz
Add non-varargs versions of methods to save to stream
This is useful when the set of options you want to use changes according to specific conditions, and makes the stream-based API consistent with the others. https://bugzilla.gnome.org/show_bug.cgi?id=683063
-rw-r--r--docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt2
-rw-r--r--gdk-pixbuf/gdk-pixbuf-core.h17
-rw-r--r--gdk-pixbuf/gdk-pixbuf-io.c149
-rw-r--r--gdk-pixbuf/gdk-pixbuf.symbols2
4 files changed, 136 insertions, 34 deletions
diff --git a/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt b/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
index 274e9ddc3..d4a41008f 100644
--- a/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
+++ b/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
@@ -91,7 +91,9 @@ gdk_pixbuf_save_to_callbackv
gdk_pixbuf_save_to_buffer
gdk_pixbuf_save_to_bufferv
gdk_pixbuf_save_to_stream
+gdk_pixbuf_save_to_streamv
gdk_pixbuf_save_to_stream_async
+gdk_pixbuf_save_to_streamv_async
gdk_pixbuf_save_to_stream_finish
</SECTION>
diff --git a/gdk-pixbuf/gdk-pixbuf-core.h b/gdk-pixbuf/gdk-pixbuf-core.h
index 5d41a1598..2f67bd4d0 100644
--- a/gdk-pixbuf/gdk-pixbuf-core.h
+++ b/gdk-pixbuf/gdk-pixbuf-core.h
@@ -449,6 +449,23 @@ void gdk_pixbuf_save_to_stream_async (GdkPixbuf *pixbuf,
gboolean gdk_pixbuf_save_to_stream_finish (GAsyncResult *async_result,
GError **error);
+void gdk_pixbuf_save_to_streamv_async (GdkPixbuf *pixbuf,
+ GOutputStream *stream,
+ const gchar *type,
+ gchar **option_keys,
+ gchar **option_values,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean gdk_pixbuf_save_to_streamv (GdkPixbuf *pixbuf,
+ GOutputStream *stream,
+ const char *type,
+ char **option_keys,
+ char **option_values,
+ GCancellable *cancellable,
+ GError **error);
+
/* Adding an alpha channel */
GdkPixbuf *gdk_pixbuf_add_alpha (const GdkPixbuf *pixbuf, gboolean substitute_color,
guchar r, guchar g, guchar b);
diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c
index 66beafdfe..3b8408411 100644
--- a/gdk-pixbuf/gdk-pixbuf-io.c
+++ b/gdk-pixbuf/gdk-pixbuf-io.c
@@ -2874,7 +2874,47 @@ save_to_stream (const gchar *buffer,
return TRUE;
}
-/**
+/**
+ * gdk_pixbuf_save_to_streamv:
+ * @pixbuf: a #GdkPixbuf
+ * @stream: a #GOutputStream to save the pixbuf to
+ * @type: name of file format
+ * @option_keys: (array zero-terminated=1): name of options to set, %NULL-terminated
+ * @option_values: (array zero-terminated=1): values for named options
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
+ * @error: (allow-none): return location for error, or %NULL
+ *
+ * Saves @pixbuf to an output stream.
+ *
+ * Supported file formats are currently "jpeg", "tiff", "png", "ico" or
+ * "bmp". See gdk_pixbuf_save_to_stream() for more details.
+ *
+ * Returns: %TRUE if the pixbuf was saved successfully, %FALSE if an
+ * error was set.
+ *
+ * Since: 2.36
+ */
+gboolean
+gdk_pixbuf_save_to_streamv (GdkPixbuf *pixbuf,
+ GOutputStream *stream,
+ const char *type,
+ char **option_keys,
+ char **option_values,
+ GCancellable *cancellable,
+ GError **error)
+{
+ SaveToStreamData data;
+
+ data.stream = stream;
+ data.cancellable = cancellable;
+
+ return gdk_pixbuf_save_to_callbackv (pixbuf, save_to_stream,
+ &data, type,
+ option_keys, option_values,
+ error);
+}
+
+/**
* gdk_pixbuf_save_to_stream:
* @pixbuf: a #GdkPixbuf
* @stream: a #GOutputStream to save the pixbuf to
@@ -2912,19 +2952,14 @@ gdk_pixbuf_save_to_stream (GdkPixbuf *pixbuf,
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);
+ res = gdk_pixbuf_save_to_streamv (pixbuf, stream, type,
+ keys, values,
+ cancellable, error);
g_strfreev (keys);
g_strfreev (values);
@@ -2976,6 +3011,59 @@ save_to_stream_thread (GTask *task,
}
/**
+ * gdk_pixbuf_save_to_streamv_async:
+ * @pixbuf: a #GdkPixbuf
+ * @stream: a #GOutputStream to which to save the pixbuf
+ * @type: name of file format
+ * @option_keys: (array zero-terminated=1): name of options to set, %NULL-terminated
+ * @option_values: (array zero-terminated=1): values for named options
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
+ * @callback: a #GAsyncReadyCallback to call when the the pixbuf is loaded
+ * @user_data: the data to pass to the callback function
+ *
+ * Saves @pixbuf to an output stream asynchronously.
+ *
+ * For more details see gdk_pixbuf_save_to_streamv(), which is the synchronous
+ * version of this function.
+ *
+ * When the operation is finished, @callback will be called in the main thread.
+ * You can then call gdk_pixbuf_save_to_stream_finish() to get the result of the operation.
+ *
+ * Since: 2.36
+ **/
+void
+gdk_pixbuf_save_to_streamv_async (GdkPixbuf *pixbuf,
+ GOutputStream *stream,
+ const gchar *type,
+ gchar **option_keys,
+ gchar **option_values,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+ SaveToStreamAsyncData *data;
+
+ g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
+ g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
+ g_return_if_fail (type != NULL);
+ g_return_if_fail (callback != NULL);
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ data = g_slice_new (SaveToStreamAsyncData);
+ data->stream = g_object_ref (stream);
+ data->type = g_strdup (type);
+ data->keys = g_strdupv (option_keys);
+ data->values = g_strdupv (option_values);
+
+ task = g_task_new (pixbuf, cancellable, callback, user_data);
+ g_task_set_source_tag (task, gdk_pixbuf_save_to_streamv_async);
+ g_task_set_task_data (task, data, (GDestroyNotify) save_to_stream_async_data_free);
+ g_task_run_in_thread (task, (GTaskThreadFunc) save_to_stream_thread);
+ g_object_unref (task);
+}
+
+/**
* gdk_pixbuf_save_to_stream_async:
* @pixbuf: a #GdkPixbuf
* @stream: a #GOutputStream to which to save the pixbuf
@@ -3004,33 +3092,25 @@ gdk_pixbuf_save_to_stream_async (GdkPixbuf *pixbuf,
gpointer user_data,
...)
{
- GTask *task;
- gchar **keys = NULL;
- gchar **values = NULL;
- va_list args;
- SaveToStreamAsyncData *data;
-
- g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
- g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
- g_return_if_fail (type != NULL);
- g_return_if_fail (callback != NULL);
- g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+ gchar **keys = NULL;
+ gchar **values = NULL;
+ va_list args;
- va_start (args, user_data);
- collect_save_options (args, &keys, &values);
- va_end (args);
+ g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
+ g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
+ g_return_if_fail (type != NULL);
+ g_return_if_fail (callback != NULL);
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
- data = g_slice_new (SaveToStreamAsyncData);
- data->stream = g_object_ref (stream);
- data->type = g_strdup (type);
- data->keys = keys;
- data->values = values;
+ va_start (args, user_data);
+ collect_save_options (args, &keys, &values);
+ va_end (args);
- task = g_task_new (pixbuf, cancellable, callback, user_data);
- g_task_set_source_tag (task, gdk_pixbuf_save_to_stream_async);
- g_task_set_task_data (task, data, (GDestroyNotify) save_to_stream_async_data_free);
- g_task_run_in_thread (task, (GTaskThreadFunc) save_to_stream_thread);
- g_object_unref (task);
+ gdk_pixbuf_save_to_streamv_async (pixbuf, stream, type,
+ keys, values,
+ cancellable, callback, user_data);
+ g_strfreev (keys);
+ g_strfreev (values);
}
/**
@@ -3059,7 +3139,8 @@ gdk_pixbuf_save_to_stream_finish (GAsyncResult *async_result,
task = G_TASK (async_result);
g_return_val_if_fail (!error || (error && !*error), FALSE);
- g_warn_if_fail (g_task_get_source_tag (task) == gdk_pixbuf_save_to_stream_async);
+ g_warn_if_fail (g_task_get_source_tag (task) == gdk_pixbuf_save_to_stream_async ||
+ g_task_get_source_tag (task) == gdk_pixbuf_save_to_streamv_async);
return g_task_propagate_boolean (task, error);
}
diff --git a/gdk-pixbuf/gdk-pixbuf.symbols b/gdk-pixbuf/gdk-pixbuf.symbols
index 1532535c0..0d2c280c4 100644
--- a/gdk-pixbuf/gdk-pixbuf.symbols
+++ b/gdk-pixbuf/gdk-pixbuf.symbols
@@ -82,6 +82,8 @@ gdk_pixbuf_savev_utf8
gdk_pixbuf_save_to_stream
gdk_pixbuf_save_to_stream_async
gdk_pixbuf_save_to_stream_finish
+gdk_pixbuf_save_to_streamv
+gdk_pixbuf_save_to_streamv_async
#endif
#endif