mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-14 08:22:25 -04:00
render/color: Add wlr_color_transform_create_from_gamma_lut
This commit is contained in:
parent
3a5dd80d20
commit
d4b4a3e57e
2 changed files with 37 additions and 0 deletions
|
|
@ -10,6 +10,7 @@
|
|||
#define WLR_RENDER_COLOR_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/**
|
||||
|
|
@ -52,4 +53,10 @@ struct wlr_color_transform *wlr_color_transform_ref(struct wlr_color_transform *
|
|||
*/
|
||||
void wlr_color_transform_unref(struct wlr_color_transform *tr);
|
||||
|
||||
/**
|
||||
* Creates a color transform based on a gamma ramp.
|
||||
*/
|
||||
struct wlr_color_transform *wlr_color_transform_create_from_gamma_lut(
|
||||
size_t ramp_size, const uint16_t *r, const uint16_t *g, const uint16_t *b);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wlr/render/color.h>
|
||||
#include "render/color.h"
|
||||
|
||||
|
|
@ -49,6 +50,35 @@ void wlr_color_transform_unref(struct wlr_color_transform *tr) {
|
|||
}
|
||||
}
|
||||
|
||||
struct wlr_color_transform *wlr_color_transform_create_from_gamma_lut(
|
||||
size_t ramp_size, const uint16_t *r, const uint16_t *g, const uint16_t *b) {
|
||||
uint16_t *data = malloc(3 * ramp_size * sizeof(uint16_t));
|
||||
if (!data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_color_transform_lut3x1d *tx = calloc(1, sizeof(*tx));
|
||||
if (!tx) {
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tx->base.type = COLOR_TRANSFORM_LUT_3x1D;
|
||||
tx->base.ref_count = 1;
|
||||
wlr_addon_set_init(&tx->base.addons);
|
||||
|
||||
tx->r = data;
|
||||
tx->g = data + ramp_size;
|
||||
tx->b = data + ramp_size * 2;
|
||||
tx->ramp_size = ramp_size;
|
||||
|
||||
memcpy(tx->r, r, ramp_size * sizeof(uint16_t));
|
||||
memcpy(tx->g, g, ramp_size * sizeof(uint16_t));
|
||||
memcpy(tx->b, b, ramp_size * sizeof(uint16_t));
|
||||
|
||||
return &tx->base;
|
||||
}
|
||||
|
||||
struct wlr_color_transform_lut3d *wlr_color_transform_lut3d_from_base(
|
||||
struct wlr_color_transform *tr) {
|
||||
assert(tr->type == COLOR_TRANSFORM_LUT_3D);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue