From 50ea9450eabe7e43b60fea4bfd4d926b39cb972e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 28 Jul 2024 11:55:23 -0400 Subject: [PATCH] cicp: Fill in some more transfer functions Handle gamma 2.2 and gamma 2.8. --- gdk/gdkcicpparams.c | 12 +++++++----- gdk/gdkcolordefs.h | 24 ++++++++++++++++++++++++ gdk/gdkcolorstate.c | 8 ++++++++ testsuite/gdk/colorstate-internal.c | 2 ++ 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/gdk/gdkcicpparams.c b/gdk/gdkcicpparams.c index 87c7668684..1a6f05b471 100644 --- a/gdk/gdkcicpparams.c +++ b/gdk/gdkcicpparams.c @@ -160,10 +160,10 @@ gdk_cicp_params_class_init (GdkCicpParamsClass *klass) * GdkCicpParams:color-primaries: * * Supported values: - * 1 - sRGB + * 1 - BT.709 / sRGB * 2 - unspecified * 5 - PAL - * 6,7 - NTSC + * 6,7 - BT.601 / NTSC * 9 - BT.2020 * 10 - CIE XYZ * 12 - Display P3 @@ -179,12 +179,14 @@ gdk_cicp_params_class_init (GdkCicpParamsClass *klass) * GdkCicpParams:transfer-function: * * Supported values: - * 1,6,14,15 - BT.709 + * 1,6,14,15 - BT.709, BT.601, BT.2020 * 2 - unspecified + * 4 - gamma 2.2 + * 5 - gamma 2.8 * 8 - linear * 13 - sRGB - * 16 - PQ - * 18 - HLG + * 16 - BT.2100 PQ + * 18 - BT.2100 HLG * * Since: 4.16 */ diff --git a/gdk/gdkcolordefs.h b/gdk/gdkcolordefs.h index c92f43053e..fb2f0adecf 100644 --- a/gdk/gdkcolordefs.h +++ b/gdk/gdkcolordefs.h @@ -38,6 +38,30 @@ srgb_eotf (float v) return v / 12.92f; } +static inline float +gamma22_oetf (float v) +{ + return powf (v, 1.f / 2.2f); +} + +static inline float +gamma22_eotf (float v) +{ + return powf (v, 2.2f); +} + +static inline float +gamma28_oetf (float v) +{ + return powf (v, 1.f / 2.8f); +} + +static inline float +gamma28_eotf (float v) +{ + return powf (v, 2.8f); +} + static inline float pq_eotf (float v) { diff --git a/gdk/gdkcolorstate.c b/gdk/gdkcolorstate.c index 94e913249b..cecd802d62 100644 --- a/gdk/gdkcolorstate.c +++ b/gdk/gdkcolorstate.c @@ -626,6 +626,14 @@ gdk_color_state_new_for_cicp (const GdkCicp *cicp, eotf = bt709_eotf; oetf = bt709_oetf; break; + case 4: + eotf = gamma22_eotf; + oetf = gamma22_oetf; + break; + case 5: + eotf = gamma28_eotf; + oetf = gamma28_oetf; + break; case 8: eotf = NONE; oetf = NONE; diff --git a/testsuite/gdk/colorstate-internal.c b/testsuite/gdk/colorstate-internal.c index 90de7f9a99..b471cdb58f 100644 --- a/testsuite/gdk/colorstate-internal.c +++ b/testsuite/gdk/colorstate-internal.c @@ -18,6 +18,8 @@ TransferTest transfers[] = { { "pq", pq_oetf, pq_eotf }, { "bt709", bt709_oetf, bt709_eotf }, { "hlg", hlg_oetf, hlg_eotf }, + { "gamma22", gamma22_oetf, gamma22_eotf }, + { "gamma28", gamma28_oetf, gamma28_eotf }, }; static void