mp_image: save fallback colorspace when dovi metadata is present

Since d9c1e9bc5c dovi metadata is
unconditionally mapped to colorspace in mp_image.

However, Dolby Vision videos can have backwards compatibility present for
players without the ability to interpret dovi metadata, like all current
VOs other than gpu-next. In this case, the original video colorspace should
be used to make sure backwards compatibility work properly.

Save the fallback colorspace for VOs which don't interpret dovi metadata.

Fixes: d9c1e9bc5c
This commit is contained in:
nanahi 2024-08-31 10:26:36 -04:00 committed by Kacper Michajłow
parent d6eb85bb1a
commit 14d3a8ed28
2 changed files with 22 additions and 0 deletions

View File

@ -848,6 +848,19 @@ bool mp_image_params_static_equal(const struct mp_image_params *p1,
return mp_image_params_equal(&a, &b); return mp_image_params_equal(&a, &b);
} }
// Restore color system, transfer, and primaries to their original values
// before dovi mapping.
void mp_image_params_restore_dovi_mapping(struct mp_image_params *params)
{
params->color.primaries = params->primaries_orig;
params->color.transfer = params->transfer_orig;
params->repr.sys = params->sys_orig;
if (!pl_color_transfer_is_hdr(params->transfer_orig))
params->color.hdr = (struct pl_hdr_metadata){0};
if (params->transfer_orig != PL_COLOR_TRC_PQ)
params->color.hdr.max_pq_y = params->color.hdr.avg_pq_y = 0;
}
// Set most image parameters, but not image format or size. // Set most image parameters, but not image format or size.
// Display size is used to set the PAR. // Display size is used to set the PAR.
void mp_image_set_attributes(struct mp_image *image, void mp_image_set_attributes(struct mp_image *image,
@ -1079,6 +1092,9 @@ struct mp_image *mp_image_from_av_frame(struct AVFrame *src)
if (sd) if (sd)
dst->a53_cc = sd->buf; dst->a53_cc = sd->buf;
dst->params.primaries_orig = dst->params.color.primaries;
dst->params.transfer_orig = dst->params.color.transfer;
dst->params.sys_orig = dst->params.repr.sys;
AVBufferRef *dovi = NULL; AVBufferRef *dovi = NULL;
sd = av_frame_get_side_data(src, AV_FRAME_DATA_DOVI_METADATA); sd = av_frame_get_side_data(src, AV_FRAME_DATA_DOVI_METADATA);
if (sd) { if (sd) {

View File

@ -50,6 +50,11 @@ struct mp_image_params {
bool force_window; // fake image created by handle_force_window bool force_window; // fake image created by handle_force_window
struct pl_color_space color; struct pl_color_space color;
struct pl_color_repr repr; struct pl_color_repr repr;
// Original values before Dolby Vision metadata mapping
enum pl_color_primaries primaries_orig;
enum pl_color_transfer transfer_orig;
enum pl_color_system sys_orig;
enum mp_csp_light light; enum mp_csp_light light;
enum pl_chroma_location chroma_location; enum pl_chroma_location chroma_location;
// The image should be rotated clockwise (0-359 degrees). // The image should be rotated clockwise (0-359 degrees).
@ -177,6 +182,7 @@ bool mp_image_params_equal(const struct mp_image_params *p1,
const struct mp_image_params *p2); const struct mp_image_params *p2);
bool mp_image_params_static_equal(const struct mp_image_params *p1, bool mp_image_params_static_equal(const struct mp_image_params *p1,
const struct mp_image_params *p2); const struct mp_image_params *p2);
void mp_image_params_restore_dovi_mapping(struct mp_image_params *params);
void mp_image_params_get_dsize(const struct mp_image_params *p, void mp_image_params_get_dsize(const struct mp_image_params *p,
int *d_w, int *d_h); int *d_w, int *d_h);