From 9fa7221a87817fe41a12a9cbdaa4bac6ee67b07d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 8 Jan 2017 08:00:53 +0100 Subject: Add vu-stack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/util.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index dc044f0..3adc1b5 100644 --- a/src/util.h +++ b/src/util.h @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ +#include #include #define ELEMENTSOF(ARRAY) (sizeof(ARRAY) / sizeof(*(ARRAY))) @@ -33,3 +34,27 @@ DEF_STR_TO_INT(toi, int, tolli, long long int) int fshut(FILE *fp, const char *fname); void enfshut(int status, FILE *fp, const char *fname); void efshut(FILE *fp, const char *fname); + +static inline double +srgb_encode(double t) +{ + double sign = 1; + if (t < 0) { + t = -t; + sign = -1; + } + t = t <= 0.0031306684425217108 ? 12.92 * t : 1.055 * pow(t, 1 / 2.4) - 0.055; + return t * sign; +} + +static inline double +srgb_decode(double t) +{ + double sign = 1; + if (t < 0) { + t = -t; + sign = -1; + } + t = t <= 0.0031306684425217108 * 12.92 ? t / 12.92 : pow((t + 0.055) / 1.055, 2.4); + return t * sign; +} -- cgit v1.2.3-70-g09d2