blind

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

blind-unpremultiply.c (1433B)


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