aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-arithm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/blind-arithm.c')
-rw-r--r--src/blind-arithm.c66
1 files changed, 42 insertions, 24 deletions
diff --git a/src/blind-arithm.c b/src/blind-arithm.c
index e8c1f95..4b540a6 100644
--- a/src/blind-arithm.c
+++ b/src/blind-arithm.c
@@ -18,40 +18,56 @@ static int skip_z = 0;
/* Because the syntax for a function returning a function pointer is disgusting. */
typedef void (*process_func)(struct stream *left, struct stream *right, size_t n);
-#define LIST_OPERATORS\
- X(add, *lh += rh)\
- X(sub, *lh -= rh)\
- X(mul, *lh *= rh)\
- X(div, *lh /= rh)\
- X(exp, *lh = pow(*lh, rh))\
- X(log, *lh = log(*lh) / log(rh))\
- X(min, *lh = MIN(*lh, rh))\
- X(max, *lh = MAX(*lh, rh))\
- X(abs, *lh = fabs(*lh - rh) + rh)
+#define LIST_OPERATORS(PIXFMT, TYPE, SUFFIX)\
+ X(add, *lh += rh, PIXFMT, TYPE)\
+ X(sub, *lh -= rh, PIXFMT, TYPE)\
+ X(mul, *lh *= rh, PIXFMT, TYPE)\
+ X(div, *lh /= rh, PIXFMT, TYPE)\
+ X(exp, *lh = pow##SUFFIX(*lh, rh), PIXFMT, TYPE)\
+ X(log, *lh = log##SUFFIX(*lh) / log##SUFFIX(rh), PIXFMT, TYPE)\
+ X(min, *lh = MIN(*lh, rh), PIXFMT, TYPE)\
+ X(max, *lh = MAX(*lh, rh), PIXFMT, TYPE)\
+ X(abs, *lh = fabs##SUFFIX(*lh - rh) + rh, PIXFMT, TYPE)
-#define C(CH, CHI, ALGO)\
- (!skip_##CH ? ((lh = ((double *)(left->buf + i)) + (CHI),\
- rh = ((double *)(right->buf + i))[CHI],\
+#define C(CH, CHI, ALGO, TYPE)\
+ (!skip_##CH ? ((lh = ((TYPE *)(left->buf + i)) + (CHI),\
+ rh = ((TYPE *)(right->buf + i))[CHI],\
(ALGO)), 0) : 0)
-#define X(NAME, ALGO)\
+#define X(NAME, ALGO, PIXFMT, TYPE)\
static void\
- process_lf_##NAME(struct stream *left, struct stream *right, size_t n)\
+ process_##PIXFMT##_##NAME(struct stream *left, struct stream *right, size_t n)\
{\
size_t i;\
- double *lh, rh;\
- for (i = 0; i < n; i += 4 * sizeof(double))\
- C(x, 0, ALGO), C(y, 1, ALGO), C(z, 2, ALGO), C(a, 3, ALGO);\
+ TYPE *lh, rh;\
+ for (i = 0; i < n; i += 4 * sizeof(TYPE)) {\
+ C(x, 0, ALGO, TYPE);\
+ C(y, 1, ALGO, TYPE);\
+ C(z, 2, ALGO, TYPE);\
+ C(a, 3, ALGO, TYPE);\
+ }\
}
-LIST_OPERATORS
+LIST_OPERATORS(xyza, double,)
+LIST_OPERATORS(xyzaf, float, f)
#undef X
static process_func
-get_lf_process(const char *operation)
+get_process_xyza(const char *operation)
{
-#define X(NAME, ALGO)\
- if (!strcmp(operation, #NAME)) return process_lf_##NAME;
-LIST_OPERATORS
+#define X(NAME, ALGO, PIXFMT, TYPE)\
+ if (!strcmp(operation, #NAME)) return process_##PIXFMT##_##NAME;
+ LIST_OPERATORS(xyza, double,)
+#undef X
+ eprintf("algorithm not recognised: %s\n", operation);
+ return NULL;
+}
+
+static process_func
+get_process_xyzaf(const char *operation)
+{
+#define X(NAME, ALGO, PIXFMT, TYPE)\
+ if (!strcmp(operation, #NAME)) return process_##PIXFMT##_##NAME;
+ LIST_OPERATORS(xyzaf, float, f)
#undef X
eprintf("algorithm not recognised: %s\n", operation);
return NULL;
@@ -87,7 +103,9 @@ main(int argc, char *argv[])
eopen_stream(&right, argv[1]);
if (!strcmp(left.pixfmt, "xyza"))
- process = get_lf_process(argv[0]);
+ process = get_process_xyza(argv[0]);
+ else if (!strcmp(left.pixfmt, "xyza f"))
+ process = get_process_xyzaf(argv[0]);
else
eprintf("pixel format %s is not supported, try xyza\n", left.pixfmt);