blind

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

blind-triangular-wave.c (1568B)


      1 /* See LICENSE file for copyright and license details. */
      2 #ifndef TYPE
      3 #include "common.h"
      4 
      5 USAGE("[-es]")
      6 
      7 static int equal = 0;
      8 static int spiral = 0;
      9 
     10 #define FILE "blind-triangular-wave.c"
     11 #include "define-functions.h"
     12 
     13 int
     14 main(int argc, char *argv[])
     15 {
     16 	struct stream stream;
     17 	void (*process)(struct stream *stream);
     18 
     19 	ARGBEGIN {
     20 	case 'e':
     21 		equal = 1;
     22 		break;
     23 	case 's':
     24 		spiral = 1;
     25 		break;
     26 	default:
     27 		usage();
     28 	} ARGEND;
     29 
     30 	if (argc)
     31 		usage();
     32 
     33 	eopen_stream(&stream, NULL);
     34 
     35 	SELECT_PROCESS_FUNCTION(&stream);
     36 	fprint_stream_head(stdout, &stream);
     37 	efflush(stdout, "<stdout>");
     38 	process(&stream);
     39 	return 0;
     40 }
     41 
     42 #else
     43 
     44 static void
     45 PROCESS(struct stream *stream)
     46 {
     47 	size_t i, j, n;
     48 	TYPE v, *p;
     49 	do {
     50 		if (equal) {
     51 			n = stream->ptr / stream->pixel_size;
     52 			for (i = 0; i < n; i++) {
     53 				p = (TYPE *)(stream->buf) + i * stream->n_chan;
     54 				v = posmod(*p, (TYPE)2);
     55 				v = v > 1 ? 2 - v : v;
     56 				if (spiral)
     57 					v = (v > (TYPE)0.5 ? 1 - v : v) * 2;
     58 				for (j = 0; j < stream->n_chan; j++)
     59 					p[j] = v;
     60 			}
     61 			n *= stream->pixel_size;
     62 		} else {
     63 			n = stream->ptr / stream->chan_size;
     64 			for (i = 0; i < n; i++) {
     65 				p = (TYPE *)(stream->buf) + i;
     66 				v = posmod(*p, (TYPE)2);
     67 				v = v > 1 ? 2 - v : v;
     68 				if (spiral)
     69 					v = (v > (TYPE)0.5 ? 1 - v : v) * 2;
     70 				*p = v;
     71 			}
     72 			n *= stream->chan_size;
     73 		}
     74 		ewriteall(STDOUT_FILENO, stream->buf, n, "<stdout>");
     75 		memmove(stream->buf, stream->buf + n, stream->ptr -= n);
     76 	} while (eread_stream(stream, SIZE_MAX));
     77 	if (stream->ptr)
     78 		eprintf("%s: incomplete frame\n", stream->file);
     79 }
     80 
     81 #endif