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-saturation.c | 47 +---------------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) (limited to 'src/vu-set-saturation.c') diff --git a/src/vu-set-saturation.c b/src/vu-set-saturation.c index 33630f2..1d3ed83 100644 --- a/src/vu-set-saturation.c +++ b/src/vu-set-saturation.c @@ -48,7 +48,6 @@ main(int argc, char *argv[]) { struct stream colour, satur; int whitepoint = 0; - size_t n; void (*process)(struct stream *colour, struct stream *satur, size_t n) = NULL; ARGBEGIN { @@ -70,55 +69,11 @@ main(int argc, char *argv[]) satur.fd = eopen(satur.file, O_RDONLY); einit_stream(&satur); - echeck_compat(&colour, &satur); - if (!strcmp(colour.pixfmt, "xyza")) process = whitepoint ? process_xyza_w : 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 (satur.ptr < sizeof(satur.buf) && !eread_stream(&satur, SIZE_MAX)) { - close(satur.fd); - satur.fd = -1; - break; - } - - n = colour.ptr < satur.ptr ? colour.ptr : satur.ptr; - n -= n % colour.pixel_size; - colour.ptr -= n; - satur.ptr -= n; - - process(&colour, &satur, n); - - ewriteall(STDOUT_FILENO, colour.buf, n, ""); - if ((n & 3) || colour.ptr != satur.ptr) { - memmove(colour.buf, colour.buf + n, colour.ptr); - memmove(satur.buf, satur.buf + n, satur.ptr); - } - } - - if (satur.fd >= 0) - close(satur.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, &satur, STDOUT_FILENO, "", process); return 0; } -- cgit v1.2.3-70-g09d2