diff options
author | Jan Ekström <jeebjp@gmail.com> | 2016-04-24 17:30:56 +0300 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2016-04-27 04:40:12 +0200 |
commit | 3003277103a26765b1e1c1c5bd4865f703a703b4 (patch) | |
tree | c2c1c145aadf4e5c06f6963b5fba2ce450ab497d | |
parent | 05b33258e3ac3fca4586c67da596330fbc9dfaf5 (diff) | |
download | ffmpeg-3003277103a26765b1e1c1c5bd4865f703a703b4.tar.gz |
pgssubdec: fix subpicture output colorspace and range
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
(cherry picked from commit 9779b6262471d553c1ed811ff7312564e39d8adf)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavcodec/pgssubdec.c | 10 | ||||
-rw-r--r-- | libavutil/colorspace.h | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c index e567f53ab4..6ff6cc4059 100644 --- a/libavcodec/pgssubdec.c +++ b/libavcodec/pgssubdec.c @@ -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); diff --git a/libavutil/colorspace.h b/libavutil/colorspace.h index 826ffd52c4..7d3f7110c9 100644 --- a/libavutil/colorspace.h +++ b/libavutil/colorspace.h @@ -41,6 +41,16 @@ 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);\ |