[gimp] libgimpcolor: add gimp_lcms_profile_is_equal()



commit 32e47cf70dd0b332da7d1324eb724ed6a457a2e4
Author: Michael Natterer <mitch gimp org>
Date:   Sat Mar 29 10:40:47 2014 +0100

    libgimpcolor: add gimp_lcms_profile_is_equal()
    
    and remove all of our own MD5 digest code and API. is_equal() uses
    lcms' own MD5 API which I missed before. Thanks Elle for pointing that
    out :)

 app/core/gimpimage-profile.c                   |    8 +--
 app/core/gimpimage-profile.h                   |    1 -
 app/widgets/gimpimageprofileview.c             |    4 +-
 libgimpcolor/gimpcolor.def                     |    1 +
 libgimpcolor/gimplcms.c                        |   86 ++++++++---------------
 libgimpcolor/gimplcms.h                        |    7 +-
 libgimpwidgets/gimpcolorprofilechooserdialog.c |    2 +-
 modules/color-selector-cmyk.c                  |    2 +-
 modules/display-filter-lcms.c                  |    8 +-
 modules/display-filter-proof.c                 |    2 +-
 plug-ins/common/lcms.c                         |   67 +++++++++----------
 plug-ins/file-jpeg/jpeg-load.c                 |    2 +-
 12 files changed, 80 insertions(+), 110 deletions(-)
---
diff --git a/app/core/gimpimage-profile.c b/app/core/gimpimage-profile.c
index 68abd7b..958e090 100644
--- a/app/core/gimpimage-profile.c
+++ b/app/core/gimpimage-profile.c
@@ -84,7 +84,7 @@ gimp_image_validate_icc_profile (GimpImage           *image,
 
   profile = gimp_lcms_profile_open_from_data (gimp_parasite_data (icc_profile),
                                               gimp_parasite_data_size (icc_profile),
-                                              NULL, error);
+                                              error);
 
   if (! profile)
     {
@@ -135,7 +135,6 @@ gimp_image_set_icc_profile (GimpImage          *image,
 
 GimpColorProfile
 gimp_image_get_profile (GimpImage  *image,
-                        guint8     *md5_digest,
                         GError    **error)
 {
   GimpColorConfig    *config;
@@ -153,12 +152,11 @@ gimp_image_get_profile (GimpImage  *image,
     {
       return gimp_lcms_profile_open_from_data (gimp_parasite_data (parasite),
                                                gimp_parasite_data_size (parasite),
-                                               md5_digest, error);
+                                               error);
     }
   else if (config->rgb_profile)
     {
-      profile = gimp_lcms_profile_open_from_file (config->rgb_profile,
-                                                  md5_digest, error);
+      profile = gimp_lcms_profile_open_from_file (config->rgb_profile, error);
 
       if (profile && ! gimp_lcms_profile_is_rgb (profile))
         {
diff --git a/app/core/gimpimage-profile.h b/app/core/gimpimage-profile.h
index 9974826..48e93af 100644
--- a/app/core/gimpimage-profile.h
+++ b/app/core/gimpimage-profile.h
@@ -30,7 +30,6 @@ void                 gimp_image_set_icc_profile      (GimpImage           *image
                                                       const GimpParasite  *icc_profile);
 
 GimpColorProfile     gimp_image_get_profile          (GimpImage           *image,
-                                                      guint8              *md5_digest,
                                                       GError             **error);
 
 
diff --git a/app/widgets/gimpimageprofileview.c b/app/widgets/gimpimageprofileview.c
index d5b342a..0ec9cd2 100644
--- a/app/widgets/gimpimageprofileview.c
+++ b/app/widgets/gimpimageprofileview.c
@@ -111,7 +111,7 @@ gimp_image_profile_view_update (GimpImageParasiteView *view)
 
   image = gimp_image_parasite_view_get_image (view);
 
-  profile = gimp_image_get_profile (image, NULL, &error);
+  profile = gimp_image_get_profile (image, &error);
 
   if (! profile && error)
     {
@@ -120,7 +120,7 @@ gimp_image_profile_view_update (GimpImageParasiteView *view)
     }
 
   if (! profile)
-    profile = gimp_lcms_create_srgb_profile (NULL);
+    profile = gimp_lcms_create_srgb_profile ();
 
   gimp_color_profile_view_set_profile (profile_view->profile_view, profile);
 
diff --git a/libgimpcolor/gimpcolor.def b/libgimpcolor/gimpcolor.def
index 1e414f1..34ba86d 100644
--- a/libgimpcolor/gimpcolor.def
+++ b/libgimpcolor/gimpcolor.def
@@ -44,6 +44,7 @@ EXPORTS
        gimp_lcms_profile_get_model
        gimp_lcms_profile_get_summary
        gimp_lcms_profile_is_cmyk
+       gimp_lcms_profile_is_equal
        gimp_lcms_profile_is_rgb
        gimp_lcms_profile_open_from_data
        gimp_lcms_profile_open_from_file
diff --git a/libgimpcolor/gimplcms.c b/libgimpcolor/gimplcms.c
index da30f8e..8f2cf2e 100644
--- a/libgimpcolor/gimplcms.c
+++ b/libgimpcolor/gimplcms.c
@@ -22,6 +22,8 @@
 
 #include "config.h"
 
+#include <string.h>
+
 #include <glib.h>  /* lcms.h uses the "inline" keyword */
 
 #include <lcms2.h>
@@ -57,25 +59,8 @@ gimp_lcms_error_quark (void)
   return quark;
 }
 
-static void
-gimp_lcms_calculate_checksum (const guint8 *data,
-                              gsize         length,
-                              guint8       *md5_digest)
-{
-  GChecksum *md5 = g_checksum_new (G_CHECKSUM_MD5);
-
-  g_checksum_update (md5,
-                     (const guchar *) data + sizeof (cmsICCHeader),
-                     length - sizeof (cmsICCHeader));
-
-  length = GIMP_LCMS_MD5_DIGEST_LENGTH;
-  g_checksum_get_digest (md5, md5_digest, &length);
-  g_checksum_free (md5);
-}
-
 GimpColorProfile
 gimp_lcms_profile_open_from_file (const gchar  *filename,
-                                  guint8       *md5_digest,
                                   GError      **error)
 {
   GimpColorProfile  profile;
@@ -97,15 +82,9 @@ gimp_lcms_profile_open_from_file (const gchar  *filename,
   profile = cmsOpenProfileFromMem (data, length);
 
   if (! profile)
-    {
-      g_set_error (error, gimp_lcms_error_quark (), 0,
-                   _("'%s' does not appear to be an ICC color profile"),
-                   gimp_filename_to_utf8 (filename));
-    }
-  else if (md5_digest)
-    {
-      gimp_lcms_calculate_checksum (data, length, md5_digest);
-    }
+    g_set_error (error, gimp_lcms_error_quark (), 0,
+                 _("'%s' does not appear to be an ICC color profile"),
+                 gimp_filename_to_utf8 (filename));
 
   g_mapped_file_unref (file);
 
@@ -115,7 +94,6 @@ gimp_lcms_profile_open_from_file (const gchar  *filename,
 GimpColorProfile
 gimp_lcms_profile_open_from_data (const guint8  *data,
                                   gsize          length,
-                                  guint8        *md5_digest,
                                   GError       **error)
 {
   GimpColorProfile  profile;
@@ -127,14 +105,8 @@ gimp_lcms_profile_open_from_data (const guint8  *data,
   profile = cmsOpenProfileFromMem (data, length);
 
   if (! profile)
-    {
-      g_set_error_literal (error, gimp_lcms_error_quark (), 0,
-                           _("Data does not appear to be an ICC color profile"));
-    }
-  else if (md5_digest)
-    {
-      gimp_lcms_calculate_checksum (data, length, md5_digest);
-    }
+    g_set_error_literal (error, gimp_lcms_error_quark (), 0,
+                         _("Data does not appear to be an ICC color profile"));
 
   return profile;
 }
@@ -237,6 +209,28 @@ gimp_lcms_profile_get_summary (GimpColorProfile profile)
 }
 
 gboolean
+gimp_lcms_profile_is_equal (GimpColorProfile profile1,
+                            GimpColorProfile profile2)
+{
+  cmsUInt8Number digest1[GIMP_LCMS_MD5_DIGEST_LENGTH];
+  cmsUInt8Number digest2[GIMP_LCMS_MD5_DIGEST_LENGTH];
+
+  g_return_val_if_fail (profile1 != NULL, FALSE);
+  g_return_val_if_fail (profile2 != NULL, FALSE);
+
+  if (! cmsMD5computeID (profile1) ||
+      ! cmsMD5computeID (profile2))
+    {
+      return FALSE;
+    }
+
+  cmsGetHeaderProfileID (profile1, digest1);
+  cmsGetHeaderProfileID (profile2, digest2);
+
+  return (memcmp (digest1, digest2, GIMP_LCMS_MD5_DIGEST_LENGTH) == 0);
+}
+
+gboolean
 gimp_lcms_profile_is_rgb (GimpColorProfile profile)
 {
   g_return_val_if_fail (profile != NULL, FALSE);
@@ -297,7 +291,7 @@ gimp_lcms_profile_set_tag (cmsHPROFILE      profile,
  * Since: GIMP 2.10
  **/
 GimpColorProfile
-gimp_lcms_create_srgb_profile (guint8 *md5_digest)
+gimp_lcms_create_srgb_profile (void)
 {
   cmsHPROFILE srgb_profile;
   cmsCIExyY   d65_srgb_specs = { 0.3127, 0.3290, 1.0 };
@@ -345,25 +339,5 @@ gimp_lcms_create_srgb_profile (guint8 *md5_digest)
    * cmsSetProfileVersion (srgb_profile, 2.1);
    **/
 
-  if (md5_digest)
-    {
-      md5_digest[0]  = 0xcb;
-      md5_digest[1]  = 0x63;
-      md5_digest[2]  = 0x14;
-      md5_digest[3]  = 0x56;
-      md5_digest[4]  = 0xd4;
-      md5_digest[5]  = 0x0a;
-      md5_digest[6]  = 0x01;
-      md5_digest[7]  = 0x62;
-      md5_digest[8]  = 0xa0;
-      md5_digest[9]  = 0xdb;
-      md5_digest[10] = 0xe6;
-      md5_digest[11] = 0x32;
-      md5_digest[12] = 0x8b;
-      md5_digest[13] = 0xea;
-      md5_digest[14] = 0x1a;
-      md5_digest[15] = 0x89;
-    }
-
   return srgb_profile;
 }
diff --git a/libgimpcolor/gimplcms.h b/libgimpcolor/gimplcms.h
index 4f1749d..b51170f 100644
--- a/libgimpcolor/gimplcms.h
+++ b/libgimpcolor/gimplcms.h
@@ -36,11 +36,9 @@ G_BEGIN_DECLS
 
 
 GimpColorProfile   gimp_lcms_profile_open_from_file   (const gchar       *filename,
-                                                       guint8            *md5_digest,
                                                        GError           **error);
 GimpColorProfile   gimp_lcms_profile_open_from_data   (const guint8      *data,
                                                        gsize              length,
-                                                       guint8            *md5_digest,
                                                        GError           **error);
 
 gchar            * gimp_lcms_profile_get_description  (GimpColorProfile   profile);
@@ -50,10 +48,13 @@ gchar            * gimp_lcms_profile_get_copyright    (GimpColorProfile   profil
 
 gchar            * gimp_lcms_profile_get_summary      (GimpColorProfile   profile);
 
+gboolean           gimp_lcms_profile_is_equal         (GimpColorProfile   profile1,
+                                                       GimpColorProfile   profile2);
+
 gboolean           gimp_lcms_profile_is_rgb           (GimpColorProfile   profile);
 gboolean           gimp_lcms_profile_is_cmyk          (GimpColorProfile   profile);
 
-GimpColorProfile   gimp_lcms_create_srgb_profile      (guint8            *md5_digest);
+GimpColorProfile   gimp_lcms_create_srgb_profile      (void);
 
 
 G_END_DECLS
diff --git a/libgimpwidgets/gimpcolorprofilechooserdialog.c b/libgimpwidgets/gimpcolorprofilechooserdialog.c
index c62aeb9..392d5f7 100644
--- a/libgimpwidgets/gimpcolorprofilechooserdialog.c
+++ b/libgimpwidgets/gimpcolorprofilechooserdialog.c
@@ -199,7 +199,7 @@ gimp_color_profile_chooser_dialog_update_preview (GimpColorProfileChooserDialog
       return;
     }
 
-  profile = gimp_lcms_profile_open_from_file (filename, NULL, &error);
+  profile = gimp_lcms_profile_open_from_file (filename, &error);
 
   if (! profile)
     {
diff --git a/modules/color-selector-cmyk.c b/modules/color-selector-cmyk.c
index fac9e56..420a7d5 100644
--- a/modules/color-selector-cmyk.c
+++ b/modules/color-selector-cmyk.c
@@ -357,7 +357,7 @@ color_config_get_rgb_profile (GimpColorConfig *config)
   if (config->rgb_profile)
     profile = cmsOpenProfileFromFile (config->rgb_profile, "r");
 
-  return profile ? profile : gimp_lcms_create_srgb_profile (NULL);
+  return profile ? profile : gimp_lcms_create_srgb_profile ();
 }
 
 static cmsHPROFILE
diff --git a/modules/display-filter-lcms.c b/modules/display-filter-lcms.c
index abc66c9..dbb1aea 100644
--- a/modules/display-filter-lcms.c
+++ b/modules/display-filter-lcms.c
@@ -318,10 +318,10 @@ cdisplay_lcms_changed (GimpColorDisplay *display)
       cmsUInt32Number softproof_flags = 0;
 
       if (! src_profile)
-        src_profile = gimp_lcms_create_srgb_profile (NULL);
+        src_profile = gimp_lcms_create_srgb_profile ();
 
       if (! dest_profile)
-        dest_profile = gimp_lcms_create_srgb_profile (NULL);
+        dest_profile = gimp_lcms_create_srgb_profile ();
 
       softproof_flags |= cmsFLAGS_SOFTPROOFING;
 
@@ -358,10 +358,10 @@ cdisplay_lcms_changed (GimpColorDisplay *display)
       cmsUInt32Number display_flags = 0;
 
       if (! src_profile)
-        src_profile = gimp_lcms_create_srgb_profile (NULL);
+        src_profile = gimp_lcms_create_srgb_profile ();
 
       if (! dest_profile)
-        dest_profile = gimp_lcms_create_srgb_profile (NULL);
+        dest_profile = gimp_lcms_create_srgb_profile ();
 
       if (config->display_use_black_point_compensation)
         {
diff --git a/modules/display-filter-proof.c b/modules/display-filter-proof.c
index 2f1b263..7a41f49 100644
--- a/modules/display-filter-proof.c
+++ b/modules/display-filter-proof.c
@@ -384,7 +384,7 @@ cdisplay_proof_changed (GimpColorDisplay *display)
   if (! proof->profile)
     return;
 
-  rgb_profile = gimp_lcms_create_srgb_profile (NULL);
+  rgb_profile = gimp_lcms_create_srgb_profile ();
 
   proof_profile = cmsOpenProfileFromFile (proof->profile, "r");
 
diff --git a/plug-ins/common/lcms.c b/plug-ins/common/lcms.c
index 75d0569..ed4fc4e 100644
--- a/plug-ins/common/lcms.c
+++ b/plug-ins/common/lcms.c
@@ -108,7 +108,6 @@ static GimpPDBStatusType  lcms_icc_file_info (const gchar      *filename,
 
 static cmsHPROFILE  lcms_image_get_profile       (GimpColorConfig *config,
                                                   gint32           image,
-                                                  guchar          *checksum,
                                                   GError         **error);
 static gboolean     lcms_image_set_profile       (gint32           image,
                                                   cmsHPROFILE      profile,
@@ -529,8 +528,6 @@ lcms_icc_apply (GimpColorConfig          *config,
   GimpPDBStatusType status       = GIMP_PDB_SUCCESS;
   cmsHPROFILE       src_profile  = NULL;
   cmsHPROFILE       dest_profile = NULL;
-  guchar            src_md5[GIMP_LCMS_MD5_DIGEST_LENGTH];
-  guchar            dest_md5[GIMP_LCMS_MD5_DIGEST_LENGTH];
   GError           *error        = NULL;
 
   g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), GIMP_PDB_CALLING_ERROR);
@@ -543,8 +540,7 @@ lcms_icc_apply (GimpColorConfig          *config,
     {
       GError *error = NULL;
 
-      dest_profile = gimp_lcms_profile_open_from_file (filename, dest_md5,
-                                                       &error);
+      dest_profile = gimp_lcms_profile_open_from_file (filename, &error);
 
       if (! dest_profile)
         {
@@ -564,7 +560,7 @@ lcms_icc_apply (GimpColorConfig          *config,
         }
     }
 
-  src_profile = lcms_image_get_profile (config, image, src_md5, &error);
+  src_profile = lcms_image_get_profile (config, image, &error);
 
   if (error)
     {
@@ -576,12 +572,12 @@ lcms_icc_apply (GimpColorConfig          *config,
     return GIMP_PDB_SUCCESS;
 
   if (! src_profile)
-    src_profile = gimp_lcms_create_srgb_profile (src_md5);
+    src_profile = gimp_lcms_create_srgb_profile ();
 
   if (! dest_profile)
-    dest_profile = gimp_lcms_create_srgb_profile (dest_md5);
+    dest_profile = gimp_lcms_create_srgb_profile ();
 
-  if (memcmp (src_md5, dest_md5, GIMP_LCMS_MD5_DIGEST_LENGTH) == 0)
+  if (gimp_lcms_profile_is_equal (src_profile, dest_profile))
     {
       gchar *src_desc  = gimp_lcms_profile_get_description (src_profile);
       gchar *dest_desc = gimp_lcms_profile_get_description (dest_profile);
@@ -632,7 +628,7 @@ lcms_icc_info (GimpColorConfig *config,
   g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), GIMP_PDB_CALLING_ERROR);
   g_return_val_if_fail (image != -1, GIMP_PDB_CALLING_ERROR);
 
-  profile = lcms_image_get_profile (config, image, NULL, &error);
+  profile = lcms_image_get_profile (config, image, &error);
 
   if (error)
     {
@@ -641,7 +637,7 @@ lcms_icc_info (GimpColorConfig *config,
     }
 
   if (! profile)
-    profile = gimp_lcms_create_srgb_profile (NULL);
+    profile = gimp_lcms_create_srgb_profile ();
 
   if (name) *name = gimp_lcms_profile_get_model (profile);
   if (desc) *desc = gimp_lcms_profile_get_description (profile);
@@ -661,7 +657,7 @@ lcms_icc_file_info (const gchar  *filename,
 {
   cmsHPROFILE profile;
 
-  profile = gimp_lcms_profile_open_from_file (filename, NULL, error);
+  profile = gimp_lcms_profile_open_from_file (filename, error);
 
   if (! profile)
     return GIMP_PDB_EXECUTION_ERROR;
@@ -678,7 +674,6 @@ lcms_icc_file_info (const gchar  *filename,
 static cmsHPROFILE
 lcms_image_get_profile (GimpColorConfig  *config,
                         gint32            image,
-                        guchar           *checksum,
                         GError          **error)
 {
   GimpParasite *parasite;
@@ -692,7 +687,7 @@ lcms_image_get_profile (GimpColorConfig  *config,
     {
       profile = gimp_lcms_profile_open_from_data (gimp_parasite_data (parasite),
                                                   gimp_parasite_data_size (parasite),
-                                                  checksum, error);
+                                                  error);
       if (! profile)
         g_prefix_error (error, _("Error parsing 'icc-profile': "));
 
@@ -700,8 +695,7 @@ lcms_image_get_profile (GimpColorConfig  *config,
     }
   else if (config->rgb_profile)
     {
-      profile = gimp_lcms_profile_open_from_file (config->rgb_profile,
-                                                  checksum, error);
+      profile = gimp_lcms_profile_open_from_file (config->rgb_profile, error);
 
       if (profile && ! gimp_lcms_profile_is_rgb (profile))
         {
@@ -796,7 +790,9 @@ lcms_image_apply_profile (gint32                    image,
                           GimpColorRenderingIntent  intent,
                           gboolean                  bpc)
 {
-  gint32 saved_selection = -1;
+  gchar  *src_desc;
+  gchar  *dest_desc;
+  gint32  saved_selection = -1;
 
   gimp_image_undo_group_start (image);
 
@@ -807,18 +803,21 @@ lcms_image_apply_profile (gint32                    image,
       return FALSE;
     }
 
-  {
-    gchar  *src  = gimp_lcms_profile_get_description (src_profile);
-    gchar  *dest = gimp_lcms_profile_get_description (dest_profile);
+  src_desc = gimp_lcms_profile_get_description (src_profile);
+  if (! src_desc)
+    src_desc = gimp_lcms_profile_get_model (src_profile);
+
+  dest_desc = gimp_lcms_profile_get_description (dest_profile);
+  if (! dest_desc)
+    dest_desc = gimp_lcms_profile_get_model (dest_profile);
 
-      /* ICC color profile conversion */
-      gimp_progress_init_printf (_("Converting from '%s' to '%s'"), src, dest);
+  gimp_progress_init_printf (_("Converting from '%s' to '%s'"),
+                             src_desc, dest_desc);
 
-      g_printerr ("lcms: converting from '%s' to '%s'\n", src, dest);
+  g_printerr ("lcms: converting from '%s' to '%s'\n", src_desc, dest_desc);
 
-      g_free (dest);
-      g_free (src);
-  }
+  g_free (dest_desc);
+  g_free (src_desc);
 
   if (! gimp_selection_is_empty (image))
     {
@@ -1233,7 +1232,7 @@ lcms_icc_combo_box_set_active (GimpColorProfileComboBox *combo,
     {
       GError *error = NULL;
 
-      profile = gimp_lcms_profile_open_from_file (filename, NULL, &error);
+      profile = gimp_lcms_profile_open_from_file (filename, &error);
 
       if (! profile)
         {
@@ -1301,8 +1300,7 @@ lcms_icc_combo_box_new (GimpColorConfig *config,
     {
       GError *error = NULL;
 
-      profile = gimp_lcms_profile_open_from_file (config->rgb_profile, NULL,
-                                                  &error);
+      profile = gimp_lcms_profile_open_from_file (config->rgb_profile, &error);
 
       if (! profile)
         {
@@ -1312,7 +1310,7 @@ lcms_icc_combo_box_new (GimpColorConfig *config,
     }
 
   if (! profile)
-    profile = gimp_lcms_create_srgb_profile (NULL);
+    profile = gimp_lcms_create_srgb_profile ();
 
   name = gimp_lcms_profile_get_description (profile);
   if (! name)
@@ -1354,7 +1352,7 @@ lcms_dialog (GimpColorConfig *config,
   gboolean                  run;
   GError                   *error   = NULL;
 
-  src_profile = lcms_image_get_profile (config, image, NULL, &error);
+  src_profile = lcms_image_get_profile (config, image, &error);
 
   if (error)
     {
@@ -1363,7 +1361,7 @@ lcms_dialog (GimpColorConfig *config,
     }
 
   if (! src_profile)
-    src_profile = gimp_lcms_create_srgb_profile (NULL);
+    src_profile = gimp_lcms_create_srgb_profile ();
 
   gimp_ui_init (PLUG_IN_BINARY, FALSE);
 
@@ -1471,8 +1469,7 @@ lcms_dialog (GimpColorConfig *config,
         {
           GError *error = NULL;
 
-          dest_profile = gimp_lcms_profile_open_from_file (filename, NULL,
-                                                           &error);
+          dest_profile = gimp_lcms_profile_open_from_file (filename, &error);
 
           if (! dest_profile)
             {
@@ -1482,7 +1479,7 @@ lcms_dialog (GimpColorConfig *config,
         }
       else
         {
-          dest_profile = gimp_lcms_create_srgb_profile (NULL);
+          dest_profile = gimp_lcms_create_srgb_profile ();
         }
 
       if (dest_profile)
diff --git a/plug-ins/file-jpeg/jpeg-load.c b/plug-ins/file-jpeg/jpeg-load.c
index 3fcf380..a264200 100644
--- a/plug-ins/file-jpeg/jpeg-load.c
+++ b/plug-ins/file-jpeg/jpeg-load.c
@@ -648,7 +648,7 @@ jpeg_load_cmyk_transform (guint8 *profile_data,
   /*  make the real sRGB profile as a fallback  */
   if (! rgb_profile)
     {
-      rgb_profile = gimp_lcms_create_srgb_profile (NULL);
+      rgb_profile = gimp_lcms_create_srgb_profile ();
     }
 
   if (config->display_intent ==


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]