aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-unpremultiply.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/blind-unpremultiply.c')
-rw-r--r--src/blind-unpremultiply.c62
1 files changed, 33 insertions, 29 deletions
diff --git a/src/blind-unpremultiply.c b/src/blind-unpremultiply.c
index 18cc7b6..7545af4 100644
--- a/src/blind-unpremultiply.c
+++ b/src/blind-unpremultiply.c
@@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
+#ifndef TYPE
#include "common.h"
USAGE("[-xyz]")
@@ -7,35 +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 (!a)\
- continue;\
- 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, "<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-unpremultiply.c"
+#include "define-functions.h"
int
main(int argc, char *argv[])
@@ -74,3 +48,33 @@ 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 (!a)
+ continue;
+ 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, "<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