diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-04-09 10:16:50 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-04-09 10:52:20 +0200 |
| commit | 80d76b61b0e2b1224f8b0417658285b90934880e (patch) | |
| tree | 52e0a47c6d44616d3a07a3fd81730e3ff8d28338 /src/blind-next-frame.c | |
| parent | blind-translate.1: document memory requirement (diff) | |
| download | blind-80d76b61b0e2b1224f8b0417658285b90934880e.tar.gz blind-80d76b61b0e2b1224f8b0417658285b90934880e.tar.bz2 blind-80d76b61b0e2b1224f8b0417658285b90934880e.tar.xz | |
blind-next-frame: add -f flag: read multiple frames
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-next-frame.c')
| -rw-r--r-- | src/blind-next-frame.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/blind-next-frame.c b/src/blind-next-frame.c index 8afa725..41ab0ca 100644 --- a/src/blind-next-frame.c +++ b/src/blind-next-frame.c @@ -6,19 +6,27 @@ #include <string.h> #include <unistd.h> -USAGE("width height pixel-format ...") +USAGE("[-f frames] width height pixel-format ...") int main(int argc, char *argv[]) { struct stream stream; - size_t n, w; + size_t n, w, h = 0; int i, anything = 0; char *p; - ENOFLAGS(argc < 3); - stream.frames = 1; + + ARGBEGIN { + case 'f': + stream.frames = etozu_flag('f', UARGF(), 1, SIZE_MAX); + break; + } ARGEND; + + if (argc < 3) + usage(); + stream.fd = STDIN_FILENO; stream.file = "<stdin>"; stream.pixfmt[0] = '\0'; @@ -44,20 +52,23 @@ main(int argc, char *argv[]) enfflush(2, stdout, "<stdout>"); w = stream.width * stream.pixel_size; - while (stream.height) { - stream.height--; - for (n = w; n; n -= stream.ptr) { - stream.ptr = 0; - if (!enread_stream(2, &stream, n)) - goto done; - anything = 1; - enwriteall(2, STDOUT_FILENO, stream.buf, stream.ptr, "<stdout>"); + while (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)) + goto done; + anything = 1; + enwriteall(2, STDOUT_FILENO, stream.buf, stream.ptr, "<stdout>"); + } } } done: - if (anything && (stream.height || n)) - enprintf(2, "incomplete frame\n"); + if (anything && (h || n || stream.frames)) + enprintf(2, "%s: is shorted than expected\n", stream.file); return !anything; } |
