From 5b804da16b09f97ad0c944daf35900a796f3bc66 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 17 Jul 2016 21:20:14 +0200 Subject: When reconnecting, reapply the ramps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/servers/coopgamma.c | 50 ------------------------------------------------ src/servers/gamma.c | 18 +++++++++++++++++ src/util.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ src/util.h | 12 +++++++++++- 4 files changed, 80 insertions(+), 51 deletions(-) diff --git a/src/servers/coopgamma.c b/src/servers/coopgamma.c index 7f8b815..935bed0 100644 --- a/src/servers/coopgamma.c +++ b/src/servers/coopgamma.c @@ -207,56 +207,6 @@ static ssize_t add_filter(struct output* restrict out, struct filter* restrict f } -/** - * Make identity mapping ramps - * - * @param ramps Output parameter for the ramps - * @param output The output for which the ramps shall be configured - * @return Zero on success, -1 on error - */ -static int make_plain_ramps(union gamma_ramps* restrict ramps, struct output* restrict output) -{ - COPY_RAMP_SIZES(&(ramps->u8), output); - switch (output->depth) - { - case 8: - if (libgamma_gamma_ramps8_initialise(&(ramps->u8))) - return -1; - libclut_start_over(&(ramps->u8), UINT8_MAX, uint8_t, 1, 1, 1); - break; - case 16: - if (libgamma_gamma_ramps16_initialise(&(ramps->u16))) - return -1; - libclut_start_over(&(ramps->u16), UINT16_MAX, uint16_t, 1, 1, 1); - break; - case 32: - if (libgamma_gamma_ramps32_initialise(&(ramps->u32))) - return -1; - libclut_start_over(&(ramps->u32), UINT32_MAX, uint32_t, 1, 1, 1); - break; - case 64: - if (libgamma_gamma_ramps64_initialise(&(ramps->u64))) - return -1; - libclut_start_over(&(ramps->u64), UINT64_MAX, uint64_t, 1, 1, 1); - break; - case -1: - if (libgamma_gamma_rampsf_initialise(&(ramps->f))) - return -1; - libclut_start_over(&(ramps->f), 1.0f, float, 1, 1, 1); - break; - case -2: - if (libgamma_gamma_rampsd_initialise(&(ramps->d))) - return -1; - libclut_start_over(&(ramps->d), (double)1, double, 1, 1, 1); - break; - default: - abort(); - } - return 0; -} - - - /** * Handle a closed connection * diff --git a/src/servers/gamma.c b/src/servers/gamma.c index 95130e6..a481095 100644 --- a/src/servers/gamma.c +++ b/src/servers/gamma.c @@ -19,6 +19,7 @@ #include "crtc.h" #include "../state.h" #include "../communication.h" +#include "../util.h" #include #include @@ -270,9 +271,26 @@ int disconnect(void) */ int reconnect(void) { + union gamma_ramps plain; + size_t i; + if (connected) return 0; + /* Reapply gamma ramps */ + for (i = 0; i < outputs_n; i++) + { + struct output* output = outputs + i; + if (output->table_size > 0) + set_gamma(output, output->table_sums + output->table_size - 1); + else + { + make_plain_ramps(&plain, output); + set_gamma(output, &plain); + libgamma_gamma_ramps8_destroy(&(plain.u8)); + } + } + connected = 1; return 0; /* TODO reconnect() */ } diff --git a/src/util.c b/src/util.c index c116998..3e2bdd2 100644 --- a/src/util.c +++ b/src/util.c @@ -17,6 +17,8 @@ */ #include "util.h" +#include + #include #include #include @@ -265,3 +267,52 @@ int verify_utf8(const char* restrict string, int allow_modified_nul) return read_bytes == 0 ? 0 : -1; } + +/** + * Make identity mapping ramps + * + * @param ramps Output parameter for the ramps + * @param output The output for which the ramps shall be configured + * @return Zero on success, -1 on error + */ +int make_plain_ramps(union gamma_ramps* restrict ramps, struct output* restrict output) +{ + COPY_RAMP_SIZES(&(ramps->u8), output); + switch (output->depth) + { + case 8: + if (libgamma_gamma_ramps8_initialise(&(ramps->u8))) + return -1; + libclut_start_over(&(ramps->u8), UINT8_MAX, uint8_t, 1, 1, 1); + break; + case 16: + if (libgamma_gamma_ramps16_initialise(&(ramps->u16))) + return -1; + libclut_start_over(&(ramps->u16), UINT16_MAX, uint16_t, 1, 1, 1); + break; + case 32: + if (libgamma_gamma_ramps32_initialise(&(ramps->u32))) + return -1; + libclut_start_over(&(ramps->u32), UINT32_MAX, uint32_t, 1, 1, 1); + break; + case 64: + if (libgamma_gamma_ramps64_initialise(&(ramps->u64))) + return -1; + libclut_start_over(&(ramps->u64), UINT64_MAX, uint64_t, 1, 1, 1); + break; + case -1: + if (libgamma_gamma_rampsf_initialise(&(ramps->f))) + return -1; + libclut_start_over(&(ramps->f), 1.0f, float, 1, 1, 1); + break; + case -2: + if (libgamma_gamma_rampsd_initialise(&(ramps->d))) + return -1; + libclut_start_over(&(ramps->d), (double)1, double, 1, 1, 1); + break; + default: + abort(); + } + return 0; +} + diff --git a/src/util.h b/src/util.h index 7429f5f..5d23f93 100644 --- a/src/util.h +++ b/src/util.h @@ -19,7 +19,7 @@ #define UTIL_H -#include +#include "types/output.h" @@ -101,6 +101,16 @@ void msleep(int ms); GCC_ONLY(__attribute__((pure, nonnull))) int verify_utf8(const char* restrict string, int allow_modified_nul); +/** + * Make identity mapping ramps + * + * @param ramps Output parameter for the ramps + * @param output The output for which the ramps shall be configured + * @return Zero on success, -1 on error + */ +GCC_ONLY(__attribute__((nonnull))) +int make_plain_ramps(union gamma_ramps* restrict ramps, struct output* restrict output); + #endif -- cgit v1.2.3-70-g09d2