diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-11 09:30:33 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-11 09:30:33 +0100 |
| commit | a21ebe8bea569e7d8961b9711d430d21c92f769b (patch) | |
| tree | dda3810db2e7ad3683bdfc6f68538da144c2a0c8 /src/vu-set-luma.c | |
| parent | Clean up code (diff) | |
| download | blind-a21ebe8bea569e7d8961b9711d430d21c92f769b.tar.gz blind-a21ebe8bea569e7d8961b9711d430d21c92f769b.tar.bz2 blind-a21ebe8bea569e7d8961b9711d430d21c92f769b.tar.xz | |
Reuse code
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/vu-set-luma.c')
| -rw-r--r-- | src/vu-set-luma.c | 47 |
1 files changed, 1 insertions, 46 deletions
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, "<stdout>"); - 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, "<stdout>"); - - 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, "<stdout>"); - } - } - + process_two_streams(&colour, &luma, STDOUT_FILENO, "<stdout>", process); return 0; } |
