From b7a82c980fe7e0c1f9029b55be97422428d65d5a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 11 Jan 2017 09:11:51 +0100 Subject: Clean up code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/vu-invert-luma.c | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) (limited to 'src/vu-invert-luma.c') 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 #include -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 :"); - } - + ewriteall(STDOUT_FILENO, colour.buf, n, ""); 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 :"); - } + ewriteall(STDOUT_FILENO, colour.buf, colour.ptr, ""); 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 :"); - } + ewriteall(STDOUT_FILENO, colour.buf, colour.ptr, ""); } } -- cgit v1.2.3-70-g09d2