blind-extract-alpha.c - blind - suckless command-line video editing utility
(HTM) git clone git://git.suckless.org/blind
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
blind-extract-alpha.c (1400B)
---
1 /* See LICENSE file for copyright and license details. */
2 #ifndef TYPE
3 #include "common.h"
4
5 USAGE("colour-file")
6
7 #define FILE "blind-extract-alpha.c"
8 #include "define-functions.h"
9
10 int
11 main(int argc, char *argv[])
12 {
13 struct stream stream;
14 int fd;
15 void (*process)(struct stream *stream, int fd, const char *fname);
16
17 UNOFLAGS(argc != 1);
18
19 eopen_stream(&stream, NULL);
20 fd = eopen(argv[0], O_WRONLY | O_CREAT | O_TRUNC, 0666);
21
22 SELECT_PROCESS_FUNCTION(&stream);
23 CHECK_CHANS(&stream, != -1, == stream.luma_chan);
24
25 fprint_stream_head(stdout, &stream);
26 efflush(stdout, "<stdout>");
27 if (dprint_stream_head(fd, &stream) < 0)
28 eprintf("dprintf %s:", argv[0]);
29 process(&stream, fd, argv[0]);
30 return 0;
31 }
32
33 #else
34
35 static void
36 PROCESS(struct stream *stream, int fd, const char *fname)
37 {
38 char buf[sizeof(stream->buf)];
39 size_t i, j, n;
40 TYPE a, *p, *b;
41 do {
42 n = stream->ptr / stream->pixel_size;
43 p = (TYPE *)(stream->buf) + stream->luma_chan;
44 b = (TYPE *)buf;
45 for (i = 0; i < n; i++, p += stream->n_chan) {
46 a = *p, *p = 1;
47 for (j = stream->n_chan - 1; j--;)
48 *b++ = a;
49 *b++ = 1;
50 }
51 n *= stream->pixel_size;
52 ewriteall(fd, stream->buf, n, fname);
53 ewriteall(STDOUT_FILENO, buf, n, "<stdout>");
54 memmove(stream->buf, stream->buf + n, stream->ptr -= n);
55 } while (eread_stream(stream, SIZE_MAX));
56 if (stream->ptr)
57 eprintf("%s: incomplete frame\n", stream->file);
58 }
59
60 #endif