[babl] add new API babl_space_get_gamma



commit f320f158d092e8fa37fc6115d79ab4ae21f26317
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Jul 8 22:19:11 2020 +0200

    add new API babl_space_get_gamma
    
    A need that has arisen in PNG export is knowing if the gamma is a simple
    gamma and the gAMA tag can be used instead of a full ICC profile.

 babl/babl-space.c | 11 +++++++++++
 babl/babl-trc.c   |  1 +
 babl/babl.h       |  9 ++++++++-
 3 files changed, 20 insertions(+), 1 deletion(-)
---
diff --git a/babl/babl-space.c b/babl/babl-space.c
index 90c0a50f9..c66262971 100644
--- a/babl/babl-space.c
+++ b/babl/babl-space.c
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "babl-internal.h"
 #include "base/util.h"
+#include "babl-trc.h"
 
 static BablSpace space_db[MAX_SPACES];
 
@@ -1443,3 +1444,13 @@ babl_space_get_rgb_luminance (const Babl *space,
   if (blue_luminance)
     *blue_luminance = space->space.RGBtoXYZ[5];
 }
+
+double
+babl_space_get_gamma (const Babl *space)
+{
+  if (space->space.trc[0] != space->space.trc[1] ||
+      space->space.trc[1] != space->space.trc[2] ||
+      space->space.trc[0]->trc.type != BABL_TRC_FORMULA_GAMMA)
+    return 0.0;
+  return space->space.trc[0]->trc.gamma;
+}
diff --git a/babl/babl-trc.c b/babl/babl-trc.c
index 59d4b1a34..e76bb9201 100644
--- a/babl/babl-trc.c
+++ b/babl/babl-trc.c
@@ -611,3 +611,4 @@ babl_trc_lut_find (float *lut,
 
   return NULL;
 }
+
diff --git a/babl/babl.h b/babl/babl.h
index 3c025bb80..4032faaef 100644
--- a/babl/babl.h
+++ b/babl/babl.h
@@ -134,7 +134,14 @@ const Babl *babl_space_from_icc (const char       *icc_data,
                                  int               icc_length,
                                  BablIccIntent     intent,
                                  const char      **error);
-
+/* babl_space_get_gamma:
+ * @space: a babl space
+ * 
+ * Returns the gamma of the TRCs of the space, iff they are all equal
+ * and a simple gamma number, otherwise 0.0 is returned.
+ */
+double
+babl_space_get_gamma (const Babl *space);
 
 // XXX : deprecated
 const Babl *babl_icc_make_space (const char       *icc_data,


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