diff options
author | Mattias Andrée <maandree@kth.se> | 2023-01-26 20:26:59 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-01-26 20:26:59 +0100 |
commit | df538ad4f3b9ca3e98822299d6f233e219bc2fd4 (patch) | |
tree | fc0db1dbd70bea43a0abfe794d3e0bc68cb05c6b /libglitter_desaturate_double.c | |
parent | m doc + test libglitter_colour_model_convert_rasters_{double,float} (diff) | |
download | libglitter-df538ad4f3b9ca3e98822299d6f233e219bc2fd4.tar.gz libglitter-df538ad4f3b9ca3e98822299d6f233e219bc2fd4.tar.bz2 libglitter-df538ad4f3b9ca3e98822299d6f233e219bc2fd4.tar.xz |
test libglitter_desaturate_{double,float}
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libglitter_desaturate_double.c | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/libglitter_desaturate_double.c b/libglitter_desaturate_double.c index ba588f4..0797ddc 100644 --- a/libglitter_desaturate_double.c +++ b/libglitter_desaturate_double.c @@ -55,7 +55,77 @@ libglitter_desaturate_double(double **rasters, size_t nrasters, size_t rowsize, int main(void) { - return 0; /* TODO add test */ + double rasters1[4 * 10 * 3][4], *rasters1list[4], primary_ys[4], saturation; + double rasters2[4 * 10 * 3][4], *rasters2list[4], saturations[4]; + size_t i, j; + + void *randptr = malloc(1); + srand((unsigned int)(uintptr_t)randptr); + free(randptr); + +#define RANDOMISE(SAT)\ + do {\ + saturation = (SAT);\ + saturations[0] = saturation;\ + saturations[1] = saturation;\ + saturations[2] = saturation;\ + saturations[3] = saturation;\ + for (i = 0; i < 4; i++) {\ + rasters1list[i] = rasters1[i];\ + rasters2list[i] = rasters2[i];\ + primary_ys[i] = rand() / (double)RAND_MAX;\ + for (j = 0; j < 4 * 10 * 3; j++)\ + rasters1[j][i] = rand() / (double)RAND_MAX;\ + }\ + memcpy(rasters2, rasters1, sizeof(rasters1));\ + } while (0) + + RANDOMISE(rand() / (double)RAND_MAX); + libglitter_desaturate_double(rasters1list, 4, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 4, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(rand() / (double)RAND_MAX); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(rand() / (double)RAND_MAX); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, NULL); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, NULL); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(0); + libglitter_desaturate_double(rasters1list, 4, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 4, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(0); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(0); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, NULL); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, NULL); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(1); + libglitter_desaturate_double(rasters1list, 4, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 4, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(1); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(1); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, NULL); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, NULL); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + return 0; } |