blind

suckless command-line video editing utility
git clone git://git.suckless.org/blind
Log | Files | Refs | README | LICENSE

commit 2640635b7d0f049ae15872ab9e7b5ef254233ccc
parent 3f57514b212fe50b2b56438f399d37a1b51745b0
Author: Mattias Andrée <maandree@kth.se>
Date:   Fri, 13 Jan 2017 05:03:19 +0100

vu-from-video: add -d

Signed-off-by: Mattias Andrée <maandree@kth.se>

Diffstat:
Msrc/util/colour.h | 32++++++++++++++++++++++++++++++++
Msrc/vu-from-video.c | 48++++++++++++++++++++++++++++++++++--------------
2 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/src/util/colour.h b/src/util/colour.h @@ -71,3 +71,35 @@ srgb_to_ciexyz(double r, double g, double b, double *x, double *y, double *z) *z = MULTIPLY(0.019333942761673460208893260415, 0.119191955081838593666354597644, 0.950302838552371742508739771438); #undef MULTIPLY } + +static inline void +scaled_yuv_to_ciexyz(double y, double u, double v, double *xp, double *yp, double *zp) +{ +#define MULTIPLY(CY, CU, CV) ((CY) * y + (CU) * u + (CV) * v) + *xp = MULTIPLY( 0.00001450325106667098632156481796684488472237717360, + 0.00000345586790639342739093228633329157872822179343, + 0.00000400923398630552893485111398685916128670214675); + *yp = MULTIPLY( 0.00001525902189669641837040624243737596543724066578, + -0.00000207722814409390653614547427030512238843584782, + -0.00000263898607692305410302407824019166326934282552); + *zp = MULTIPLY( 0.00001661446153041708825425643025752719950105529279, + 0.00002885925752619118069149627137104374696718878113, + -0.00000071781086875769179526501342566979779746816348); +#undef MULTIPLY +} + +static inline void +ciexyz_to_scaled_yuv(double x, double y, double z, double *yp, double *up, double *vp) +{ +#define MULTIPLY(CX, CY, CZ) ((CX) * x + (CY) * y + (CZ) * z) + *yp = MULTIPLY( 26625.38231027395886485464870929718017578125, + 40524.0090949436053051613271236419677734375, + -271.5313105642117079696618020534515380859375); + *up = MULTIPLY( -11278.3751445417292416095733642578125, + -26409.91773157499847002327442169189453125, + 34100.5706543184860493056476116180419921875); + *vp = MULTIPLY( 162829.60100012840121053159236907958984375, + -123829.313212639070115983486175537109375, + -28411.65702312920984695665538311004638671875); +#undef MULTIPLY +} diff --git a/src/vu-from-video.c b/src/vu-from-video.c @@ -2,6 +2,7 @@ #include "stream.h" #include "util.h" +#include <arpa/inet.h> #if defined(HAVE_PRCTL) # include <sys/prctl.h> #endif @@ -14,7 +15,9 @@ #include <string.h> #include <unistd.h> -USAGE("[-r frame-rate] [-w width -h height] input-file output-file") +USAGE("[-r frame-rate] [-w width -h height] [-d] input-file output-file") + +static int draft = 0; static void read_metadata(FILE *fp, char *fname, size_t *width, size_t *height, size_t *frames) @@ -106,19 +109,33 @@ convert_segment(char *buf, size_t n, int fd, char *file) double y, u, v, max = (double)UINT16_MAX; double r, g, b; pixel_t pixels[1024]; - for (ptr = i = 0; ptr < n; ptr += 8, i++) { - pixels[i][3] = ntohs(((uint16_t *)(buf + ptr))[0]) / max; - y = ntohs(((uint16_t *)(buf + ptr))[1]) / max; - u = ntohs(((uint16_t *)(buf + ptr))[2]) / max; - v = ntohs(((uint16_t *)(buf + ptr))[3]) / max; - yuv_to_srgb(y, u, v, &r, &g, &b); - r = srgb_decode(r); - g = srgb_decode(g); - b = srgb_decode(b); - srgb_to_ciexyz(r, g, b, pixels[i] + 0, pixels[i] + 1, pixels[i] + 2); - if (++i == 1024) { - i = 0; - ewriteall(fd, pixels, sizeof(pixels), file); + if (draft) { + for (ptr = i = 0; ptr < n; ptr += 8, i++) { + pixels[i][3] = ntohs(((uint16_t *)(buf + ptr))[0]) / max; + y = ntohs(((uint16_t *)(buf + ptr))[1]); + u = ntohs(((uint16_t *)(buf + ptr))[2]); + v = ntohs(((uint16_t *)(buf + ptr))[3]); + scaled_yuv_to_ciexyz(y, u, v, pixels[i] + 0, pixels[i] + 1, pixels[i] + 2); + if (++i == 1024) { + i = 0; + ewriteall(fd, pixels, sizeof(pixels), file); + } + } + } else { + for (ptr = i = 0; ptr < n; ptr += 8, i++) { + pixels[i][3] = ntohs(((uint16_t *)(buf + ptr))[0]) / max; + y = ntohs(((uint16_t *)(buf + ptr))[1]) / max; + u = ntohs(((uint16_t *)(buf + ptr))[2]) / max; + v = ntohs(((uint16_t *)(buf + ptr))[3]) / max; + yuv_to_srgb(y, u, v, &r, &g, &b); + r = srgb_decode(r); + g = srgb_decode(g); + b = srgb_decode(b); + srgb_to_ciexyz(r, g, b, pixels[i] + 0, pixels[i] + 1, pixels[i] + 2); + if (++i == 1024) { + i = 0; + ewriteall(fd, pixels, sizeof(pixels), file); + } } } if (i) @@ -209,6 +226,9 @@ main(int argc, char *argv[]) struct stat st; ARGBEGIN { + case 'd': + draft = 1; + break; case 'r': frame_rate = EARG(); break;