[gimp] libgimpcolor: add a function to check if a profile is linear RGB



commit d8f19f31cece296e18bd4b51c23c6dfebc8829eb
Author: Øyvind Kolås <pippin gimp org>
Date:   Mon Nov 23 00:01:37 2015 +0100

    libgimpcolor: add a function to check if a profile is linear RGB

 libgimpcolor/gimpcolorprofile.c |   46 +++++++++++++++++++++++++++++++++++++++
 libgimpcolor/gimpcolorprofile.h |    1 +
 2 files changed, 47 insertions(+), 0 deletions(-)
---
diff --git a/libgimpcolor/gimpcolorprofile.c b/libgimpcolor/gimpcolorprofile.c
index 33b1152..14a80eb 100644
--- a/libgimpcolor/gimpcolorprofile.c
+++ b/libgimpcolor/gimpcolorprofile.c
@@ -4,6 +4,7 @@
  * gimpcolorprofile.c
  * Copyright (C) 2014  Michael Natterer <mitch gimp org>
  *                     Elle Stone <ellestone ninedegreesbelow com>
+ *                     Øyvind Kolås <pippin gimp org>
  *
  * This library is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1291,3 +1292,48 @@ gimp_color_profile_get_format (const Babl *format,
 
   return output_format;
 }
+
+/**
+ * gimp_color_profile_is_linear:
+ * @profile: a #GimpColorProfile
+ *
+ * This function determines is the ICC profile represented by a GimpColorProfile
+ * is a linear RGB profile or not, some profiles that are LUTs though linear
+ * will also return FALSE;
+ *
+ * Return value: TRUE if the profile is a matrix shaping profile with linear
+ * TRCs.
+ *
+ * Since: 2.10
+ **/
+gboolean
+gimp_color_profile_is_linear (GimpColorProfile *profile)
+{
+  cmsHPROFILE prof;
+  cmsToneCurve *curve;
+
+  if (!profile)
+    return FALSE;
+  prof = profile->priv->lcms_profile;
+
+  if (!cmsIsMatrixShaper (prof))
+    return FALSE;
+
+  if(cmsIsCLUT(prof, INTENT_PERCEPTUAL, LCMS_USED_AS_INPUT))
+    return FALSE;
+
+  if(cmsIsCLUT(prof, INTENT_PERCEPTUAL, LCMS_USED_AS_OUTPUT))
+    return FALSE;
+
+  curve = cmsReadTag(prof, cmsSigRedTRCTag);
+  if (curve == NULL || !cmsIsToneCurveLinear (curve))
+    return FALSE;
+  curve = cmsReadTag(prof, cmsSigGreenTRCTag);
+  if (curve == NULL || !cmsIsToneCurveLinear (curve))
+    return FALSE;
+  curve = cmsReadTag(prof, cmsSigBlueTRCTag);
+  if (curve == NULL || !cmsIsToneCurveLinear (curve))
+    return FALSE;
+
+  return TRUE;
+}
diff --git a/libgimpcolor/gimpcolorprofile.h b/libgimpcolor/gimpcolorprofile.h
index 3c290d7..b184e7d 100644
--- a/libgimpcolor/gimpcolorprofile.h
+++ b/libgimpcolor/gimpcolorprofile.h
@@ -99,6 +99,7 @@ gboolean           gimp_color_profile_is_equal              (GimpColorProfile  *
                                                              GimpColorProfile  *profile2);
 
 gboolean           gimp_color_profile_is_rgb                (GimpColorProfile  *profile);
+gboolean           gimp_color_profile_is_linear             (GimpColorProfile  *profile);
 gboolean           gimp_color_profile_is_cmyk               (GimpColorProfile  *profile);
 
 const Babl       * gimp_color_profile_get_format            (const Babl        *format,


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