aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-norm.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-07-16 00:59:42 +0200
committerMattias Andrée <maandree@kth.se>2017-07-16 00:59:42 +0200
commitc216ac3049102422a41ba2c9476b0dbf4f3e4034 (patch)
tree809793e1f01fafcb67422f654b6e9dbcab897660 /src/blind-norm.c
parentInstall the scripts (diff)
downloadblind-c216ac3049102422a41ba2c9476b0dbf4f3e4034.tar.gz
blind-c216ac3049102422a41ba2c9476b0dbf4f3e4034.tar.bz2
blind-c216ac3049102422a41ba2c9476b0dbf4f3e4034.tar.xz
Use #include instead of #define
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-norm.c')
-rw-r--r--src/blind-norm.c70
1 files changed, 37 insertions, 33 deletions
diff --git a/src/blind-norm.c b/src/blind-norm.c
index 13db67c..8a2b223 100644
--- a/src/blind-norm.c
+++ b/src/blind-norm.c
@@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
+#ifndef TYPE
#include "common.h"
USAGE("[-axyz]")
@@ -8,39 +9,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 x, y, z, a, norm;\
- do {\
- n = stream->ptr / stream->pixel_size;\
- for (i = 0; i < n; i++) {\
- x = ((TYPE *)(stream->buf))[4 * i + 0];\
- y = ((TYPE *)(stream->buf))[4 * i + 1];\
- z = ((TYPE *)(stream->buf))[4 * i + 2];\
- a = ((TYPE *)(stream->buf))[4 * i + 3];\
- norm = sqrt(x * x + y * y + z * z + a * a);\
- if (!skip_x)\
- ((TYPE *)(stream->buf))[4 * i + 0] = norm;\
- if (!skip_y)\
- ((TYPE *)(stream->buf))[4 * i + 1] = norm;\
- if (!skip_z)\
- ((TYPE *)(stream->buf))[4 * i + 2] = norm;\
- if (!skip_a)\
- ((TYPE *)(stream->buf))[4 * i + 3] = norm;\
- }\
- 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)
+#define FILE "blind-norm.c"
+#include "define-functions.h"
int
main(int argc, char *argv[])
@@ -82,3 +52,37 @@ main(int argc, char *argv[])
process(&stream);
return 0;
}
+
+#else
+
+static void
+PROCESS(struct stream *stream)
+{
+ size_t i, n;
+ TYPE x, y, z, a, norm;\
+ do {
+ n = stream->ptr / stream->pixel_size;
+ for (i = 0; i < n; i++) {
+ x = ((TYPE *)(stream->buf))[4 * i + 0];
+ y = ((TYPE *)(stream->buf))[4 * i + 1];
+ z = ((TYPE *)(stream->buf))[4 * i + 2];
+ a = ((TYPE *)(stream->buf))[4 * i + 3];
+ norm = sqrt(x * x + y * y + z * z + a * a);
+ if (!skip_x)
+ ((TYPE *)(stream->buf))[4 * i + 0] = norm;
+ if (!skip_y)
+ ((TYPE *)(stream->buf))[4 * i + 1] = norm;
+ if (!skip_z)
+ ((TYPE *)(stream->buf))[4 * i + 2] = norm;
+ if (!skip_a)
+ ((TYPE *)(stream->buf))[4 * i + 3] = norm;
+ }
+ 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);
+}
+
+#endif