blind

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

blind-dot-product.c (960B)


      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-dot-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 	fprint_stream_head(stdout, &left);
     23 	efflush(stdout, "<stdout>");
     24 	process_two_streams(&left, &right, STDOUT_FILENO, "<stdout>", process);
     25 	return 0;
     26 }
     27 
     28 #else
     29 
     30 static void
     31 PROCESS(struct stream *left, struct stream *right, size_t n)
     32 {
     33 	size_t i, j, s = left->n_chan * sizeof(TYPE);
     34 	TYPE v, *l, *r;
     35 	for (i = 0; i < n; i += s) {
     36 		l = (TYPE *)(left->buf + i);
     37 		r = (TYPE *)(right->buf + i);
     38 		v = 0;
     39 		for (j = 0; j < left->n_chan; j++)
     40 			v += l[j] * r[j];
     41 		for (j = 0; j < left->n_chan; j++)
     42 			l[j] = v;
     43 	}
     44 }
     45 
     46 #endif