diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-07-02 16:59:44 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-07-02 16:59:44 +0200 |
| commit | 4dfdb29707bf7af8df1fae28907d5e492338e8b8 (patch) | |
| tree | 53cfdbd9271c30d0e58242aca6ff2fa09222a76b /src | |
| parent | Fix typo (diff) | |
| download | blind-4dfdb29707bf7af8df1fae28907d5e492338e8b8.tar.gz blind-4dfdb29707bf7af8df1fae28907d5e492338e8b8.tar.bz2 blind-4dfdb29707bf7af8df1fae28907d5e492338e8b8.tar.xz | |
Add blind-{,un}premultiply, blind-{dot,cross,quaternion}-product, and blind-vector-projection
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
| -rw-r--r-- | src/blind-cross-product.c | 62 | ||||
| -rw-r--r-- | src/blind-dot-product.c | 55 | ||||
| -rw-r--r-- | src/blind-premultiply.c | 76 | ||||
| -rw-r--r-- | src/blind-quaternion-product.c | 62 | ||||
| -rw-r--r-- | src/blind-unpremultiply.c | 78 | ||||
| -rw-r--r-- | src/blind-vector-projection.c | 91 |
6 files changed, 424 insertions, 0 deletions
diff --git a/src/blind-cross-product.c b/src/blind-cross-product.c new file mode 100644 index 0000000..693a6f2 --- /dev/null +++ b/src/blind-cross-product.c @@ -0,0 +1,62 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("right-hand-stream") + +#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;\ + 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;\ + x = *ly * *rz - *lz * *ry;\ + y = *lz * *rx - *lx * *rz;\ + z = *lx * *ry - *ly * *rx;\ + a = *la * *ra;\ + *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); + + UNOFLAGS(argc != 2); + + 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, "<stdout>"); + process_two_streams(&left, &right, STDOUT_FILENO, "<stdout>", process); + return 0; +} diff --git a/src/blind-dot-product.c b/src/blind-dot-product.c new file mode 100644 index 0000000..044b7bf --- /dev/null +++ b/src/blind-dot-product.c @@ -0,0 +1,55 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("right-hand-stream") + +#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;\ + 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;\ + *lx = *ly = *lz = *la = *lx * *rx + *ly * *ry + *lz * *rz + *la * *ra;\ + }\ + } + +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); + + UNOFLAGS(argc != 2); + + 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, "<stdout>"); + process_two_streams(&left, &right, STDOUT_FILENO, "<stdout>", process); + return 0; +} diff --git a/src/blind-premultiply.c b/src/blind-premultiply.c new file mode 100644 index 0000000..3f34f05 --- /dev/null +++ b/src/blind-premultiply.c @@ -0,0 +1,76 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-xyz]") + +static int skip_x = 0; +static int skip_y = 0; +static int skip_z = 0; + + +#define PROCESS(TYPE, SUFFIX)\ + static void\ + process_##SUFFIX(struct stream *stream)\ + {\ + size_t i, n;\ + TYPE a;\ + do {\ + n = stream->ptr / stream->pixel_size;\ + for (i = 0; i < n; i++) {\ + a = ((TYPE *)(stream->buf))[4 * i + 3];\ + if (!skip_x)\ + ((TYPE *)(stream->buf))[4 * i + 0] *= a;\ + if (!skip_y)\ + ((TYPE *)(stream->buf))[4 * i + 1] *= a;\ + if (!skip_z)\ + ((TYPE *)(stream->buf))[4 * i + 2] *= a;\ + }\ + n *= stream->pixel_size;\ + ewriteall(STDOUT_FILENO, stream->buf, n, "<stdout>");\ + memmove(stream->buf, stream->buf + n, stream->ptr -= n);\ + } while (eread_stream(stream, SIZE_MAX));\ + if (stream->ptr)\ + eprintf("%s: incomplete frame\n", stream->file);\ + } + +PROCESS(double, lf) +PROCESS(float, f) + + +int +main(int argc, char *argv[]) +{ + struct stream stream; + void (*process)(struct stream *stream); + + ARGBEGIN { + case 'x': + skip_x = 1; + break; + case 'y': + skip_y = 1; + break; + case 'z': + skip_z = 1; + break; + default: + usage(); + } ARGEND; + + if (argc) + usage(); + + eopen_stream(&stream, NULL); + + if (!strcmp(stream.pixfmt, "xyza")) + process = process_lf; + else if (!strcmp(stream.pixfmt, "xyza f")) + process = process_f; + else + eprintf("pixel format %s is not supported, try xyza\n", stream.pixfmt); + + fprint_stream_head(stdout, &stream); + efflush(stdout, "<stdout>"); + process(&stream); + return 0; +} diff --git a/src/blind-quaternion-product.c b/src/blind-quaternion-product.c new file mode 100644 index 0000000..6d24e24 --- /dev/null +++ b/src/blind-quaternion-product.c @@ -0,0 +1,62 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("right-hand-stream") + +#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;\ + 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;\ + x = *lx * *rx - *ly * *ry - *lz * *rz - *la * *ra;\ + y = *lz * *ra - *la * *rz + *lx * *ry + *ly * *rx;\ + z = *la * *ry - *ly * *rz + *lx * *rz + *lz * *rx;\ + a = *ly * *rz - *lz * *rz + *lx * *ra + *la * *rx;\ + *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); + + UNOFLAGS(argc != 2); + + 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, "<stdout>"); + process_two_streams(&left, &right, STDOUT_FILENO, "<stdout>", process); + return 0; +} diff --git a/src/blind-unpremultiply.c b/src/blind-unpremultiply.c new file mode 100644 index 0000000..d0639c8 --- /dev/null +++ b/src/blind-unpremultiply.c @@ -0,0 +1,78 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-xyz]") + +static int skip_x = 0; +static int skip_y = 0; +static int skip_z = 0; + + +#define PROCESS(TYPE, SUFFIX)\ + static void\ + process_##SUFFIX(struct stream *stream)\ + {\ + size_t i, n;\ + TYPE a;\ + do {\ + n = stream->ptr / stream->pixel_size;\ + for (i = 0; i < n; i++) {\ + a = ((TYPE *)(stream->buf))[4 * i + 3];\ + if (!a)\ + continue;\ + if (!skip_x)\ + ((TYPE *)(stream->buf))[4 * i + 0] /= a;\ + if (!skip_y)\ + ((TYPE *)(stream->buf))[4 * i + 1] /= a;\ + if (!skip_z)\ + ((TYPE *)(stream->buf))[4 * i + 2] /= a;\ + }\ + n *= stream->pixel_size;\ + ewriteall(STDOUT_FILENO, stream->buf, n, "<stdout>");\ + memmove(stream->buf, stream->buf + n, stream->ptr -= n);\ + } while (eread_stream(stream, SIZE_MAX));\ + if (stream->ptr)\ + eprintf("%s: incomplete frame\n", stream->file);\ + } + +PROCESS(double, lf) +PROCESS(float, f) + + +int +main(int argc, char *argv[]) +{ + struct stream stream; + void (*process)(struct stream *stream); + + ARGBEGIN { + case 'x': + skip_x = 1; + break; + case 'y': + skip_y = 1; + break; + case 'z': + skip_z = 1; + break; + default: + usage(); + } ARGEND; + + if (argc) + usage(); + + eopen_stream(&stream, NULL); + + if (!strcmp(stream.pixfmt, "xyza")) + process = process_lf; + else if (!strcmp(stream.pixfmt, "xyza f")) + process = process_f; + else + eprintf("pixel format %s is not supported, try xyza\n", stream.pixfmt); + + fprint_stream_head(stdout, &stream); + efflush(stdout, "<stdout>"); + process(&stream); + return 0; +} 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, "<stdout>"); + process_two_streams(&left, &right, STDOUT_FILENO, "<stdout>", process); + return 0; +} |
