blind-matrix-scale.c - blind - suckless command-line video editing utility | |
git clone git://git.suckless.org/blind | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
blind-matrix-scale.c (1558B) | |
--- | |
1 /* See LICENSE file for copyright and license details. */ | |
2 #ifndef TYPE | |
3 #include "common.h" | |
4 | |
5 USAGE("[-c]") | |
6 | |
7 static int per_channel = 0; | |
8 | |
9 #define FILE "blind-matrix-scale.c" | |
10 #include "define-functions.h" | |
11 | |
12 int | |
13 main(int argc, char *argv[]) | |
14 { | |
15 struct stream stream; | |
16 void (*process)(struct stream *stream); | |
17 | |
18 ARGBEGIN { | |
19 case 'c': | |
20 per_channel = 1; | |
21 break; | |
22 default: | |
23 usage(); | |
24 } ARGEND; | |
25 | |
26 if (argc) | |
27 usage(); | |
28 | |
29 eopen_stream(&stream, NULL); | |
30 | |
31 SELECT_PROCESS_FUNCTION(&stream); | |
32 CHECK_CHANS(&stream, == 3, == 1); | |
33 | |
34 if (stream.width > 2 || stream.height > 2 || stream.width * stre… | |
35 eprintf("<stdin>: each frame must contain exactly 2 pixe… | |
36 | |
37 stream.width = 3; | |
38 stream.height = 3; | |
39 fprint_stream_head(stdout, &stream); | |
40 efflush(stdout, "<stdout>"); | |
41 | |
42 process(&stream); | |
43 return 0; | |
44 } | |
45 | |
46 #else | |
47 | |
48 static void | |
49 PROCESS(struct stream *stream) | |
50 { | |
51 typedef TYPE pixel_t[4]; | |
52 pixel_t matrix[9]; | |
53 pixel_t buf[2]; | |
54 size_t i; | |
55 | |
56 for (i = 0; i < stream->n_chan; i++) { | |
57 matrix[0][i] = 1, matrix[1][i] = 0, matrix[2][i] = 0; | |
58 matrix[3][i] = 0, matrix[4][i] = 1, matrix[5][i] = 0; | |
59 matrix[6][i] = 0, matrix[7][i] = 0, matrix[8][i] = 1; | |
60 } | |
61 | |
62 while (eread_frame(stream, buf)) { | |
63 if (per_channel) { | |
64 for (i = 0; i < stream->n_chan; i++) { | |
65 matrix[0][i] = buf[0][i]; | |
66 matrix[4][i] = buf[1][i]; | |
67 } | |
68 } else { | |
69 buf[0][1] *= buf[0][3]; | |
70 buf[1][1] *= buf[1][3]; | |
71 for (i = 0; i < stream->n_chan; i++) { | |
72 matrix[0][i] = buf[0][1]; | |
73 matrix[4][i] = buf[1][1]; | |
74 } | |
75 } | |
76 ewriteall(STDOUT_FILENO, matrix, sizeof(matrix), "<stdou… | |
77 } | |
78 } | |
79 | |
80 #endif |