diff mbox series

[FFmpeg-devel,1/4] avfilter/formats: Don't unnecessarily reget pixfmt descriptor

Message ID AM7PR03MB66608C2ED64B95243E9065C78FA79@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit e1ddaf229d801bf9c1b09e46841cbba300b945b6
Headers show
Series [FFmpeg-devel,1/4] avfilter/formats: Don't unnecessarily reget pixfmt descriptor | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 27, 2021, 2:57 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
If I am not mistaken, then the check for chroma is wrong, as there
are pixel formats with just luma and alpha. The clean check would
probably be desc->nb_components > (1 + !!(desc->flags &
AV_PIX_FMT_FLAG_ALPHA)), while desc->nb_components > 2 would also just
work. Maybe there should be an AV_PIX_FMT_FLAG_CHROMA for this?

 libavfilter/formats.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 1d2a51c0af..29e318aa3b 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -113,9 +113,9 @@  static int merge_formats_internal(AVFilterFormats *a, AVFilterFormats *b,
        To avoid that, pretend that there are no common formats to force the
        insertion of a conversion filter. */
     if (type == AVMEDIA_TYPE_VIDEO)
-        for (i = 0; i < a->nb_formats; i++)
+        for (i = 0; i < a->nb_formats; i++) {
+            const AVPixFmtDescriptor *const adesc = av_pix_fmt_desc_get(a->formats[i]);
             for (j = 0; j < b->nb_formats; j++) {
-                const AVPixFmtDescriptor *adesc = av_pix_fmt_desc_get(a->formats[i]);
                 const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
                 alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
                 chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
@@ -124,6 +124,7 @@  static int merge_formats_internal(AVFilterFormats *a, AVFilterFormats *b,
                     chroma1|= adesc->nb_components > 1;
                 }
             }
+        }
 
     // If chroma or alpha can be lost through merging then do not merge
     if (alpha2 > alpha1 || chroma2 > chroma1)