blind

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

blind-cross-product.c (1305B)


      1 /* See LICENSE file for copyright and license details. */
      2 #ifndef TYPE
      3 #include "common.h"
      4 
      5 USAGE("right-hand-stream")
      6 
      7 #define FILE "blind-cross-product.c"
      8 #include "define-functions.h"
      9 
     10 int
     11 main(int argc, char *argv[])
     12 {
     13 	struct stream left, right;
     14 	void (*process)(struct stream *left, struct stream *right, size_t n);
     15 
     16 	UNOFLAGS(argc != 1);
     17 
     18 	eopen_stream(&left, NULL);
     19 	eopen_stream(&right, argv[0]);
     20 
     21 	SELECT_PROCESS_FUNCTION(&left);
     22 	CHECK_ALPHA_CHAN(&left);
     23 	CHECK_N_CHAN(&left, 4, 4);
     24 
     25 	fprint_stream_head(stdout, &left);
     26 	efflush(stdout, "<stdout>");
     27 	process_two_streams(&left, &right, STDOUT_FILENO, "<stdout>", process);
     28 	return 0;
     29 }
     30 
     31 #else
     32 
     33 static void
     34 PROCESS(struct stream *left, struct stream *right, size_t n)
     35 {
     36 	size_t i;
     37 	TYPE *lx, *ly, *lz, *la, *rx, *ry, *rz, *ra, x, y, z, a;
     38 	for (i = 0; i < n; i += 4 * sizeof(TYPE)) {
     39 		lx = ((TYPE *)(left->buf + i)) + 0, rx = ((TYPE *)(right->buf + i)) + 0;
     40 		ly = ((TYPE *)(left->buf + i)) + 1, ry = ((TYPE *)(right->buf + i)) + 1;
     41 		lz = ((TYPE *)(left->buf + i)) + 2, rz = ((TYPE *)(right->buf + i)) + 2;
     42 		la = ((TYPE *)(left->buf + i)) + 3, ra = ((TYPE *)(right->buf + i)) + 3;
     43 		x = *ly * *rz - *lz * *ry;
     44 		y = *lz * *rx - *lx * *rz;
     45 		z = *lx * *ry - *ly * *rx;
     46 		a = *la * *ra;
     47 		*lx = x;
     48 		*ly = y;
     49 		*lz = z;
     50 		*la = a;
     51 	}
     52 }
     53 
     54 #endif