blind

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

blind-dual-key.c (2574B)


      1 /* See LICENSE file for copyright and license details. */
      2 #ifndef TYPE
      3 #include "common.h"
      4 
      5 USAGE("[-m] X Y Z dual-X dual-Y dual-Z dual-stream")
      6 
      7 static double X1, Y1, Z1, X2, Y2, Z2;
      8 
      9 #define FILE "blind-dual-key.c"
     10 #include "define-functions.h"
     11 
     12 int
     13 main(int argc, char *argv[])
     14 {
     15 	struct stream stream, dual;
     16 	void (*process)(struct stream *stream, struct stream *dual, size_t n);
     17 
     18 	UNOFLAGS(argc != 7);
     19 
     20 	X1 = etolf_arg("the X value", argv[0]);
     21 	Y1 = etolf_arg("the Y value", argv[1]);
     22 	Z1 = etolf_arg("the Z value", argv[2]);
     23 
     24 	X2 = etolf_arg("the dual-X value", argv[3]);
     25 	Y2 = etolf_arg("the dual-Y value", argv[4]);
     26 	Z2 = etolf_arg("the dual-Z value", argv[5]);
     27 
     28 	eopen_stream(&stream, NULL);
     29 	eopen_stream(&dual, argv[6]);
     30 
     31 	SELECT_PROCESS_FUNCTION(&stream);
     32 	CHECK_ALPHA_CHAN(&stream);
     33 	CHECK_N_CHAN(&stream, 4, 4);
     34 
     35 	fprint_stream_head(stdout, &stream);
     36 	efflush(stdout, "<stdout>");
     37 	process_two_streams(&stream, &dual, STDOUT_FILENO, "<stdout>", process);
     38 	return 0;
     39 }
     40 
     41 #else
     42 
     43 static void
     44 PROCESS(struct stream *stream, struct stream *dual, size_t n)
     45 {
     46 	size_t i;
     47 	TYPE x1k = (TYPE)X1, y1k = (TYPE)Y1, z1k = (TYPE)Z1;
     48 	TYPE x2k = (TYPE)X2, y2k = (TYPE)Y2, z2k = (TYPE)Z2;
     49 	TYPE x1, y1, z1, a1, x2, y2, z2, a2;
     50 	TYPE alpha, xalpha, yalpha, zalpha;
     51 	for (i = 0; i < n; i += stream->pixel_size) {
     52 		x1 = ((TYPE *)(stream->buf + i))[0];
     53 		y1 = ((TYPE *)(stream->buf + i))[1];
     54 		z1 = ((TYPE *)(stream->buf + i))[2];
     55 		a1 = ((TYPE *)(stream->buf + i))[3];
     56 		x2 = ((TYPE *)(dual->buf + i))[0];
     57 		y2 = ((TYPE *)(dual->buf + i))[1];
     58 		z2 = ((TYPE *)(dual->buf + i))[2];
     59 		a2 = ((TYPE *)(dual->buf + i))[3];
     60 		if (x1 == x2 && y1 == y2 && z1 == z2) {
     61 			if (a1 != a2)
     62 				((TYPE *)(stream->buf + i))[3] = (a1 + a2) / 2;
     63 			continue;
     64 		}
     65 		xalpha = x1 == x2 ? (TYPE)0 : (x2 - x1 + x1k - x2k) / (x1k - x2k);
     66 		yalpha = y1 == y2 ? (TYPE)0 : (y2 - y1 + y1k - y2k) / (y1k - y2k);
     67 		zalpha = z1 == z2 ? (TYPE)0 : (z2 - z1 + z1k - z2k) / (z1k - z2k);
     68 		alpha = xalpha > yalpha ? xalpha : yalpha;
     69 		alpha = alpha  > zalpha ? alpha  : zalpha;
     70 		if (!alpha) {
     71 			((TYPE *)(stream->buf + i))[0] = (TYPE)0;
     72 			((TYPE *)(stream->buf + i))[1] = (TYPE)0;
     73 			((TYPE *)(stream->buf + i))[2] = (TYPE)0;
     74 			((TYPE *)(stream->buf + i))[3] = (TYPE)0;
     75 		} else {
     76 			((TYPE *)(stream->buf + i))[0] = ((x1 - x1k + x2 - x2k) / alpha + x1k + x2k) / 2;
     77 			((TYPE *)(stream->buf + i))[1] = ((y1 - y1k + y2 - y2k) / alpha + y1k + y2k) / 2;
     78 			((TYPE *)(stream->buf + i))[2] = ((z1 - z1k + z2 - z2k) / alpha + z1k + z2k) / 2;
     79 			((TYPE *)(stream->buf + i))[3] = (a1 + a2) / 2 * alpha;
     80 		}
     81 	}
     82 }
     83 
     84 #endif