From 835df7bd1e81852062dd70ce1a054fc9b510e50f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 25 Jul 2017 22:12:23 +0200 Subject: Fix blind-kernel and blind-temporal-mean,d add blind-{spatial,temporal}-arithm and blind-spatial-mean, and add support for multiple streams in blind-arithm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blind-temporal-arithm.c | 94 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/blind-temporal-arithm.c (limited to 'src/blind-temporal-arithm.c') diff --git a/src/blind-temporal-arithm.c b/src/blind-temporal-arithm.c new file mode 100644 index 0000000..f9f7b51 --- /dev/null +++ b/src/blind-temporal-arithm.c @@ -0,0 +1,94 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("operation") + +/* Because the syntax for a function returning a function pointer is disgusting. */ +typedef void (*process_func)(struct stream *stream, void *image); + +#define LIST_OPERATORS(PIXFMT, TYPE)\ + X(add, *img + *buf, PIXFMT, TYPE)\ + X(mul, *img * *buf, PIXFMT, TYPE)\ + X(min, MIN(*img, *buf), PIXFMT, TYPE)\ + X(max, MAX(*img, *buf), PIXFMT, TYPE) + +#define X(NAME, ALGO, PIXFMT, TYPE)\ + static void\ + process_##PIXFMT##_##NAME(struct stream *stream, void *image)\ + {\ + TYPE *buf, *img = image;\ + size_t i, n, j = 0, m = stream->frame_size / sizeof(TYPE);\ + do {\ + n = stream->ptr / sizeof(TYPE);\ + buf = (TYPE *)(stream->buf);\ + for (i = 0; i < n; i++, buf++) {\ + *img = ALGO;\ + if (++j == m) {\ + j = 0;\ + img = image;\ + } else {\ + img++;\ + }\ + }\ + n *= sizeof(TYPE);\ + memmove(stream->buf, stream->buf + n, stream->ptr -= n);\ + } while (eread_stream(stream, SIZE_MAX));\ + } +LIST_OPERATORS(lf, double) +LIST_OPERATORS(f, float) +#undef X + +static process_func +get_process_lf(const char *operation) +{ +#define X(NAME, _ALGO, PIXFMT, TYPE)\ + if (!strcmp(operation, #NAME)) return process_##PIXFMT##_##NAME; + LIST_OPERATORS(lf, double) +#undef X + eprintf("algorithm not recognised: %s\n", operation); + return NULL; +} + +static process_func +get_process_f(const char *operation) +{ +#define X(NAME, _ALGO, PIXFMT, TYPE)\ + if (!strcmp(operation, #NAME)) return process_##PIXFMT##_##NAME; + LIST_OPERATORS(f, float) +#undef X + eprintf("algorithm not recognised: %s\n", operation); + return NULL; +} + +int +main(int argc, char *argv[]) +{ + struct stream stream; + process_func process; + char *img; + + UNOFLAGS(argc != 1); + + eopen_stream(&stream, NULL); + + if (stream.encoding == DOUBLE) + process = get_process_lf(argv[0]); + else + process = get_process_f(argv[0]); + + echeck_dimensions(&stream, WIDTH | HEIGHT, NULL); + img = emalloc(stream.frame_size); + if (!eread_frame(&stream, img)) + eprintf("video has no frames\n"); + + process(&stream, img); + if (stream.ptr) + eprintf("%s: incomplete frame\n", stream.file); + + stream.frames = 1; + fprint_stream_head(stdout, &stream); + efflush(stdout, ""); + ewriteall(STDOUT_FILENO, img, stream.frame_size, ""); + free(img); + return 0; +} -- cgit v1.2.3-70-g09d2