From fa9da2764aaeeb63bd77972409a038cb0729cb0f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 15 Jul 2016 18:48:48 +0200 Subject: Add libclut_translate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libclut.h | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test.c | 1 + 2 files changed, 83 insertions(+) (limited to 'src') diff --git a/src/libclut.h b/src/libclut.h index eee13f1..ad2b857 100644 --- a/src/libclut.h +++ b/src/libclut.h @@ -688,6 +688,88 @@ static inline int libclut_0__(double x) { return libclut_eq__(x, 0); } while (0) +/** + * Translates a gamma ramp structure to another gamma ramp structure type. + * + * None of the parameter may have side-effects. + * + * @param dclut Pointer to the desired gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars `red_size`, + * `green_size`, and `blue_size`. Ramp structures from + * libgamma can be used. + * @param dmax The maximum value on each stop in the ramps in `dclut`. + * @param dtype The data type used for each stop in the ramps in `dclut`. + * @param sclut Pointer to the set gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars `red_size`, + * `green_size`, and `blue_size`. Ramp structures from + * libgamma can be used. + * @param smax The maximum value on each stop in the ramps in `sclut`. + * @param stype The data type used for each stop in the ramps in `sclut`. + * (Not actually used.) + */ +#define libclut_translate(dclut, dmax, dtype, sclut, smax, stype) \ + do \ + { \ + libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, red); \ + libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, green); \ + libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, blue); \ + } \ + while (0) + +/** + * Translates a gamma ramp structure to another gamma ramp structure type. + * + * None of the parameter may have side-effects. + * + * This is intended for internal use. + * + * @param dclut Pointer to the desired gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars `red_size`, + * `green_size`, and `blue_size`. Ramp structures from + * libgamma can be used. + * @param dmax The maximum value on each stop in the ramps in `dclut`. + * @param dtype The data type used for each stop in the ramps in `dclut`. + * @param sclut Pointer to the set gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars `red_size`, + * `green_size`, and `blue_size`. Ramp structures from + * libgamma can be used. + * @param smax The maximum value on each stop in the ramps in `sclut`. + * @param stype The data type used for each stop in the ramps in `sclut`. + * (Not actually used.) + * @param channel The channel, must be either "red", "green", or "blue". + */ +#define libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, channel) \ + do \ + { \ + size_t di__, si__, sj__; \ + size_t dn__ = (dclut)->channel##_size; \ + size_t sn__ = (sclut)->channel##_size; \ + double dm__ = (double)(dmax); \ + double sm__ = (double)(smax); \ + double smdm__ = sm__ / dm__; \ + double x__, y__; \ + if (dn__ == sn__) \ + for (di__ = 0; di__ < dn__; di__++) \ + { \ + y__ = (double)((sclut)->channel[si__]) * smdm__; \ + (dclut)->channel[di__] = (dtype)y__; \ + } \ + else \ + for (di__ = 0; di__ < dn__; di__++) \ + { \ + x__ = di__ / (dn__ - 1) * (sn__ - 1); \ + si__ = (size_t)(x__); \ + sj__ = si__ + (si__ != sn__); \ + x__ -= (double)si__; \ + y__ = (double)((sclut)->channel[si__]) * (1 - x__); \ + y__ += (double)((sclut)->channel[sj__]) * (x__); \ + y__ *= smdm__; \ + (dclut)->channel[di__] = (dtype)y__; \ + } \ + } \ + while (0) + + /** * Applies a filter or calibration. * diff --git a/src/test.c b/src/test.c index d77021e..6b24f70 100644 --- a/src/test.c +++ b/src/test.c @@ -334,6 +334,7 @@ int main(int argc, char *argv[]) /* TODO test these too: (also add this to the makefile) + libclut_translate libclut_cie_contrast libclut_cie_brightness libclut_cie_invert -- cgit v1.2.3-70-g09d2