From 4a3ac9442a7e6fb810f3c56b4a00ffa120cae475 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 9 Apr 2017 11:19:31 +0200 Subject: Add blind-skip-pattern 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 - man/blind-next-frame.1 | 3 +- man/blind-skip-pattern.1 | 26 +++++++++++++++ src/blind-skip-pattern.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 man/blind-skip-pattern.1 create mode 100644 src/blind-skip-pattern.c diff --git a/Makefile b/Makefile index b791e17..377adb9 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ BIN =\ blind-set-luma\ blind-set-saturation\ blind-single-colour\ + blind-skip-pattern\ blind-split\ blind-stack\ blind-time-blur\ diff --git a/TODO b/TODO index e5bfc30..163fd36 100644 --- a/TODO +++ b/TODO @@ -14,7 +14,6 @@ blind-affine-colour apply an affine transformation to the colour of each pixel, -l for linear transformation, -p for transforming each pixel with their own transformation. blind-invert-chroma invert the chroma -blind-skip-pattern discard frames according to pattern, e.g. every other frame blind-from-sent convert a sent presentation to a one-frame-per-slide blind video blind-from-video: add options to: diff --git a/man/blind-next-frame.1 b/man/blind-next-frame.1 index 55fe74f..fe888cb 100644 --- a/man/blind-next-frame.1 +++ b/man/blind-next-frame.1 @@ -50,7 +50,8 @@ An error occurred. .BR blind-read-head (1), .BR blind-write-head (1), .BR blind-to-image (1), -.BR blind-from-image (1) +.BR blind-from-image (1), +.BR blind-skip-pattern (1) .SH AUTHORS Mattias Andrée .RI < maandree@kth.se > diff --git a/man/blind-skip-pattern.1 b/man/blind-skip-pattern.1 new file mode 100644 index 0000000..4565820 --- /dev/null +++ b/man/blind-skip-pattern.1 @@ -0,0 +1,26 @@ +.TH BLIND-SKIP-PATTERN 1 blind +.SH NAME +blind-skip-pattern - Skips frames in a video according to pattern +.SH SYNOPSIS +.B blind-skip-pattern +.RI ( skipped-frames +| +.RI + included-frames )\ ... +.SH DESCRIPTION +For every argument, +.B blind-skip-pattern +skips +.I skipped-frames +frames from stdin or prints +.I included-frames +frames from stdin to stdout, +until the end of stdin is reached. +After the last argument, +.B blind-skip-pattern +jumps back to the first argument. +.SH SEE ALSO +.BR blind (7), +.BR blind-next-frame (1), +.SH AUTHORS +Mattias Andrée +.RI < maandree@kth.se > diff --git a/src/blind-skip-pattern.c b/src/blind-skip-pattern.c new file mode 100644 index 0000000..1debeca --- /dev/null +++ b/src/blind-skip-pattern.c @@ -0,0 +1,84 @@ +/* See LICENSE file for copyright and license details. */ +#include "stream.h" +#include "util.h" + +#include +#include +#include + +USAGE("(skipped-frames | +included-frames) ...") + +static int +process_frame(struct stream *stream, int include, size_t rown) +{ + size_t h, n; + int anything = 0; + + for (h = stream->height; h;) { + h--; + for (n = rown; n; n -= stream->ptr) { + stream->ptr = 0; + if (!eread_stream(stream, n)) + goto done; + anything = 1; + if (include) + ewriteall(STDOUT_FILENO, stream->buf, stream->ptr, ""); + } + } +done: + + if (anything && (h || n || stream->frames)) + eprintf("%s: is shorted than expected\n", stream->file); + + return !anything; +} + +int +main(int argc, char *argv[]) +{ + struct stream stream; + int i, include; + size_t f, n, rown, total = 0; + char *includes; + size_t *ns; + + UNOFLAGS(!argc); + + stream.fd = STDIN_FILENO; + stream.file = ""; + einit_stream(&stream); + + includes = emalloc((size_t)argc); + ns = ecalloc((size_t)argc, sizeof(*ns)); + + for (i = 0; i < argc; i++) { + include = argv[i][0] == '+'; + n = etozu_arg(include ? "included frame count" : "skipped frame count", + argv[i] + include, 0, SIZE_MAX); + ns[i] = n; + includes[i] = (char)include; + } + if (!total) + eprintf("null pattern is not allowed"); + + for (i = 0, total = 0, f = stream.frames;; i = (i + 1) % argc) { + include = (int)includes[i]; + for (n = ns[i]; n-- && f--;) + total += (size_t)include; + } + + stream.frames = total; + fprint_stream_head(stdout, &stream); + efflush(stdout, ""); + + rown = stream.width * stream.pixel_size; + for (i = 0;; i = (i + 1) % argc) { + include = (int)includes[i]; + n = ns[i]; + while (n-- && process_frame(&stream, include, rown)); + } + + free(includes); + free(ns); + return 0; +} -- cgit v1.2.3-70-g09d2