From a8d1c8147b3ff61690270bfee455872665248148 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 27 Jul 2017 01:03:39 +0200 Subject: Add blind-transition, improve blind-dissolve, and fix blind-{cone,spiral}-gradient MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 3 +- README | 3 ++ TODO | 1 + man/blind-dissolve.1 | 1 + man/blind-set-alpha.1 | 1 + man/blind-square-gradient.1 | 1 - man/blind-transition.1 | 43 ++++++++++++++++++++ man/blind.7 | 3 ++ src/blind-cone-gradient.c | 4 +- src/blind-dissolve.c | 30 ++++++-------- src/blind-spiral-gradient.c | 2 +- src/blind-transition.c | 98 +++++++++++++++++++++++++++++++++++++++++++++ 12 files changed, 168 insertions(+), 22 deletions(-) create mode 100644 man/blind-transition.1 create mode 100644 src/blind-transition.c diff --git a/Makefile b/Makefile index cb85dd0..2b4b900 100644 --- a/Makefile +++ b/Makefile @@ -92,15 +92,16 @@ BIN =\ blind-temporal-arithm\ blind-temporal-mean\ blind-time-blur\ - blind-triangular-wave\ blind-to-image\ blind-to-named\ blind-to-portable\ blind-to-text\ blind-to-video\ blind-translate\ + blind-transition\ blind-transpose\ blind-triangle-tessellation\ + blind-triangular-wave\ blind-unpremultiply\ blind-vector-projection\ blind-write-head diff --git a/README b/README index 6ad6865..f93ac1a 100644 --- a/README +++ b/README @@ -306,6 +306,9 @@ UTILITIES blind-translate(1) Perform framewise translation of a video + blind-transition(1) + Turn a gradient video to transition-gradient video + blind-transpose(1) Transpose a video diff --git a/TODO b/TODO index a7ba144..5dcb7d1 100644 --- a/TODO +++ b/TODO @@ -8,6 +8,7 @@ blind-find-frame a graphical tool for locating frames, should highlight key fram blind-invert-chroma invert the chroma blind-from-sent convert a sent presentation to a one-frame-per-slide blind video +blind-sigmoid https://en.wikipedia.org/wiki/Sigmoid_function blind-kirsch https://en.wikipedia.org/wiki/Kirsch_operator blind-gaussian-noise https://en.wikipedia.org/wiki/Gaussian_noise blind-threshold https://en.wikipedia.org/wiki/Thresholding_(image_processing) diff --git a/man/blind-dissolve.1 b/man/blind-dissolve.1 index b4f236c..2a91d27 100644 --- a/man/blind-dissolve.1 +++ b/man/blind-dissolve.1 @@ -14,6 +14,7 @@ where the the alpha channel fades to zero. Fade in from zero alpha instead of out to zero alpha. .SH SEE ALSO .BR blind (7), +.BR blind-transition (1), .BR blind-set-alpha (1), .BR blind-stack (1), .BR blind-single-colour (1) diff --git a/man/blind-set-alpha.1 b/man/blind-set-alpha.1 index fe23ee2..8eb3bb1 100644 --- a/man/blind-set-alpha.1 +++ b/man/blind-set-alpha.1 @@ -32,6 +32,7 @@ alpha value. .BR blind (7), .BR blind-single-colour (1), .BR blind-dissolve (1), +.BR blind-transition (1), .BR blind-arithm (1), .BR blind-set-luma (1), .BR blind-invert-luma (1), diff --git a/man/blind-square-gradient.1 b/man/blind-square-gradient.1 index 92daa3e..4b945d7 100644 --- a/man/blind-square-gradient.1 +++ b/man/blind-square-gradient.1 @@ -3,7 +3,6 @@ blind-square-gradient - Generate a video with a square gradient .SH SYNOPSIS .B blind-square-gradient -[-b] -w .I width -h diff --git a/man/blind-transition.1 b/man/blind-transition.1 new file mode 100644 index 0000000..15e7fa5 --- /dev/null +++ b/man/blind-transition.1 @@ -0,0 +1,43 @@ +.TH BLIND-TRANSITION 1 blind +.SH NAME +blind-transition - Turn a gradient video to transition-gradient video +.SH SYNOPSIS +.B blind-transition +[-ir] [-s +.IR softness-stream ] +.SH DESCRIPTION +.B blind-transition +reads a video from stdin and prints a version of +it to stdout suitable for input to +.BR blind-set-alpha (1) +to for creation an transition effect. +.P +The luma in stdin is used to determine when a +pixel in the video shall be opaque. +.SH OPTION +.TP +.B -i +Invert the transition. +.TP +.B -r +Reverse the transition. +.TP +.BR -s \ \fIsoftness-stream\fP +The luma multiplied by the opacity for each pixel +in each frame in the video from +.I softness-stream +will be used as the transitional softness for that +pixel in the video. +.SH SEE ALSO +.BR blind (7), +.BR blind-set-alpha (1), +.BR blind-dissolve (1), +.BR blind-stack (1), +.BR blind-cone-gradient (1), +.BR blind-linear-gradient (1), +.BR blind-radial-gradient (1), +.BR blind-spiral-gradient (1), +.BR blind-square-gradient (1) +.SH AUTHORS +Mattias Andrée +.RI < maandree@kth.se > diff --git a/man/blind.7 b/man/blind.7 index e7fc942..1bf0a3b 100644 --- a/man/blind.7 +++ b/man/blind.7 @@ -323,6 +323,9 @@ Converts blind video to a regular video .BR blind-tranlate (1) Perform framewise translation of a video .TP +.BR blind-transition (1) +Turn a gradient video to transition-gradient video +.TP .BR blind-transpose (1) Transpose a video .TP diff --git a/src/blind-cone-gradient.c b/src/blind-cone-gradient.c index 764307f..095c56e 100644 --- a/src/blind-cone-gradient.c +++ b/src/blind-cone-gradient.c @@ -96,7 +96,7 @@ PROCESS(struct stream *stream) x = (TYPE)ix - x1; if (!x && !y) { v = 0.5; - } else { + } else { v = atan2(y, x); v -= u; v += 2 * (TYPE)M_PI; @@ -112,7 +112,7 @@ PROCESS(struct stream *stream) } } for (i = 0; i < stream->n_chan; i++) - buf[ptr][i] = x; + buf[ptr][i] = v; if (++ptr == ELEMENTSOF(buf)) { ewriteall(STDOUT_FILENO, buf, sizeof(buf), ""); ptr = 0; diff --git a/src/blind-dissolve.c b/src/blind-dissolve.c index a73ae21..be92c2e 100644 --- a/src/blind-dissolve.c +++ b/src/blind-dissolve.c @@ -6,28 +6,23 @@ USAGE("[-r]") static size_t fm; static double fm_double; static float fm_float; +static int reverse = 0; -#define PROCESS(TYPE, NREV)\ +#define PROCESS(TYPE)\ do {\ size_t i;\ - TYPE a;\ - for (i = 0; i < n; i += stream->pixel_size) {\ - a = ((TYPE *)(stream->buf + i))[3];\ - a = a * (TYPE)(NREV f) / fm_##TYPE;\ - ((TYPE *)(stream->buf + i))[3] = a;\ - }\ + TYPE a = fm ? (TYPE)(reverse ? f : fm - f) / fm_##TYPE : (TYPE)0.5;\ + for (i = 0; i < n; i += stream->pixel_size)\ + ((TYPE *)(stream->buf + i))[3] *= a;\ } while (0) -static void process_xyza (struct stream *stream, size_t n, size_t f) {PROCESS(double, fm -);} -static void process_xyza_r (struct stream *stream, size_t n, size_t f) {PROCESS(double,);} -static void process_xyzaf (struct stream *stream, size_t n, size_t f) {PROCESS(float, fm -);} -static void process_xyzaf_r(struct stream *stream, size_t n, size_t f) {PROCESS(float,);} +static void process_lf(struct stream *stream, size_t n, size_t f) {PROCESS(double);} +static void process_f (struct stream *stream, size_t n, size_t f) {PROCESS(float);} int main(int argc, char *argv[]) { struct stream stream; - int reverse = 0; void (*process)(struct stream *stream, size_t n, size_t f); ARGBEGIN { @@ -43,12 +38,13 @@ main(int argc, char *argv[]) eopen_stream(&stream, NULL); - if (!strcmp(stream.pixfmt, "xyza")) - process = reverse ? process_xyza_r : process_xyza; - else if (!strcmp(stream.pixfmt, "xyza f")) - process = reverse ? process_xyzaf_r : process_xyzaf; + if (stream.encoding == DOUBLE) + process = process_lf; else - eprintf("pixel format %s is not supported, try xyza\n", stream.pixfmt); + process = process_f; + + if (!stream.frames) + eprintf("video's length is not recorded"); fprint_stream_head(stdout, &stream); efflush(stdout, ""); diff --git a/src/blind-spiral-gradient.c b/src/blind-spiral-gradient.c index a52205d..6ea0601 100644 --- a/src/blind-spiral-gradient.c +++ b/src/blind-spiral-gradient.c @@ -162,7 +162,7 @@ PROCESS(struct stream *stream) else r = mod(r, 1 / (TYPE)spirals) * (TYPE)spirals + r - mod(r, (TYPE)1); for (i = 0; i < stream->n_chan; i++) - buf[ptr][i] = x; + buf[ptr][i] = r; if (++ptr == ELEMENTSOF(buf)) { ewriteall(STDOUT_FILENO, buf, sizeof(buf), ""); ptr = 0; diff --git a/src/blind-transition.c b/src/blind-transition.c new file mode 100644 index 0000000..8463575 --- /dev/null +++ b/src/blind-transition.c @@ -0,0 +1,98 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-ir] [-s softness-stream]") + +static size_t fm; +static double fm_double; +static float fm_float; +static int reverse = 0; +static int invert = 0; +static const char *softness_file = NULL; +static struct stream softness; + +#define PROCESS(TYPE)\ + do {\ + size_t i, j = 0;\ + TYPE a, s, t = fm ? (TYPE)(reverse ? fm - f : f) / fm_##TYPE : 0.5;\ + if (!softness_file) {\ + for (i = 0; i < n; i += stream->pixel_size) {\ + a = ((TYPE *)(stream->buf + i))[1];\ + if (invert)\ + a = (TYPE)1 - a;\ + a = (TYPE)(a >= t);\ + ((TYPE *)(stream->buf + i))[0] = a * (TYPE)D65_XYZ_X;\ + ((TYPE *)(stream->buf + i))[1] = a;\ + ((TYPE *)(stream->buf + i))[2] = a * (TYPE)D65_XYZ_Z;\ + ((TYPE *)(stream->buf + i))[3] = 1;\ + }\ + } else {\ + for (i = 0; i < n; i += stream->pixel_size, j += softness.pixel_size) {\ + while (j + softness.pixel_size > softness.ptr) {\ + memmove(softness.buf, softness.buf + j, softness.ptr -= j);\ + j = 0;\ + if (!eread_stream(&softness, SIZE_MAX))\ + return;\ + }\ + s = ((TYPE *)(softness.buf + j))[1];\ + s *= ((TYPE *)(softness.buf + j))[3];\ + a = ((TYPE *)(stream->buf + i))[1];\ + if (invert)\ + a = (TYPE)1 - a;\ + a = (a / (1 + 2 * s) + s - t) / s;\ + a = a < 0 ? (TYPE)0 : a > 1 ? (TYPE)1 : a;\ + ((TYPE *)(stream->buf + i))[0] = a * (TYPE)D65_XYZ_X;\ + ((TYPE *)(stream->buf + i))[1] = a;\ + ((TYPE *)(stream->buf + i))[2] = a * (TYPE)D65_XYZ_Z;\ + ((TYPE *)(stream->buf + i))[3] = 1;\ + }\ + }\ + } while (0) + +static void process_lf(struct stream *stream, size_t n, size_t f) {PROCESS(double);} +static void process_f (struct stream *stream, size_t n, size_t f) {PROCESS(float);} + +int +main(int argc, char *argv[]) +{ + struct stream stream; + void (*process)(struct stream *stream, size_t n, size_t f); + + ARGBEGIN { + case 'i': + invert = 1; + break; + case 'r': + reverse = 1; + break; + case 's': + softness_file = UARGF(); + break; + default: + usage(); + } ARGEND; + + if (argc) + usage(); + + eopen_stream(&stream, NULL); + if (softness_file) { + eopen_stream(&softness, softness_file); + echeck_compat(&stream, &softness); + } + + if (stream.encoding == DOUBLE) + process = process_lf; + else + process = process_f; + + if (!stream.frames) + eprintf("video's length is not recorded"); + + fprint_stream_head(stdout, &stream); + efflush(stdout, ""); + fm_double = (double)(fm = stream.frames - 1); + fm_float = (float)fm_double; + process_each_frame_segmented(&stream, STDOUT_FILENO, "", process); + return 0; +} -- cgit v1.2.3-70-g09d2