aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-01-27 21:31:32 +0100
committerMattias Andrée <maandree@kth.se>2023-01-27 21:31:41 +0100
commit51a7b0d48fa4539fcb8104afbcd8d010653ad428 (patch)
treead588867c4682ef7b728cf180e0a76fcf06b246b
parentTest libglitter_create_render_context and libglitter_update_render_context (diff)
downloadlibglitter-51a7b0d48fa4539fcb8104afbcd8d010653ad428.tar.gz
libglitter-51a7b0d48fa4539fcb8104afbcd8d010653ad428.tar.bz2
libglitter-51a7b0d48fa4539fcb8104afbcd8d010653ad428.tar.xz
Test libglitter_compose_{double,float,uint{64,32,16,8}}
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--libglitter_compose_double.c354
-rw-r--r--libglitter_compose_uint64.c11
2 files changed, 352 insertions, 13 deletions
diff --git a/libglitter_compose_double.c b/libglitter_compose_double.c
index 53da733..0419f4a 100644
--- a/libglitter_compose_double.c
+++ b/libglitter_compose_double.c
@@ -114,15 +114,363 @@ libglitter_compose_double(double **outputs, const double *restrict input, size_t
#else
-# ifndef ONLY_INT_COMPATIBLE
int
main(void)
{
- return 0; /* TODO add test */
+ double input[20 * 60];
+ double output1[3 * 10 * 4];
+ double output2[sizeof(output1) / sizeof(*output1)];
+ double output3[sizeof(output1) / sizeof(*output1)];
+ double zeroes[sizeof(input) / sizeof(*input)];
+ double *outputs[3];
+ LIBGLITTER_RENDER_CONTEXT *ctx;
+ uint8_t cellmap[12];
+ uint8_t ncellvalues[3];
+ size_t input_rowsize;
+ size_t output_rowsize;
+ size_t output_cellsize;
+ size_t wmul, hmul;
+ size_t i;
+
+#define OPOS(X, Y) ((Y) * output_rowsize * output_cellsize + (X) * output_cellsize)
+#define IPOS(X, Y, IX, IY) (((Y) * hmul + (IY)) * input_rowsize + ((X) * wmul + (IX)))
+#define V(VAL) ((double)(VAL))
+#define VV(VAL) (V(VAL) + (double)1 / 2)
+
+ memset(zeroes, 0, sizeof(zeroes));
+
+ /* vstrips */
+ for (i = 0; i < 2; i++) {
+ input_rowsize = 5 * 3;
+ output_rowsize = 10;
+ output_cellsize = 4;
+ wmul = 3;
+ hmul = 1;
+ ncellvalues[0] = 1;
+ ncellvalues[1] = 1;
+ ncellvalues[2] = 1;
+ cellmap[0] = !i ? 0 : 1;
+ cellmap[1] = !i ? 1 : 2;
+ cellmap[2] = !i ? 2 : 0;
+ outputs[0] = !i ? output1 : output3;
+ outputs[1] = !i ? output2 : output1;
+ outputs[2] = !i ? output3 : output2;
+ memset(input, 0, sizeof(input));
+ memset(output1, 0, sizeof(output1));
+ memset(output2, 0, sizeof(output2));
+ memset(output3, 0, sizeof(output3));
+ input[IPOS(0, 0, 0, 0)] = V(111);
+ input[IPOS(0, 0, 1, 0)] = V(112);
+ input[IPOS(0, 0, 2, 0)] = V(113);
+ input[IPOS(0, 1, 0, 0)] = V(121);
+ input[IPOS(0, 1, 1, 0)] = V(122);
+ input[IPOS(0, 1, 2, 0)] = V(123);
+ input[IPOS(1, 0, 0, 0)] = V(211);
+ input[IPOS(1, 0, 1, 0)] = V(212);
+ input[IPOS(1, 0, 2, 0)] = V(213);
+ input[IPOS(1, 1, 0, 0)] = V(221);
+ input[IPOS(1, 1, 1, 0)] = V(222);
+ input[IPOS(1, 1, 2, 0)] = V(223);
+ input[IPOS(2, 0, 0, 0)] = V(311);
+ input[IPOS(2, 0, 1, 0)] = V(312);
+ input[IPOS(2, 0, 2, 0)] = V(313);
+ input[IPOS(2, 1, 0, 0)] = V(321);
+ input[IPOS(2, 1, 1, 0)] = V(322);
+ input[IPOS(2, 1, 2, 0)] = V(323);
+ ctx = libglitter_create_render_context(3, input_rowsize, wmul, hmul, cellmap, ncellvalues);
+ ASSERT(ctx);
+ ASSERT(ctx->render_method == RENDER_METHOD_VSTRIPS);
+ libglitter_compose_double(outputs, input, output_rowsize, output_cellsize, 3, 2, ctx);
+ ASSERT(output1[OPOS(0, 0)] == V(111));
+ ASSERT(output2[OPOS(0, 0)] == V(112));
+ ASSERT(output3[OPOS(0, 0)] == V(113));
+ ASSERT(output1[OPOS(0, 1)] == V(121));
+ ASSERT(output2[OPOS(0, 1)] == V(122));
+ ASSERT(output3[OPOS(0, 1)] == V(123));
+ ASSERT(output1[OPOS(1, 0)] == V(211));
+ ASSERT(output2[OPOS(1, 0)] == V(212));
+ ASSERT(output3[OPOS(1, 0)] == V(213));
+ ASSERT(output1[OPOS(1, 1)] == V(221));
+ ASSERT(output2[OPOS(1, 1)] == V(222));
+ ASSERT(output3[OPOS(1, 1)] == V(223));
+ ASSERT(output1[OPOS(2, 0)] == V(311));
+ ASSERT(output2[OPOS(2, 0)] == V(312));
+ ASSERT(output3[OPOS(2, 0)] == V(313));
+ ASSERT(output1[OPOS(2, 1)] == V(321));
+ ASSERT(output2[OPOS(2, 1)] == V(322));
+ ASSERT(output3[OPOS(2, 1)] == V(323));
+ output1[OPOS(0, 0)] = 0;
+ output2[OPOS(0, 0)] = 0;
+ output3[OPOS(0, 0)] = 0;
+ output1[OPOS(0, 1)] = 0;
+ output2[OPOS(0, 1)] = 0;
+ output3[OPOS(0, 1)] = 0;
+ output1[OPOS(1, 0)] = 0;
+ output2[OPOS(1, 0)] = 0;
+ output3[OPOS(1, 0)] = 0;
+ output1[OPOS(1, 1)] = 0;
+ output2[OPOS(1, 1)] = 0;
+ output3[OPOS(1, 1)] = 0;
+ output1[OPOS(2, 0)] = 0;
+ output2[OPOS(2, 0)] = 0;
+ output3[OPOS(2, 0)] = 0;
+ output1[OPOS(2, 1)] = 0;
+ output2[OPOS(2, 1)] = 0;
+ output3[OPOS(2, 1)] = 0;
+ ASSERT(!memcmp(output1, zeroes, sizeof(output1)));
+ ASSERT(!memcmp(output2, zeroes, sizeof(output2)));
+ ASSERT(!memcmp(output3, zeroes, sizeof(output3)));
+ libglitter_free_render_context(ctx);
+ }
+
+ /* hstrips */
+ for (i = 0; i < 2; i++) {
+ input_rowsize = 5;
+ output_rowsize = 10;
+ output_cellsize = 4;
+ wmul = 1;
+ hmul = 3;
+ ncellvalues[0] = 1;
+ ncellvalues[1] = 1;
+ ncellvalues[2] = 1;
+ cellmap[0] = !i ? 0 : 1;
+ cellmap[1] = !i ? 1 : 2;
+ cellmap[2] = !i ? 2 : 0;
+ outputs[0] = !i ? output1 : output3;
+ outputs[1] = !i ? output2 : output1;
+ outputs[2] = !i ? output3 : output2;
+ memset(input, 0, sizeof(input));
+ memset(output1, 0, sizeof(output1));
+ memset(output2, 0, sizeof(output2));
+ memset(output3, 0, sizeof(output3));
+ input[IPOS(0, 0, 0, 0)] = V(111);
+ input[IPOS(0, 0, 0, 1)] = V(112);
+ input[IPOS(0, 0, 0, 2)] = V(113);
+ input[IPOS(1, 0, 0, 0)] = V(121);
+ input[IPOS(1, 0, 0, 1)] = V(122);
+ input[IPOS(1, 0, 0, 2)] = V(123);
+ input[IPOS(0, 1, 0, 0)] = V(211);
+ input[IPOS(0, 1, 0, 1)] = V(212);
+ input[IPOS(0, 1, 0, 2)] = V(213);
+ input[IPOS(1, 1, 0, 0)] = V(221);
+ input[IPOS(1, 1, 0, 1)] = V(222);
+ input[IPOS(1, 1, 0, 2)] = V(223);
+ input[IPOS(0, 2, 0, 0)] = V(311);
+ input[IPOS(0, 2, 0, 1)] = V(312);
+ input[IPOS(0, 2, 0, 2)] = V(313);
+ input[IPOS(1, 2, 0, 0)] = V(321);
+ input[IPOS(1, 2, 0, 1)] = V(322);
+ input[IPOS(1, 2, 0, 2)] = V(323);
+ ctx = libglitter_create_render_context(3, input_rowsize, wmul, hmul, cellmap, ncellvalues);
+ ASSERT(ctx);
+ ASSERT(ctx->render_method == RENDER_METHOD_HSTRIPS);
+ libglitter_compose_double(outputs, input, output_rowsize, output_cellsize, 2, 3, ctx);
+ ASSERT(output1[OPOS(0, 0)] == V(111));
+ ASSERT(output2[OPOS(0, 0)] == V(112));
+ ASSERT(output3[OPOS(0, 0)] == V(113));
+ ASSERT(output1[OPOS(1, 0)] == V(121));
+ ASSERT(output2[OPOS(1, 0)] == V(122));
+ ASSERT(output3[OPOS(1, 0)] == V(123));
+ ASSERT(output1[OPOS(0, 1)] == V(211));
+ ASSERT(output2[OPOS(0, 1)] == V(212));
+ ASSERT(output3[OPOS(0, 1)] == V(213));
+ ASSERT(output1[OPOS(1, 1)] == V(221));
+ ASSERT(output2[OPOS(1, 1)] == V(222));
+ ASSERT(output3[OPOS(1, 1)] == V(223));
+ ASSERT(output1[OPOS(0, 2)] == V(311));
+ ASSERT(output2[OPOS(0, 2)] == V(312));
+ ASSERT(output3[OPOS(0, 2)] == V(313));
+ ASSERT(output1[OPOS(1, 2)] == V(321));
+ ASSERT(output2[OPOS(1, 2)] == V(322));
+ ASSERT(output3[OPOS(1, 2)] == V(323));
+ output1[OPOS(0, 0)] = 0;
+ output2[OPOS(0, 0)] = 0;
+ output3[OPOS(0, 0)] = 0;
+ output1[OPOS(1, 0)] = 0;
+ output2[OPOS(1, 0)] = 0;
+ output3[OPOS(1, 0)] = 0;
+ output1[OPOS(0, 1)] = 0;
+ output2[OPOS(0, 1)] = 0;
+ output3[OPOS(0, 1)] = 0;
+ output1[OPOS(1, 1)] = 0;
+ output2[OPOS(1, 1)] = 0;
+ output3[OPOS(1, 1)] = 0;
+ output1[OPOS(0, 2)] = 0;
+ output2[OPOS(0, 2)] = 0;
+ output3[OPOS(0, 2)] = 0;
+ output1[OPOS(1, 2)] = 0;
+ output2[OPOS(1, 2)] = 0;
+ output3[OPOS(1, 2)] = 0;
+ ASSERT(!memcmp(output1, zeroes, sizeof(output1)));
+ ASSERT(!memcmp(output2, zeroes, sizeof(output2)));
+ ASSERT(!memcmp(output3, zeroes, sizeof(output3)));
+ libglitter_free_render_context(ctx);
+ }
+
+ /* simple */
+ for (i = 0; i < 2; i++) {
+ input_rowsize = 14;
+ output_rowsize = 4;
+ output_cellsize = 2;
+ wmul = !i ? 4 : 1;
+ hmul = !i ? 1 : 4;
+ ncellvalues[0] = !i ? 1 : 2;
+ ncellvalues[1] = !i ? 1 : 1;
+ ncellvalues[2] = !i ? 2 : 1;
+ cellmap[0] = !i ? 0 : 1;
+ cellmap[1] = !i ? 1 : 2;
+ cellmap[2] = !i ? 2 : 0;
+ cellmap[3] = !i ? 2 : 0;
+ outputs[0] = !i ? output1 : output3;
+ outputs[1] = !i ? output2 : output1;
+ outputs[2] = !i ? output3 : output2;
+ memset(input, 0, sizeof(input));
+ memset(output1, 0, sizeof(output1));
+ memset(output2, 0, sizeof(output2));
+ memset(output3, 0, sizeof(output3));
+ input[IPOS(0, 0, !i ? 0 : 0, i ? 0 : 0)] = V(111);
+ input[IPOS(0, 0, !i ? 1 : 0, i ? 1 : 0)] = V(112);
+ input[IPOS(0, 0, !i ? 2 : 0, i ? 2 : 0)] = V(113);
+ input[IPOS(0, 0, !i ? 3 : 0, i ? 3 : 0)] = V(115);
+ input[IPOS(1, 0, !i ? 0 : 0, i ? 0 : 0)] = V(121);
+ input[IPOS(1, 0, !i ? 1 : 0, i ? 1 : 0)] = V(122);
+ input[IPOS(1, 0, !i ? 2 : 0, i ? 2 : 0)] = V(123);
+ input[IPOS(1, 0, !i ? 3 : 0, i ? 3 : 0)] = V(124);
+ input[IPOS(0, 1, !i ? 0 : 0, i ? 0 : 0)] = V(211);
+ input[IPOS(0, 1, !i ? 1 : 0, i ? 1 : 0)] = V(212);
+ input[IPOS(0, 1, !i ? 2 : 0, i ? 2 : 0)] = V(213);
+ input[IPOS(0, 1, !i ? 3 : 0, i ? 3 : 0)] = V(215);
+ input[IPOS(1, 1, !i ? 0 : 0, i ? 0 : 0)] = V(221);
+ input[IPOS(1, 1, !i ? 1 : 0, i ? 1 : 0)] = V(222);
+ input[IPOS(1, 1, !i ? 2 : 0, i ? 2 : 0)] = V(223);
+ input[IPOS(1, 1, !i ? 3 : 0, i ? 3 : 0)] = V(224);
+ input[IPOS(0, 2, !i ? 0 : 0, i ? 0 : 0)] = V(311);
+ input[IPOS(0, 2, !i ? 1 : 0, i ? 1 : 0)] = V(312);
+ input[IPOS(0, 2, !i ? 2 : 0, i ? 2 : 0)] = V(313);
+ input[IPOS(0, 2, !i ? 3 : 0, i ? 3 : 0)] = V(315);
+ input[IPOS(1, 2, !i ? 0 : 0, i ? 0 : 0)] = V(321);
+ input[IPOS(1, 2, !i ? 1 : 0, i ? 1 : 0)] = V(322);
+ input[IPOS(1, 2, !i ? 2 : 0, i ? 2 : 0)] = V(323);
+ input[IPOS(1, 2, !i ? 3 : 0, i ? 3 : 0)] = V(324);
+ ctx = libglitter_create_render_context(3, input_rowsize, wmul, hmul, cellmap, ncellvalues);
+ ASSERT(ctx);
+ ASSERT(ctx->render_method == RENDER_METHOD_SIMPLE);
+ libglitter_compose_double(outputs, input, output_rowsize, output_cellsize, 2, 3, ctx);
+ ASSERT(output1[OPOS(0, 0)] == V(111));
+ ASSERT(output2[OPOS(0, 0)] == V(112));
+ ASSERT(output3[OPOS(0, 0)] == V(114));
+ ASSERT(output1[OPOS(1, 0)] == V(121));
+ ASSERT(output2[OPOS(1, 0)] == V(122));
+ ASSERT(output3[OPOS(1, 0)] == VV(123));
+ ASSERT(output1[OPOS(0, 1)] == V(211));
+ ASSERT(output2[OPOS(0, 1)] == V(212));
+ ASSERT(output3[OPOS(0, 1)] == V(214));
+ ASSERT(output1[OPOS(1, 1)] == V(221));
+ ASSERT(output2[OPOS(1, 1)] == V(222));
+ ASSERT(output3[OPOS(1, 1)] == VV(223));
+ ASSERT(output1[OPOS(0, 2)] == V(311));
+ ASSERT(output2[OPOS(0, 2)] == V(312));
+ ASSERT(output3[OPOS(0, 2)] == V(314));
+ ASSERT(output1[OPOS(1, 2)] == V(321));
+ ASSERT(output2[OPOS(1, 2)] == V(322));
+ ASSERT(output3[OPOS(1, 2)] == VV(323));
+ output1[OPOS(0, 0)] = 0;
+ output2[OPOS(0, 0)] = 0;
+ output3[OPOS(0, 0)] = 0;
+ output1[OPOS(1, 0)] = 0;
+ output2[OPOS(1, 0)] = 0;
+ output3[OPOS(1, 0)] = 0;
+ output1[OPOS(0, 1)] = 0;
+ output2[OPOS(0, 1)] = 0;
+ output3[OPOS(0, 1)] = 0;
+ output1[OPOS(1, 1)] = 0;
+ output2[OPOS(1, 1)] = 0;
+ output3[OPOS(1, 1)] = 0;
+ output1[OPOS(0, 2)] = 0;
+ output2[OPOS(0, 2)] = 0;
+ output3[OPOS(0, 2)] = 0;
+ output1[OPOS(1, 2)] = 0;
+ output2[OPOS(1, 2)] = 0;
+ output3[OPOS(1, 2)] = 0;
+ ASSERT(!memcmp(output1, zeroes, sizeof(output1)));
+ ASSERT(!memcmp(output2, zeroes, sizeof(output2)));
+ ASSERT(!memcmp(output3, zeroes, sizeof(output3)));
+ libglitter_free_render_context(ctx);
+ }
+
+ /* generic */
+ for (i = 0; i < 1; i++) {
+ input_rowsize = 14;
+ output_rowsize = 4;
+ output_cellsize = 2;
+ wmul = !i ? 3 : 1;
+ hmul = !i ? 1 : 3;
+ ncellvalues[0] = !i ? 1 : 2;
+ ncellvalues[1] = !i ? 2 : 1;
+ cellmap[0] = !i ? 0 : 1;
+ cellmap[1] = !i ? 1 : 0;
+ cellmap[2] = !i ? 1 : 0;
+ outputs[0] = !i ? output1 : output2;
+ outputs[1] = !i ? output2 : output1;
+ outputs[2] = NULL;
+ memset(input, 0, sizeof(input));
+ memset(output1, 0, sizeof(output1));
+ memset(output2, 0, sizeof(output2));
+ input[IPOS(0, 0, !i ? 0 : 0, i ? 0 : 0)] = V(111);
+ input[IPOS(0, 0, !i ? 1 : 0, i ? 1 : 0)] = V(112);
+ input[IPOS(0, 0, !i ? 2 : 0, i ? 2 : 0)] = V(114);
+ input[IPOS(1, 0, !i ? 0 : 0, i ? 0 : 0)] = V(121);
+ input[IPOS(1, 0, !i ? 1 : 0, i ? 1 : 0)] = V(122);
+ input[IPOS(1, 0, !i ? 2 : 0, i ? 2 : 0)] = V(123);
+ input[IPOS(0, 1, !i ? 0 : 0, i ? 0 : 0)] = V(211);
+ input[IPOS(0, 1, !i ? 1 : 0, i ? 1 : 0)] = V(212);
+ input[IPOS(0, 1, !i ? 2 : 0, i ? 2 : 0)] = V(214);
+ input[IPOS(1, 1, !i ? 0 : 0, i ? 0 : 0)] = V(221);
+ input[IPOS(1, 1, !i ? 1 : 0, i ? 1 : 0)] = V(222);
+ input[IPOS(1, 1, !i ? 2 : 0, i ? 2 : 0)] = V(223);
+ input[IPOS(0, 2, !i ? 0 : 0, i ? 0 : 0)] = V(311);
+ input[IPOS(0, 2, !i ? 1 : 0, i ? 1 : 0)] = V(312);
+ input[IPOS(0, 2, !i ? 2 : 0, i ? 2 : 0)] = V(314);
+ input[IPOS(1, 2, !i ? 0 : 0, i ? 0 : 0)] = V(321);
+ input[IPOS(1, 2, !i ? 1 : 0, i ? 1 : 0)] = V(322);
+ input[IPOS(1, 2, !i ? 2 : 0, i ? 2 : 0)] = V(323);
+ ctx = libglitter_create_render_context(2, input_rowsize, wmul, hmul, cellmap, ncellvalues);
+ ASSERT(ctx);
+ ASSERT(ctx->render_method == RENDER_METHOD_GENERIC);
+ libglitter_compose_double(outputs, input, output_rowsize, output_cellsize, 2, 3, ctx);
+ ASSERT(output1[OPOS(0, 0)] == V(111));
+ ASSERT(output2[OPOS(0, 0)] == V(113));
+ ASSERT(output1[OPOS(1, 0)] == V(121));
+ ASSERT(output2[OPOS(1, 0)] == VV(122));
+ ASSERT(output1[OPOS(0, 1)] == V(211));
+ ASSERT(output2[OPOS(0, 1)] == V(213));
+ ASSERT(output1[OPOS(1, 1)] == V(221));
+ ASSERT(output2[OPOS(1, 1)] == VV(222));
+ ASSERT(output1[OPOS(0, 2)] == V(311));
+ ASSERT(output2[OPOS(0, 2)] == V(313));
+ ASSERT(output1[OPOS(1, 2)] == V(321));
+ ASSERT(output2[OPOS(1, 2)] == VV(322));
+ output1[OPOS(0, 0)] = 0;
+ output2[OPOS(0, 0)] = 0;
+ output1[OPOS(1, 0)] = 0;
+ output2[OPOS(1, 0)] = 0;
+ output1[OPOS(0, 1)] = 0;
+ output2[OPOS(0, 1)] = 0;
+ output1[OPOS(1, 1)] = 0;
+ output2[OPOS(1, 1)] = 0;
+ output1[OPOS(0, 2)] = 0;
+ output2[OPOS(0, 2)] = 0;
+ output1[OPOS(1, 2)] = 0;
+ output2[OPOS(1, 2)] = 0;
+ ASSERT(!memcmp(output1, zeroes, sizeof(output1)));
+ ASSERT(!memcmp(output2, zeroes, sizeof(output2)));
+ libglitter_free_render_context(ctx);
+ }
+
+ return 0;
}
-# endif
#endif
diff --git a/libglitter_compose_uint64.c b/libglitter_compose_uint64.c
index 6784055..323f10b 100644
--- a/libglitter_compose_uint64.c
+++ b/libglitter_compose_uint64.c
@@ -2,6 +2,7 @@
#include "common.h"
#define ONLY_INT_COMPATIBLE
#define double uint64_t
+#define libglitter_compose_double libglitter_compose_uint64
#include "libglitter_compose_double.c"
#ifdef greater_t
# define MIX(A, B) (((greater_t)(A) + (greater_t)(B)) >> 1)
@@ -93,14 +94,4 @@ libglitter_compose_uint64(uint64_t **outputs, const uint64_t *restrict input, si
}
-#else
-
-
-int
-main(void)
-{
- return 0; /* TODO add test */
-}
-
-
#endif