2023-09-09 20:04:45 -04:00
|
|
|
#ifndef RENDER_COLOR_H
|
|
|
|
|
#define RENDER_COLOR_H
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2025-01-27 18:41:16 +01:00
|
|
|
#include <wlr/render/color.h>
|
2023-09-09 20:04:45 -04:00
|
|
|
#include <wlr/util/addon.h>
|
|
|
|
|
|
2024-08-24 14:33:22 -04:00
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-09 20:04:45 -04:00
|
|
|
/**
|
|
|
|
|
* 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 {
|
2024-08-24 14:33:22 -04:00
|
|
|
struct wlr_color_transform base;
|
|
|
|
|
|
2023-09-09 20:04:45 -04:00
|
|
|
float *lut_3d;
|
|
|
|
|
size_t dim_len;
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-28 09:57:41 +01:00
|
|
|
void wlr_color_transform_init(struct wlr_color_transform *tr,
|
|
|
|
|
enum wlr_color_transform_type type);
|
|
|
|
|
|
2024-08-24 14:33:22 -04:00
|
|
|
/**
|
|
|
|
|
* 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);
|
2023-09-09 20:04:45 -04:00
|
|
|
|
2025-02-27 18:29:22 +01:00
|
|
|
/**
|
|
|
|
|
* Obtain primaries values from a well-known primaries name.
|
|
|
|
|
*/
|
|
|
|
|
void wlr_color_primaries_from_named(struct wlr_color_primaries *out,
|
|
|
|
|
enum wlr_color_named_primaries named);
|
|
|
|
|
|
2025-01-27 18:04:02 +01:00
|
|
|
/**
|
|
|
|
|
* Compute the matrix to convert RGB color values to CIE 1931 XYZ.
|
|
|
|
|
*/
|
|
|
|
|
void wlr_color_primaries_to_xyz(const struct wlr_color_primaries *primaries, float matrix[static 9]);
|
|
|
|
|
|
2025-02-26 08:58:15 +01:00
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
|
2023-09-09 20:04:45 -04:00
|
|
|
#endif
|