lavfi/swapuv: support all planar yuv pixel formats
authorPaul B Mahol <onemda@gmail.com>
Sat, 22 Dec 2012 01:48:17 +0000 (01:48 +0000)
committerPaul B Mahol <onemda@gmail.com>
Wed, 23 Jan 2013 16:13:23 +0000 (16:13 +0000)
Signed-off-by: Paul B Mahol <onemda@gmail.com>
libavfilter/vf_swapuv.c

index e7e5e88..82cc07c 100644 (file)
@@ -23,6 +23,7 @@
  * swap UV filter
  */
 
+#include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "formats.h"
 #include "internal.h"
@@ -48,18 +49,36 @@ static int filter_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
     return ff_filter_frame(link->dst->outputs[0], inpicref);
 }
 
+static int is_planar_yuv(const AVPixFmtDescriptor *desc)
+{
+    int i;
+
+    if (desc->flags & ~(PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_ALPHA) ||
+        desc->nb_components < 3 ||
+        (desc->comp[1].depth_minus1 != desc->comp[2].depth_minus1))
+        return 0;
+    for (i = 0; i < desc->nb_components; i++) {
+        if (desc->comp[i].offset_plus1 != 1 ||
+            desc->comp[i].shift != 0 ||
+            desc->comp[i].plane != i)
+            return 0;
+    }
+
+    return 1;
+}
+
 static int query_formats(AVFilterContext *ctx)
 {
-    static const enum AVPixelFormat pix_fmts[] = {
-        AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVA420P,
-        AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
-        AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUVJ440P,
-        AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVJ422P,
-        AV_PIX_FMT_YUV411P,
-        AV_PIX_FMT_NONE,
-    };
-
-    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+    AVFilterFormats *formats = NULL;
+    int fmt;
+
+    for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
+        if (is_planar_yuv(desc))
+            ff_add_format(&formats, fmt);
+    }
+
+    ff_set_common_formats(ctx, formats);
     return 0;
 }