(wrong string) ée

From: <git_AT_suckless.org>
Date: Sun, 9 Jul 2017 22:30:25 +0200 (CEST)

commit 88752940275b41cf4b8c978f226ff7d55a5f6575
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Wed Jul 5 00:07:13 2017 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Wed Jul 5 00:07:13 2017 +0200

    Add blind-extract-alpha
    
    Signed-off-by: Mattias Andrée <maandree_AT_kth.se>

diff --git a/Makefile b/Makefile
index dcce94b..a67e3e0 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -21,6 +21,7 @@ BIN =\
         blind-dot-product\
         blind-double-sine-wave\
         blind-extend\
+ blind-extract-alpha\
         blind-find-rectangle\
         blind-flip\
         blind-flop\
diff --git a/README b/README
index 7316743..261618d 100644
--- a/README
+++ b/README
_AT_@ -63,6 +63,9 @@ UTILITIES
        blind-extend(1)
               Add margins to a video
 
+ blind-extract-alpha(1)
+ Split a video into an alpha mask video and a colour mask video
+
        blind-find-rectangle(1)
               Locate a coloured rectangle
 
diff --git a/man/blind-extract-alpha.1 b/man/blind-extract-alpha.1
new file mode 100644
index 0000000..e17122a
--- /dev/null
+++ b/man/blind-extract-alpha.1
_AT_@ -0,0 +1,20 @@
+.TH BLIND-EXTRACT-ALPHA 1 blind
+.SH NAME
+blind-extract-alpha - Split a video into an alpha mask video and a colour mask video
+.SH SYNOPSIS
+.B blind-extract-alpha
+.I colour-file
+.SH DESCRIPTION
+.B blind-split
+reads a video from stdin and writes the same video,
+except fully opaque, to
+.IR colour-file ,
+and writes a fully opaque video to stdout where
+the colour channels have the values from the alpha
+channel from the video in stdin.
+.SH SEE ALSO
+.BR blind (7),
+.BR blind-set-alpha (7)
+.SH AUTHORS
+Mattias Andrée
+.RI < maandree_AT_kth.se >
diff --git a/man/blind-set-alpha.1 b/man/blind-set-alpha.1
index 724856e..fe23ee2 100644
--- a/man/blind-set-alpha.1
+++ b/man/blind-set-alpha.1
_AT_@ -35,7 +35,8 @@ alpha value.
 .BR blind-arithm (1),
 .BR blind-set-luma (1),
 .BR blind-invert-luma (1),
-.BR blind-set-saturation (1)
+.BR blind-set-saturation (1),
+.BR blind-extract-alpha (1)
 .SH AUTHORS
 Mattias Andrée
 .RI < maandree_AT_kth.se >
diff --git a/man/blind.7 b/man/blind.7
index 9c8e195..79ac8eb 100644
--- a/man/blind.7
+++ b/man/blind.7
_AT_@ -79,6 +79,9 @@ Apply double-sine-wave repetition to gradient
 .BR blind-extend (1)
 Add margins to a video
 .TP
+.BR blind-extract-alpha (1)
+Split a video into an alpha mask video and a colour mask video
+.TP
 .BR blind-find-rectangle (1)
 Locate a coloured rectangle
 .TP
diff --git a/src/blind-extract-alpha.c b/src/blind-extract-alpha.c
new file mode 100644
index 0000000..ac27724
--- /dev/null
+++ b/src/blind-extract-alpha.c
_AT_@ -0,0 +1,62 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+USAGE("colour-file")
+
+#define PROCESS(TYPE, SUFFIX)\
+ static void\
+ process_##SUFFIX(struct stream *stream, int fd, const char *fname)\
+ {\
+ char buf[sizeof(stream->buf)];\
+ size_t i, n;\
+ TYPE a;\
+ do {\
+ n = stream->ptr / stream->pixel_size;\
+ for (i = 0; i < n; i++) {\
+ a = ((TYPE *)(stream->buf))[4 * i + 3];\
+ ((TYPE *)(stream->buf))[4 * i + 3] = 1;\
+ ((TYPE *)buf)[4 * i + 0] = a;\
+ ((TYPE *)buf)[4 * i + 1] = a;\
+ ((TYPE *)buf)[4 * i + 2] = a;\
+ ((TYPE *)buf)[4 * i + 3] = 1;\
+ }\
+ n *= stream->pixel_size;\
+ ewriteall(fd, stream->buf, n, fname);\
+ ewriteall(STDOUT_FILENO, 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;
+ int fd;
+ void (*process)(struct stream *stream, int fd, const char *fname);
+
+ UNOFLAGS(argc != 1);
+
+ eopen_stream(&stream, NULL);
+ fd = eopen(argv[0], O_WRONLY | O_CREAT | O_TRUNC, 0666);
+
+ 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>");
+ if (dprint_stream_head(fd, &stream) < 0)
+ eprintf("dprintf %s:", argv[0]);
+
+ process(&stream, fd, argv[0]);
+ return 0;
+}
diff --git a/src/stream.c b/src/stream.c
index 6c9dc72..c21d269 100644
--- a/src/stream.c
+++ b/src/stream.c
_AT_@ -123,6 +123,13 @@ fprint_stream_head(FILE *fp, struct stream *stream)
 }
 
 
+int
+dprint_stream_head(int fd, struct stream *stream)
+{
+ return DPRINTF_HEAD(fd, stream->frames, stream->width, stream->height, stream->pixfmt);
+}
+
+
 size_t
 enread_stream(int status, struct stream *stream, size_t n)
 {
diff --git a/src/stream.h b/src/stream.h
index d15ce8d..8733f43 100644
--- a/src/stream.h
+++ b/src/stream.h
_AT_@ -88,6 +88,7 @@ void enopen_stream(int status, struct stream *stream, const char *file);
 int set_pixel_size(struct stream *stream);
 void enset_pixel_size(int status, struct stream *stream);
 void fprint_stream_head(FILE *fp, struct stream *stream);
+int dprint_stream_head(int fd, struct stream *stream);
 size_t enread_stream(int status, struct stream *stream, size_t n);
 void eninf_check_fd(int status, int fd, const char *file);
 void encheck_dimensions(int status, const struct stream *stream, enum dimension dimensions, const char *prefix);
Received on Sun Jul 09 2017 - 22:30:25 CEST

This archive was generated by hypermail 2.3.0 : Sun Jul 09 2017 - 22:36:32 CEST