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_tiff (const gchar *filename, GdkPixbuf *pixbuf, GError **error)
41 gchar *contents = NULL;
42 gchar *contents_encode = NULL;
48 ret = g_file_get_contents (ICC_PROFILE, &contents, &length, error);
51 contents_encode = g_base64_encode ((const guchar *) contents, length);
52 ret = gdk_pixbuf_save (pixbuf, filename, "tiff", error,
53 "icc-profile", contents_encode,
55 len = strlen (contents_encode);
56 g_debug ("ICC profile was %i bytes", len);
59 g_free (contents_encode);
64 save_image_verify (const gchar *filename, GError **error)
67 GdkPixbuf *pixbuf = NULL;
69 gchar *icc_profile = NULL;
73 pixbuf = gdk_pixbuf_new_from_file (filename, error);
78 option = gdk_pixbuf_get_option (pixbuf, "icc-profile");
80 *error = g_error_new (1, 0, "no profile set");
85 icc_profile = (gchar *) g_base64_decode (option, &len);
86 if (len != ICC_PROFILE_SIZE) {
87 *error = g_error_new (1, 0,
88 "profile length invalid, got %" G_GSIZE_FORMAT,
90 g_file_set_contents ("error.icc", icc_profile, len, NULL);
98 g_object_unref (pixbuf);
104 main (int argc, char **argv)
110 GError *error = NULL;
112 gtk_init (&argc, &argv);
114 root = gdk_get_default_root_window ();
115 pixbuf = gdk_pixbuf_get_from_window (root,
119 g_debug ("try to save PNG with a profile");
120 ret = save_image_png ("icc-profile.png", pixbuf, &error);
122 g_warning ("FAILED: did not save image: %s", error->message);
123 g_error_free (error);
128 g_debug ("try to save TIFF with a profile");
129 ret = save_image_tiff ("icc-profile.tiff", pixbuf, &error);
131 g_warning ("FAILED: did not save image: %s", error->message);
132 g_error_free (error);
137 g_debug ("try to load PNG and get color attributes");
138 ret = save_image_verify ("icc-profile.png", &error);
140 g_warning ("FAILED: did not load image: %s", error->message);
141 g_error_free (error);
146 g_debug ("try to load TIFF and get color attributes");
147 ret = save_image_verify ("icc-profile.tiff", &error);
149 g_warning ("FAILED: did not load image: %s", error->message);
150 g_error_free (error);
156 g_debug ("ALL OKAY!");