aboutsummaryrefslogtreecommitdiffstats
path: root/src/vu-set-saturation.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-01-11 09:30:33 +0100
committerMattias Andrée <maandree@kth.se>2017-01-11 09:30:33 +0100
commita21ebe8bea569e7d8961b9711d430d21c92f769b (patch)
treedda3810db2e7ad3683bdfc6f68538da144c2a0c8 /src/vu-set-saturation.c
parentClean up code (diff)
downloadblind-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-saturation.c')
-rw-r--r--src/vu-set-saturation.c47
1 files changed, 1 insertions, 46 deletions
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, "<stdout>");
- 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, "<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, &satur, STDOUT_FILENO, "<stdout>", process);
return 0;
}