From 3a5dd80d20f43626dab37a95d356541af2ac09a9 Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Sat, 24 Aug 2024 12:57:21 -0400 Subject: [PATCH] render/color: Add COLOR_TRANSFORM_LUT_3x1D type --- include/render/color.h | 38 ++++++++++++++++++++++++++++++++++++++ render/color.c | 12 ++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/render/color.h b/include/render/color.h index 4ab587be1..e18177c38 100644 --- a/include/render/color.h +++ b/include/render/color.h @@ -7,6 +7,7 @@ enum wlr_color_transform_type { COLOR_TRANSFORM_SRGB, COLOR_TRANSFORM_LUT_3D, + COLOR_TRANSFORM_LUT_3x1D, }; struct wlr_color_transform { @@ -37,6 +38,36 @@ struct wlr_color_transform_lut3d { size_t dim_len; }; +/** + * This is a color transform that is specified by three seperate ramps that + * modify the RGB values individually. This means that this color transform type + * cannot be used to create a transform that can infruence color channels + * depending on the values of other color channels. + * + * This color transform is modeled off of the wlr-gamma-control-unstable-v1 + * wayland protocol. + * + * The memory layout of this type requires that the r, g, b color channel ramps + * are inline in memory. A ramp value can be retrieved from memory: + * + * offset = dim_len * rgb_channel_index + ramp_index + * + * This is an offset into the `r` pointer and can be used to retrieve the ramps + * from the other channels as the ramps are linear in memory. The three pointers + * are given for convenience. + * + * Note that when freeing the color transform, only the `r` channel is freed as + * a it's expected that a single malloc will allocate all three channels at once. + */ +struct wlr_color_transform_lut3x1d { + struct wlr_color_transform base; + + uint16_t *r; + uint16_t *g; + uint16_t *b; + size_t ramp_size; +}; + /** * Gets a wlr_color_transform_lut3d from a generic wlr_color_transform. * Asserts that the base type is COLOR_TRANSFORM_LUT_3D @@ -44,4 +75,11 @@ struct wlr_color_transform_lut3d { struct wlr_color_transform_lut3d *wlr_color_transform_lut3d_from_base( struct wlr_color_transform *tr); +/** + * Gets a wlr_color_transform_lut3x1d from a generic wlr_color_transform. + * Asserts that the base type is COLOR_TRANSFORM_LUT_3x1D + */ +struct wlr_color_transform_lut3x1d *wlr_color_transform_lut3x1d_from_base( + struct wlr_color_transform *tr); + #endif diff --git a/render/color.c b/render/color.c index 9f8d76b06..403a6532b 100644 --- a/render/color.c +++ b/render/color.c @@ -23,6 +23,11 @@ static void color_transform_destroy(struct wlr_color_transform *tr) { wlr_color_transform_lut3d_from_base(tr); free(lut3d->lut_3d); break; + case COLOR_TRANSFORM_LUT_3x1D:; + struct wlr_color_transform_lut3x1d *lut3x1d = + wlr_color_transform_lut3x1d_from_base(tr); + free(lut3x1d->r); + break; } wlr_addon_set_finish(&tr->addons); free(tr); @@ -50,3 +55,10 @@ struct wlr_color_transform_lut3d *wlr_color_transform_lut3d_from_base( struct wlr_color_transform_lut3d *lut3d = wl_container_of(tr, lut3d, base); return lut3d; } + +struct wlr_color_transform_lut3x1d *wlr_color_transform_lut3x1d_from_base( + struct wlr_color_transform *tr) { + assert(tr->type == COLOR_TRANSFORM_LUT_3x1D); + struct wlr_color_transform_lut3x1d *lut = wl_container_of(tr, lut, base); + return lut; +}