aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-repeat-tessellation.c
blob: 4e4fc6073d1445d682bd375bfd8c29860c19d879 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* See LICENSE file for copyright and license details. */
#include "common.h"

USAGE("-w width -h height")

int
main(int argc, char *argv[])
{
	struct stream stream;
	size_t width = 0;
	size_t height = 0;
	size_t x, y, p, w;
	char *buf;

	ARGBEGIN {
	case 'w':
		width = etozu_flag('w', UARGF(), 1, SIZE_MAX);
		break;
	case 'h':
		height = etozu_flag('h', UARGF(), 1, SIZE_MAX);
		break;
	default:
		usage();
	} ARGEND;

	if (!width || !height || argc)
		usage();

	eopen_stream(&stream, NULL);
	echeck_dimensions(&stream, WIDTH | HEIGHT, NULL);
	x = stream.width,  stream.width = width;
	y = stream.height, stream.height = height;
	fprint_stream_head(stdout, &stream);
	efflush(stdout, "<stdout>");
	stream.width  = x;
	stream.height = y;
	buf = emalloc(stream.frame_size);

	w = width % stream.width;
	while (eread_frame(&stream, buf)) {
		for (y = 0; y < height; y++) {
			p = (y % stream.height) * stream.row_size;
			for (x = 0; x < width / stream.width; x++)
				ewriteall(STDOUT_FILENO, buf + p, stream.row_size, "<stdout>");
			if (w)
				ewriteall(STDOUT_FILENO, buf + p, w * stream.pixel_size, "<stdout>");
		}
	}

	free(buf);
	return 0;
}