]> git.sesse.net Git - ffmpeg/commitdiff
avfilter/yadif: simplify the code for better readability
authorLimin Wang <lance.lmwang@gmail.com>
Tue, 11 Aug 2020 16:21:54 +0000 (00:21 +0800)
committerLimin Wang <lance.lmwang@gmail.com>
Wed, 26 Aug 2020 06:21:11 +0000 (14:21 +0800)
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
libavfilter/vf_bwdif.c
libavfilter/vf_yadif.c
libavfilter/x86/vf_bwdif_init.c
libavfilter/x86/vf_yadif_init.c
libavfilter/yadif.h
libavfilter/yadif_common.c

index b6aed7a450359a6185b3badadcbefb3802d3fea2..583a96570ebfeb73cbb633203d38ed8312483e69 100644 (file)
@@ -219,8 +219,8 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
     YADIFContext *yadif = &s->yadif;
     ThreadData *td  = arg;
     int linesize = yadif->cur->linesize[td->plane];
-    int clip_max = (1 << (yadif->csp->comp[td->plane].depth)) - 1;
-    int df = (yadif->csp->comp[td->plane].depth + 7) / 8;
+    int clip_max = (1 << (yadif->depth)) - 1;
+    int df = (yadif->depth + 7) / 8;
     int refs = linesize / df;
     int slice_start = (td->h *  jobnr   ) / nb_jobs;
     int slice_end   = (td->h * (jobnr+1)) / nb_jobs;
@@ -267,13 +267,13 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic,
     ThreadData td = { .frame = dstpic, .parity = parity, .tff = tff };
     int i;
 
-    for (i = 0; i < yadif->csp->nb_components; i++) {
+    for (i = 0; i < yadif->nb_components; i++) {
         int w = dstpic->width;
         int h = dstpic->height;
 
         if (i == 1 || i == 2) {
-            w = AV_CEIL_RSHIFT(w, yadif->csp->log2_chroma_w);
-            h = AV_CEIL_RSHIFT(h, yadif->csp->log2_chroma_h);
+            w = AV_CEIL_RSHIFT(w, yadif->hsub);
+            h = AV_CEIL_RSHIFT(h, yadif->vsub);
         }
 
         td.w     = w;
@@ -348,9 +348,8 @@ static int config_props(AVFilterLink *link)
         return AVERROR(EINVAL);
     }
 
-    yadif->csp = av_pix_fmt_desc_get(link->format);
     yadif->filter = filter;
-    if (yadif->csp->comp[0].depth > 8) {
+    if (yadif->depth > 8) {
         s->filter_intra = filter_intra_16bit;
         s->filter_line  = filter_line_c_16bit;
         s->filter_edge  = filter_edge_16bit;
index 43dea67addc6544d4ca8d824d0908ccd19c6244c..acc55a481fedb417bb722570c0ed451c1872e6f1 100644 (file)
@@ -192,7 +192,7 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
     YADIFContext *s = ctx->priv;
     ThreadData *td  = arg;
     int refs = s->cur->linesize[td->plane];
-    int df = (s->csp->comp[td->plane].depth + 7) / 8;
+    int df = (s->depth + 7) / 8;
     int pix_3 = 3 * df;
     int slice_start = (td->h *  jobnr   ) / nb_jobs;
     int slice_end   = (td->h * (jobnr+1)) / nb_jobs;
@@ -233,13 +233,13 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic,
     ThreadData td = { .frame = dstpic, .parity = parity, .tff = tff };
     int i;
 
-    for (i = 0; i < yadif->csp->nb_components; i++) {
+    for (i = 0; i < yadif->nb_components; i++) {
         int w = dstpic->width;
         int h = dstpic->height;
 
         if (i == 1 || i == 2) {
-            w = AV_CEIL_RSHIFT(w, yadif->csp->log2_chroma_w);
-            h = AV_CEIL_RSHIFT(h, yadif->csp->log2_chroma_h);
+            w = AV_CEIL_RSHIFT(w, yadif->hsub);
+            h = AV_CEIL_RSHIFT(h, yadif->vsub);
         }
 
 
@@ -292,6 +292,7 @@ static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
     YADIFContext *s = ctx->priv;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
 
     outlink->time_base.num = ctx->inputs[0]->time_base.num;
     outlink->time_base.den = ctx->inputs[0]->time_base.den * 2;
@@ -307,9 +308,12 @@ static int config_output(AVFilterLink *outlink)
         return AVERROR(EINVAL);
     }
 
-    s->csp = av_pix_fmt_desc_get(outlink->format);
     s->filter = filter;
-    if (s->csp->comp[0].depth > 8) {
+    s->depth         = desc->comp[0].depth;
+    s->nb_components = desc->nb_components;
+    s->hsub          = desc->log2_chroma_w;
+    s->vsub          = desc->log2_chroma_h;
+    if (s->depth > 8) {
         s->filter_line  = filter_line_c_16bit;
         s->filter_edges = filter_edges_16bit;
     } else {
index b1e70b3bc680d87faff8fd3940fd8639fef8625e..817bd846630b9bae8ed9bd966d0cbd2bd0cbbfaa 100644 (file)
@@ -55,7 +55,7 @@ av_cold void ff_bwdif_init_x86(BWDIFContext *bwdif)
 {
     YADIFContext *yadif = &bwdif->yadif;
     int cpu_flags = av_get_cpu_flags();
-    int bit_depth = (!yadif->csp) ? 8 : yadif->csp->comp[0].depth;
+    int bit_depth = yadif->depth;
 
     if (bit_depth <= 8) {
 #if ARCH_X86_32
index c39bc44da6471b4883c4085bd5b8ffb7451066bd..ecf012af7cf34478dd8fafdc4ebf831da29db442 100644 (file)
@@ -60,8 +60,7 @@ void ff_yadif_filter_line_10bit_ssse3(void *dst, void *prev, void *cur,
 av_cold void ff_yadif_init_x86(YADIFContext *yadif)
 {
     int cpu_flags = av_get_cpu_flags();
-    int bit_depth = (!yadif->csp) ? 8
-                                  : yadif->csp->comp[0].depth;
+    int bit_depth = yadif->depth;
 
     if (bit_depth >= 15) {
 #if ARCH_X86_32
index c928911b357b70b577458823b34a8724d5da81db..773f29bac99f742e37f24261ede6dea5435f282d 100644 (file)
@@ -72,7 +72,10 @@ typedef struct YADIFContext {
     void (*filter_edges)(void *dst, void *prev, void *cur, void *next,
                          int w, int prefs, int mrefs, int parity, int mode);
 
-    const AVPixFmtDescriptor *csp;
+    int nb_components;
+    int depth;
+    int hsub;
+    int vsub;
     int eof;
     uint8_t *temp_line;
     int temp_line_size;
index a10cf7a17fd8a6efe1844940092e1cee01f3de71..8c20e22af97ad04e1fb3f0e3829ab0ed2e6dfbf3 100644 (file)
@@ -69,7 +69,7 @@ static int return_frame(AVFilterContext *ctx, int is_second)
 static int checkstride(YADIFContext *yadif, const AVFrame *a, const AVFrame *b)
 {
     int i;
-    for (i = 0; i < yadif->csp->nb_components; i++)
+    for (i = 0; i < yadif->nb_components; i++)
         if (a->linesize[i] != b->linesize[i])
             return 1;
     return 0;