blind-single-colour.c - blind - suckless command-line video editing utility | |
git clone git://git.suckless.org/blind | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
blind-single-colour.c (2028B) | |
--- | |
1 /* See LICENSE file for copyright and license details. */ | |
2 #ifndef TYPE | |
3 #include "common.h" | |
4 | |
5 USAGE("[-f frames | -f 'inf'] [-F pixel-format] -w width -h height (X Y … | |
6 | |
7 static struct stream stream = { .width = 0, .height = 0, .frames = 1 }; | |
8 static double X, Y, Z, alpha = 1; | |
9 static int inf = 0; | |
10 | |
11 #define FILE "blind-single-colour.c" | |
12 #include "define-functions.h" | |
13 | |
14 int | |
15 main(int argc, char *argv[]) | |
16 { | |
17 char *arg; | |
18 const char *pixfmt = "xyza"; | |
19 void (*process)(void); | |
20 | |
21 ARGBEGIN { | |
22 case 'f': | |
23 arg = UARGF(); | |
24 if (!strcmp(arg, "inf")) | |
25 inf = 1, stream.frames = 0; | |
26 else | |
27 stream.frames = etozu_flag('f', arg, 1, SIZE_MAX… | |
28 break; | |
29 case 'F': | |
30 pixfmt = UARGF(); | |
31 break; | |
32 case 'w': | |
33 stream.width = etozu_flag('w', UARGF(), 1, SIZE_MAX); | |
34 break; | |
35 case 'h': | |
36 stream.height = etozu_flag('h', UARGF(), 1, SIZE_MAX); | |
37 break; | |
38 default: | |
39 usage(); | |
40 } ARGEND; | |
41 | |
42 if (!stream.width || !stream.height || !argc || argc > 4) | |
43 usage(); | |
44 | |
45 if (argc < 3) { | |
46 Y = etolf_arg("the Y value", argv[0]); | |
47 X = Y * D65_XYZ_X; | |
48 Z = Y * D65_XYZ_Z; | |
49 } else { | |
50 X = etolf_arg("the X value", argv[0]); | |
51 Y = etolf_arg("the Y value", argv[1]); | |
52 Z = etolf_arg("the Z value", argv[2]); | |
53 } | |
54 if (~argc & 1) | |
55 alpha = etolf_arg("the alpha value", argv[argc - 1]); | |
56 | |
57 if (inf) | |
58 einf_check_fd(STDOUT_FILENO, "<stdout>"); | |
59 | |
60 eset_pixel_format(&stream, pixfmt); | |
61 SELECT_PROCESS_FUNCTION(&stream); | |
62 CHECK_N_CHAN(&stream, 4, 4); | |
63 if (argc < 3) | |
64 CHECK_COLOUR_SPACE(&stream, CIEXYZ); | |
65 | |
66 fprint_stream_head(stdout, &stream); | |
67 efflush(stdout, "<stdout>"); | |
68 | |
69 process(); | |
70 return 0; | |
71 } | |
72 | |
73 #else | |
74 | |
75 static void | |
76 PROCESS(void) | |
77 { | |
78 typedef TYPE pixel_t[4]; | |
79 pixel_t buf[BUFSIZ / 4]; | |
80 size_t x, y, n, r; | |
81 for (x = 0; x < ELEMENTSOF(buf); x++) { | |
82 buf[x][0] = (TYPE)X; | |
83 buf[x][1] = (TYPE)Y; | |
84 buf[x][2] = (TYPE)Z; | |
85 buf[x][3] = (TYPE)alpha; | |
86 } | |
87 while (inf || stream.frames--) | |
88 for (y = stream.height; y--;) | |
89 for (x = stream.width * sizeof(*buf); x;) | |
90 for (x -= n = MIN(sizeof(buf), x); n; n … | |
91 r = ewrite(STDOUT_FILENO, buf, n… | |
92 } | |
93 | |
94 #endif |