blind-set-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-set-alpha.c (1645B)
---
1 /* See LICENSE file for copyright and license details. */
2 #include "common.h"
3
4 USAGE("[-i] alpha-stream")
5
6 #define PROCESS(TYPE, INV)\
7 do {\
8 size_t i;\
9 TYPE *luma = (TYPE *)(alpha->buf) + alpha->luma_chan;\
10 TYPE *alph = (TYPE *)(alpha->buf) + alpha->alpha_chan;\
11 TYPE *out = (TYPE *)(colour->buf) + colour->alpha_chan;\
12 n /= colour->chan_size;\
13 for (i = 0; i < n; i += colour->n_chan)\
14 out[i] *= (INV luma[i]) * alph[i];\
15 } while (0)
16
17 static void process_lf (struct stream *colour, struct stream *alpha, size_t n) {PROCESS(double,);}
18 static void process_lf_i(struct stream *colour, struct stream *alpha, size_t n) {PROCESS(double, 1 -);}
19 static void process_f (struct stream *colour, struct stream *alpha, size_t n) {PROCESS(float,);}
20 static void process_f_i (struct stream *colour, struct stream *alpha, size_t n) {PROCESS(float, 1 -);}
21
22 int
23 main(int argc, char *argv[])
24 {
25 int invert = 0;
26 struct stream colour, alpha;
27 void (*process)(struct stream *colour, struct stream *alpha, size_t n);
28
29 ARGBEGIN {
30 case 'i':
31 invert = 1;
32 break;
33 default:
34 usage();
35 } ARGEND;
36
37 if (argc != 1)
38 usage();
39
40 eopen_stream(&colour, NULL);
41 eopen_stream(&alpha, argv[0]);
42
43 CHECK_CHANS(&colour, != -1, != -1);
44 CHECK_ALPHA(&colour);
45 if (colour.encoding == DOUBLE)
46 process = invert ? process_lf_i : process_lf;
47 else if (colour.encoding == FLOAT)
48 process = invert ? process_f_i : process_f;
49 else
50 eprintf("pixel format %s is not supported, try xyza\n", colour.pixfmt);
51
52 fprint_stream_head(stdout, &colour);
53 efflush(stdout, "<stdout>");
54 process_two_streams(&colour, &alpha, STDOUT_FILENO, "<stdout>", process);
55 return 0;
56 }