blind

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

blind-rectangle-tessellation.c (2045B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include "common.h"
      3 
      4 USAGE("[-F pixel-format] block-width block-height")
      5 
      6 #define SET_XYZA(TYPE)\
      7 	(colours = alloca(4 * stream.pixel_size),\
      8 	 ((TYPE *)colours)[ 0] = (TYPE)0.412457445582367600,\
      9 	 ((TYPE *)colours)[ 1] = (TYPE)0.212673370378408280,\
     10 	 ((TYPE *)colours)[ 2] = (TYPE)0.019333942761673460,\
     11 	 ((TYPE *)colours)[ 3] = (TYPE)1,\
     12 	 ((TYPE *)colours)[ 4] = (TYPE)0.770033310827883400,\
     13 	 ((TYPE *)colours)[ 5] = (TYPE)0.927825100869440000,\
     14 	 ((TYPE *)colours)[ 6] = (TYPE)0.138525897843512050,\
     15 	 ((TYPE *)colours)[ 7] = (TYPE)1,\
     16 	 ((TYPE *)colours)[ 8] = (TYPE)0.357575865245515900,\
     17 	 ((TYPE *)colours)[ 9] = (TYPE)0.715151730491031800,\
     18 	 ((TYPE *)colours)[10] = (TYPE)0.119191955081838600,\
     19 	 ((TYPE *)colours)[11] = (TYPE)1,\
     20 	 ((TYPE *)colours)[12] = (TYPE)D65_XYZ_X,\
     21 	 ((TYPE *)colours)[13] = (TYPE)1.0000,\
     22 	 ((TYPE *)colours)[14] = (TYPE)D65_XYZ_Z,\
     23 	 ((TYPE *)colours)[15] = (TYPE)1)
     24 
     25 static struct stream stream = { .width = 0, .height = 0, .frames = 1 };
     26 
     27 int
     28 main(int argc, char *argv[])
     29 {
     30 	size_t width, height;
     31 	const char *pixfmt = "xyza";
     32 	char *colours;
     33 	size_t x1, y1, x2, y2;
     34 
     35 	ARGBEGIN {
     36 	case 'F':
     37 		pixfmt = UARGF();
     38 		break;
     39 	default:
     40 		usage();
     41 	} ARGEND;
     42 
     43 	if (argc != 2)
     44 		usage();
     45 
     46 	width  = etozu_arg("block-width", argv[0], 1, SIZE_MAX);
     47 	height = etozu_arg("block-height", argv[1], 1, SIZE_MAX);
     48 
     49 	eset_pixel_format(&stream, pixfmt);
     50 	CHECK_N_CHAN(&stream, 4, 4);
     51 	if (stream.encoding == DOUBLE)
     52 		SET_XYZA(double);
     53 	else if (stream.encoding == FLOAT)
     54 		SET_XYZA(float);
     55 	else
     56 		eprintf("pixel format %s is not supported, try xyza\n", stream.pixfmt);
     57 
     58 	stream.width  = 2 * width;
     59 	stream.height = 2 * height;
     60 	fprint_stream_head(stdout, &stream);
     61 	efflush(stdout, "<stdout>");
     62 
     63 	for (y1 = 0; y1 < 2; y1++)
     64 		for (y2 = 0; y2 < height; y2++)
     65 			for (x1 = 0; x1 < 2; x1++)
     66 				for (x2 = 0; x2 < width; x2++)
     67 					ewriteall(STDOUT_FILENO, colours + (y1 * 2 + x1) * stream.pixel_size,
     68 					          stream.pixel_size, "<stdout>");
     69 
     70 	return 0;
     71 }