Skip to content

Commit 41b8aa0

Browse files
committed
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
1 parent 3eafbbe commit 41b8aa0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

libavcodec/pgssubdec.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,14 @@ static int parse_palette_segment(AVCodecContext *avctx,
354354
cb = bytestream_get_byte(&buf);
355355
alpha = bytestream_get_byte(&buf);
356356

357-
YUV_TO_RGB1(cb, cr);
358-
YUV_TO_RGB2(r, g, b, y);
357+
/* Default to BT.709 colorimetry. In case of <= 576 height use BT.601 */
358+
if (avctx->height <= 0 || avctx->height > 576) {
359+
YUV_TO_RGB1_CCIR_BT709(cb, cr);
360+
} else {
361+
YUV_TO_RGB1_CCIR(cb, cr);
362+
}
363+
364+
YUV_TO_RGB2_CCIR(r, g, b, y);
359365

360366
ff_dlog(avctx, "Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);
361367

libavutil/colorspace.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
4242
}
4343

44+
#define YUV_TO_RGB1_CCIR_BT709(cb1, cr1)\
45+
{\
46+
cb = (cb1) - 128;\
47+
cr = (cr1) - 128;\
48+
r_add = FIX(1.5747*255.0/224.0) * cr + ONE_HALF;\
49+
g_add = - FIX(0.1873*255.0/224.0) * cb - FIX(0.4682*255.0/224.0) * cr + \
50+
ONE_HALF;\
51+
b_add = FIX(1.8556*255.0/224.0) * cb + ONE_HALF;\
52+
}
53+
4454
#define YUV_TO_RGB2_CCIR(r, g, b, y1)\
4555
{\
4656
y = ((y1) - 16) * FIX(255.0/219.0);\

0 commit comments

Comments
 (0)