From b3042abffb9f4e4c7edd16934af99716bcdc2901 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 2 Jul 2017 17:18:20 +0200 Subject: Add blind-norm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 1 + README | 3 ++ TODO | 1 + man/blind-arithm.1 | 1 + man/blind-cross-product.1 | 1 + man/blind-dot-product.1 | 1 + man/blind-norm.1 | 34 +++++++++++++++++ man/blind-quaternion-product.1 | 1 + man/blind-vector-projection.1 | 1 + man/blind.7 | 3 ++ src/blind-norm.c | 86 ++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 133 insertions(+) create mode 100644 man/blind-norm.1 create mode 100644 src/blind-norm.c diff --git a/Makefile b/Makefile index 555345e..098658d 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ BIN =\ blind-invert-luma\ blind-make-kernel\ blind-next-frame\ + blind-norm\ blind-quaternion-product\ blind-premultiply\ blind-read-head\ diff --git a/README b/README index 1d8dae0..f282e2d 100644 --- a/README +++ b/README @@ -93,6 +93,9 @@ UTILITIES blind-next-frame(1) Extracts the next frame from a video + blind-norm(1) + Calculate the norm of colours in a video + blind-premultiply(1) Premultiply the alpha channel of a video diff --git a/TODO b/TODO index 8b299d3..991e9ad 100644 --- a/TODO +++ b/TODO @@ -65,6 +65,7 @@ unsigned char (xyza 8) could be added as another format, it's probably good for UNTESTED: + blind-norm blind-dot-product blind-cross-product blind-quaternion-product diff --git a/man/blind-arithm.1 b/man/blind-arithm.1 index 2e93364..5b559ef 100644 --- a/man/blind-arithm.1 +++ b/man/blind-arithm.1 @@ -77,6 +77,7 @@ Do not modify the Y channel (the second channel). Do not modify the Z channel (the third channel). .SH SEE ALSO .BR blind (7), +.BR blind-norm (1), .BR blind-dot-product (1), .BR blind-cross-product (1), .BR blind-quaternion-product (1), diff --git a/man/blind-cross-product.1 b/man/blind-cross-product.1 index ce8074e..d1daad8 100644 --- a/man/blind-cross-product.1 +++ b/man/blind-cross-product.1 @@ -24,6 +24,7 @@ is ignored but may be partially read. .SH SEE ALSO .BR blind (7), .BR blind-arithm (1), +.BR blind-norm (1), .BR blind-dot-product (1), .BR blind-quaternion-product (1), .BR blind-vector-projection (1) diff --git a/man/blind-dot-product.1 b/man/blind-dot-product.1 index 6547d65..9a1b6ed 100644 --- a/man/blind-dot-product.1 +++ b/man/blind-dot-product.1 @@ -23,6 +23,7 @@ is ignored but may be partially read. .SH SEE ALSO .BR blind (7), .BR blind-arithm (1), +.BR blind-norm (1), .BR blind-cross-product (1), .BR blind-quaternion-product (1), .BR blind-vector-projection (1) diff --git a/man/blind-norm.1 b/man/blind-norm.1 new file mode 100644 index 0000000..370016d --- /dev/null +++ b/man/blind-norm.1 @@ -0,0 +1,34 @@ +.TH BLIND-NORM 1 blind +.SH NAME +blind-norm - Calculate the norm of colours in a video +.SH SYNOPSIS +.B blind-norm +[-axyz] +.SH DESCRIPTION +.B blind-norm +reads a video from stdin, calculates the norm the +colours of each pixel and prints the resulting +video to stdout. +.SH OPTIONS +.TP +.B -a +Do not modify the alpha channel (the fourth channel). +.TP +.B -x +Do not modify the X channel (the first channel). +.TP +.B -y +Do not modify the Y channel (the second channel). +.TP +.B -z +Do not modify the Z channel (the third channel). +.SH SEE ALSO +.BR blind (7), +.BR blind-arithm (1), +.BR blind-dot-product (1), +.BR blind-cross-product (1), +.BR blind-quaternion-product (1), +.BR blind-vector-projection (1) +.SH AUTHORS +Mattias Andrée +.RI < maandree@kth.se > diff --git a/man/blind-quaternion-product.1 b/man/blind-quaternion-product.1 index 4c0f508..ed2e563 100644 --- a/man/blind-quaternion-product.1 +++ b/man/blind-quaternion-product.1 @@ -28,6 +28,7 @@ is ignored but may be partially read. .SH SEE ALSO .BR blind (7), .BR blind-arithm (1), +.BR blind-norm (1), .BR blind-cross-product (1), .BR blind-quaternion-product (1), .BR blind-vector-projection (1) diff --git a/man/blind-vector-projection.1 b/man/blind-vector-projection.1 index ee6b053..7e71ee4 100644 --- a/man/blind-vector-projection.1 +++ b/man/blind-vector-projection.1 @@ -33,6 +33,7 @@ The scalar projection is stored in all four channels. .SH SEE ALSO .BR blind (7), .BR blind-arithm (1), +.BR blind-norm (1), .BR blind-dot-product (1), .BR blind-cross-product (1), .BR blind-quaternion-product (1) diff --git a/man/blind.7 b/man/blind.7 index 3a47864..48dc48a 100644 --- a/man/blind.7 +++ b/man/blind.7 @@ -106,6 +106,9 @@ Create a custom convolution matrix .BR blind-next-frame (1) Extracts the next frame from a video .TP +.BR blind-norm (1) +Calculate the norm of colours in a video +.TP .BR blind-premultiply (1) Premultiply the alpha channel of a video .TP diff --git a/src/blind-norm.c b/src/blind-norm.c new file mode 100644 index 0000000..c4d04a0 --- /dev/null +++ b/src/blind-norm.c @@ -0,0 +1,86 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-axyz]") + +static int skip_a = 0; +static int skip_x = 0; +static int skip_y = 0; +static int skip_z = 0; + + +#define PROCESS(TYPE, SUFFIX)\ + static void\ + process_##SUFFIX(struct stream *stream)\ + {\ + size_t i, n;\ + TYPE x, y, z, a, norm;\ + do {\ + n = stream->ptr / stream->pixel_size;\ + for (i = 0; i < n; i++) {\ + x = ((TYPE *)(stream->buf))[4 * i + 0];\ + y = ((TYPE *)(stream->buf))[4 * i + 1];\ + z = ((TYPE *)(stream->buf))[4 * i + 2];\ + a = ((TYPE *)(stream->buf))[4 * i + 3];\ + norm = sqrt(x * x + y * y + z * z + a * a);\ + if (!skip_x)\ + ((TYPE *)(stream->buf))[4 * i + 0] = norm;\ + if (!skip_y)\ + ((TYPE *)(stream->buf))[4 * i + 1] = norm;\ + if (!skip_z)\ + ((TYPE *)(stream->buf))[4 * i + 2] = norm;\ + if (!skip_a)\ + ((TYPE *)(stream->buf))[4 * i + 3] = norm;\ + }\ + n *= stream->pixel_size;\ + ewriteall(STDOUT_FILENO, stream->buf, n, "");\ + memmove(stream->buf, stream->buf + n, stream->ptr -= n);\ + } while (eread_stream(stream, SIZE_MAX));\ + if (stream->ptr)\ + eprintf("%s: incomplete frame\n", stream->file);\ + } + +PROCESS(double, lf) +PROCESS(float, f) + + +int +main(int argc, char *argv[]) +{ + struct stream stream; + void (*process)(struct stream *stream); + + ARGBEGIN { + case 'a': + skip_a = 1; + break; + case 'x': + skip_x = 1; + break; + case 'y': + skip_y = 1; + break; + case 'z': + skip_z = 1; + break; + default: + usage(); + } ARGEND; + + if (argc) + usage(); + + eopen_stream(&stream, NULL); + + if (!strcmp(stream.pixfmt, "xyza")) + process = process_lf; + else if (!strcmp(stream.pixfmt, "xyza f")) + process = process_f; + else + eprintf("pixel format %s is not supported, try xyza\n", stream.pixfmt); + + fprint_stream_head(stdout, &stream); + efflush(stdout, ""); + process(&stream); + return 0; +} -- cgit v1.2.3-70-g09d2