| blind-transpose.c - blind - suckless command-line video editing utility | |
| git clone git://git.suckless.org/blind | |
| Log | |
| Files | |
| Refs | |
| README | |
| LICENSE | |
| --- | |
| blind-transpose.c (1379B) | |
| --- | |
| 1 /* See LICENSE file for copyright and license details. */ | |
| 2 #include "common.h" | |
| 3 | |
| 4 USAGE("") | |
| 5 | |
| 6 static size_t srcw, srch, srcwps, srchps, ps, n; | |
| 7 | |
| 8 #define PROCESS(TYPE)\ | |
| 9 do {\ | |
| 10 size_t x, i;\ | |
| 11 char *src, *img;\ | |
| 12 for (x = 0; x < srchps; x += ps) {\ | |
| 13 img = row + x;\ | |
| 14 src = col + x * srcw;\ | |
| 15 for (i = 0; i < n; i++)\ | |
| 16 ((TYPE *)img)[i] = ((TYPE *)src)[i];\ | |
| 17 }\ | |
| 18 } while (0) | |
| 19 | |
| 20 static void process_long(char *row, char *col) {PROCESS(long);} | |
| 21 static void process_char(char *row, char *col) {PROCESS(char);} | |
| 22 | |
| 23 int | |
| 24 main(int argc, char *argv[]) | |
| 25 { | |
| 26 struct stream stream; | |
| 27 char *buf, *image; | |
| 28 size_t y; | |
| 29 void (*process)(char *row, char *col); | |
| 30 | |
| 31 UNOFLAGS(argc); | |
| 32 | |
| 33 eopen_stream(&stream, NULL); | |
| 34 echeck_dimensions(&stream, WIDTH | HEIGHT, NULL); | |
| 35 srch = stream.height, srchps = stream.col_size; | |
| 36 srcw = stream.width, srcwps = stream.row_size; | |
| 37 stream.height = srcw; | |
| 38 stream.width = srch; | |
| 39 fprint_stream_head(stdout, &stream); | |
| 40 efflush(stdout, "<stdout>"); | |
| 41 | |
| 42 buf = emalloc(stream.frame_size); | |
| 43 image = emalloc(srchps); | |
| 44 | |
| 45 ps = stream.pixel_size; | |
| 46 process = ps % sizeof(long) ? process_char : process_long; | |
| 47 n = ps / (ps % sizeof(long) ? sizeof(char) : sizeof(long)); | |
| 48 while (eread_frame(&stream, buf)) { | |
| 49 for (y = 0; y < srcwps; y += stream.pixel_size) { | |
| 50 process(image, buf + y); | |
| 51 ewriteall(STDOUT_FILENO, image, srchps, "<stdout… | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 free(buf); | |
| 56 free(image); | |
| 57 return 0; | |
| 58 } |