render/color: introduce wlr_color_primaries_from_named()

This commit is contained in:
Simon Ser 2025-02-27 18:29:22 +01:00
parent 7d076d0bc9
commit e11012a024
2 changed files with 35 additions and 0 deletions

View file

@ -45,6 +45,12 @@ struct wlr_color_transform_lut3d {
struct wlr_color_transform_lut3d *wlr_color_transform_lut3d_from_base(
struct wlr_color_transform *tr);
/**
* 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);
/**
* Compute the matrix to convert RGB color values to CIE 1931 XYZ.
*/

View file

@ -5,6 +5,22 @@
#include "render/color.h"
#include "util/matrix.h"
// See H.273 ColourPrimaries
static const struct wlr_color_primaries COLOR_PRIMARIES_SRGB = { // code point 1
.red = { 0.640, 0.330 },
.green = { 0.300, 0.600 },
.blue = { 0.150, 0.060 },
.white = { 0.3127, 0.3290 },
};
static const struct wlr_color_primaries COLOR_PRIMARIES_BT2020 = { // code point 9
.red = { 0.708, 0.292 },
.green = { 0.170, 0.797 },
.blue = { 0.131, 0.046 },
.white = { 0.3127, 0.3290 },
};
struct wlr_color_transform *wlr_color_transform_init_srgb(void) {
struct wlr_color_transform *tx = calloc(1, sizeof(struct wlr_color_transform));
if (!tx) {
@ -53,6 +69,19 @@ struct wlr_color_transform_lut3d *wlr_color_transform_lut3d_from_base(
return lut3d;
}
void wlr_color_primaries_from_named(struct wlr_color_primaries *out,
enum wlr_color_named_primaries named) {
switch (named) {
case WLR_COLOR_NAMED_PRIMARIES_SRGB:
*out = COLOR_PRIMARIES_SRGB;
return;
case WLR_COLOR_NAMED_PRIMARIES_BT2020:
*out = COLOR_PRIMARIES_BT2020;
return;
}
abort();
}
static void multiply_matrix_vector(float out[static 3], float m[static 9], float v[static 3]) {
float result[3] = {
m[0] * v[0] + m[1] * v[1] + m[2] * v[2],