From f320f158d092e8fa37fc6115d79ab4ae21f26317 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Wed, 8 Jul 2020 22:19:11 +0200 Subject: [PATCH] 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 90c0a50..c662629 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 59d4b1a..e76bb92 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 3c025bb..4032faa 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, -- 2.30.2