summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
Diffstat (limited to 'video')
-rw-r--r--video/csputils.c19
-rw-r--r--video/csputils.h1
-rw-r--r--video/mp_image.c9
3 files changed, 25 insertions, 4 deletions
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) {
diff --git a/video/csputils.h b/video/csputils.h
index 9257102df5..757ac72cdc 100644
--- a/video/csputils.h
+++ b/video/csputils.h
@@ -180,6 +180,7 @@ int mp_csp_levels_to_avcol_range(enum mp_csp_levels range);
int mp_csp_prim_to_avcol_pri(enum mp_csp_prim prim);
enum mp_csp mp_csp_guess_colorspace(int width, int height);
+enum mp_csp_prim mp_csp_guess_primaries(int width, int height);
enum mp_chroma_location avchroma_location_to_mp(int avloc);
int mp_chroma_location_to_av(enum mp_chroma_location mploc);
diff --git a/video/mp_image.c b/video/mp_image.c
index eb754499d1..d83a9ae3c1 100644
--- a/video/mp_image.c
+++ b/video/mp_image.c
@@ -537,14 +537,15 @@ void mp_image_params_guess_csp(struct mp_image_params *params)
if (params->colorlevels == MP_CSP_LEVELS_AUTO)
params->colorlevels = MP_CSP_LEVELS_TV;
if (params->primaries == MP_CSP_PRIM_AUTO) {
- // We assume BT.709 primaries for all untagged BT.609/BT.709
- // content, because it offers the minimal deviation from all three,
- // including both NTSC and PAL/SECAM.
+ // Guess based on the colormatrix as a first priority
if (params->colorspace == MP_CSP_BT_2020_NC ||
params->colorspace == MP_CSP_BT_2020_C) {
params->primaries = MP_CSP_PRIM_BT_2020;
- } else {
+ } else if (params->colorspace == MP_CSP_BT_709) {
params->primaries = MP_CSP_PRIM_BT_709;
+ } else {
+ // Ambiguous colormatrix for BT.601, guess based on res
+ params->primaries = mp_csp_guess_primaries(params->w, params->h);
}
}
} else if (fmt.flags & MP_IMGFLAG_RGB) {