URI: 
       Add blind-norm - blind - suckless command-line video editing utility
  HTML git clone git://git.suckless.org/blind
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit b3042abffb9f4e4c7edd16934af99716bcdc2901
   DIR parent 4dfdb29707bf7af8df1fae28907d5e492338e8b8
  HTML Author: Mattias Andrée <maandree@kth.se>
       Date:   Sun,  2 Jul 2017 17:18:20 +0200
       
       Add blind-norm
       
       Signed-off-by: Mattias Andrée <maandree@kth.se>
       
       Diffstat:
         M Makefile                            |       1 +
         M README                              |       3 +++
         M TODO                                |       1 +
         M man/blind-arithm.1                  |       1 +
         M man/blind-cross-product.1           |       1 +
         M man/blind-dot-product.1             |       1 +
         A man/blind-norm.1                    |      34 +++++++++++++++++++++++++++++++
         M man/blind-quaternion-product.1      |       1 +
         M man/blind-vector-projection.1       |       1 +
         M man/blind.7                         |       3 +++
         A src/blind-norm.c                    |      86 ++++++++++++++++++++++++++++++
       
       11 files changed, 133 insertions(+), 0 deletions(-)
       ---
   DIR diff --git 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\
   DIR diff --git 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
        
   DIR diff --git 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
   DIR diff --git 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),
   DIR diff --git 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)
   DIR diff --git 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)
   DIR diff --git a/man/blind-norm.1 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 >
   DIR diff --git 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)
   DIR diff --git 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)
   DIR diff --git 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
   DIR diff --git a/src/blind-norm.c 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, "<stdout>");\
       +                        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, "<stdout>");
       +        process(&stream);
       +        return 0;
       +}