aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-single-colour.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/blind-single-colour.c')
-rw-r--r--src/blind-single-colour.c65
1 files changed, 43 insertions, 22 deletions
diff --git a/src/blind-single-colour.c b/src/blind-single-colour.c
index 8eb25b9..f7a1afe 100644
--- a/src/blind-single-colour.c
+++ b/src/blind-single-colour.c
@@ -6,20 +6,42 @@
#include <string.h>
#include <unistd.h>
-USAGE("[-f frames | -f 'inf'] -w width -h height (X Y Z | Y) [alpha]")
+USAGE("[-f frames | -f 'inf'] [-F pixel-format] -w width -h height (X Y Z | Y) [alpha]")
-typedef double pixel_t[4];
+static struct stream stream = { .width = 0, .height = 0, .frames = 1 };
+static double X, Y, Z, alpha = 1;
+static int inf = 0;
+
+#define PROCESS(TYPE)\
+ do {\
+ typedef TYPE pixel_t[4];\
+ pixel_t buf[BUFSIZ / 4];\
+ size_t x, y, n;\
+ ssize_t r;\
+ \
+ for (x = 0; x < ELEMENTSOF(buf); x++) {\
+ buf[x][0] = (TYPE)X;\
+ buf[x][1] = (TYPE)Y;\
+ buf[x][2] = (TYPE)Z;\
+ buf[x][3] = (TYPE)alpha;\
+ }\
+ while (inf || stream.frames--)\
+ for (y = stream.height; y--;)\
+ for (x = stream.width * sizeof(*buf); x;)\
+ for (x -= n = MIN(sizeof(buf), x); n; n -= (size_t)r)\
+ if ((r = write(STDOUT_FILENO, buf, n)) < 0)\
+ eprintf("write <stdout>:");\
+ } while (0)
+
+static void process_xyza(void) {PROCESS(double);}
+static void process_xyzaf(void) {PROCESS(float);}
int
main(int argc, char *argv[])
{
- struct stream stream = { .width = 0, .height = 0, .frames = 1 };
- double X, Y, Z, alpha = 1;
- size_t x, y, n;
- pixel_t buf[BUFSIZ / 4];
- ssize_t r;
- int inf = 0;
char *arg;
+ const char *pixfmt = "xyza";
+ void (*process)(void) = NULL;
ARGBEGIN {
case 'f':
@@ -29,6 +51,9 @@ main(int argc, char *argv[])
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;
@@ -57,22 +82,18 @@ main(int argc, char *argv[])
if (inf)
einf_check_fd(STDOUT_FILENO, "<stdout>");
- strcpy(stream.pixfmt, "xyza");
+ pixfmt = get_pixel_format(pixfmt, "xyza");
+ if (!strcmp(pixfmt, "xyza"))
+ process = process_xyza;
+ else if (!strcmp(pixfmt, "xyza f"))
+ process = process_xyzaf;
+ else
+ eprintf("pixel format %s is not supported, try xyza\n", pixfmt);
+
+ strcpy(stream.pixfmt, pixfmt);
fprint_stream_head(stdout, &stream);
efflush(stdout, "<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 || stream.frames--)
- for (y = stream.height; y--;)
- for (x = stream.width * sizeof(*buf); x;)
- for (x -= n = MIN(sizeof(buf), x); n; n -= (size_t)r)
- if ((r = write(STDOUT_FILENO, buf, n)) < 0)
- eprintf("write <stdout>:");
-
+ process();
return 0;
}