[gnome-color-manager] Save extra metadata in the ICC profile after calibration
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Save extra metadata in the ICC profile after calibration
- Date: Mon, 13 Jun 2011 12:36:08 +0000 (UTC)
commit ed385aedc16def452cf11301d33678806bd30214
Author: Richard Hughes <richard hughsie com>
Date: Mon Jun 13 13:35:57 2011 +0100
Save extra metadata in the ICC profile after calibration
configure.ac | 4 +-
src/gcm-calibrate-main.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 524b427..4ac480c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,9 +93,9 @@ dnl ---------------------------------------------------------------------------
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.14.0 gobject-2.0 gthread-2.0 gio-2.0 >= 2.25.9)
PKG_CHECK_MODULES(XORG, xrandr)
PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 2.91.0)
-PKG_CHECK_MODULES(LCMS, lcms2)
+PKG_CHECK_MODULES(LCMS, lcms2 >= 2.2)
PKG_CHECK_MODULES(X11, x11)
-PKG_CHECK_MODULES(COLORD, colord >= 0.1.6)
+PKG_CHECK_MODULES(COLORD, colord >= 0.1.9)
PKG_CHECK_MODULES(CLUTTER, clutter-gtk-1.0 mash-0.1, has_clutter=yes, has_clutter=no)
AM_CONDITIONAL(HAVE_CLUTTER, test x$has_clutter = xyes)
diff --git a/src/gcm-calibrate-main.c b/src/gcm-calibrate-main.c
index 1fa1f2b..c2ace38 100644
--- a/src/gcm-calibrate-main.c
+++ b/src/gcm-calibrate-main.c
@@ -28,6 +28,8 @@
#include <locale.h>
#include <canberra-gtk.h>
#include <colord.h>
+#include <lcms2.h>
+#include <stdlib.h>
#include "gcm-utils.h"
#include "gcm-debug.h"
@@ -310,6 +312,82 @@ gcm_calib_get_vbox_for_page (GcmCalibratePriv *calib,
return NULL;
}
+static cmsBool
+_cmsDictAddEntryAscii (cmsHANDLE dict,
+ const gchar *key,
+ const gchar *value)
+{
+ cmsBool ret;
+ wchar_t mb_key[1024];
+ wchar_t mb_value[1024];
+ mbstowcs (mb_key, key, sizeof (mb_key));
+ mbstowcs (mb_value, value, sizeof (mb_value));
+ ret = cmsDictAddEntry (dict, mb_key, mb_value, NULL, NULL);
+ return ret;
+}
+
+static gboolean
+gcm_calib_set_extra_metadata (const gchar *filename, GError **error)
+{
+ cmsHANDLE dict = NULL;
+ cmsHPROFILE lcms_profile;
+ gboolean ret = TRUE;
+ gchar *data = NULL;
+ gsize len;
+
+ /* parse */
+ ret = g_file_get_contents (filename, &data, &len, error);
+ if (!ret)
+ goto out;
+ lcms_profile = cmsOpenProfileFromMem (data, len);
+ if (lcms_profile == NULL) {
+ g_set_error_literal (error, 1, 0,
+ "failed to open profile");
+ ret = FALSE;
+ goto out;
+ }
+
+ /* just create a new dict */
+ dict = cmsDictAlloc (NULL);
+ _cmsDictAddEntryAscii (dict,
+ CD_PROFILE_METADATA_CMF_PRODUCT,
+ PACKAGE_NAME);
+ _cmsDictAddEntryAscii (dict,
+ CD_PROFILE_METADATA_CMF_BINARY,
+ "gcm-calibrate");
+ _cmsDictAddEntryAscii (dict,
+ CD_PROFILE_METADATA_CMF_VERSION,
+ PACKAGE_VERSION);
+ _cmsDictAddEntryAscii (dict,
+ CD_PROFILE_METADATA_DATA_SOURCE,
+ CD_PROFILE_METADATA_DATA_SOURCE_CALIB);
+
+ /* just write dict */
+ ret = cmsWriteTag (lcms_profile, cmsSigMetaTag, dict);
+ if (!ret) {
+ g_set_error_literal (error, 1, 0,
+ "cannot write metadata");
+ goto out;
+ }
+
+ /* write profile id */
+ ret = cmsMD5computeID (lcms_profile);
+ if (!ret) {
+ g_set_error_literal (error, 1, 0,
+ "failed to write profile id");
+ goto out;
+ }
+
+ /* save, TODO: get error */
+ cmsSaveProfileToFile (lcms_profile, filename);
+ ret = TRUE;
+out:
+ g_free (data);
+ if (dict != NULL)
+ cmsDictFree (dict);
+ return ret;
+}
+
static gboolean
gcm_calib_start_idle_cb (gpointer user_data)
{
@@ -358,6 +436,15 @@ gcm_calib_start_idle_cb (gpointer user_data)
goto out;
}
+ /* set some private properties */
+ ret = gcm_calib_set_extra_metadata (filename, &error);
+ if (!ret) {
+ g_warning ("failed to set extra metadata: %s",
+ error->message);
+ g_error_free (error);
+ goto out;
+ }
+
/* copy the ICC file to the proper location */
file = g_file_new_for_path (filename);
dest = gcm_utils_get_profile_destination (file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]