aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-next-frame.c
blob: d3f43a14a7e2457f10274e4bedd1d48af88364fc (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
/* See LICENSE file for copyright and license details. */
#include "common.h"

NUSAGE(2, "[-f frames] width height pixel-format ...")

int
main(int argc, char *argv[])
{
	struct stream stream = { .frames = 1, .fd = STDIN_FILENO, .file = "<stdin>" };
	size_t n;
	int i;
	char *p;

	ARGBEGIN {
	case 'f':
		stream.frames = entozu_flag(2, 'f', UARGF(), 1, SIZE_MAX);
		break;
	default:
		usage();
	} ARGEND;

	if (argc < 3)
		usage();

	stream.pixfmt[0] = '\0';
	stream.width  = entozu_arg(2, "the width",  argv[0], 1, SIZE_MAX);
	stream.height = entozu_arg(2, "the height", argv[1], 1, SIZE_MAX);
	argv += 2, argc -= 2;

	n = (size_t)argc - 1;
	for (i = 0; i < argc; i++)
		n += strlen(argv[i]);
	if (n < sizeof(stream.pixfmt)) {
		p = stpcpy(stream.pixfmt, argv[0]);
		for (i = 1; i < argc; i++) {
			*p++ = ' ';
			p = stpcpy(p, argv[i]);
		}
	}
	enset_pixfmt(2, &stream, NULL);

	fprint_stream_head(stdout, &stream);
	enfflush(2, stdout, "<stdout>");

	n = ensend_frames(2, &stream, STDOUT_FILENO, stream.frames, "<stdout>");
	if (!n)
		return 1;
	else if (n < stream.frames)
		enprintf(2, "%s: is shorter than expected\n", stream.file);
	return 0;
}