From fe2178160d6374136e6ca2f02f12d7f42f9cb531 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 23 Apr 2020 12:55:54 +0200 Subject: img_format: remove duplication in FFmpeg yuv vs. rgb pixfmt check mp_imgfmt_get_forced_csp() should be consistent with the MP_CSP_RGB/YUV flags. At least the different handling of the XYZ exception was a mess, even if the result was the same. --- video/img_format.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/video/img_format.c b/video/img_format.c index 6379dd41d1..b1247747ea 100644 --- a/video/img_format.c +++ b/video/img_format.c @@ -279,17 +279,16 @@ struct mp_imgfmt_desc mp_imgfmt_get_desc(int mpfmt) ? MP_IMGFLAG_BE : MP_IMGFLAG_LE; } + enum mp_csp csp = mp_imgfmt_get_forced_csp(mpfmt); + if ((pd->flags & AV_PIX_FMT_FLAG_HWACCEL)) { desc.flags |= MP_IMGFLAG_HWACCEL; - } else if (fmt == AV_PIX_FMT_XYZ12LE || fmt == AV_PIX_FMT_XYZ12BE) { + } else if (csp == MP_CSP_XYZ) { /* nothing */ - } else if (!(pd->flags & AV_PIX_FMT_FLAG_RGB) && - fmt != AV_PIX_FMT_MONOBLACK && - fmt != AV_PIX_FMT_PAL8) - { - desc.flags |= MP_IMGFLAG_YUV; - } else { + } else if (csp == MP_CSP_RGB) { desc.flags |= MP_IMGFLAG_RGB; + } else { + desc.flags |= MP_IMGFLAG_YUV; } if (pd->flags & AV_PIX_FMT_FLAG_ALPHA) @@ -407,6 +406,9 @@ enum mp_csp mp_imgfmt_get_forced_csp(int imgfmt) enum AVPixelFormat pixfmt = imgfmt2pixfmt(imgfmt); const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(pixfmt); + if (pixdesc && (pixdesc->flags & AV_PIX_FMT_FLAG_HWACCEL)) + return MP_CSP_AUTO; + // FFmpeg does not provide a flag for XYZ, so this is the best we can do. if (pixdesc && strncmp(pixdesc->name, "xyz", 3) == 0) return MP_CSP_XYZ; -- cgit v1.2.3