From 664f8e9832e7ee9835816621faf4b57ffbcc8628 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 2 Apr 2014 00:40:36 +0200 Subject: video: Include better heuristics for guessing primaries These consult the vertical resolution, matching against 576 for PAL and 480/486 for NTSC. The documentation has also been updated. Signed-off-by: wm4 --- video/csputils.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'video/csputils.c') diff --git a/video/csputils.c b/video/csputils.c index 202585187a..c462c43c34 100644 --- a/video/csputils.c +++ b/video/csputils.c @@ -160,6 +160,25 @@ enum mp_csp mp_csp_guess_colorspace(int width, int height) return width >= 1280 || height > 576 ? MP_CSP_BT_709 : MP_CSP_BT_601; } +enum mp_csp_prim mp_csp_guess_primaries(int width, int height) +{ + // HD content + if (width >= 1280 || height > 576) + return MP_CSP_PRIM_BT_709; + + switch (height) { + case 576: // Typical PAL content, including anamorphic/squared + return MP_CSP_PRIM_BT_601_625; + + case 480: // Typical NTSC content, including squared + case 486: // NTSC Pro or anamorphic NTSC + return MP_CSP_PRIM_BT_601_525; + + default: // No good metric, just pick BT.709 to minimize damage + return MP_CSP_PRIM_BT_709; + } +} + enum mp_chroma_location avchroma_location_to_mp(int avloc) { switch (avloc) { -- cgit v1.2.3