[gimp] plug-ins: deduct color space from profile if not specified otherwise.



commit 00e828a3ef411bee43b6086034af2cc620229b25
Author: Jehan <jehan girinstud io>
Date:   Fri Mar 9 22:12:23 2018 +0100

    plug-ins: deduct color space from profile if not specified otherwise.
    
    As explained in the previous commit, the color space is not always
    properly declared, in particular with J2K files. If a profile is present
    in such a case, try to deduct the color space from this information.

 plug-ins/common/file-jp2-load.c |   65 ++++++++++++++++++++++-----------------
 1 files changed, 37 insertions(+), 28 deletions(-)
---
diff --git a/plug-ins/common/file-jp2-load.c b/plug-ins/common/file-jp2-load.c
index dad1941..dcdc443 100644
--- a/plug-ins/common/file-jp2-load.c
+++ b/plug-ins/common/file-jp2-load.c
@@ -805,6 +805,7 @@ load_image (const gchar  *filename,
   opj_codec_t       *codec;
   opj_dparameters_t  parameters;
   opj_image_t       *image;
+  GimpColorProfile  *profile = NULL;
   gint32             image_ID;
   gint32             layer_ID;
   GimpImageType      image_type;
@@ -870,6 +871,42 @@ load_image (const gchar  *filename,
       goto out;
     }
 
+  if (image->icc_profile_buf)
+    {
+      if (image->icc_profile_len)
+        {
+          profile = gimp_color_profile_new_from_icc_profile (image->icc_profile_buf,
+                                                             image->icc_profile_len,
+                                                             error);
+          if (! profile)
+            goto out;
+
+          if (image->color_space == OPJ_CLRSPC_UNSPECIFIED)
+            {
+              if (gimp_color_profile_is_rgb (profile))
+                image->color_space = OPJ_CLRSPC_SRGB;
+              else if (gimp_color_profile_is_gray (profile))
+                image->color_space = OPJ_CLRSPC_GRAY;
+              else if (gimp_color_profile_is_cmyk (profile))
+                image->color_space = OPJ_CLRSPC_CMYK;
+            }
+
+          gimp_image_set_color_profile (image_ID, profile);
+          g_object_unref (profile);
+        }
+      else
+        {
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                       _("Couldn't decode CIELAB JP2 image in '%s'."),
+                       gimp_filename_to_utf8 (filename));
+          goto out;
+        }
+
+      free (image->icc_profile_buf);
+      image->icc_profile_buf = NULL;
+      image->icc_profile_len = 0;
+    }
+
   if ((image->color_space != OPJ_CLRSPC_SYCC) &&
       (image->numcomps == 3) &&
       (image->comps[0].dx == image->comps[0].dy) &&
@@ -1060,34 +1097,6 @@ load_image (const gchar  *filename,
   free (pixels);
 
   g_object_unref (buffer);
-
-  if (image->icc_profile_buf)
-    {
-      if (image->icc_profile_len)
-        {
-          GimpColorProfile *profile;
-
-          profile = gimp_color_profile_new_from_icc_profile
-            (image->icc_profile_buf, image->icc_profile_len, error);
-          if (! profile)
-            goto out;
-
-          gimp_image_set_color_profile (image_ID, profile);
-          g_object_unref (profile);
-        }
-      else
-        {
-          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                       _("Couldn't decode CIELAB JP2 image in '%s'."),
-                       gimp_filename_to_utf8 (filename));
-          goto out;
-        }
-
-      free (image->icc_profile_buf);
-      image->icc_profile_buf = NULL;
-      image->icc_profile_len = 0;
-    }
-
   gimp_progress_update (1.0);
 
  out:


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