From d471f2902eb4f824fb5b62c3a30b26581d1e22b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Thu, 31 Aug 2023 16:52:28 +0200 Subject: mp_image: add imgfmt_name to mp_image_params Convenience to override name if imgfmt is not set. Allows to create mp_image_params without setting imgfmt. Will be useful for the next change where mp_imgfmt is not available. This is workaround that will be remved once all codebase switches to pl_fmt. --- player/command.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'player') diff --git a/player/command.c b/player/command.c index 5b61ae3498..75debf781d 100644 --- a/player/command.c +++ b/player/command.c @@ -2321,22 +2321,24 @@ static const char *get_aspect_ratio_name(double ratio) static int property_imgparams(const struct mp_image_params *p, int action, void *arg) { - if (!p->imgfmt) + if (!p->imgfmt && !p->imgfmt_name) return M_PROPERTY_UNAVAILABLE; int d_w, d_h; mp_image_params_get_dsize(p, &d_w, &d_h); - struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(p->imgfmt); int bpp = 0; - for (int i = 0; i < desc.num_planes; i++) - bpp += desc.bpp[i] >> (desc.xs[i] + desc.ys[i]); - enum pl_alpha_mode alpha = p->repr.alpha; - // Alpha type is not supported by FFmpeg, so PL_ALPHA_UNKNOWN may mean alpha - // is of an unknown type, or simply not present. Normalize to AUTO=no alpha. - if (!!(desc.flags & MP_IMGFLAG_ALPHA) != (alpha != PL_ALPHA_UNKNOWN)) - alpha = (desc.flags & MP_IMGFLAG_ALPHA) ? PL_ALPHA_INDEPENDENT : PL_ALPHA_UNKNOWN; + if (p->imgfmt) { + struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(p->imgfmt); + for (int i = 0; i < desc.num_planes; i++) + bpp += desc.bpp[i] >> (desc.xs[i] + desc.ys[i]); + + // Alpha type is not supported by FFmpeg, so PL_ALPHA_UNKNOWN may mean alpha + // is of an unknown type, or simply not present. Normalize to AUTO=no alpha. + if (!!(desc.flags & MP_IMGFLAG_ALPHA) != (alpha != PL_ALPHA_UNKNOWN)) + alpha = (desc.flags & MP_IMGFLAG_ALPHA) ? PL_ALPHA_INDEPENDENT : PL_ALPHA_UNKNOWN; + } const struct pl_hdr_metadata *hdr = &p->color.hdr; bool has_cie_y = pl_hdr_metadata_contains(hdr, PL_HDR_METADATA_CIE_Y); @@ -2346,8 +2348,10 @@ static int property_imgparams(const struct mp_image_params *p, int action, void bool has_crop = mp_rect_w(p->crop) > 0 && mp_rect_h(p->crop) > 0; const char *aspect_name = get_aspect_ratio_name(d_w / (double)d_h); const char *sar_name = get_aspect_ratio_name(p->w / (double)p->h); + const char *pixelformat_name = p->imgfmt_name ? p->imgfmt_name : + mp_imgfmt_to_name(p->imgfmt); struct m_sub_property props[] = { - {"pixelformat", SUB_PROP_STR(mp_imgfmt_to_name(p->imgfmt))}, + {"pixelformat", SUB_PROP_STR(pixelformat_name)}, {"hw-pixelformat", SUB_PROP_STR(mp_imgfmt_to_name(p->hw_subfmt)), .unavailable = !p->hw_subfmt}, {"average-bpp", SUB_PROP_INT(bpp), -- cgit v1.2.3