commit ddc1fb232ef66f402b44e5e3ec55654faec7ada2
parent 541acb83c081808dc2c19e2cb9a891792462999b
Author: Mattias Andrée <maandree@kth.se>
Date: Tue, 10 Jan 2017 07:44:06 +0100
vu-single-colour: print header
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat:
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/src/vu-single-colour.c b/src/vu-single-colour.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "arg.h"
+#include "stream.h"
#include "util.h"
#include <inttypes.h>
@@ -17,35 +18,39 @@ usage(void)
int
main(int argc, char *argv[])
{
+ struct stream stream;
double X, Y, Z, alpha = 1;
- size_t width = 0, height = 0, frames = 1;
size_t x, y, n;
pixel_t buf[1024];
ssize_t r;
int inf = 0;
char *arg;
+ stream.width = 0;
+ stream.height = 0;
+ stream.frames = 1;
+
ARGBEGIN {
case 'f':
arg = EARGF(usage());
if (!strcmp(arg, "inf"))
- inf = 1, frames = 0;
- else if (tozu(arg, 1, SIZE_MAX, &frames))
+ inf = 1, stream.frames = 0;
+ else if (tozu(arg, 1, SIZE_MAX, &stream.frames))
eprintf("argument of -f must be an integer in [1, %zu] or 'inf'\n", SIZE_MAX);
break;
case 'w':
- if (tozu(EARGF(usage()), 1, SIZE_MAX, &width))
+ if (tozu(EARGF(usage()), 1, SIZE_MAX, &stream.width))
eprintf("argument of -w must be an integer in [1, %zu]\n", SIZE_MAX);
break;
case 'h':
- if (tozu(EARGF(usage()), 1, SIZE_MAX, &height))
+ if (tozu(EARGF(usage()), 1, SIZE_MAX, &stream.height))
eprintf("argument of -h must be an integer in [1, %zu]\n", SIZE_MAX);
break;
default:
usage();
} ARGEND;
- if (!width || !height || !argc || argc > 4)
+ if (!stream.width || !stream.height || !argc || argc > 4)
usage();
if (argc < 3) {
@@ -64,15 +69,21 @@ main(int argc, char *argv[])
if (!(argc & 1) && tolf(argv[argc - 1], &alpha))
eprintf("the alpha value must be a floating-point value\n");
+ strcpy(stream.pixfmt, "xyza");
+ fprint_stream_head(stdout, &stream);
+ fflush(stdout);
+ if (ferror(stdout))
+ eprintf("<stdout>:");
+
for (x = 0; x < ELEMENTSOF(buf); x++) {
buf[x][0] = X;
buf[x][1] = Y;
buf[x][2] = Z;
buf[x][3] = alpha;
}
- while (inf || frames--) {
- for (y = height; y--;) {
- for (x = width; x;) {
+ while (inf || stream.frames--) {
+ for (y = stream.height; y--;) {
+ for (x = stream.width; x;) {
x -= n = ELEMENTSOF(buf) < x ? ELEMENTSOF(buf) : x;
for (n *= sizeof(*buf); n; n -= (size_t)r) {
r = write(STDOUT_FILENO, buf, n);