From 0397b7620352c69b33116eb9263956deb3d5923d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 13 Jul 2016 20:41:53 +0200 Subject: Fix bugs and test libclut_clip and libclut_apply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libclut.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/libclut.h') diff --git a/src/libclut.h b/src/libclut.h index e469260..01f00b4 100644 --- a/src/libclut.h +++ b/src/libclut.h @@ -693,17 +693,17 @@ * @param ftype Same as `type`, but for the filter to apply. (Not actually used). * @param channel The channel, must be either "red", "green", or "blue". */ -#define libclut_apply__(clut, max, type, filter, fmax, ftype, channel) \ - do \ - { \ - size_t i__, rn__ = (clut)->channel##_size, fn__ = (filter)->channel##_size; \ - size_t x__, rm__ = (double)(max), m__ = (double)(max) / (double)(fmax); \ - for (i__ = 0; i__ < rn__; i__++) \ - { \ - x__ = (size_t)((double)((clut)->channel[i__]) / rm__ * fn__); \ - (clut)->channel[i__] = (type)((double)((filter)->channel[x__]) * m__); \ - } \ - } \ +#define libclut_apply__(clut, max, type, filter, fmax, ftype, channel) \ + do \ + { \ + size_t i__, rn__ = (clut)->channel##_size - 1, fn__ = (filter)->channel##_size - 1; \ + double x__, rm__ = (double)(max), m__ = (double)(max) / (double)(fmax); \ + for (i__ = 0; i__ < rn__; i__++) \ + { \ + x__ = (double)((clut)->channel[i__]) / rm__ * fn__; \ + (clut)->channel[i__] = (type)((double)((filter)->channel[(size_t)x__]) * m__); \ + } \ + } \ while (0) @@ -730,8 +730,8 @@ #define libclut_cie_apply(clut, max, type, filter, fmax, ftype, r, g, b) \ do \ { \ - size_t rfn__ = (filter)->red_size, gfn__ = (filter)->green_size; \ - size_t bfn__ = (filter)->blue_size, x__; \ + size_t rfn__ = (filter)->red_size - 1, gfn__ = (filter)->green_size - 1; \ + size_t bfn__ = (filter)->blue_size - 1, x__; \ size_t rm__ = (double)(max), fm__ = (double)(fmax); \ libclut_cie__(clut, max, type, 0, r, g, b, \ (x__ = (size_t)(Y__ / rm__ * rfn__), (double)((filter)->red[x__]) / fm__), \ -- cgit v1.2.3-70-g09d2