diff options
author | Richard Hughes <richard@hughsie.com> | 2010-03-02 14:16:57 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2010-03-02 14:16:57 +0000 |
commit | d6dad8a04abb514fc01ebd3ce312ea1c3f382c8c (patch) | |
tree | 2cf84dde57b68cf8835733677f3d78bbb3dbd321 | |
parent | f5a7aed1bc2b1bb6de2beca6dbc5f1f8e8a2a680 (diff) | |
download | gtk+-d6dad8a04abb514fc01ebd3ce312ea1c3f382c8c.tar.gz |
Add a simple test in testpixbuf-color which shows the color management API in usecolor-management
-rw-r--r-- | demos/testpixbuf-color.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/demos/testpixbuf-color.c b/demos/testpixbuf-color.c index 78fa939289..9e6873643d 100644 --- a/demos/testpixbuf-color.c +++ b/demos/testpixbuf-color.c @@ -100,6 +100,77 @@ out: return ret; } +static gboolean +transform_image (const gchar *filename, GError **error) +{ + GtkWidget *image_test; + GtkWidget *dialog; + GtkWidget *vbox; + gint response; + GdkPixbuf *pixbuf; + GtkColorEngine *engine = NULL; + GtkColorProfile *profile = NULL; + GtkColorTransform *transform = NULL; + gchar *icc_profile = NULL; + gsize len = 0; + gboolean ret; + const gchar *option; + + image_test = gtk_image_new_from_file (filename); + pixbuf = gtk_image_get_pixbuf (GTK_IMAGE(image_test)); + + /* check values */ + option = gdk_pixbuf_get_option (pixbuf, "icc-profile"); + if (option == NULL) { + *error = g_error_new (1, 0, "no profile set"); + goto out; + } + + /* decode base64 */ + icc_profile = (gchar *) g_base64_decode (option, &len); + if (len == 0) { + *error = g_error_new (1, 0, "no embedded profile"); + goto out; + } + + /* transform this image with the embedded profile */ + engine = gtk_color_engine_get_default (); + profile = gtk_color_engine_create_profile (engine, (const guint8 *)icc_profile, len, error); + if (profile == NULL) { + ret = FALSE; + goto out; + } + transform = gtk_color_engine_create_transform_from_profiles (engine, profile, NULL); + ret = gtk_color_transform_apply_pixbuf_in_place (transform, pixbuf, error); + if (!ret) + goto out; + + /* show in a dialog as an example */ + dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Are the fish yellow?"); + vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); + gtk_box_pack_end (GTK_BOX(vbox), image_test, TRUE, TRUE, 12); + gtk_widget_set_size_request (GTK_WIDGET(image_test), 300, 300); + gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); + gtk_widget_show (image_test); + + /* ask the user to ensure the image was converted */ + response = gtk_dialog_run (GTK_DIALOG (dialog)); + if (response != GTK_RESPONSE_YES) { + ret = FALSE; + *error = g_error_new (1, 0, "failed to convert fish"); + goto out; + } +out: + if (transform != NULL) + g_object_unref (transform); + if (profile != NULL) + g_object_unref (profile); + if (engine != NULL) + g_object_unref (engine); + g_free (icc_profile); + return ret; +} + int main (int argc, char **argv) { @@ -118,6 +189,15 @@ main (int argc, char **argv) 0, 0, 0, 0, 150, 160); /* PASS */ + g_debug ("try to render color corrected image"); + ret = transform_image ("icc-profile-fish.png", &error); + if (!ret) { + g_warning ("FAILED: did not load image: %s", error->message); + g_error_free (error); + goto out; + } + + /* PASS */ g_debug ("try to save PNG with a profile"); ret = save_image_png ("icc-profile.png", pixbuf, &error); if (!ret) { |