From a21ebe8bea569e7d8961b9711d430d21c92f769b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 11 Jan 2017 09:30:33 +0100 Subject: Reuse code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/vu-set-luma.c | 47 +---------------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) (limited to 'src/vu-set-luma.c') diff --git a/src/vu-set-luma.c b/src/vu-set-luma.c index 151a15f..4500645 100644 --- a/src/vu-set-luma.c +++ b/src/vu-set-luma.c @@ -25,7 +25,6 @@ int main(int argc, char *argv[]) { struct stream colour, luma; - size_t n; void (*process)(struct stream *colour, struct stream *luma, size_t n); ENOFLAGS(argc != 1); @@ -38,55 +37,11 @@ main(int argc, char *argv[]) luma.fd = eopen(luma.file, O_RDONLY); einit_stream(&luma); - echeck_compat(&colour, &luma); - if (!strcmp(colour.pixfmt, "xyza")) process = process_xyza; else eprintf("pixel format %s is not supported, try xyza\n", colour.pixfmt); - for (;;) { - if (colour.ptr < sizeof(colour.buf) && !eread_stream(&colour, SIZE_MAX)) { - close(colour.fd); - colour.fd = -1; - break; - } - if (luma.ptr < sizeof(luma.buf) && !eread_stream(&luma, SIZE_MAX)) { - close(luma.fd); - luma.fd = -1; - break; - } - - n = colour.ptr < luma.ptr ? colour.ptr : luma.ptr; - n -= n % colour.pixel_size; - colour.ptr -= n; - luma.ptr -= n; - - process(&colour, &luma, n); - - ewriteall(STDOUT_FILENO, colour.buf, n, ""); - if ((n & 3) || colour.ptr != luma.ptr) { - memmove(colour.buf, colour.buf + n, colour.ptr); - memmove(luma.buf, luma.buf + n, luma.ptr); - } - } - - if (luma.fd >= 0) - close(luma.fd); - - ewriteall(STDOUT_FILENO, colour.buf, colour.ptr, ""); - - if (colour.fd >= 0) { - for (;;) { - colour.ptr = 0; - if (!eread_stream(&colour, SIZE_MAX)) { - close(colour.fd); - colour.fd = -1; - break; - } - ewriteall(STDOUT_FILENO, colour.buf, colour.ptr, ""); - } - } - + process_two_streams(&colour, &luma, STDOUT_FILENO, "", process); return 0; } -- cgit v1.2.3-70-g09d2