From 4dfdb29707bf7af8df1fae28907d5e492338e8b8 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 2 Jul 2017 16:59:44 +0200 Subject: Add blind-{,un}premultiply, blind-{dot,cross,quaternion}-product, and blind-vector-projection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blind-vector-projection.c | 91 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/blind-vector-projection.c (limited to 'src/blind-vector-projection.c') diff --git a/src/blind-vector-projection.c b/src/blind-vector-projection.c new file mode 100644 index 0000000..199e01f --- /dev/null +++ b/src/blind-vector-projection.c @@ -0,0 +1,91 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-r | -s] plane-stream") + +static int level = 1; + +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations" +#endif + +#define PROCESS(TYPE, SUFFIX)\ + static void\ + process_##SUFFIX(struct stream *left, struct stream *right, size_t n)\ + {\ + size_t i;\ + TYPE *lx, *ly, *lz, *la, rx, ry, rz, ra, x, y, z, a, norm;\ + for (i = 0; i < n; i += 4 * sizeof(TYPE)) {\ + lx = ((TYPE *)(left->buf + i)) + 0, rx = ((TYPE *)(right->buf + i))[0];\ + ly = ((TYPE *)(left->buf + i)) + 1, ry = ((TYPE *)(right->buf + i))[1];\ + lz = ((TYPE *)(left->buf + i)) + 2, rz = ((TYPE *)(right->buf + i))[2];\ + la = ((TYPE *)(left->buf + i)) + 3, ra = ((TYPE *)(right->buf + i))[3];\ + norm = rx * rx + ry * ry + rz * rz + ra * ra;\ + norm = sqrt(norm);\ + x = y = z = a = *lx * rx + *ly * ry + *lz * rz + *la * ra;\ + if (level) {\ + x *= rx;\ + y *= ry;\ + z *= rz;\ + a *= rz;\ + if (level > 1) {\ + x = *lx - x;\ + y = *ly - y;\ + z = *lz - z;\ + a = *la - a;\ + }\ + }\ + *lx = x;\ + *ly = y;\ + *lz = z;\ + *la = a;\ + }\ + } + +PROCESS(double, lf) +PROCESS(float, f) + +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic pop +#endif + +int +main(int argc, char *argv[]) +{ + struct stream left, right; + void (*process)(struct stream *left, struct stream *right, size_t n); + + ARGBEGIN { + case 'r': + if (level == 0) + usage(); + level = 2; + break; + case 's': + if (level == 2) + usage(); + level = 0; + break; + default: + usage(); + } ARGEND; + + if (argc != 2) + usage(); + + eopen_stream(&left, NULL); + eopen_stream(&right, argv[1]); + + if (!strcmp(left.pixfmt, "xyza")) + process = process_lf; + else if (!strcmp(left.pixfmt, "xyza f")) + process = process_f; + else + eprintf("pixel format %s is not supported, try xyza\n", left.pixfmt); + + fprint_stream_head(stdout, &left); + efflush(stdout, ""); + process_two_streams(&left, &right, STDOUT_FILENO, "", process); + return 0; +} -- cgit v1.2.3-70-g09d2