diff options
Diffstat (limited to 'src/vu-invert-luma.c')
| -rw-r--r-- | src/vu-invert-luma.c | 42 |
1 files changed, 8 insertions, 34 deletions
diff --git a/src/vu-invert-luma.c b/src/vu-invert-luma.c index 52b360f..2089e8f 100644 --- a/src/vu-invert-luma.c +++ b/src/vu-invert-luma.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include "arg.h" #include "stream.h" #include "util.h" @@ -8,11 +7,7 @@ #include <string.h> #include <unistd.h> -static void -usage(void) -{ - eprintf("usage: %s [-i] mask-stream\n", argv0); -} +USAGE("[-i] mask-stream") static void process_xyza(struct stream *colour, struct stream *mask, size_t n) @@ -46,10 +41,8 @@ int main(int argc, char *argv[]) { int invert = 0; - struct stream colour; - struct stream mask; - ssize_t r; - size_t i, n; + struct stream colour, mask; + size_t n; void (*process)(struct stream *colour, struct stream *mask, size_t n) = NULL; ARGBEGIN { @@ -68,15 +61,10 @@ main(int argc, char *argv[]) einit_stream(&colour); mask.file = argv[0]; - mask.fd = open(mask.file, O_RDONLY); - if (mask.fd < 0) - eprintf("open %s:", mask.file); + mask.fd = eopen(mask.file, O_RDONLY); einit_stream(&mask); - if (colour.width != mask.width || colour.height != mask.height) - eprintf("videos do not have the same geometry\n"); - if (colour.pixel_size != mask.pixel_size) - eprintf("videos use incompatible pixel formats\n"); + echeck_compat(&colour, &mask); if (!strcmp(colour.pixfmt, "xyza")) process = invert ? process_xyza_i : process_xyza; @@ -102,12 +90,7 @@ main(int argc, char *argv[]) process(&colour, &mask, n); - for (i = 0; i < n; i += (size_t)r) { - r = write(STDOUT_FILENO, colour.buf + i, n - i); - if (r < 0) - eprintf("write <stdout>:"); - } - + ewriteall(STDOUT_FILENO, colour.buf, n, "<stdout>"); if ((n & 3) || colour.ptr != mask.ptr) { memmove(colour.buf, colour.buf + n, colour.ptr); memmove(mask.buf, mask.buf + n, mask.ptr); @@ -117,11 +100,7 @@ main(int argc, char *argv[]) if (mask.fd >= 0) close(mask.fd); - for (i = 0; i < colour.ptr; i += (size_t)r) { - r = write(STDOUT_FILENO, colour.buf + i, colour.ptr - i); - if (r < 0) - eprintf("write <stdout>:"); - } + ewriteall(STDOUT_FILENO, colour.buf, colour.ptr, "<stdout>"); if (colour.fd >= 0) { for (;;) { @@ -131,12 +110,7 @@ main(int argc, char *argv[]) colour.fd = -1; break; } - - for (i = 0; i < colour.ptr; i += (size_t)r) { - r = write(STDOUT_FILENO, colour.buf + i, colour.ptr - i); - if (r < 0) - eprintf("write <stdout>:"); - } + ewriteall(STDOUT_FILENO, colour.buf, colour.ptr, "<stdout>"); } } |
