[FFmpeg-devel] [PATCH v3] avfilter/vf_lut: simplify code

lance.lmwang at gmail.com lance.lmwang at gmail.com
Fri Nov 22 17:54:19 EET 2019


From: Limin Wang <lance.lmwang at gmail.com>

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
have pass fate testing for fate-filter-pixfmts-lut

 libavfilter/vf_lut.c | 67 ++++++++++------------------------------------------
 1 file changed, 12 insertions(+), 55 deletions(-)

diff --git a/libavfilter/vf_lut.c b/libavfilter/vf_lut.c
index 1fdc5e1..328c64d 100644
--- a/libavfilter/vf_lut.c
+++ b/libavfilter/vf_lut.c
@@ -220,6 +220,10 @@ static int config_props(AVFilterLink *inlink)
     int min[4], max[4];
     int val, color, ret;
 
+    s->is_yuv = !(desc->flags & AV_PIX_FMT_FLAG_RGB) &&
+                 (desc->flags & AV_PIX_FMT_FLAG_PLANAR) &&
+                 desc->nb_components >= 3;
+    s->is_rgb = ff_fill_rgba_map(rgba_map, inlink->format) >= 0;
     s->hsub = desc->log2_chroma_w;
     s->vsub = desc->log2_chroma_h;
 
@@ -227,42 +231,7 @@ static int config_props(AVFilterLink *inlink)
     s->var_values[VAR_H] = inlink->h;
     s->is_16bit = desc->comp[0].depth > 8;
 
-    switch (inlink->format) {
-    case AV_PIX_FMT_YUV410P:
-    case AV_PIX_FMT_YUV411P:
-    case AV_PIX_FMT_YUV420P:
-    case AV_PIX_FMT_YUV422P:
-    case AV_PIX_FMT_YUV440P:
-    case AV_PIX_FMT_YUV444P:
-    case AV_PIX_FMT_YUVA420P:
-    case AV_PIX_FMT_YUVA422P:
-    case AV_PIX_FMT_YUVA444P:
-    case AV_PIX_FMT_YUV420P9LE:
-    case AV_PIX_FMT_YUV422P9LE:
-    case AV_PIX_FMT_YUV444P9LE:
-    case AV_PIX_FMT_YUVA420P9LE:
-    case AV_PIX_FMT_YUVA422P9LE:
-    case AV_PIX_FMT_YUVA444P9LE:
-    case AV_PIX_FMT_YUV420P10LE:
-    case AV_PIX_FMT_YUV422P10LE:
-    case AV_PIX_FMT_YUV440P10LE:
-    case AV_PIX_FMT_YUV444P10LE:
-    case AV_PIX_FMT_YUVA420P10LE:
-    case AV_PIX_FMT_YUVA422P10LE:
-    case AV_PIX_FMT_YUVA444P10LE:
-    case AV_PIX_FMT_YUV420P12LE:
-    case AV_PIX_FMT_YUV422P12LE:
-    case AV_PIX_FMT_YUV440P12LE:
-    case AV_PIX_FMT_YUV444P12LE:
-    case AV_PIX_FMT_YUV420P14LE:
-    case AV_PIX_FMT_YUV422P14LE:
-    case AV_PIX_FMT_YUV444P14LE:
-    case AV_PIX_FMT_YUV420P16LE:
-    case AV_PIX_FMT_YUV422P16LE:
-    case AV_PIX_FMT_YUV444P16LE:
-    case AV_PIX_FMT_YUVA420P16LE:
-    case AV_PIX_FMT_YUVA422P16LE:
-    case AV_PIX_FMT_YUVA444P16LE:
+    if (s->is_yuv) {
         min[Y] = 16 * (1 << (desc->comp[0].depth - 8));
         min[U] = 16 * (1 << (desc->comp[1].depth - 8));
         min[V] = 16 * (1 << (desc->comp[2].depth - 8));
@@ -271,29 +240,17 @@ static int config_props(AVFilterLink *inlink)
         max[U] = 240 * (1 << (desc->comp[1].depth - 8));
         max[V] = 240 * (1 << (desc->comp[2].depth - 8));
         max[A] = (1 << desc->comp[0].depth) - 1;
-        break;
-    case AV_PIX_FMT_RGB48LE:
-    case AV_PIX_FMT_RGBA64LE:
-        min[0] = min[1] = min[2] = min[3] = 0;
-        max[0] = max[1] = max[2] = max[3] = 65535;
-        break;
-    default:
+    } else {
         min[0] = min[1] = min[2] = min[3] = 0;
-        max[0] = max[1] = max[2] = max[3] = 255 * (1 << (desc->comp[0].depth - 8));
+        if (inlink->format == AV_PIX_FMT_RGB48LE ||
+            inlink->format == AV_PIX_FMT_RGBA64LE)
+            max[0] = max[1] = max[2] = max[3] = 65535;
+        else
+            max[0] = max[1] = max[2] = max[3] = 255 * (1 << (desc->comp[0].depth - 8));
     }
 
-    s->is_yuv = s->is_rgb = 0;
     s->is_planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
-    if      (ff_fmt_is_in(inlink->format, yuv_pix_fmts)) s->is_yuv = 1;
-    else if (ff_fmt_is_in(inlink->format, rgb_pix_fmts)) s->is_rgb = 1;
-
-    if (s->is_rgb) {
-        ff_fill_rgba_map(rgba_map, inlink->format);
-        s->step = av_get_bits_per_pixel(desc) >> 3;
-        if (s->is_16bit) {
-            s->step = s->step >> 1;
-        }
-    }
+    s->step = av_get_padded_bits_per_pixel(desc) >> (3 + s->is_16bit) ;
 
     for (color = 0; color < desc->nb_components; color++) {
         double res;
-- 
2.6.4



More information about the ffmpeg-devel mailing list