1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
9 #define ICC_PROFILE "/usr/share/color/icc/bluish.icc"
10 #define ICC_PROFILE_SIZE 3966
13 save_image_png (const gchar *filename, GdkPixbuf *pixbuf, GError **error)
15 gchar *contents = NULL;
16 gchar *contents_encode = NULL;
22 ret = g_file_get_contents (ICC_PROFILE, &contents, &length, error);
25 contents_encode = g_base64_encode ((const guchar *) contents, length);
26 ret = gdk_pixbuf_save (pixbuf, filename, "png", error,
27 "tEXt::Software", "Hello my name is dave",
28 "icc-profile", contents_encode,
30 len = strlen (contents_encode);
31 g_debug ("ICC profile was %i bytes", len);
34 g_free (contents_encode);
39 save_image_verify (const gchar *filename, GError **error)
42 GdkPixbuf *pixbuf = NULL;
44 gchar *icc_profile = NULL;
48 pixbuf = gdk_pixbuf_new_from_file (filename, error);
53 option = gdk_pixbuf_get_option (pixbuf, "icc-profile");
55 *error = g_error_new (1, 0, "no profile set");
60 icc_profile = (gchar *) g_base64_decode (option, &len);
61 if (len != ICC_PROFILE_SIZE) {
62 *error = g_error_new (1, 0, "profile length invalid, got %i", len);
63 g_file_set_contents ("error.icc", icc_profile, len, NULL);
71 g_object_unref (pixbuf);
77 main (int argc, char **argv)
85 gtk_init (&argc, &argv);
87 gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
89 root = gdk_get_default_root_window ();
90 pixbuf = gdk_pixbuf_get_from_drawable (NULL, root, NULL,
91 0, 0, 0, 0, 150, 160);
94 g_debug ("try to save PNG with a profile");
95 ret = save_image_png ("icc-profile.png", pixbuf, &error);
97 g_warning ("FAILED: did not save image: %s", error->message);
103 g_debug ("try to load PNG and get color attributes");
104 ret = save_image_verify ("icc-profile.png", &error);
106 g_warning ("FAILED: did not load image: %s", error->message);
107 g_error_free (error);
113 g_debug ("ALL OKAY!");