From 6bcf1120ccde684a7ab09fd690931ce125fe4631 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 12 Jan 2017 09:40:50 +0100 Subject: Add vu-from-text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 1 + TODO | 1 - src/stream.c | 2 +- src/vu-from-text.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/vu-from-text.c diff --git a/Makefile b/Makefile index f562893..17cb9a7 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ BIN =\ vu-flip\ vu-flop\ vu-from-image\ + vu-from-text\ vu-gauss-blur\ vu-invert-luma\ vu-next-frame\ diff --git a/TODO b/TODO index b913861..1b37640 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,6 @@ vu-chroma-key replace a chroma with transparency vu-primary-key replace a primary with transparency, -g for greyscaled images vu-from-video use ffmpeg to convert from another format vu-to-video use ffmpeg to convert to another format -vu-from-text convert each pixel from text vu-primaries given three selectable primaries split the video into three side-by-side which only one primary active vu-apply-map remap pixels (distortion) using the X and Y values, -t for tiling, -s for diff --git a/src/stream.c b/src/stream.c index 4f20455..edee6a7 100644 --- a/src/stream.c +++ b/src/stream.c @@ -17,7 +17,7 @@ eninit_stream(int status, struct stream *stream) size_t n; char *p = NULL, *w, *h, *f, *end; - for (stream->ptr = 0; p;) { + for (stream->ptr = 0; stream->fd >= 0 && p;) { r = read(stream->fd, stream->buf + stream->ptr, sizeof(stream->buf) - stream->ptr); if (r < 0) enprintf(status, "read %s:", stream->file); diff --git a/src/vu-from-text.c b/src/vu-from-text.c new file mode 100644 index 0000000..88cee62 --- /dev/null +++ b/src/vu-from-text.c @@ -0,0 +1,71 @@ +/* See LICENSE file for copyright and license details. */ +#include "stream.h" +#include "util.h" + +#include +#include +#include +#include + +USAGE("") + +static void +process_xyza(struct stream *stream) +{ + double buf[BUFSIZ / sizeof(double)]; + size_t i; + int r, done = 0; + + while (!done) { + for (i = 0; i < ELEMENTSOF(buf); i += (size_t)r) { + r = scanf("%lf", buf + i); + if (r == EOF) { + done = 1; + break; + } + } + ewriteall(STDOUT_FILENO, buf, i * sizeof(*buf), ""); + } +} + +int +main(int argc, char *argv[]) +{ + struct stream stream; + size_t size = 0; + char *line = NULL; + ssize_t len; + void (*process)(struct stream *stream) = NULL; + + ENOFLAGS(argc); + + len = getline(&line, &size, stdin); + if (len < 0) { + if (ferror(stdin)) + eprintf("getline :"); + else + eprintf(": no input\n"); + } + if (len && line[len - 1] == '\n') + line[--len] = '\n'; + if (len + 6 > sizeof(stream.buf)) + eprintf(": head is too long\n"); + stream.fd = -1; + stream.file = ""; + memcpy(stream.buf, line, (size_t)len); + memcpy(stream.buf + len, "\n\0uivf", 6); + stream.ptr = (size_t)len + 6; + free(line); + ewriteall(STDOUT_FILENO, stream.buf, stream.ptr, ""); + einit_stream(&stream); + + if (!strcmp(stream.pixfmt, "xyza")) + process = process_xyza; + else + eprintf("pixel format %s is not supported, try xyza\n", stream.pixfmt); + + process(&stream); + + efshut(stdin, ""); + return 0; +} -- cgit v1.2.3-70-g09d2