]> git.sesse.net Git - ffmpeg/commitdiff
pgssubdec: fix subpicture output colorspace and range
authorJan Ekström <jeebjp@gmail.com>
Sun, 24 Apr 2016 14:30:56 +0000 (17:30 +0300)
committerCarl Eugen Hoyos <cehoyos@ag.or.at>
Sun, 24 Apr 2016 21:05:04 +0000 (23:05 +0200)
Functionality used before didn't widen the values from limited to
full range. Additionally, now the decoder uses BT.709 where it
should be used according to the video resolution.

Default for not yet set colorimetry is BT.709 due to most observed
HDMV content being HD.

BT.709 coefficients were gathered from the first two parts of BT.709
to BT.2020 conversion guide in ARIB STD-B62 (Pt. 1, Chapter 6.2.2).
They were additionally confirmed by manually calculating values.

Fixes #4637

libavcodec/pgssubdec.c
libavutil/colorspace.h

index 07a2a7862928248cab42a33e020e98fd5ab4ff72..133d08bfa72ce0bab9b3acb327f0b4c9d9116954 100644 (file)
@@ -354,8 +354,14 @@ static int parse_palette_segment(AVCodecContext *avctx,
         cb        = bytestream_get_byte(&buf);
         alpha     = bytestream_get_byte(&buf);
 
-        YUV_TO_RGB1(cb, cr);
-        YUV_TO_RGB2(r, g, b, y);
+        /* Default to BT.709 colorimetry. In case of <= 576 height use BT.601 */
+        if (avctx->height <= 0 || avctx->height > 576) {
+            YUV_TO_RGB1_CCIR_BT709(cb, cr);
+        } else {
+            YUV_TO_RGB1_CCIR(cb, cr);
+        }
+
+        YUV_TO_RGB2_CCIR(r, g, b, y);
 
         ff_dlog(avctx, "Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);
 
index 826ffd52c4c5935b58f55e5c036b85da4697918a..7d3f7110c9625e46749e9cd618c63aed32ca3824 100644 (file)
     b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
 }
 
+#define YUV_TO_RGB1_CCIR_BT709(cb1, cr1)\
+{\
+    cb = (cb1) - 128;\
+    cr = (cr1) - 128;\
+    r_add = FIX(1.5747*255.0/224.0) * cr + ONE_HALF;\
+    g_add = - FIX(0.1873*255.0/224.0) * cb - FIX(0.4682*255.0/224.0) * cr + \
+            ONE_HALF;\
+    b_add = FIX(1.8556*255.0/224.0) * cb + ONE_HALF;\
+}
+
 #define YUV_TO_RGB2_CCIR(r, g, b, y1)\
 {\
     y = ((y1) - 16) * FIX(255.0/219.0);\