diff options
author | Richard Hughes <richard@hughsie.com> | 2013-03-25 20:54:14 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2013-03-25 20:54:14 +0000 |
commit | f41e3c2890cef38d6d6026047b30a076d5c13b46 (patch) | |
tree | be11869ea7440b73d14530dca70edd958cf4fe85 /lib | |
parent | e697851132eb122d1b969248f5f4b43b737d76be (diff) | |
download | colord-f41e3c2890cef38d6d6026047b30a076d5c13b46.tar.gz |
libcolord: Add the ability to get the file embedded profile ID
Diffstat (limited to 'lib')
-rw-r--r-- | lib/colord/cd-icc.c | 76 | ||||
-rw-r--r-- | lib/colord/cd-icc.h | 4 | ||||
-rw-r--r-- | lib/colord/cd-self-test.c | 5 |
3 files changed, 80 insertions, 5 deletions
diff --git a/lib/colord/cd-icc.c b/lib/colord/cd-icc.c index b3ec93e..04f3754 100644 --- a/lib/colord/cd-icc.c +++ b/lib/colord/cd-icc.c @@ -59,6 +59,7 @@ struct _CdIccPrivate CdProfileKind kind; cmsHPROFILE lcms_profile; gboolean can_delete; + gchar *checksum; gchar *filename; gdouble version; GHashTable *mluc_data[CD_MLUC_LAST]; /* key is 'en_GB' or '' for default */ @@ -77,6 +78,7 @@ enum { PROP_KIND, PROP_COLORSPACE, PROP_CAN_DELETE, + PROP_CHECKSUM, PROP_LAST }; @@ -463,6 +465,36 @@ const struct { }; /** + * cd_icc_get_precooked_md5: + **/ +static gchar * +cd_icc_get_precooked_md5 (cmsHPROFILE lcms_profile) +{ + cmsUInt8Number icc_id[16]; + gboolean md5_precooked = FALSE; + gchar *md5 = NULL; + guint i; + + /* check to see if we have a pre-cooked MD5 */ + cmsGetHeaderProfileID (lcms_profile, icc_id); + for (i = 0; i < 16; i++) { + if (icc_id[i] != 0) { + md5_precooked = TRUE; + break; + } + } + if (md5_precooked == FALSE) + goto out; + + /* convert to a hex string */ + md5 = g_new0 (gchar, 32 + 1); + for (i = 0; i < 16; i++) + g_snprintf (md5 + i * 2, 3, "%02x", icc_id[i]); +out: + return md5; +} + +/** * cd_icc_load: **/ static void @@ -518,6 +550,9 @@ cd_icc_load (CdIcc *icc, CdIccLoadFlags flags) } } + /* get precooked profile ID if one exists */ + priv->checksum = cd_icc_get_precooked_md5 (priv->lcms_profile); + /* read default translations */ cd_icc_get_description (icc, NULL, NULL); cd_icc_get_copyright (icc, NULL, NULL); @@ -585,6 +620,14 @@ cd_icc_load_data (CdIcc *icc, /* load cached data */ cd_icc_load (icc, flags); + + /* calculate the data MD5 if there was no embedded profile */ + if (priv->checksum == NULL && + (flags & CD_ICC_LOAD_FLAGS_FALLBACK_MD5) > 0) { + priv->checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5, + (const guchar *) data, + data_len); + } out: return ret; } @@ -1471,7 +1514,6 @@ cd_icc_get_created (CdIcc *icc) g_return_val_if_fail (CD_IS_ICC (icc), NULL); - /* get the profile creation time and date */ ret = cmsGetHeaderCreationDateTime (priv->lcms_profile, &created_tm); if (!ret) @@ -1489,6 +1531,26 @@ out: } /** + * cd_icc_get_checksum: + * @icc: A valid #CdIcc + * + * Gets the profile checksum if one exists. + * This will either be the embedded profile ID, or the file checksum if + * the #CdIcc object was loaded using cd_icc_load_data() or cd_icc_load_file() + * and the %CD_ICC_LOAD_FLAGS_FALLBACK_MD5 flag is used. + * + * Return value: An embedded MD5 checksum, or %NULL for not set + * + * Since: 0.1.32 + **/ +const gchar * +cd_icc_get_checksum (CdIcc *icc) +{ + g_return_val_if_fail (CD_IS_ICC (icc), NULL); + return icc->priv->checksum; +} + +/** * cd_icc_get_locale_key: **/ static gchar * @@ -1938,6 +2000,9 @@ cd_icc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec * case PROP_CAN_DELETE: g_value_set_boolean (value, priv->can_delete); break; + case PROP_CHECKSUM: + g_value_set_string (value, priv->checksum); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -2028,6 +2093,14 @@ cd_icc_class_init (CdIccClass *klass) G_PARAM_READABLE); g_object_class_install_property (object_class, PROP_CAN_DELETE, pspec); + /** + * CdIcc:checksum: + */ + pspec = g_param_spec_string ("checksum", NULL, NULL, + NULL, + G_PARAM_READABLE); + g_object_class_install_property (object_class, PROP_CHECKSUM, pspec); + g_type_class_add_private (klass, sizeof (CdIccPrivate)); } @@ -2066,6 +2139,7 @@ cd_icc_finalize (GObject *object) guint i; g_free (priv->filename); + g_free (priv->checksum); g_ptr_array_unref (priv->named_colors); g_hash_table_destroy (priv->metadata); for (i = 0; i < CD_MLUC_LAST; i++) diff --git a/lib/colord/cd-icc.h b/lib/colord/cd-icc.h index 65725e8..e96f31a 100644 --- a/lib/colord/cd-icc.h +++ b/lib/colord/cd-icc.h @@ -93,6 +93,8 @@ typedef struct * @CD_ICC_LOAD_FLAGS_NAMED_COLORS: Parse any named colors in the profile. * @CD_ICC_LOAD_FLAGS_TRANSLATIONS: Parse all translations in the profile. * @CD_ICC_LOAD_FLAGS_METADATA: Parse the metadata in the profile. + * @CD_ICC_LOAD_FLAGS_FALLBACK_MD5: Calculate the profile MD5 if a profile + * ID was not supplied in the profile. * * Flags used when loading an ICC profile. * @@ -103,6 +105,7 @@ typedef enum { CD_ICC_LOAD_FLAGS_NAMED_COLORS = (1 << 0), CD_ICC_LOAD_FLAGS_TRANSLATIONS = (1 << 1), CD_ICC_LOAD_FLAGS_METADATA = (1 << 2), + CD_ICC_LOAD_FLAGS_FALLBACK_MD5 = (1 << 3), /* new entries go here: */ CD_ICC_LOAD_FLAGS_ALL = 0xff, CD_ICC_LOAD_FLAGS_LAST @@ -170,6 +173,7 @@ void cd_icc_remove_metadata (CdIcc *icc, GPtrArray *cd_icc_get_named_colors (CdIcc *icc); gboolean cd_icc_get_can_delete (CdIcc *icc); GDateTime *cd_icc_get_created (CdIcc *icc); +const gchar *cd_icc_get_checksum (CdIcc *icc); const gchar *cd_icc_get_description (CdIcc *icc, const gchar *locale, GError **error); diff --git a/lib/colord/cd-self-test.c b/lib/colord/cd-self-test.c index 5470fc4..7836de5 100644 --- a/lib/colord/cd-self-test.c +++ b/lib/colord/cd-self-test.c @@ -3323,6 +3323,7 @@ colord_icc_func (void) /* check profile properties */ g_assert_cmpint (cd_icc_get_size (icc), ==, 25244); + g_assert_cmpstr (cd_icc_get_checksum (icc), ==, "9ace8cce8baac8d492a93a2a232d7702"); g_assert_cmpfloat (cd_icc_get_version (icc), ==, 3.4); g_assert (g_str_has_suffix (cd_icc_get_filename (icc), "ibm-t61.icc")); g_assert_cmpint (cd_icc_get_kind (icc), ==, CD_PROFILE_KIND_DISPLAY_DEVICE); @@ -3363,10 +3364,6 @@ colord_icc_func (void) g_assert_no_error (error); g_assert_cmpstr (str, ==, "Huey, LENOVO - 6464Y1H - 15\" (2009-12-23)"); - /* modify some details about the profile */ - cd_icc_set_colorspace (icc, CD_COLORSPACE_XYZ); - cd_icc_set_kind (icc, CD_PROFILE_KIND_OUTPUT_DEVICE); - g_object_unref (icc); } |