add new API babl_space_get_gamma
authorØyvind Kolås <pippin@gimp.org>
Wed, 8 Jul 2020 20:19:11 +0000 (22:19 +0200)
committerØyvind Kolås <pippin@gimp.org>
Wed, 8 Jul 2020 20:20:49 +0000 (22:20 +0200)
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
babl/babl-trc.c
babl/babl.h

index 90c0a50f9a7377b37c587b389bc0a8ca22e28960..c662629713625ac6cf426bf17e9820cde7f5c2bd 100644 (file)
@@ -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;
+}
index 59d4b1a34edfe1c436adf88022c771adab4406f1..e76bb9201c042a264af862d85fe6068e41cb1956 100644 (file)
@@ -611,3 +611,4 @@ babl_trc_lut_find (float *lut,
 
   return NULL;
 }
+
index 3c025bb808b4eb63fe4a33456a9c0bc76dff4891..4032faaef885149ec86ba55e1f248b16982b4403 100644 (file)
@@ -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,