New public API to save pixbufs to non-file locations. (#82203, Tim Evans)

Wed Jan  7 02:41:14 2004  Matthias Clasen  <maclas@gmx.de>

	* gdk-pixbuf-io.c (gdk_pixbuf_save_to_bufferv):
	* gdk-pixbuf-io.c (gdk_pixbuf_save_to_buffer):
	* gdk-pixbuf-io.c (gdk_pixbuf_save_to_callbackv):
	* gdk-pixbuf-io.c (gdk_pixbuf_save_to_callback): New public API
	to save pixbufs to non-file locations.  (#82203, Tim Evans)

	* gdk-pixbuf.h:
	* gdk_pixbuf.def: Declare the new public API.

	* gdk-pixbuf-io.h: Add save_to_callback to the module interface.

	* io-jpeg.c:
	* io-png.c: Implement save_to_callback.

	* gdk-pixbuf-io.c (gdk_pixbuf_savev):
	* gdk-pixbuf-io.c (gdk_pixbuf_save): Update documentation.

	* gdk-pixbuf-io.c (gdk_pixbuf_real_save): Support saving via
	image_module->save_to_callback.

	* gdk-pixbuf-io.c (gdk_pixbuf_real_save_to_callback): New generic
	save_to_callback function which falls back to image_module->save
	on a temp file.
This commit is contained in:
Matthias Clasen
2004-01-07 01:57:42 +00:00
committed by Matthias Clasen
parent 5b26e695a1
commit 03376d79fa
8 changed files with 698 additions and 27 deletions

View File

@ -741,12 +741,40 @@ png_warning_callback(png_structp png_read_ptr,
/* Save */
static gboolean
gdk_pixbuf__png_image_save (FILE *f,
GdkPixbuf *pixbuf,
gchar **keys,
gchar **values,
GError **error)
typedef struct {
GdkPixbufSaveFunc save_func;
gpointer user_data;
GError **error;
} SaveToFunctionIoPtr;
static void
png_save_to_callback_write_func (png_structp png_ptr,
png_bytep data,
png_size_t length)
{
SaveToFunctionIoPtr *ioptr = png_get_io_ptr (png_ptr);
if (!ioptr->save_func (data, length, ioptr->error, ioptr->user_data)) {
/* If save_func has already set an error, which it
should have done, this won't overwrite it. */
png_error (png_ptr, "write function failed");
}
}
static void
png_save_to_callback_flush_func (png_structp png_ptr)
{
;
}
static gboolean real_save_png (GdkPixbuf *pixbuf,
gchar **keys,
gchar **values,
GError **error,
gboolean to_callback,
FILE *f,
GdkPixbufSaveFunc save_func,
gpointer user_data)
{
png_structp png_ptr;
png_infop info_ptr;
@ -762,6 +790,7 @@ gdk_pixbuf__png_image_save (FILE *f,
int bpc;
int num_keys;
gboolean success = TRUE;
SaveToFunctionIoPtr to_callback_ioptr;
num_keys = 0;
@ -860,7 +889,16 @@ gdk_pixbuf__png_image_save (FILE *f,
png_set_text (png_ptr, info_ptr, text_ptr, num_keys);
}
png_init_io (png_ptr, f);
if (to_callback) {
to_callback_ioptr.save_func = save_func;
to_callback_ioptr.user_data = user_data;
to_callback_ioptr.error = error;
png_set_write_fn (png_ptr, &to_callback_ioptr,
png_save_to_callback_write_func,
png_save_to_callback_flush_func);
} else {
png_init_io (png_ptr, f);
}
if (has_alpha) {
png_set_IHDR (png_ptr, info_ptr, w, h, bpc,
@ -901,6 +939,29 @@ cleanup:
return success;
}
static gboolean
gdk_pixbuf__png_image_save (FILE *f,
GdkPixbuf *pixbuf,
gchar **keys,
gchar **values,
GError **error)
{
return real_save_png (pixbuf, keys, values, error,
FALSE, f, NULL, NULL);
}
static gboolean
gdk_pixbuf__png_image_save_to_callback (GdkPixbufSaveFunc save_func,
gpointer user_data,
GdkPixbuf *pixbuf,
gchar **keys,
gchar **values,
GError **error)
{
return real_save_png (pixbuf, keys, values, error,
TRUE, NULL, save_func, user_data);
}
void
MODULE_ENTRY (png, fill_vtable) (GdkPixbufModule *module)
{
@ -909,6 +970,7 @@ MODULE_ENTRY (png, fill_vtable) (GdkPixbufModule *module)
module->stop_load = gdk_pixbuf__png_image_stop_load;
module->load_increment = gdk_pixbuf__png_image_load_increment;
module->save = gdk_pixbuf__png_image_save;
module->save_to_callback = gdk_pixbuf__png_image_save_to_callback;
}
void