aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-to-video.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-01-14 04:40:03 +0100
committerMattias Andrée <maandree@kth.se>2017-01-14 04:40:03 +0100
commita2dfbb3368ce0e998f774dd294383772651d1302 (patch)
tree094dbc3206297d3b3b0d090daff426ce66ea45f7 /src/blind-to-video.c
parentRename to blind (diff)
downloadblind-a2dfbb3368ce0e998f774dd294383772651d1302.tar.gz
blind-a2dfbb3368ce0e998f774dd294383772651d1302.tar.bz2
blind-a2dfbb3368ce0e998f774dd294383772651d1302.tar.xz
Fix errors, blind-{to,from}-{video,image} works
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-to-video.c')
-rw-r--r--src/blind-to-video.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/blind-to-video.c b/src/blind-to-video.c
index ac4707e..0793a0a 100644
--- a/src/blind-to-video.c
+++ b/src/blind-to-video.c
@@ -2,7 +2,6 @@
#include "stream.h"
#include "util.h"
-#include <arpa/inet.h>
#if defined(HAVE_PRCTL)
# include <sys/prctl.h>
#endif
@@ -28,22 +27,21 @@ process_xyza(char *buf, size_t n, int fd, const char *fname)
pixels = pixbuf;
end = pixbuf + ELEMENTSOF(pixbuf);
if (draft) {
- for (ptr = 0; ptr < n; ptr += sizeof(pixel)) {
+ for (ptr = 0; ptr < n; ptr += 4 * sizeof(double)) {
pixel = (double *)(buf + ptr);
- a = (long int)(pixel[3] * 0xFFFFL);
ciexyz_to_scaled_yuv(pixel[0], pixel[1], pixel[2], &r, &g, &b);
- y = (long int)r + 16 * 256;
- u = (long int)g + 128 * 256;
- v = (long int)b + 128 * 256;
- *pixels++ = htons((uint16_t)(a < 0 ? 0 : a > 0xFFFFL ? 0xFFFFL : a));
- *pixels++ = htons((uint16_t)(y < 0 ? 0 : y > 0xFFFFL ? 0xFFFFL : y));
- *pixels++ = htons((uint16_t)(u < 0 ? 0 : u > 0xFFFFL ? 0xFFFFL : u));
- *pixels++ = htons((uint16_t)(v < 0 ? 0 : v > 0xFFFFL ? 0xFFFFL : v));
+ y = (long int)r + 16L * 256L;
+ u = (long int)g + 128L * 256L;
+ v = (long int)b + 128L * 256L;
+ *pixels++ = 0xFFFFU;
+ *pixels++ = htole16((uint16_t)(y < 0 ? 0 : y > 0xFFFFL ? 0xFFFFL : y));
+ *pixels++ = htole16((uint16_t)(u < 0 ? 0 : u > 0xFFFFL ? 0xFFFFL : u));
+ *pixels++ = htole16((uint16_t)(v < 0 ? 0 : v > 0xFFFFL ? 0xFFFFL : v));
if (pixels == end)
ewriteall(fd, pixels = pixbuf, sizeof(pixbuf), fname);
}
} else {
- for (ptr = 0; ptr < n; ptr += sizeof(pixel)) {
+ for (ptr = 0; ptr < n; ptr += 4 * sizeof(double)) {
pixel = (double *)(buf + ptr);
a = (long int)(pixel[3] * 0xFFFFL);
ciexyz_to_srgb(pixel[0], pixel[1], pixel[2], &r, &g, &b);
@@ -51,22 +49,19 @@ process_xyza(char *buf, size_t n, int fd, const char *fname)
g = srgb_encode(g);
b = srgb_encode(b);
srgb_to_yuv(r, g, b, pixel + 0, pixel + 1, pixel + 2);
- y = (long int)(pixel[0] * 0xFFFFL);
- u = (long int)(pixel[1] * 0xFFFFL);
- v = (long int)(pixel[2] * 0xFFFFL);
- y += 16 * 256;
- u += 128 * 256;
- v += 128 * 256;
- *pixels++ = htons((uint16_t)(a < 0 ? 0 : a > 0xFFFFL ? 0xFFFFL : a));
- *pixels++ = htons((uint16_t)(y < 0 ? 0 : y > 0xFFFFL ? 0xFFFFL : y));
- *pixels++ = htons((uint16_t)(u < 0 ? 0 : u > 0xFFFFL ? 0xFFFFL : u));
- *pixels++ = htons((uint16_t)(v < 0 ? 0 : v > 0xFFFFL ? 0xFFFFL : v));
+ y = (long int)(pixel[0] * 0xFFFFL) + 16L * 256L;
+ u = (long int)(pixel[1] * 0xFFFFL) + 128L * 256L;
+ v = (long int)(pixel[2] * 0xFFFFL) + 128L * 256L;
+ *pixels++ = htole16((uint16_t)(a < 0 ? 0 : a > 0xFFFFL ? 0xFFFFL : a));
+ *pixels++ = htole16((uint16_t)(y < 0 ? 0 : y > 0xFFFFL ? 0xFFFFL : y));
+ *pixels++ = htole16((uint16_t)(u < 0 ? 0 : u > 0xFFFFL ? 0xFFFFL : u));
+ *pixels++ = htole16((uint16_t)(v < 0 ? 0 : v > 0xFFFFL ? 0xFFFFL : v));
if (pixels == end)
ewriteall(fd, pixels = pixbuf, sizeof(pixbuf), fname);
}
}
if (pixels != pixbuf)
- ewriteall(fd, pixels = pixbuf, sizeof(pixbuf), fname);
+ ewriteall(fd, pixbuf, (size_t)(pixels - pixbuf) * sizeof(*pixels), fname);
}
int
@@ -128,11 +123,14 @@ main(int argc, char *argv[])
if (dup2(pipe_rw[0], STDIN_FILENO) == -1)
eprintf("dup2:");
close(pipe_rw[0]);
+ execvp("ffmpeg", cmd);
eprintf("exec ffmpeg:");
}
+ free(cmd);
+
close(pipe_rw[0]);
- while (!eread_stream(&stream, SIZE_MAX)) {
+ while (eread_stream(&stream, SIZE_MAX)) {
n = stream.ptr - (stream.ptr % stream.pixel_size);
process(stream.buf, n, pipe_rw[1], "<subprocess>");
memmove(stream.buf, stream.buf + n, stream.ptr -= n);