From a4de782272cd6a3876b2fe661386a7a01a26e27a Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 19 Sep 2017 19:20:27 +0200 Subject: mp_image: don't guess colorspace params in mp_image_copy_attributes() This is "wrong", because you might want mp_image_copy_attributes() to preserve the information that the colorspace parameters are unknown. This is important for hwdec -copy modes, which call this function before fix_image_params() and mp_colorspace_merge() are called. Instead, just wipe the colorspace attributes if the pixel format changes in an apparently incompatible way. Use mp_image_params_guess_csp() logic for this and factor that into its own function. mp_image_set_attributes() attempts to do something similar, so change that in the same way. Also, mp_image_params_guess_csp() just returned if the imgfmt was invalid or unset - just remove that part, because it annoyingly doesn't fit into the new code, and had little reason to exist to begin with. (Probably.) --- video/mp_image.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'video') diff --git a/video/mp_image.c b/video/mp_image.c index 326feb233e..aee1f913e6 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -511,6 +511,12 @@ void mp_check_gpu_memcpy(struct mp_log *log, bool *once) } } +static enum mp_csp mp_image_params_get_forced_csp(struct mp_image_params *params) +{ + int imgfmt = params->hw_subfmt ? params->hw_subfmt : params->imgfmt; + return mp_imgfmt_get_forced_csp(imgfmt); +} + void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src) { dst->pict_type = src->pict_type; @@ -526,7 +532,10 @@ void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src) dst->params.color = src->params.color; dst->params.chroma_location = src->params.chroma_location; dst->params.spherical = src->params.spherical; - mp_image_params_guess_csp(&dst->params); // ensure colorspace consistency + // ensure colorspace consistency + if (mp_image_params_get_forced_csp(&dst->params) != + mp_image_params_get_forced_csp(&src->params)) + dst->params.color = (struct mp_colorspace){0}; if ((dst->fmt.flags & MP_IMGFLAG_PAL) && (src->fmt.flags & MP_IMGFLAG_PAL)) { if (dst->planes[1] && src->planes[1]) { if (mp_image_make_writeable(dst)) @@ -733,7 +742,7 @@ void mp_image_set_attributes(struct mp_image *image, nparams.w = image->w; nparams.h = image->h; if (nparams.imgfmt != params->imgfmt) - mp_image_params_guess_csp(&nparams); + nparams.color = (struct mp_colorspace){0}; mp_image_set_params(image, &nparams); } @@ -742,12 +751,7 @@ void mp_image_set_attributes(struct mp_image *image, // the colorspace as implied by the pixel format. void mp_image_params_guess_csp(struct mp_image_params *params) { - int imgfmt = params->hw_subfmt ? params->hw_subfmt : params->imgfmt; - struct mp_imgfmt_desc fmt = mp_imgfmt_get_desc(imgfmt); - if (!fmt.id) - return; - - enum mp_csp forced_csp = mp_imgfmt_get_forced_csp(imgfmt); + enum mp_csp forced_csp = mp_image_params_get_forced_csp(params); if (forced_csp == MP_CSP_AUTO) { // YUV/other if (params->color.space != MP_CSP_BT_601 && params->color.space != MP_CSP_BT_709 && -- cgit v1.2.3