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