From 4154609e5de76bc8858d3f86e0af09ba2700c488 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 23 Sep 2017 21:57:45 +0200 Subject: Fix colour distortion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This matrices are not convert to or from the proper YUV colour space both rather the ones used in videos. srgb_to_yuv was created by converting the image [sRGB(100%, 0, 0); sRGB(0, 100%, 0); sRGB(0, 0, 100%)] to YUV with FFmpeg and transposing the matrix. yuv_to_srgb is the inversion of that matrix, the values in the first column should all be 1 but are not due to rounding/truncation error. Signed-off-by: Mattias Andrée --- src/blind-from-video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/blind-from-video.c') diff --git a/src/blind-from-video.c b/src/blind-from-video.c index f258058..3041ea1 100644 --- a/src/blind-from-video.c +++ b/src/blind-from-video.c @@ -75,7 +75,7 @@ get_metadata(char *file, size_t *width, size_t *height) do {\ typedef TYPE pixel_t[4];\ size_t i, ptr;\ - TYPE y, u, v, max = (TYPE)UINT16_MAX, ymax = (TYPE)0xDAF4;\ + TYPE y, u, v, max = (TYPE)0xFF00L, ymax = (TYPE)0xDAF4L;\ TYPE r, g, b;\ pixel_t pixels[1024];\ uint16_t *pix;\ @@ -97,6 +97,7 @@ get_metadata(char *file, size_t *width, size_t *height) for (ptr = i = 0; ptr < n; ptr += 8) {\ pix = (uint16_t *)(buf + ptr);\ pixels[i][3] = le16toh(pix[0]) / max;\ + pixels[i][3] = CLIP(0, pixels[i][3], 1);\ y = (TYPE)((long int)le16toh(pix[1]) - 0x1001L) / ymax;\ u = (TYPE)((long int)le16toh(pix[2]) - 0x8000L) / max;\ v = (TYPE)((long int)le16toh(pix[3]) - 0x8000L) / max;\ -- cgit v1.2.3-70-g09d2