aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-flop.c
blob: 5f737f395c774a81a9fc73a72b5936f3fa7fff16 (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
/* See LICENSE file for copyright and license details. */
#include "stream.h"
#include "util.h"

#include <inttypes.h>
#include <string.h>
#include <unistd.h>

USAGE("")

int
main(int argc, char *argv[])
{
	struct stream stream;
	char *buf, *image;
	size_t i, j, n, m;

	ENOFLAGS(argc);

	stream.file = "<stdin>";
	stream.fd = STDIN_FILENO;
	einit_stream(&stream);
	fprint_stream_head(stdout, &stream);
	efflush(stdout, "<stdout>");

	if (stream.width > SIZE_MAX / stream.pixel_size)
		eprintf("<stdin>: video frame is too wide\n");
	n = stream.width * stream.pixel_size;
	buf   = emalloc(n);
	image = emalloc(n);

	m = n - stream.pixel_size;
	while (eread_row(&stream, buf, n)) {
		for (i = 0; i < stream.pixel_size; i++)
			for (j = 0; j < n; j += stream.pixel_size)
				image[m - j + i] = buf[i + j];
		ewriteall(STDOUT_FILENO, image, n, "<stdout>");
	}

	free(buf);
	free(image);
	return 0;
}