wlroots/include/render/color.h
Alexander Orzechowski 3187479c07 render/color: Invert ownership model of color_transform types.
Color transform can have multiple types and these different types
want to store different metadata. We previously stored this metadata
directly on wlr_color_transform even for transforms that don't use it.

Instead, let's take the prior art from wlr_scene where each scene node
is built on a base node. Notice how wlr_color_transform_lut3d now has
a `struct wlr_color_transform base`. This is advantageous in multiple
ways:

1. We don't allocate memory for metadata that will never be used.
2. This is more type safe: Compositors can pass around a
struct wlr_color_transform_lut3d if they know they only want to use a
3d_lut.
3. This is more scalable. As we add more transform types, we don't have
to keep growing a monolithic struct.
2024-08-24 14:33:22 -04:00

48 lines
1.2 KiB
C

#ifndef RENDER_COLOR_H
#define RENDER_COLOR_H
#include <stdint.h>
#include <wlr/util/addon.h>
enum wlr_color_transform_type {
COLOR_TRANSFORM_SRGB,
COLOR_TRANSFORM_LUT_3D,
};
struct wlr_color_transform {
int ref_count;
struct wlr_addon_set addons; // per-renderer helper state
enum wlr_color_transform_type type;
};
/**
* The formula is approximated via a 3D look-up table. A 3D LUT is a
* three-dimensional array where each element is an RGB triplet. The flat lut_3d
* array has a length of dim_len³.
*
* Color channel values in the range [0.0, 1.0] are mapped linearly to
* 3D LUT indices such that 0.0 maps exactly to the first element and 1.0 maps
* exactly to the last element in each dimension.
*
* The offset of the RGB triplet given red, green and blue indices r_index,
* g_index and b_index is:
*
* offset = 3 * (r_index + dim_len * g_index + dim_len * dim_len * b_index)
*/
struct wlr_color_transform_lut3d {
struct wlr_color_transform base;
float *lut_3d;
size_t dim_len;
};
/**
* Gets a wlr_color_transform_lut3d from a generic wlr_color_transform.
* Asserts that the base type is COLOR_TRANSFORM_LUT_3D
*/
struct wlr_color_transform_lut3d *wlr_color_transform_lut3d_from_base(
struct wlr_color_transform *tr);
#endif