From e76229ac4f95ac8c6e4e38e60689a09a091e4048 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 2 Jul 2017 23:58:01 +0200 Subject: Add gradients MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blind-coordinate-field.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/blind-coordinate-field.c (limited to 'src/blind-coordinate-field.c') diff --git a/src/blind-coordinate-field.c b/src/blind-coordinate-field.c new file mode 100644 index 0000000..2d73399 --- /dev/null +++ b/src/blind-coordinate-field.c @@ -0,0 +1,77 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-f frames | -f 'inf'] [-F pixel-format] -w width -h height") + +static struct stream stream = { .width = 0, .height = 0, .frames = 1 }; +static int inf = 0; + +#define PROCESS(TYPE)\ + do {\ + TYPE buf[4] = {0, 0, 0, 0};\ + size_t x, y;\ + \ + while (inf || stream.frames--) {\ + for (y = 0; y < stream.height; y++) {\ + buf[1] = (TYPE)y;\ + for (x = 0; x < stream.width; x++) {\ + buf[0] = (TYPE)x;\ + if (write(STDOUT_FILENO, buf, sizeof(buf)) < 0)\ + eprintf("write :");\ + }\ + }\ + }\ + } while (0) + +static void process_lf(void) {PROCESS(double);} +static void process_f(void) {PROCESS(float);} + +int +main(int argc, char *argv[]) +{ + char *arg; + const char *pixfmt = "xyza"; + void (*process)(void); + + ARGBEGIN { + case 'f': + arg = UARGF(); + if (!strcmp(arg, "inf")) + inf = 1, stream.frames = 0; + else + stream.frames = etozu_flag('f', arg, 1, SIZE_MAX); + break; + case 'F': + pixfmt = UARGF(); + break; + case 'w': + stream.width = etozu_flag('w', UARGF(), 1, SIZE_MAX); + break; + case 'h': + stream.height = etozu_flag('h', UARGF(), 1, SIZE_MAX); + break; + default: + usage(); + } ARGEND; + + if (!stream.width || !stream.height || argc) + usage(); + + if (inf) + einf_check_fd(STDOUT_FILENO, ""); + + pixfmt = get_pixel_format(pixfmt, "xyza"); + if (!strcmp(pixfmt, "xyza")) + process = process_lf; + else if (!strcmp(pixfmt, "xyza f")) + process = process_f; + else + eprintf("pixel format %s is not supported, try xyza\n", pixfmt); + + strcpy(stream.pixfmt, pixfmt); + fprint_stream_head(stdout, &stream); + efflush(stdout, ""); + + process(); + return 0; +} -- cgit v1.2.3-70-g09d2