blind

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

blind-round-wave.c (1450B)


      1 /* See LICENSE file for copyright and license details. */
      2 #ifndef TYPE
      3 #include "common.h"
      4 
      5 USAGE("[-e]")
      6 
      7 static int equal = 0;
      8 
      9 #define FILE "blind-round-wave.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 'e':
     20 		equal = 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 	fprint_stream_head(stdout, &stream);
     33 	efflush(stdout, "<stdout>");
     34 	process(&stream);
     35 	return 0;
     36 }
     37 
     38 #else
     39 
     40 static void
     41 PROCESS(struct stream *stream)
     42 {
     43 	size_t i, j, n;
     44 	TYPE v, *p;
     45 	do {
     46 		if (equal) {
     47 			n = stream->ptr / stream->pixel_size;
     48 			for (i = 0; i < n; i++) {
     49 				p = (TYPE *)(stream->buf) + i * stream->n_chan;
     50 				v = posmod(*p + 1, (TYPE)4) - 1;
     51 				v = v < 1 ? 1 - v * v / 2 : (v - 2) * (v - 2) / 2;
     52 				for (j = 0; j < stream->n_chan; j++)
     53 					p[j] = v;
     54 			}
     55 			n *= stream->pixel_size;
     56 		} else {
     57 			n = stream->ptr / stream->chan_size;
     58 			for (i = 0; i < n; i++) {
     59 				p = (TYPE *)(stream->buf) + i;
     60 				v = posmod(*p + 1, (TYPE)4) - 1;
     61 				*p = v < 1 ? 1 - v * v / 2 : (v - 2) * (v - 2) / 2;
     62 			}
     63 			n *= stream->chan_size;
     64 		}
     65 		ewriteall(STDOUT_FILENO, stream->buf, n, "<stdout>");
     66 		memmove(stream->buf, stream->buf + n, stream->ptr -= n);
     67 	} while (eread_stream(stream, SIZE_MAX));
     68 	if (stream->ptr)
     69 		eprintf("%s: incomplete frame\n", stream->file);
     70 }
     71 
     72 #endif