From c216ac3049102422a41ba2c9476b0dbf4f3e4034 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 16 Jul 2017 00:59:42 +0200 Subject: Use #include instead of #define MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blind-premultiply.c | 58 ++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'src/blind-premultiply.c') diff --git a/src/blind-premultiply.c b/src/blind-premultiply.c index 3d9065a..5d46c06 100644 --- a/src/blind-premultiply.c +++ b/src/blind-premultiply.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#ifndef TYPE #include "common.h" USAGE("[-xyz]") @@ -7,33 +8,8 @@ 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, "");\ - 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) +#define FILE "blind-premultiply.c" +#include "define-functions.h" int main(int argc, char *argv[]) @@ -72,3 +48,31 @@ main(int argc, char *argv[]) process(&stream); return 0; } + +#else + +static void +PROCESS(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, ""); + 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); +} + +#endif -- cgit v1.2.3-70-g09d2