summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-09-19 19:20:27 +0200
committerwm4 <wm4@nowhere>2017-09-19 19:20:27 +0200
commita4de782272cd6a3876b2fe661386a7a01a26e27a (patch)
treed929311357d7f86c864ce7932f6ceab90dc43a6c /video
parent06927fefdd8eac166083157e63ae356b31bc1b2d (diff)
downloadmpv-a4de782272cd6a3876b2fe661386a7a01a26e27a.tar.bz2
mpv-a4de782272cd6a3876b2fe661386a7a01a26e27a.tar.xz
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.)
Diffstat (limited to 'video')
-rw-r--r--video/mp_image.c20
1 files changed, 12 insertions, 8 deletions
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 &&