blind

suckless command-line video editing utility
git clone git://git.suckless.org/blind
Log | Files | Refs | README | LICENSE

blind-flop.c (1097B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include "common.h"
      3 
      4 USAGE("")
      5 
      6 static struct stream stream;
      7 static char *buf, *image;
      8 static size_t n, m, ps;
      9 
     10 #define PROCESS(TYPE)\
     11 	do {\
     12 		size_t i, j;\
     13 		for (i = 0; i < ps; i++)\
     14 			for (j = 0; j < n; j += ps)\
     15 				((TYPE *)image)[m - j + i] = ((TYPE *)buf)[i + j];\
     16 	} while (0)
     17 
     18 static void process_long(void) {PROCESS(long);}
     19 static void process_char(void) {PROCESS(char);}
     20 
     21 int
     22 main(int argc, char *argv[])
     23 {
     24 	void (*process)(void) = process_char;
     25 
     26 	UNOFLAGS(argc);
     27 
     28 	eopen_stream(&stream, NULL);
     29 	echeck_dimensions(&stream, WIDTH, NULL);
     30 	fprint_stream_head(stdout, &stream);
     31 	efflush(stdout, "<stdout>");
     32 	buf   = emalloc(stream.row_size);
     33 	image = emalloc(stream.row_size);
     34 
     35 	m = (n = stream.row_size) - (ps = stream.pixel_size);
     36 	if (!(stream.pixel_size % sizeof(long))) {
     37 		process = process_long;
     38 		m  /= sizeof(long);
     39 		n  /= sizeof(long);
     40 		ps /= sizeof(long);
     41 	}
     42 
     43 	while (eread_row(&stream, buf)) {
     44 		process();
     45 		ewriteall(STDOUT_FILENO, image, stream.row_size, "<stdout>");
     46 	}
     47 
     48 	free(buf);
     49 	free(image);
     50 	return 0;
     51 }