blind

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

blind-dissolve.c (1255B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include "common.h"
      3 
      4 USAGE("[-r]")
      5 
      6 static size_t fm;
      7 static double fm_double;
      8 static float fm_float;
      9 static int reverse = 0;
     10 
     11 #define PROCESS(TYPE)\
     12 	do {\
     13 		size_t i = (size_t)(stream->alpha_chan) * stream->chan_size;\
     14 		TYPE a = fm ? (TYPE)(reverse ? f : fm - f) / fm_##TYPE : (TYPE)0.5;\
     15 		for (; i < n; i += stream->pixel_size)\
     16 			*(TYPE *)(stream->buf + i) *= a;\
     17 	} while (0)
     18 
     19 static void process_lf(struct stream *stream, size_t n, size_t f) {PROCESS(double);}
     20 static void process_f (struct stream *stream, size_t n, size_t f) {PROCESS(float);}
     21 
     22 int
     23 main(int argc, char *argv[])
     24 {
     25 	struct stream stream;
     26 	void (*process)(struct stream *stream, size_t n, size_t f);
     27 
     28 	ARGBEGIN {
     29 	case 'r':
     30 		reverse = 1;
     31 		break;
     32 	default:
     33 		usage();
     34 	} ARGEND;
     35 
     36 	if (argc)
     37 		usage();
     38 
     39 	eopen_stream(&stream, NULL);
     40 
     41 	SELECT_PROCESS_FUNCTION(&stream);
     42 	CHECK_CHANS(&stream, != -1, == stream.luma_chan);
     43 
     44 	if (!stream.frames)
     45 		eprintf("video's length is not recorded");
     46 
     47 	fprint_stream_head(stdout, &stream);
     48 	efflush(stdout, "<stdout>");
     49 	fm_double = (double)(fm = stream.frames - 1);
     50 	fm_float = (float)fm_double;
     51 	process_each_frame_segmented(&stream, STDOUT_FILENO, "<stdout>", process);
     52 	return 0;
     53 }