diff options
author | Mattias Andrée <maandree@kth.se> | 2016-07-15 18:48:48 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-07-15 18:48:48 +0200 |
commit | fa9da2764aaeeb63bd77972409a038cb0729cb0f (patch) | |
tree | 36b392ba4d78af10e7d34df8b002963fd1e4451a | |
parent | Suppress warning (diff) | |
download | libclut-fa9da2764aaeeb63bd77972409a038cb0729cb0f.tar.gz libclut-fa9da2764aaeeb63bd77972409a038cb0729cb0f.tar.bz2 libclut-fa9da2764aaeeb63bd77972409a038cb0729cb0f.tar.xz |
Add libclut_translate
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | src/libclut.h | 82 | ||||
-rw-r--r-- | src/test.c | 1 |
2 files changed, 83 insertions, 0 deletions
diff --git a/src/libclut.h b/src/libclut.h index eee13f1..ad2b857 100644 --- a/src/libclut.h +++ b/src/libclut.h @@ -689,6 +689,88 @@ static inline int libclut_0__(double x) { return libclut_eq__(x, 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. * * None of the parameter may have side-effects. @@ -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 |