render/color: introduce COLOR_TRANSFORM_LUT_3X1D

This will be useful to apply LUTs applied via wlr_gamma_control_v1,
and to add wlr_color_transform support to wlr_output.
This commit is contained in:
Simon Ser 2025-05-24 11:19:32 +02:00 committed by Kenny Levinsen
parent 3665b53e29
commit 74217a4d93
4 changed files with 116 additions and 5 deletions

View file

@ -8,6 +8,7 @@
enum wlr_color_transform_type {
COLOR_TRANSFORM_SRGB,
COLOR_TRANSFORM_LCMS2,
COLOR_TRANSFORM_LUT_3X1D,
};
struct wlr_color_transform {
@ -20,6 +21,21 @@ struct wlr_color_transform {
void wlr_color_transform_init(struct wlr_color_transform *tr,
enum wlr_color_transform_type type);
/**
* The formula is approximated via three 1D look-up tables. The flat lut_3x1d
* array has a length of 3 * dim.
*
* The offset of a color value for a given channel and color index is:
*
* offset = channel_index * dim + color_index
*/
struct wlr_color_transform_lut_3x1d {
struct wlr_color_transform base;
uint16_t *lut_3x1d;
size_t dim;
};
/**
* Get a struct wlr_color_transform_lcms2 from a generic struct wlr_color_transform.
* Asserts that the base type is COLOR_TRANSFORM_LCMS2.
@ -35,6 +51,20 @@ void color_transform_lcms2_finish(struct wlr_color_transform_lcms2 *tr);
void color_transform_lcms2_eval(struct wlr_color_transform_lcms2 *tr,
float out[static 3], const float in[static 3]);
/**
* Get a struct wlr_color_transform_lut_3x1d from a generic
* struct wlr_color_transform. Asserts that the base type is
* COLOR_TRANSFORM_LUT_3X1D.
*/
struct wlr_color_transform_lut_3x1d *color_transform_lut_3x1d_from_base(
struct wlr_color_transform *tr);
/**
* Evaluate a 3x1D LUT color transform for a given RGB triplet.
*/
void color_transform_lut_3x1d_eval(struct wlr_color_transform_lut_3x1d *tr,
float out[static 3], const float in[static 3]);
/**
* Obtain primaries values from a well-known primaries name.
*/