From 0ce0d8d6e0c420ccafa79e0203b928c3559a4311 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 5 Mar 2021 00:43:38 +0100 Subject: Split source files, merge public header files, eliminite use gpp, rewrite makefile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- set_ramps_fun.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 set_ramps_fun.h (limited to 'set_ramps_fun.h') diff --git a/set_ramps_fun.h b/set_ramps_fun.h new file mode 100644 index 0000000..bdd1fe8 --- /dev/null +++ b/set_ramps_fun.h @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ + +/* + * This file is intended to be included from + * libgamma_crtc_set_gamma_ramps{8,16,32,64,f,d}_f + */ + + +libgamma_crtc_information_t info; +struct APPEND_RAMPS(libgamma_gamma_) ramps; +size_t i, n; +int e; + +/* Get the size of the gamma ramps */ +if (libgamma_get_crtc_information(&info, this, LIBGAMMA_CRTC_INFO_GAMMA_SIZE)) { + e = info.gamma_size_error; + if (e < 0) + return e; + errno = e; + return LIBGAMMA_ERRNO_SET; + } + +/* Copy the size of the gamma ramps and calculte the grand size */ +n = ramps. red_size = info. red_gamma_size; +n += ramps.green_size = info.green_gamma_size; +n += ramps. blue_size = info. blue_gamma_size; + +/* Allocate gamma ramps */ +ramps. red = malloc(n * sizeof(TYPE)); +ramps.green = &ramps. red[ramps. red_size]; +ramps. blue = &ramps.green[ramps.green_size]; +if (!ramps.red) + return LIBGAMMA_ERRNO_SET; + +/* Generate the gamma ramp for the red channel */ +for (i = 0, n = ramps.red_size; i < n; i++) + ramps.red[i] = red_function((float)i / (float)(n - 1)); + +/* Generate the gamma ramp for the green channel */ +for (i = 0, n = ramps.green_size; i < n; i++) + ramps.green[i] = green_function((float)i / (float)(n - 1)); + +/* Generate the gamma ramp for the blue channel */ +for (i = 0, n = ramps.blue_size; i < n; i++) + ramps.blue[i] = blue_function((float)i / (float)(n - 1)); + +/* Apply the gamma ramps */ +e = APPEND_RAMPS(libgamma_crtc_set_gamma_)(this, ramps); +free(ramps.red); +return e; -- cgit v1.2.3-70-g09d2