diff options
Diffstat (limited to 'src/blind-to-video.c')
| -rw-r--r-- | src/blind-to-video.c | 108 |
1 files changed, 57 insertions, 51 deletions
diff --git a/src/blind-to-video.c b/src/blind-to-video.c index ab09bfe..1c9ef99 100644 --- a/src/blind-to-video.c +++ b/src/blind-to-video.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#ifndef TYPE #include "common.h" USAGE("[-d] frame-rate ffmpeg-arguments ...") @@ -6,55 +7,8 @@ USAGE("[-d] frame-rate ffmpeg-arguments ...") static int draft = 0; static int fd; -#define PROCESS(TYPE)\ - do {\ - char *buf = stream->buf;\ - TYPE *pixel, r, g, b;\ - uint16_t *pixels, *end;\ - uint16_t pixbuf[BUFSIZ / sizeof(uint16_t)];\ - long int a, y, u, v;\ - size_t ptr;\ - pixels = pixbuf;\ - end = pixbuf + ELEMENTSOF(pixbuf);\ - if (draft) {\ - for (ptr = 0; ptr < n; ptr += 4 * sizeof(TYPE)) {\ - pixel = (TYPE *)(buf + ptr);\ - ciexyz_to_scaled_yuv(pixel[0], pixel[1], pixel[2], &r, &g, &b);\ - y = (long int)r + 16L * 256L;\ - u = (long int)g + 128L * 256L;\ - v = (long int)b + 128L * 256L;\ - *pixels++ = 0xFFFFU;\ - *pixels++ = htole((uint16_t)CLIP(0, y, 0xFFFFL));\ - *pixels++ = htole((uint16_t)CLIP(0, u, 0xFFFFL));\ - *pixels++ = htole((uint16_t)CLIP(0, v, 0xFFFFL));\ - if (pixels == end)\ - ewriteall(fd, pixels = pixbuf, sizeof(pixbuf), "<subprocess>");\ - }\ - } else {\ - for (ptr = 0; ptr < n; ptr += 4 * sizeof(TYPE)) {\ - pixel = (TYPE *)(buf + ptr);\ - a = (long int)(pixel[3] * 0xFFFFL);\ - ciexyz_to_srgb(pixel[0], pixel[1], pixel[2], &r, &g, &b);\ - r = srgb_encode(r);\ - 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) + 16L * 256L;\ - u = (long int)(pixel[1] * 0xFFFFL) + 128L * 256L;\ - v = (long int)(pixel[2] * 0xFFFFL) + 128L * 256L;\ - *pixels++ = htole((uint16_t)CLIP(0, a, 0xFFFFL));\ - *pixels++ = htole((uint16_t)CLIP(0, y, 0xFFFFL));\ - *pixels++ = htole((uint16_t)CLIP(0, u, 0xFFFFL));\ - *pixels++ = htole((uint16_t)CLIP(0, v, 0xFFFFL));\ - if (pixels == end)\ - ewriteall(fd, pixels = pixbuf, sizeof(pixbuf), "<subprocess>");\ - }\ - }\ - ewriteall(fd, pixbuf, (size_t)(pixels - pixbuf) * sizeof(*pixels), "<subprocess>");\ - } while (0) - -static void process_xyza (struct stream *stream, size_t n) {PROCESS(double);} -static void process_xyzaf(struct stream *stream, size_t n) {PROCESS(float);} +#define FILE "blind-to-video.c" +#include "define-functions.h" int main(int argc, char *argv[]) @@ -94,9 +48,9 @@ main(int argc, char *argv[]) sprintf(geometry, "%zux%zu", stream.width, stream.height); if (!strcmp(stream.pixfmt, "xyza")) - process = process_xyza; + process = process_lf; else if (!strcmp(stream.pixfmt, "xyza f")) - process = process_xyzaf; + process = process_f; else eprintf("pixel format %s is not supported, try xyza\n", stream.pixfmt); @@ -121,3 +75,55 @@ main(int argc, char *argv[]) ewaitpid(pid, &status, 0); return !!status; } + +#else + +static void +PROCESS(struct stream *stream, size_t n) +{ + char *buf = stream->buf; + TYPE *pixel, r, g, b; + uint16_t *pixels, *end; + uint16_t pixbuf[BUFSIZ / sizeof(uint16_t)]; + long int a, y, u, v; + size_t ptr; + pixels = pixbuf; + end = pixbuf + ELEMENTSOF(pixbuf); + if (draft) { + for (ptr = 0; ptr < n; ptr += 4 * sizeof(TYPE)) { + pixel = (TYPE *)(buf + ptr); + ciexyz_to_scaled_yuv(pixel[0], pixel[1], pixel[2], &r, &g, &b); + y = (long int)r + 16L * 256L; + u = (long int)g + 128L * 256L; + v = (long int)b + 128L * 256L; + *pixels++ = 0xFFFFU; + *pixels++ = htole((uint16_t)CLIP(0, y, 0xFFFFL)); + *pixels++ = htole((uint16_t)CLIP(0, u, 0xFFFFL)); + *pixels++ = htole((uint16_t)CLIP(0, v, 0xFFFFL)); + if (pixels == end) + ewriteall(fd, pixels = pixbuf, sizeof(pixbuf), "<subprocess>"); + } + } else { + for (ptr = 0; ptr < n; ptr += 4 * sizeof(TYPE)) { + pixel = (TYPE *)(buf + ptr); + a = (long int)(pixel[3] * 0xFFFFL); + ciexyz_to_srgb(pixel[0], pixel[1], pixel[2], &r, &g, &b); + r = srgb_encode(r); + 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) + 16L * 256L; + u = (long int)(pixel[1] * 0xFFFFL) + 128L * 256L; + v = (long int)(pixel[2] * 0xFFFFL) + 128L * 256L; + *pixels++ = htole((uint16_t)CLIP(0, a, 0xFFFFL)); + *pixels++ = htole((uint16_t)CLIP(0, y, 0xFFFFL)); + *pixels++ = htole((uint16_t)CLIP(0, u, 0xFFFFL)); + *pixels++ = htole((uint16_t)CLIP(0, v, 0xFFFFL)); + if (pixels == end) + ewriteall(fd, pixels = pixbuf, sizeof(pixbuf), "<subprocess>"); + } + } + ewriteall(fd, pixbuf, (size_t)(pixels - pixbuf) * sizeof(*pixels), "<subprocess>"); +} + +#endif |
