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 --- libgamma_internal_translated_ramp_set_.c | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 libgamma_internal_translated_ramp_set_.c (limited to 'libgamma_internal_translated_ramp_set_.c') diff --git a/libgamma_internal_translated_ramp_set_.c b/libgamma_internal_translated_ramp_set_.c new file mode 100644 index 0000000..4b4a9af --- /dev/null +++ b/libgamma_internal_translated_ramp_set_.c @@ -0,0 +1,57 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +/** + * Just an arbitrary version + */ +#define ANY bits64 + + +/** + * Set the gamma ramps for a CRTC, re-encoding version + * + * @param this The CRTC state + * @param ramps The gamma ramps to apply + * @param depth_user The depth of the gamma ramps that are provided by the user, + * `-1` for `float`, `-2` for `double` + * @param depth_system The depth of the gamma ramps as required by the adjustment method, + * `-1` for `float`, `-2` for `double` + * @param fun Function that is to be used write the ramps, its parameters have + * the same function as those of this function with the same names, + * and the return value too is identical + * @return Zero on success, otherwise (negative) the value of an + * error identifier provided by this library + */ +int +libgamma_internal_translated_ramp_set_(libgamma_crtc_state_t *restrict this, gamma_ramps_any_t ramps, + signed depth_user, signed depth_system, set_ramps_any_fun *fun) +{ + size_t n; + int r; + gamma_ramps_any_t ramps_sys; + uint64_t *restrict ramps_full; + + /* Allocate ramps with proper data type */ + if ((r = libgamma_internal_allocated_any_ramp(&ramps_sys, ramps, depth_system, &n))) + return r; + + /* Allocate intermediary ramps */ + ramps_full = malloc(n * sizeof(uint64_t)); + if (!ramps_full) { + free(ramps_sys.ANY.red); + return LIBGAMMA_ERRNO_SET; + } + + /* Translate ramps to 64-bit integers. */ + libgamma_internal_translate_to_64(depth_user, n, ramps_full, ramps); + /* Translate ramps to the proper format. */ + libgamma_internal_translate_from_64(depth_system, n, ramps_sys, ramps_full); + free(ramps_full); + + /* Apply the ramps */ + r = fun(this, ramps_sys); + + free(ramps_sys.ANY.red); + return r; +} -- cgit v1.2.3-70-g09d2