commit 878849c465604d90d236b3c8766bf75a4b6836d2
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Sun May 7 16:48:25 2017 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Sun May 7 17:10:45 2017 +0200
Add blind-convert
Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
diff --git a/Makefile b/Makefile
index 3bdd7cd..c2444d8 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -7,6 +7,7 @@ BIN =\
blind-colour-srgb\
blind-compress\
blind-concat\
+ blind-convert\
blind-crop\
blind-cut\
blind-decompress\
diff --git a/src/blind-convert.c b/src/blind-convert.c
new file mode 100644
index 0000000..e26e304
--- /dev/null
+++ b/src/blind-convert.c
_AT_@ -0,0 +1,82 @@
+/* See LICENSE file for copyright and license details. */
+#include "stream.h"
+#include "util.h"
+
+#include <string.h>
+
+USAGE("pixel-format ...")
+
+static void (*outconv)(double x, double y, double z, double a);
+
+#define INCONV(TYPE)\
+ do {\
+ TYPE *pixel, x, y, z, a;\
+ size_t n;\
+ do {\
+ pixel = (TYPE *)stream->buf;\
+ for (n = stream->ptr / stream->pixel_size; n--; pixel += 4) {\
+ x = (TYPE)(pixel[0]);\
+ y = (TYPE)(pixel[1]);\
+ z = (TYPE)(pixel[2]);\
+ a = (TYPE)(pixel[3]);\
+ outconv(x, y, z, a);\
+ }\
+ n = stream->ptr - (stream->ptr % stream->pixel_size);\
+ 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);\
+ } while (0)
+
+#define OUTCONV(TYPE)\
+ do {\
+ TYPE pixel[4];\
+ pixel[0] = (TYPE)x;\
+ pixel[1] = (TYPE)y;\
+ pixel[2] = (TYPE)z;\
+ pixel[3] = (TYPE)a;\
+ ewriteall(STDOUT_FILENO, pixel, sizeof(pixel), "<stdout>");\
+ } while (0)
+
+static void inconv_xyza (struct stream *stream) {INCONV(double);}
+static void inconv_xyzaf(struct stream *stream) {INCONV(float);}
+
+static void outconv_xyza (double x, double y, double z, double a) {OUTCONV(double);}
+static void outconv_xyzaf(double x, double y, double z, double a) {OUTCONV(float);}
+
+int
+main(int argc, char *argv[])
+{
+ struct stream stream;
+ const char *pixfmt;
+ void (*inconv)(struct stream *stream);
+
+ UNOFLAGS(!argc);
+
+ eopen_stream(&stream, NULL);
+
+ if (!strcmp(stream.pixfmt, "xyza"))
+ inconv = inconv_xyza;
+ else if (!strcmp(stream.pixfmt, "xyza f"))
+ inconv = inconv_xyzaf;
+ else
+ eprintf("input pixel format %s is not supported\n", stream.pixfmt);
+
+ pixfmt = stream.pixfmt;
+ while (*argv)
+ pixfmt = get_pixel_format(*argv++, pixfmt);
+
+ if (!strcmp(pixfmt, "xyza"))
+ outconv = outconv_xyza;
+ else if (!strcmp(pixfmt, "xyza f"))
+ outconv = outconv_xyzaf;
+ else
+ eprintf("output pixel format %s is not supported\n", pixfmt);
+
+ strcpy(stream.pixfmt, pixfmt);
+ fprint_stream_head(stdout, &stream);
+ efflush(stdout, "<stdout>");
+
+ inconv(&stream);
+ return 0;
+}
diff --git a/src/blind-next-frame.c b/src/blind-next-frame.c
index 14d2326..bd47f1d 100644
--- a/src/blind-next-frame.c
+++ b/src/blind-next-frame.c
_AT_@ -56,9 +56,8 @@ main(int argc, char *argv[])
w = stream.width * stream.pixel_size;
for (; stream.frames; stream.frames--) {
for (h = stream.height; h; h--) {
- for (n = w; n; n -= stream.ptr) {
- stream.ptr = 0;
- if (!enread_stream(2, &stream, n))
+ for (n = w; n; n -= stream.ptr, stream.ptr = 0) {
+ if (!stream.ptr && !enread_stream(2, &stream, n))
goto done;
anything = 1;
enwriteall(2, STDOUT_FILENO, stream.buf, stream.ptr, "<stdout>");
diff --git a/src/stream.c b/src/stream.c
index 6ff71c0..46edfa8 100644
--- a/src/stream.c
+++ b/src/stream.c
_AT_@ -106,6 +106,8 @@ set_pixel_size(struct stream *stream)
{
if (!strcmp(stream->pixfmt, "xyza"))
stream->pixel_size = 4 * sizeof(double);
+ else if (!strcmp(stream->pixfmt, "xyza f"))
+ stream->pixel_size = 4 * sizeof(float);
else
return -1;
return 0;
Received on Sun May 07 2017 - 17:18:19 CEST
This archive was generated by hypermail 2.3.0
: Sun May 07 2017 - 17:24:23 CEST