mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-31 22:25:21 -04:00
render/color: introduce wlr_color_transform
Co-authored-by: Manuel Stoeckl <code@mstoeckl.com>
This commit is contained in:
parent
ee0007c0f2
commit
895e3d18b9
11 changed files with 266 additions and 0 deletions
|
|
@ -20,6 +20,9 @@ endif
|
|||
if not features.get('vulkan-renderer')
|
||||
exclude_files += 'render/vulkan.h'
|
||||
endif
|
||||
if not features.get('color-management')
|
||||
exclude_files += 'render/color.h'
|
||||
endif
|
||||
if not features.get('session')
|
||||
exclude_files += 'backend/session.h'
|
||||
endif
|
||||
|
|
|
|||
39
include/render/color.h
Normal file
39
include/render/color.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef RENDER_COLOR_H
|
||||
#define RENDER_COLOR_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <wlr/util/addon.h>
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
float *lut_3d;
|
||||
size_t dim_len;
|
||||
};
|
||||
|
||||
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;
|
||||
struct wlr_color_transform_lut3d lut3d;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -14,4 +14,6 @@
|
|||
|
||||
#mesondefine WLR_HAS_SESSION
|
||||
|
||||
#mesondefine WLR_HAS_COLOR_MANAGEMENT
|
||||
|
||||
#endif
|
||||
|
|
|
|||
55
include/wlr/render/color.h
Normal file
55
include/wlr/render/color.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This an unstable interface of wlroots. No guarantees are made regarding the
|
||||
* future consistency of this API.
|
||||
*/
|
||||
#ifndef WLR_USE_UNSTABLE
|
||||
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
|
||||
#endif
|
||||
|
||||
#ifndef WLR_RENDER_COLOR_H
|
||||
#define WLR_RENDER_COLOR_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/**
|
||||
* A color transformation formula, which maps a linear color space with
|
||||
* sRGB primaries to an output color space.
|
||||
*
|
||||
* For ease of use, this type is heap allocated and reference counted.
|
||||
* Use wlr_color_transform_ref()/wlr_color_transform_unref(). The initial reference
|
||||
* count after creation is 1.
|
||||
*
|
||||
* Color transforms are immutable; their type/parameters should not be changed,
|
||||
* and this API provides no functions to modify them after creation.
|
||||
*
|
||||
* This formula may be implemented using a 3d look-up table, or some other
|
||||
* means.
|
||||
*/
|
||||
struct wlr_color_transform;
|
||||
|
||||
/**
|
||||
* Initialize a color transformation to convert linear
|
||||
* (with sRGB(?) primaries) to an ICC profile. Returns NULL on failure.
|
||||
*/
|
||||
struct wlr_color_transform *wlr_color_transform_init_linear_to_icc(
|
||||
const void *data, size_t size);
|
||||
|
||||
/**
|
||||
* Initialize a color transformation to apply sRGB encoding.
|
||||
* Returns NULL on failure.
|
||||
*/
|
||||
struct wlr_color_transform *wlr_color_transform_init_srgb(void);
|
||||
|
||||
/**
|
||||
* Increase the reference count of the color transform by 1.
|
||||
*/
|
||||
void wlr_color_transform_ref(struct wlr_color_transform *tr);
|
||||
|
||||
/**
|
||||
* Reduce the reference count of the color transform by 1; freeing it and
|
||||
* all associated resources when the reference count hits zero.
|
||||
*/
|
||||
void wlr_color_transform_unref(struct wlr_color_transform *tr);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue