From 10b8880fc7344dae3c44ae87c536d3a0fbf7aabe Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 26 Feb 2025 08:58:15 +0100 Subject: [PATCH] render/color: add wlr_color_transfer_function_get_default_luminance() --- include/render/color.h | 6 ++++++ include/wlr/render/color.h | 7 +++++++ render/color.c | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/render/color.h b/include/render/color.h index 9da4f9a74..cddf1e219 100644 --- a/include/render/color.h +++ b/include/render/color.h @@ -56,4 +56,10 @@ void wlr_color_primaries_from_named(struct wlr_color_primaries *out, */ void wlr_color_primaries_to_xyz(const struct wlr_color_primaries *primaries, float matrix[static 9]); +/** + * Get default luminances for a transfer function. + */ +void wlr_color_transfer_function_get_default_luminance(enum wlr_color_transfer_function tf, + struct wlr_color_luminances *lum); + #endif diff --git a/include/wlr/render/color.h b/include/wlr/render/color.h index 32d8e9540..dc6f4097f 100644 --- a/include/wlr/render/color.h +++ b/include/wlr/render/color.h @@ -42,6 +42,13 @@ struct wlr_color_primaries { struct wlr_color_cie1931_xy red, green, blue, white; }; +/** + * Luminance range and reference white luminance level, in cd/m². + */ +struct wlr_color_luminances { + float min, max, reference; +}; + /** * A color transformation formula, which maps a linear color space with * sRGB primaries to an output color space. diff --git a/render/color.c b/render/color.c index ece6b38bd..c708938c7 100644 --- a/render/color.c +++ b/render/color.c @@ -128,3 +128,23 @@ void wlr_color_primaries_to_xyz(const struct wlr_color_primaries *primaries, flo }; memcpy(matrix, result, sizeof(result)); } + +void wlr_color_transfer_function_get_default_luminance(enum wlr_color_transfer_function tf, + struct wlr_color_luminances *lum) { + switch (tf) { + case WLR_COLOR_TRANSFER_FUNCTION_ST2084_PQ: + *lum = (struct wlr_color_luminances){ + .min = 0.005, + .max = 10000, + .reference = 203, + }; + break; + default: + *lum = (struct wlr_color_luminances){ + .min = 0.2, + .max = 80, + .reference = 80, + }; + break; + } +}