From 4df594b3f48679f594e6f738981cb3baca8a42d9 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 7 May 2017 16:11:31 +0200 Subject: Add support for floats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blind-to-text.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/blind-to-text.c') diff --git a/src/blind-to-text.c b/src/blind-to-text.c index 7fefbfc..59ab8c3 100644 --- a/src/blind-to-text.c +++ b/src/blind-to-text.c @@ -8,17 +8,19 @@ USAGE("") -static void -process_xyza(struct stream *stream, size_t n) -{ - size_t i; - for (i = 0; i < n; i += stream->pixel_size) - printf("%lf %lf %lf %lf\n", - ((double *)(stream->buf + i))[0], - ((double *)(stream->buf + i))[1], - ((double *)(stream->buf + i))[2], - ((double *)(stream->buf + i))[3]); -} +#define PROCESS(TYPE, CAST, FMT)\ + do {\ + size_t i;\ + for (i = 0; i < n; i += stream->pixel_size)\ + printf("%"FMT" %"FMT" %"FMT" %"FMT"\n",\ + (CAST)(((TYPE *)(stream->buf + i))[0]),\ + (CAST)(((TYPE *)(stream->buf + i))[1]),\ + (CAST)(((TYPE *)(stream->buf + i))[2]),\ + (CAST)(((TYPE *)(stream->buf + i))[3]));\ + } while (0) + +static void process_xyza (struct stream *stream, size_t n) {PROCESS(double, double, "lf");} +static void process_xyzaf(struct stream *stream, size_t n) {PROCESS(float, double, "lf");} int main(int argc, char *argv[]) @@ -32,6 +34,8 @@ main(int argc, char *argv[]) if (!strcmp(stream.pixfmt, "xyza")) process = process_xyza; + else if (!strcmp(stream.pixfmt, "xyza f")) + process = process_xyzaf; else eprintf("pixel format %s is not supported, try xyza\n", stream.pixfmt); -- cgit v1.2.3-70-g09d2