[gimp] plug-ins: use the GimpColorProfile API instead of the "icc-profile" parasite



commit 1d37c67879b3449704acc68c8cf2f27a957dac22
Author: Michael Natterer <mitch gimp org>
Date:   Thu Aug 20 11:15:26 2015 +0200

    plug-ins: use the GimpColorProfile API instead of the "icc-profile" parasite

 plug-ins/common/file-jp2-load.c        |   54 ++++++++++++++----------
 plug-ins/common/file-png.c             |   72 ++++++++++++++++++--------------
 plug-ins/common/file-tiff-load.c       |   24 +++++++----
 plug-ins/common/file-tiff-save.c       |   20 +++++----
 plug-ins/file-jpeg/jpeg-load.c         |   30 +++++++------
 plug-ins/file-jpeg/jpeg-save.c         |   41 +++++++++++-------
 plug-ins/file-psd/psd-image-res-load.c |   19 +++++----
 plug-ins/file-psd/psd-save.c           |   31 ++++++++-----
 plug-ins/file-psd/psd.h                |    1 -
 9 files changed, 168 insertions(+), 124 deletions(-)
---
diff --git a/plug-ins/common/file-jp2-load.c b/plug-ins/common/file-jp2-load.c
index 261142b..0facb3c 100644
--- a/plug-ins/common/file-jp2-load.c
+++ b/plug-ins/common/file-jp2-load.c
@@ -58,8 +58,9 @@ static void     run               (const gchar      *name,
                                    GimpParam       **return_vals);
 static gint32   load_image        (const gchar      *filename,
                                    GError          **error);
-static void     load_icc_profile  (jas_image_t      *jas_image,
-                                   gint              image_ID);
+static gboolean load_icc_profile  (jas_image_t      *jas_image,
+                                   gint              image_ID,
+                                   GError          **error);
 
 
 const GimpPlugInInfo PLUG_IN_INFO =
@@ -434,7 +435,7 @@ load_image (const gchar  *filename,
                        NULL, pixels, GEGL_AUTO_ROWSTRIDE);
     }
 
-  load_icc_profile (image, image_ID);
+  load_icc_profile (image, image_ID, NULL);
 
   jas_matrix_destroy (matrix);
   free (pixels);
@@ -449,28 +450,29 @@ load_image (const gchar  *filename,
   return image_ID;
 }
 
-static void
-load_icc_profile (jas_image_t *jas_image,
-                  gint         image_ID)
+static gboolean
+load_icc_profile (jas_image_t  *jas_image,
+                  gint          image_ID,
+                  GError      **error)
 {
-  jas_cmprof_t  *cm_prof;
-  jas_iccprof_t *jas_icc;
-  jas_stream_t  *stream;
-  guint32        profile_size;
-  guchar        *jas_iccile;
-  GimpParasite  *parasite;
+  jas_cmprof_t     *cm_prof;
+  jas_iccprof_t    *jas_icc;
+  jas_stream_t     *stream;
+  guint32           profile_size;
+  guchar           *jas_iccile;
+  GimpColorProfile *profile;
 
   cm_prof = jas_image_cmprof (jas_image);
   if (!cm_prof)
-    return;
+    return FALSE;
 
   jas_icc = jas_iccprof_createfromcmprof (cm_prof);
   if (!jas_icc)
-    return;
+    return FALSE;
 
   stream = jas_stream_memopen (NULL, -1);
   if (!stream)
-    return;
+    return FALSE;
 
   jas_iccprof_save (jas_icc, stream);
 
@@ -480,14 +482,20 @@ load_icc_profile (jas_image_t *jas_image,
   jas_iccile = g_malloc (profile_size);
   jas_stream_read (stream, jas_iccile, profile_size);
 
-  parasite = gimp_parasite_new ("icc-profile",
-                                GIMP_PARASITE_PERSISTENT |
-                                GIMP_PARASITE_UNDOABLE,
-                                profile_size, jas_iccile);
-  gimp_image_attach_parasite (image_ID, parasite);
-  gimp_parasite_free (parasite);
-
-  g_free (jas_iccile);
   jas_stream_close (stream);
   jas_iccprof_destroy (jas_icc);
+
+  profile = gimp_color_profile_new_from_icc_profile (jas_iccile, profile_size,
+                                                     error);
+  g_free (jas_iccile);
+
+  if (profile)
+    {
+      gimp_image_set_color_profile (image_ID, profile);
+      g_object_unref (profile);
+
+      return TRUE;
+    }
+
+  return FALSE;
 }
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index 2ecee68..4c825e3 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -1254,36 +1254,38 @@ load_image (const gchar  *filename,
   {
     png_uint_32 proflen;
     png_charp   profname;
-    png_bytep   profile;
+    png_charp   prof;
     int         profcomp;
 
-    if (png_get_iCCP (pp, info, &profname, &profcomp, &profile, &proflen))
+    if (png_get_iCCP (pp, info, &profname, &profcomp, &prof, &proflen))
       {
-        GimpParasite *parasite;
-
-        parasite = gimp_parasite_new ("icc-profile",
-                                      GIMP_PARASITE_PERSISTENT |
-                                      GIMP_PARASITE_UNDOABLE,
-                                      proflen, profile);
+        GimpColorProfile *profile;
 
-        gimp_image_attach_parasite (image, parasite);
-        gimp_parasite_free (parasite);
-
-        if (profname)
+        profile = gimp_color_profile_new_from_icc_profile ((guint8 *) prof,
+                                                           proflen, NULL);
+        if (profile)
           {
-            gchar *tmp = g_convert (profname, strlen (profname),
-                                    "ISO-8859-1", "UTF-8", NULL, NULL, NULL);
+            gimp_image_set_color_profile (image, profile);
+            g_object_unref (profile);
 
-            if (tmp)
+            if (profname)
               {
-                parasite = gimp_parasite_new ("icc-profile-name",
-                                              GIMP_PARASITE_PERSISTENT |
-                                              GIMP_PARASITE_UNDOABLE,
-                                              strlen (tmp), tmp);
-                gimp_image_attach_parasite (image, parasite);
-                gimp_parasite_free (parasite);
-
-                g_free (tmp);
+                gchar *tmp = g_convert (profname, strlen (profname),
+                                        "ISO-8859-1", "UTF-8", NULL, NULL, NULL);
+
+                if (tmp)
+                  {
+                    GimpParasite *parasite;
+
+                    parasite = gimp_parasite_new ("icc-profile-name",
+                                                  GIMP_PARASITE_PERSISTENT |
+                                                  GIMP_PARASITE_UNDOABLE,
+                                                  strlen (tmp), tmp);
+                    gimp_image_attach_parasite (image, parasite);
+                    gimp_parasite_free (parasite);
+
+                    g_free (tmp);
+                  }
               }
           }
       }
@@ -1653,15 +1655,21 @@ save_image (const gchar  *filename,
 
 #if defined(PNG_iCCP_SUPPORTED)
   {
-    GimpParasite *profile_parasite;
-    gchar        *profile_name = NULL;
+    GimpColorProfile *profile;
 
-    profile_parasite = gimp_image_get_parasite (orig_image_ID, "icc-profile");
+    profile = gimp_image_get_color_profile (orig_image_ID);
 
-    if (profile_parasite)
+    if (profile)
       {
-        GimpParasite *parasite = gimp_image_get_parasite (orig_image_ID,
-                                                          "icc-profile-name");
+        GimpParasite *parasite;
+        gchar        *profile_name = NULL;
+        const guint8 *icc_data;
+        gsize         icc_length;
+
+        icc_data = gimp_color_profile_get_icc_profile (profile, &icc_length);
+
+        parasite = gimp_image_get_parasite (orig_image_ID,
+                                            "icc-profile-name");
         if (parasite)
           profile_name = g_convert (gimp_parasite_data (parasite),
                                     gimp_parasite_data_size (parasite),
@@ -1671,10 +1679,12 @@ save_image (const gchar  *filename,
                       info,
                       profile_name ? profile_name : "ICC profile",
                       0,
-                      (guchar *) gimp_parasite_data (profile_parasite),
-                      gimp_parasite_data_size (profile_parasite));
+                      (png_charp) icc_data,
+                      icc_length);
 
         g_free (profile_name);
+
+        g_object_unref (profile);
       }
   }
 #endif
diff --git a/plug-ins/common/file-tiff-load.c b/plug-ins/common/file-tiff-load.c
index 22894b3..2aa1548 100644
--- a/plug-ins/common/file-tiff-load.c
+++ b/plug-ins/common/file-tiff-load.c
@@ -919,19 +919,25 @@ load_image (const gchar        *filename,
         }
 
 
-      /* attach a parasite containing an ICC profile - if found in the TIFF */
+      /* set the ICC profile - if found in the TIFF */
 
 #ifdef TIFFTAG_ICCPROFILE
-      /* If TIFFTAG_ICCPROFILE is defined we are dealing with a libtiff version
-       * that can handle ICC profiles. Otherwise just ignore this section. */
+      /* If TIFFTAG_ICCPROFILE is defined we are dealing with a
+       * libtiff version that can handle ICC profiles. Otherwise just
+       * ignore this section.
+       */
       if (TIFFGetField (tif, TIFFTAG_ICCPROFILE, &profile_size, &icc_profile))
         {
-          parasite = gimp_parasite_new ("icc-profile",
-                                        GIMP_PARASITE_PERSISTENT |
-                                        GIMP_PARASITE_UNDOABLE,
-                                        profile_size, icc_profile);
-          gimp_image_attach_parasite (image, parasite);
-          gimp_parasite_free (parasite);
+          GimpColorProfile *profile;
+
+          profile = gimp_color_profile_new_from_icc_profile (icc_profile,
+                                                             profile_size,
+                                                             NULL);
+          if (profile)
+            {
+              gimp_image_set_color_profile (image, profile);
+              g_object_unref (profile);
+            }
         }
 #endif
 
diff --git a/plug-ins/common/file-tiff-save.c b/plug-ins/common/file-tiff-save.c
index ce9369a..560e226 100644
--- a/plug-ins/common/file-tiff-save.c
+++ b/plug-ins/common/file-tiff-save.c
@@ -1076,18 +1076,20 @@ save_image (const gchar  *filename,
   /* do we have an ICC profile? If so, write it to the TIFF file */
 #ifdef TIFFTAG_ICCPROFILE
   {
-    GimpParasite *parasite;
-    uint32        profile_size;
-    const guchar *icc_profile;
+    GimpColorProfile *profile;
 
-    parasite = gimp_image_get_parasite (orig_image, "icc-profile");
-    if (parasite)
+    profile = gimp_image_get_color_profile (orig_image);
+
+    if (profile)
       {
-        profile_size = gimp_parasite_data_size (parasite);
-        icc_profile = gimp_parasite_data (parasite);
+        const guint8 *icc_data;
+        gsize         icc_length;
+
+        icc_data = gimp_color_profile_get_icc_profile (profile, &icc_length);
+
+        TIFFSetField (tif, TIFFTAG_ICCPROFILE, icc_length, icc_data);
 
-        TIFFSetField (tif, TIFFTAG_ICCPROFILE, profile_size, icc_profile);
-        gimp_parasite_free (parasite);
+        g_object_unref (profile);
       }
   }
 #endif
diff --git a/plug-ins/file-jpeg/jpeg-load.c b/plug-ins/file-jpeg/jpeg-load.c
index 57990c4..28515c5 100644
--- a/plug-ins/file-jpeg/jpeg-load.c
+++ b/plug-ins/file-jpeg/jpeg-load.c
@@ -244,9 +244,9 @@ load_image (const gchar  *filename,
 
   if (! preview)
     {
-      GString  *comment_buffer = NULL;
-      guint8   *profile        = NULL;
-      guint     profile_size   = 0;
+      GString *comment_buffer = NULL;
+      guint8  *icc_data       = NULL;
+      guint    icc_length     = 0;
 
       /* Step 5.0: save the original JPEG settings in a parasite */
       jpeg_detect_original_settings (&cinfo, image_ID);
@@ -309,25 +309,27 @@ load_image (const gchar  *filename,
         }
 
       /* Step 5.3: check for an embedded ICC profile in APP2 markers */
-      jpeg_icc_read_profile (&cinfo, &profile, &profile_size);
+      jpeg_icc_read_profile (&cinfo, &icc_data, &icc_length);
 
       if (cinfo.out_color_space == JCS_CMYK)
         {
-          cmyk_transform = jpeg_load_cmyk_transform (profile, profile_size);
+          cmyk_transform = jpeg_load_cmyk_transform (icc_data, icc_length);
         }
-      else if (profile) /* don't attach the profile if we are transforming */
+      else if (icc_data) /* don't attach the profile if we are transforming */
         {
-          GimpParasite *parasite;
+          GimpColorProfile *profile;
 
-          parasite = gimp_parasite_new ("icc-profile",
-                                        GIMP_PARASITE_PERSISTENT |
-                                        GIMP_PARASITE_UNDOABLE,
-                                        profile_size, profile);
-          gimp_image_attach_parasite (image_ID, parasite);
-          gimp_parasite_free (parasite);
+          profile = gimp_color_profile_new_from_icc_profile (icc_data,
+                                                             icc_length,
+                                                             NULL);
+          if (profile)
+            {
+              gimp_image_set_color_profile (image_ID, profile);
+              g_object_unref (profile);
+            }
         }
 
-      g_free (profile);
+      g_free (icc_data);
 
       /* Do not attach the "jpeg-save-options" parasite to the image
        * because this conflicts with the global defaults (bug #75398).
diff --git a/plug-ins/file-jpeg/jpeg-save.c b/plug-ins/file-jpeg/jpeg-save.c
index f9f36a4..10dd802 100644
--- a/plug-ins/file-jpeg/jpeg-save.c
+++ b/plug-ins/file-jpeg/jpeg-save.c
@@ -265,18 +265,18 @@ save_image (const gchar  *filename,
             gboolean      preview,
             GError      **error)
 {
-  GimpImageType  drawable_type;
-  GeglBuffer    *buffer = NULL;
-  const Babl    *format;
-  GimpParasite  *parasite;
   static struct jpeg_compress_struct cinfo;
   static struct my_error_mgr         jerr;
-  JpegSubsampling             subsampling;
-  FILE     * volatile outfile;
-  guchar   *data;
-  guchar   *src;
-  gboolean  has_alpha;
-  gint      rowstride, yend;
+
+  GimpImageType    drawable_type;
+  GeglBuffer      *buffer;
+  const Babl      *format;
+  JpegSubsampling  subsampling;
+  FILE            * volatile outfile;
+  guchar          *data;
+  guchar          *src;
+  gboolean         has_alpha;
+  gint             rowstride, yend;
 
   drawable_type = gimp_drawable_type (drawable_ID);
   buffer = gimp_drawable_get_buffer (drawable_ID);
@@ -540,14 +540,21 @@ save_image (const gchar  *filename,
     }
 
   /* Step 4.2: store the color profile if there is one */
-  parasite = gimp_image_get_parasite (orig_image_ID, "icc-profile");
-  if (parasite)
-    {
-      jpeg_icc_write_profile (&cinfo,
-                              gimp_parasite_data (parasite),
-                              gimp_parasite_data_size (parasite));
-      gimp_parasite_free (parasite);
+  {
+    GimpColorProfile *profile = gimp_image_get_color_profile (orig_image_ID);
+
+    if (profile)
+      {
+        const guint8 *icc_data;
+        gsize         icc_length;
+
+        icc_data = gimp_color_profile_get_icc_profile (profile, &icc_length);
+
+        jpeg_icc_write_profile (&cinfo, icc_data, icc_length);
+
+        g_object_unref (profile);
     }
+  }
 
   /* Step 5: while (scan lines remain to be written) */
   /*           jpeg_write_scanlines(...); */
diff --git a/plug-ins/file-psd/psd-image-res-load.c b/plug-ins/file-psd/psd-image-res-load.c
index 4acc37a..fdd3375 100644
--- a/plug-ins/file-psd/psd-image-res-load.c
+++ b/plug-ins/file-psd/psd-image-res-load.c
@@ -1099,8 +1099,8 @@ load_resource_1039 (const PSDimageres  *res_a,
                     GError            **error)
 {
   /* Load ICC profile */
-  GimpParasite  *parasite;
-  gchar         *icc_profile;
+  GimpColorProfile *profile;
+  gchar            *icc_profile;
 
   IFDBG(2) g_debug ("Process image resource block: 1039: ICC Profile");
 
@@ -1112,12 +1112,15 @@ load_resource_1039 (const PSDimageres  *res_a,
       return -1;
     }
 
-  parasite = gimp_parasite_new (GIMP_PARASITE_ICC_PROFILE,
-                                GIMP_PARASITE_PERSISTENT |
-                                GIMP_PARASITE_UNDOABLE,
-                                res_a->data_len, icc_profile);
-  gimp_image_attach_parasite (image_id, parasite);
-  gimp_parasite_free (parasite);
+  profile = gimp_color_profile_new_from_icc_profile ((guint8 *) icc_profile,
+                                                     res_a->data_len,
+                                                     NULL);
+  if (profile)
+    {
+      gimp_image_set_color_profile (image_id, profile);
+      g_object_unref (profile);
+    }
+
   g_free (icc_profile);
 
   return 0;
diff --git a/plug-ins/file-psd/psd-save.c b/plug-ins/file-psd/psd-save.c
index 22c4941..f6737e5 100644
--- a/plug-ins/file-psd/psd-save.c
+++ b/plug-ins/file-psd/psd-save.c
@@ -645,7 +645,6 @@ save_resources (FILE   *fd,
   gint32        idActLayer;          /* Id of the active layer */
   guint         nActiveLayer = 0;    /* Number of the active layer */
   gboolean      ActiveLayerPresent;  /* TRUE if there's an active layer */
-  GimpParasite *parasite;
 
   glong         eof_pos;             /* Position for End of file */
   glong         rsc_pos;             /* Position for Lengths of Resources section */
@@ -836,19 +835,27 @@ save_resources (FILE   *fd,
     }
 
   /* --------------- Write ICC profile data ------------------- */
-  parasite = gimp_image_get_parasite (image_id, "icc-profile");
-  if (parasite)
-    {
-      gint32 profile_length = gimp_parasite_data_size (parasite);
+  {
+    GimpColorProfile *profile;
 
-      xfwrite (fd, "8BIM", 4, "imageresources signature");
-      write_gint16 (fd, 0x040f, "0x040f Id");
-      write_gint16 (fd, 0, "Id name"); /* Set to null string (two zeros) */
-      write_gint32 (fd, profile_length, "0x040f resource size");
-      xfwrite (fd, gimp_parasite_data (parasite), profile_length, "ICC profile");
+    profile = gimp_image_get_color_profile (image_id);
 
-      gimp_parasite_free (parasite);
-    }
+    if (profile)
+      {
+        const guint8 *icc_data;
+        gsize         icc_length;
+
+        icc_data = gimp_color_profile_get_icc_profile (profile, &icc_length);
+
+        xfwrite (fd, "8BIM", 4, "imageresources signature");
+        write_gint16 (fd, 0x040f, "0x040f Id");
+        write_gint16 (fd, 0, "Id name"); /* Set to null string (two zeros) */
+        write_gint32 (fd, icc_length, "0x040f resource size");
+        xfwrite (fd, icc_data, icc_length, "ICC profile");
+
+        g_object_unref (profile);
+      }
+  }
 
 
   /* --------------- Write Total Section Length --------------- */
diff --git a/plug-ins/file-psd/psd.h b/plug-ins/file-psd/psd.h
index efcf89b..d28ff8f 100644
--- a/plug-ins/file-psd/psd.h
+++ b/plug-ins/file-psd/psd.h
@@ -40,7 +40,6 @@
 #define DECODE_XMP_PROC                 "plug-in-metadata-decode-xmp"
 
 #define GIMP_PARASITE_COMMENT           "gimp-comment"
-#define GIMP_PARASITE_ICC_PROFILE       "icc-profile"
 #define GIMP_PARASITE_EXIF              "exif-data"
 #define GIMP_PARASITE_IPTC              "iptc-data"
 


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