git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

scenefx/include/render/color.h (3K)

  1 #ifndef RENDER_COLOR_H
  2 #define RENDER_COLOR_H
  3 
  4 #include <stdint.h>
  5 #include <wlr/render/color.h>
  6 #include <wlr/util/addon.h>
  7 
  8 enum wlr_color_transform_type {
  9 	COLOR_TRANSFORM_INVERSE_EOTF,
 10 	COLOR_TRANSFORM_LCMS2,
 11 	COLOR_TRANSFORM_LUT_3X1D,
 12 	COLOR_TRANSFORM_MATRIX,
 13 	COLOR_TRANSFORM_PIPELINE,
 14 };
 15 
 16 struct wlr_color_transform {
 17 	int ref_count;
 18 	struct wlr_addon_set addons; // per-renderer helper state
 19 
 20 	enum wlr_color_transform_type type;
 21 };
 22 
 23 struct wlr_color_transform_inverse_eotf {
 24 	struct wlr_color_transform base;
 25 
 26 	enum wlr_color_transfer_function tf;
 27 };
 28 
 29 /**
 30  * The formula is approximated via three 1D look-up tables. The flat lut_3x1d
 31  * array has a length of 3 * dim.
 32  *
 33  * The offset of a color value for a given channel and color index is:
 34  *
 35  *     offset = channel_index * dim + color_index
 36  */
 37 struct wlr_color_transform_lut_3x1d {
 38 	struct wlr_color_transform base;
 39 
 40 	uint16_t *lut_3x1d;
 41 	size_t dim;
 42 };
 43 
 44 struct wlr_color_transform_matrix {
 45 	struct wlr_color_transform base;
 46 
 47 	float matrix[9];
 48 };
 49 
 50 struct wlr_color_transform_pipeline {
 51 	struct wlr_color_transform base;
 52 
 53 	struct wlr_color_transform **transforms;
 54 	size_t len;
 55 };
 56 
 57 void wlr_color_transform_init(struct wlr_color_transform *tr,
 58 	enum wlr_color_transform_type type);
 59 
 60 /**
 61  * Get a struct wlr_color_transform_lcms2 from a generic struct wlr_color_transform.
 62  * Asserts that the base type is COLOR_TRANSFORM_LCMS2.
 63  */
 64 struct wlr_color_transform_lcms2 *color_transform_lcms2_from_base(
 65 	struct wlr_color_transform *tr);
 66 
 67 void color_transform_lcms2_finish(struct wlr_color_transform_lcms2 *tr);
 68 
 69 /**
 70  * Evaluate a LCMS2 color transform for a given RGB triplet.
 71  */
 72 void color_transform_lcms2_eval(struct wlr_color_transform_lcms2 *tr,
 73 	float out[static 3], const float in[static 3]);
 74 
 75 /**
 76  * Gets a wlr_color_transform_inverse_eotf from a generic wlr_color_transform.
 77  * Asserts that the base type is COLOR_TRANSFORM_INVERSE_EOTF
 78  */
 79 struct wlr_color_transform_inverse_eotf *wlr_color_transform_inverse_eotf_from_base(
 80 	struct wlr_color_transform *tr);
 81 
 82 /**
 83  * Get a struct wlr_color_transform_lut_3x1d from a generic
 84  * struct wlr_color_transform. Asserts that the base type is
 85  * COLOR_TRANSFORM_LUT_3X1D.
 86  */
 87 struct wlr_color_transform_lut_3x1d *color_transform_lut_3x1d_from_base(
 88 	struct wlr_color_transform *tr);
 89 
 90 /**
 91  * Create a simplified / normalized wlr_color_transform pipeline.
 92  * `transforms` may contain NULL transforms, they will be interpreted as the
 93  * identity transform, and removed.
 94  * `*result` may be set to a transform of a type different from
 95  * `wlr_color_transform_pipeline`, or to NULL if all input transforms are NULL
 96  */
 97 bool color_transform_compose(struct wlr_color_transform **result,
 98 	struct wlr_color_transform **transforms, size_t len);
 99 
100 /**
101  * Compute the matrix to convert RGB color values to CIE 1931 XYZ.
102  */
103 void wlr_color_primaries_to_xyz(const struct wlr_color_primaries *primaries, float matrix[static 9]);
104 
105 /**
106  * Get default luminances for a transfer function.
107  */
108 void wlr_color_transfer_function_get_default_luminance(enum wlr_color_transfer_function tf,
109 	struct wlr_color_luminances *lum);
110 
111 #endif