aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-sinc-wave.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/blind-sinc-wave.c')
-rw-r--r--src/blind-sinc-wave.c130
1 files changed, 67 insertions, 63 deletions
diff --git a/src/blind-sinc-wave.c b/src/blind-sinc-wave.c
index f809c8e..ed36ce8 100644
--- a/src/blind-sinc-wave.c
+++ b/src/blind-sinc-wave.c
@@ -1,73 +1,13 @@
/* See LICENSE file for copyright and license details. */
+#ifndef TYPE
#include "common.h"
USAGE("[-e] [theta0-stream]")
static int equal = 0;
-#define PROCESS(TYPE, SUFFIX)\
- static void\
- process_##SUFFIX(struct stream *grad, struct stream *theta0)\
- {\
- size_t i, n, m = 0;\
- TYPE *theta0xyza;\
- TYPE x, theta0x = 0;\
- TYPE y, theta0y = 0;\
- TYPE z, theta0z = 0;\
- TYPE a, theta0a = 0;\
- do {\
- if (!m) {\
- m = grad->frame_size;\
- if (theta0) {\
- while (theta0->ptr < theta0->frame_size)\
- if (!eread_stream(theta0, theta0->frame_size - theta0->ptr))\
- return;\
- theta0xyza = (TYPE *)theta0->buf;\
- theta0x = (theta0xyza)[0];\
- theta0y = (theta0xyza)[1];\
- theta0z = (theta0xyza)[2];\
- theta0a = (theta0xyza)[3];\
- memmove(theta0->buf, theta0->buf + theta0->frame_size,\
- theta0->ptr -= theta0->frame_size);\
- }\
- }\
- n = MIN(grad->ptr, m) / grad->pixel_size;\
- if (equal) {\
- for (i = 0; i < n; i++) {\
- a = ((TYPE *)(grad->buf))[4 * i + 3];\
- a = (a ? sin(a + theta0y) / a : sin(a + theta0y)) / 2 + (TYPE)0.5;\
- ((TYPE *)(grad->buf))[4 * i + 0] = a;\
- ((TYPE *)(grad->buf))[4 * i + 1] = a;\
- ((TYPE *)(grad->buf))[4 * i + 2] = a;\
- ((TYPE *)(grad->buf))[4 * i + 3] = a;\
- }\
- } else {\
- for (i = 0; i < n; i++) {\
- x = ((TYPE *)(grad->buf))[4 * i + 0];\
- y = ((TYPE *)(grad->buf))[4 * i + 1];\
- z = ((TYPE *)(grad->buf))[4 * i + 2];\
- a = ((TYPE *)(grad->buf))[4 * i + 3];\
- x = (x ? sin(x + theta0x) / x : sin(x + theta0x)) / 2 + (TYPE)0.5;\
- y = (y ? sin(y + theta0y) / y : sin(y + theta0y)) / 2 + (TYPE)0.5;\
- z = (z ? sin(z + theta0z) / z : sin(z + theta0z)) / 2 + (TYPE)0.5;\
- a = (a ? sin(a + theta0a) / a : sin(a + theta0a)) / 2 + (TYPE)0.5;\
- ((TYPE *)(grad->buf))[4 * i + 0] = x;\
- ((TYPE *)(grad->buf))[4 * i + 1] = y;\
- ((TYPE *)(grad->buf))[4 * i + 2] = z;\
- ((TYPE *)(grad->buf))[4 * i + 3] = a;\
- }\
- }\
- n *= grad->pixel_size;\
- m -= n;\
- ewriteall(STDOUT_FILENO, grad->buf, n, "<stdout>");\
- memmove(grad->buf, grad->buf + n, grad->ptr -= n);\
- } while (eread_stream(grad, SIZE_MAX));\
- if (grad->ptr)\
- eprintf("%s: incomplete frame\n", grad->file);\
- }
-
-PROCESS(double, lf)
-PROCESS(float, f)
+#define FILE "blind-sinc-wave.c"
+#include "define-functions.h"
int
main(int argc, char *argv[])
@@ -111,3 +51,67 @@ main(int argc, char *argv[])
process(&stream, have_theta0 ? &theta0 : NULL);
return 0;
}
+
+#else
+
+static void
+PROCESS(struct stream *grad, struct stream *theta0)
+{
+ size_t i, n, m = 0;
+ TYPE *theta0xyza;
+ TYPE x, theta0x = 0;
+ TYPE y, theta0y = 0;
+ TYPE z, theta0z = 0;
+ TYPE a, theta0a = 0;
+ do {
+ if (!m) {
+ m = grad->frame_size;
+ if (theta0) {
+ while (theta0->ptr < theta0->frame_size)
+ if (!eread_stream(theta0, theta0->frame_size - theta0->ptr))
+ return;
+ theta0xyza = (TYPE *)theta0->buf;
+ theta0x = (theta0xyza)[0];
+ theta0y = (theta0xyza)[1];
+ theta0z = (theta0xyza)[2];
+ theta0a = (theta0xyza)[3];
+ memmove(theta0->buf, theta0->buf + theta0->frame_size,
+ theta0->ptr -= theta0->frame_size);
+ }
+ }
+ n = MIN(grad->ptr, m) / grad->pixel_size;
+ if (equal) {
+ for (i = 0; i < n; i++) {
+ a = ((TYPE *)(grad->buf))[4 * i + 3];
+ a = (a ? sin(a + theta0y) / a : sin(a + theta0y)) / 2 + (TYPE)0.5;
+ ((TYPE *)(grad->buf))[4 * i + 0] = a;
+ ((TYPE *)(grad->buf))[4 * i + 1] = a;
+ ((TYPE *)(grad->buf))[4 * i + 2] = a;
+ ((TYPE *)(grad->buf))[4 * i + 3] = a;
+ }
+ } else {
+ for (i = 0; i < n; i++) {
+ x = ((TYPE *)(grad->buf))[4 * i + 0];
+ y = ((TYPE *)(grad->buf))[4 * i + 1];
+ z = ((TYPE *)(grad->buf))[4 * i + 2];
+ a = ((TYPE *)(grad->buf))[4 * i + 3];
+ x = (x ? sin(x + theta0x) / x : sin(x + theta0x)) / 2 + (TYPE)0.5;
+ y = (y ? sin(y + theta0y) / y : sin(y + theta0y)) / 2 + (TYPE)0.5;
+ z = (z ? sin(z + theta0z) / z : sin(z + theta0z)) / 2 + (TYPE)0.5;
+ a = (a ? sin(a + theta0a) / a : sin(a + theta0a)) / 2 + (TYPE)0.5;
+ ((TYPE *)(grad->buf))[4 * i + 0] = x;
+ ((TYPE *)(grad->buf))[4 * i + 1] = y;
+ ((TYPE *)(grad->buf))[4 * i + 2] = z;
+ ((TYPE *)(grad->buf))[4 * i + 3] = a;
+ }
+ }
+ n *= grad->pixel_size;
+ m -= n;
+ ewriteall(STDOUT_FILENO, grad->buf, n, "<stdout>");
+ memmove(grad->buf, grad->buf + n, grad->ptr -= n);
+ } while (eread_stream(grad, SIZE_MAX));
+ if (grad->ptr)
+ eprintf("%s: incomplete frame\n", grad->file);
+}
+
+#endif