diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-10 03:30:49 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-10 03:52:41 +0100 |
| commit | 5633798e72ede46bfbd897e972cbfd4932f29372 (patch) | |
| tree | c0559b705a7982eff9fb33a00fd7d99eec41a002 | |
| parent | Rename vu-image-to-frame to vu-from-image and vu-frame-to-image to vu-to-image (diff) | |
| download | blind-5633798e72ede46bfbd897e972cbfd4932f29372.tar.gz blind-5633798e72ede46bfbd897e972cbfd4932f29372.tar.bz2 blind-5633798e72ede46bfbd897e972cbfd4932f29372.tar.xz | |
vu-to-image: add farbfeld support
Signed-off-by: Mattias Andrée <maandree@kth.se>
| -rw-r--r-- | src/vu-to-image.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/vu-to-image.c b/src/vu-to-image.c index 3b93dd9..9252f3e 100644 --- a/src/vu-to-image.c +++ b/src/vu-to-image.c @@ -3,6 +3,7 @@ #include "stream.h" #include "util.h" +#include <arpa/inet.h> #include <inttypes.h> #include <stdio.h> #include <stdlib.h> @@ -16,7 +17,7 @@ static int alpha_warning_triggered = 0; static void usage(void) { - eprintf("usage: %s [-d depth]\n", argv0); + eprintf("usage: %s [-d depth | -f]\n", argv0); } static void @@ -95,7 +96,7 @@ int main(int argc, char *argv[]) { struct stream stream; - int depth = 16, bytes; + int depth = 16, bytes, farbfeld = 0; unsigned long long int max; size_t n; void (*process)(struct stream *stream, size_t n, int bytes, unsigned long long int max); @@ -105,11 +106,14 @@ main(int argc, char *argv[]) if (toi(EARGF(usage()), 1, 64, &depth)) eprintf("argument of -d must be an integer in [1, 64]\n"); break; + case 'f': + farbfeld = 1; + break; default: usage(); } ARGEND; - if (argc) + if (argc || (farbfeld && depth != 16)) usage(); stream.fd = STDIN_FILENO; @@ -125,13 +129,28 @@ main(int argc, char *argv[]) else eprintf("pixel format %s is not supported, try xyza\n", stream.pixfmt); - printf("P7\n" - "WIDTH %zu\n" - "HEIGHT %zu\n" - "DEPTH 4\n" /* Depth actually means channels */ - "MAXVAL %llu\n" - "TUPLTYPE RGB_ALPHA\n" - "ENDHDR\n", stream.width, stream.height, max); + if (farbfeld) { + uint32_t width = stream.width, height = stream.height; + if (stream.width > UINT32_MAX) + eprintf("%s: frame is too wide\n", stream.file); + if (stream.height > UINT32_MAX) + eprintf("%s: frame is too tall\n", stream.file); + printf("farbfeld"); + memmove(stream.buf + 8, stream.buf, stream.ptr); + stream.ptr += 8; + width = htonl(width); + height = htonl(height); + memcpy(stream.buf + 0, &width, 4); + memcpy(stream.buf + 4, &height, 4); + } else { + printf("P7\n" + "WIDTH %zu\n" + "HEIGHT %zu\n" + "DEPTH 4\n" /* Depth actually means channels */ + "MAXVAL %llu\n" + "TUPLTYPE RGB_ALPHA\n" + "ENDHDR\n", stream.width, stream.height, max); + } fflush(stdout); if (ferror(stdout)) eprintf("<stdout>:"); |
