From 5119687ac964ec77c977e8f4d365a95eeca32fef Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 7 Jan 2004 01:59:11 +0000 Subject: [PATCH] Make s, S, Control-S, p, P, Control-P, i, I, Control-I test Wed Jan 7 02:50:55 2004 Matthias Clasen * demos/testpixbuf-save.c: Make s, S, Control-S, p, P, Control-P, i, I, Control-I test gdk_pixbuf_save(), gdk_pixbuf_save_to_buffer() and gdk_pixbuf_save_to_callback() with jpeg, png and ico formats, respectively. Tests #82203. --- ChangeLog | 7 ++ ChangeLog.pre-2-10 | 7 ++ ChangeLog.pre-2-4 | 7 ++ ChangeLog.pre-2-6 | 7 ++ ChangeLog.pre-2-8 | 7 ++ demos/testpixbuf-save.c | 208 ++++++++++++++++++++++++++++++++++------ 6 files changed, 215 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5b24ea8d18..2d0e2c78c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Wed Jan 7 02:50:55 2004 Matthias Clasen + + * demos/testpixbuf-save.c: Make s, S, Control-S, p, P, Control-P, + i, I, Control-I test gdk_pixbuf_save(), gdk_pixbuf_save_to_buffer() + and gdk_pixbuf_save_to_callback() with jpeg, png and ico formats, + respectively. Tests #82203. + 2004-01-06 Federico Mena Quintero * gtk/gtkfilesel.c (gtk_file_selection_create_dir_confirmed): Use diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 5b24ea8d18..2d0e2c78c1 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +Wed Jan 7 02:50:55 2004 Matthias Clasen + + * demos/testpixbuf-save.c: Make s, S, Control-S, p, P, Control-P, + i, I, Control-I test gdk_pixbuf_save(), gdk_pixbuf_save_to_buffer() + and gdk_pixbuf_save_to_callback() with jpeg, png and ico formats, + respectively. Tests #82203. + 2004-01-06 Federico Mena Quintero * gtk/gtkfilesel.c (gtk_file_selection_create_dir_confirmed): Use diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 5b24ea8d18..2d0e2c78c1 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +Wed Jan 7 02:50:55 2004 Matthias Clasen + + * demos/testpixbuf-save.c: Make s, S, Control-S, p, P, Control-P, + i, I, Control-I test gdk_pixbuf_save(), gdk_pixbuf_save_to_buffer() + and gdk_pixbuf_save_to_callback() with jpeg, png and ico formats, + respectively. Tests #82203. + 2004-01-06 Federico Mena Quintero * gtk/gtkfilesel.c (gtk_file_selection_create_dir_confirmed): Use diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 5b24ea8d18..2d0e2c78c1 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +Wed Jan 7 02:50:55 2004 Matthias Clasen + + * demos/testpixbuf-save.c: Make s, S, Control-S, p, P, Control-P, + i, I, Control-I test gdk_pixbuf_save(), gdk_pixbuf_save_to_buffer() + and gdk_pixbuf_save_to_callback() with jpeg, png and ico formats, + respectively. Tests #82203. + 2004-01-06 Federico Mena Quintero * gtk/gtkfilesel.c (gtk_file_selection_create_dir_confirmed): Use diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 5b24ea8d18..2d0e2c78c1 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +Wed Jan 7 02:50:55 2004 Matthias Clasen + + * demos/testpixbuf-save.c: Make s, S, Control-S, p, P, Control-P, + i, I, Control-I test gdk_pixbuf_save(), gdk_pixbuf_save_to_buffer() + and gdk_pixbuf_save_to_callback() with jpeg, png and ico formats, + respectively. Tests #82203. + 2004-01-06 Federico Mena Quintero * gtk/gtkfilesel.c (gtk_file_selection_create_dir_confirmed): Use diff --git a/demos/testpixbuf-save.c b/demos/testpixbuf-save.c index b3928ede86..1c2cfa41f2 100644 --- a/demos/testpixbuf-save.c +++ b/demos/testpixbuf-save.c @@ -67,18 +67,96 @@ compare_pixbufs (GdkPixbuf *pixbuf, GdkPixbuf *compare, const gchar *file_type) } } +static gboolean +save_to_loader (const gchar *buf, gsize count, GError **err, gpointer data) +{ + GdkPixbufLoader *loader = data; + + return gdk_pixbuf_loader_write (loader, buf, count, err); +} + +static GdkPixbuf * +buffer_to_pixbuf (const gchar *buf, gsize count, GError **err) +{ + GdkPixbufLoader *loader; + GdkPixbuf *pixbuf; + + loader = gdk_pixbuf_loader_new (); + if (gdk_pixbuf_loader_write (loader, buf, count, err) && + gdk_pixbuf_loader_close (loader, err)) { + pixbuf = g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader)); + g_object_unref (G_OBJECT (loader)); + return pixbuf; + } else { + return NULL; + } +} + +static void +do_compare (GdkPixbuf *pixbuf, GdkPixbuf *compare, GError *err) +{ + if (compare == NULL) { + fprintf (stderr, "%s", err->message); + g_error_free (err); + } else { + compare_pixbufs (pixbuf, compare, "jpeg"); + g_object_unref (compare); + } +} + static void keypress_check (GtkWidget *widget, GdkEventKey *evt, gpointer data) { GdkPixbuf *pixbuf; GtkDrawingArea *da = (GtkDrawingArea*)data; GError *err = NULL; - + gchar *buffer; + gsize count; + GdkPixbufLoader *loader; + pixbuf = (GdkPixbuf *) g_object_get_data (G_OBJECT (da), "pixbuf"); if (evt->keyval == 'q') gtk_main_quit (); - if (evt->keyval == 's') { + + if (evt->keyval == 's' && (evt->state & GDK_CONTROL_MASK)) { + /* save to callback */ + if (pixbuf == NULL) { + fprintf (stderr, "PIXBUF NULL\n"); + return; + } + + loader = gdk_pixbuf_loader_new (); + if (!gdk_pixbuf_save_to_callback (pixbuf, save_to_loader, loader, "jpeg", + &err, + "quality", "100", + NULL) || + !gdk_pixbuf_loader_close (loader, &err)) { + fprintf (stderr, "%s", err->message); + g_error_free (err); + } else { + do_compare (pixbuf, + g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader)), + err); + g_object_unref (G_OBJECT (loader)); + } + } + else if (evt->keyval == 'S') { + /* save to buffer */ + if (!gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &count, "jpeg", + &err, + "quality", "100", + NULL)) { + fprintf (stderr, "%s", err->message); + g_error_free (err); + } else { + do_compare (pixbuf, + buffer_to_pixbuf (buffer, count, &err), + err); + } + } + else if (evt->keyval == 's') { + /* save normally */ if (pixbuf == NULL) { fprintf (stderr, "PIXBUF NULL\n"); return; @@ -91,20 +169,49 @@ keypress_check (GtkWidget *widget, GdkEventKey *evt, gpointer data) fprintf (stderr, "%s", err->message); g_error_free (err); } else { - GdkPixbuf *compare; - - compare = gdk_pixbuf_new_from_file ("foo.jpg", &err); - - if (!compare) { - fprintf (stderr, "%s", err->message); - g_error_free (err); - } else { - compare_pixbufs (pixbuf, compare, "jpeg"); - g_object_unref (compare); - } - + do_compare (pixbuf, + gdk_pixbuf_new_from_file ("foo.jpg", &err), + err); } - } else if (evt->keyval == 'p') { + } + + if (evt->keyval == 'p' && (evt->state & GDK_CONTROL_MASK)) { + /* save to callback */ + if (pixbuf == NULL) { + fprintf (stderr, "PIXBUF NULL\n"); + return; + } + + loader = gdk_pixbuf_loader_new (); + if (!gdk_pixbuf_save_to_callback (pixbuf, save_to_loader, loader, "png", + &err, + "tEXt::Software", "testpixbuf-save", + NULL) + || !gdk_pixbuf_loader_close (loader, &err)) { + fprintf (stderr, "%s", err->message); + g_error_free (err); + } else { + do_compare (pixbuf, + g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader)), + err); + g_object_unref (G_OBJECT (loader)); + } + } + else if (evt->keyval == 'P') { + /* save to buffer */ + if (!gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &count, "png", + &err, + "tEXt::Software", "testpixbuf-save", + NULL)) { + fprintf (stderr, "%s", err->message); + g_error_free (err); + } else { + do_compare (pixbuf, + buffer_to_pixbuf (buffer, count, &err), + err); + } + } + else if (evt->keyval == 'p') { if (pixbuf == NULL) { fprintf (stderr, "PIXBUF NULL\n"); return; @@ -117,20 +224,65 @@ keypress_check (GtkWidget *widget, GdkEventKey *evt, gpointer data) fprintf (stderr, "%s", err->message); g_error_free (err); } else { - GdkPixbuf *compare; - - compare = gdk_pixbuf_new_from_file ("foo.png", &err); - - if (!compare) { - fprintf (stderr, "%s", err->message); - g_error_free (err); - } else { - compare_pixbufs (pixbuf, compare, "png"); - g_object_unref (compare); - } - + do_compare(pixbuf, + gdk_pixbuf_new_from_file ("foo.png", &err), + err); } - } else if (evt->keyval == 'a') { + } + + if (evt->keyval == 'i' && (evt->state & GDK_CONTROL_MASK)) { + /* save to callback */ + if (pixbuf == NULL) { + fprintf (stderr, "PIXBUF NULL\n"); + return; + } + + loader = gdk_pixbuf_loader_new (); + if (!gdk_pixbuf_save_to_callback (pixbuf, save_to_loader, loader, "ico", + &err, + NULL) + || !gdk_pixbuf_loader_close (loader, &err)) { + fprintf (stderr, "%s", err->message); + g_error_free (err); + } else { + do_compare (pixbuf, + g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader)), + err); + g_object_unref (G_OBJECT (loader)); + } + } + else if (evt->keyval == 'I') { + /* save to buffer */ + if (!gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &count, "ico", + &err, + NULL)) { + fprintf (stderr, "%s", err->message); + g_error_free (err); + } else { + do_compare (pixbuf, + buffer_to_pixbuf (buffer, count, &err), + err); + } + } + else if (evt->keyval == 'i') { + if (pixbuf == NULL) { + fprintf (stderr, "PIXBUF NULL\n"); + return; + } + + if (!gdk_pixbuf_save (pixbuf, "foo.ico", "ico", + &err, + NULL)) { + fprintf (stderr, "%s", err->message); + g_error_free (err); + } else { + do_compare(pixbuf, + gdk_pixbuf_new_from_file ("foo.ico", &err), + err); + } + } + + if (evt->keyval == 'a') { if (pixbuf == NULL) { fprintf (stderr, "PIXBUF NULL\n"); return;