[FFmpeg-cvslog] avfilter/vf_neighbor: simplify code little

Paul B Mahol git at videolan.org
Tue May 1 16:10:10 EEST 2018


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue May  1 14:50:48 2018 +0200| [ddf844d17c40fd6053f06d67d8973c302e01b61c] | committer: Paul B Mahol

avfilter/vf_neighbor: simplify code little

Signed-off-by: Paul B Mahol <onemda at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ddf844d17c40fd6053f06d67d8973c302e01b61c
---

 libavfilter/vf_neighbor.c | 66 +++++++++++++++++++++++------------------------
 1 file changed, 32 insertions(+), 34 deletions(-)

diff --git a/libavfilter/vf_neighbor.c b/libavfilter/vf_neighbor.c
index bd69c9e77f..1eb89c208d 100644
--- a/libavfilter/vf_neighbor.c
+++ b/libavfilter/vf_neighbor.c
@@ -165,41 +165,39 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     for (plane = 0; plane < s->nb_planes; plane++) {
         const int threshold = s->threshold[plane];
+        const int stride = in->linesize[plane];
+        const int dstride = out->linesize[plane];
+        const uint8_t *src = in->data[plane];
+        uint8_t *dst = out->data[plane];
+        const int height = s->planeheight[plane];
+        const int width  = s->planewidth[plane];
+
+        if (!threshold) {
+            av_image_copy_plane(dst, dstride, src, stride, width, height);
+            continue;
+        }
 
-        if (threshold) {
-            const int stride = in->linesize[plane];
-            const int dstride = out->linesize[plane];
-            const uint8_t *src = in->data[plane];
-            uint8_t *dst = out->data[plane];
-            const int height = s->planeheight[plane];
-            const int width  = s->planewidth[plane];
-
-            for (y = 0; y < height; y++) {
-                const int nh = y > 0;
-                const int ph = y < height - 1;
-                const uint8_t *coordinates[] = { src - nh * stride, src + 1 - nh * stride, src + 2 - nh * stride,
-                                                 src,                                      src + 2,
-                                                 src + ph * stride, src + 1 + ph * stride, src + 2 + ph * stride};
-
-                const uint8_t *coordinateslb[] = { src - nh * stride, src - nh * stride, src + 1 - nh * stride,
-                                                   src,                                  src + 1,
-                                                   src + ph * stride, src + ph * stride, src + 1 + ph * stride};
-
-                const uint8_t *coordinatesrb[] = { src + width - 2 - nh * stride, src + width - 1 - nh * stride, src + width - 1 - nh * stride,
-                                                   src + width - 2,                                              src + width - 1,
-                                                   src + width - 2 + ph * stride, src + width - 1 + ph * stride, src + width - 1 + ph * stride};
-
-                s->filter(dst,             src,             1,         threshold, coordinateslb, s->coordinates);
-                s->filter(dst         + 1, src         + 1, width - 2, threshold, coordinates,   s->coordinates);
-                s->filter(dst + width - 1, src + width - 1, 1,         threshold, coordinatesrb, s->coordinates);
-
-                src += stride;
-                dst += dstride;
-            }
-        } else {
-            av_image_copy_plane(out->data[plane], out->linesize[plane],
-                                in->data[plane], in->linesize[plane],
-                                s->planewidth[plane], s->planeheight[plane]);
+        for (y = 0; y < height; y++) {
+            const int nh = y > 0;
+            const int ph = y < height - 1;
+            const uint8_t *coordinates[] = { src - nh * stride, src + 1 - nh * stride, src + 2 - nh * stride,
+                                             src,                                      src + 2,
+                                             src + ph * stride, src + 1 + ph * stride, src + 2 + ph * stride};
+
+            const uint8_t *coordinateslb[] = { src - nh * stride, src - nh * stride, src + 1 - nh * stride,
+                                               src,                                  src + 1,
+                                               src + ph * stride, src + ph * stride, src + 1 + ph * stride};
+
+            const uint8_t *coordinatesrb[] = { src + width - 2 - nh * stride, src + width - 1 - nh * stride, src + width - 1 - nh * stride,
+                                               src + width - 2,                                              src + width - 1,
+                                               src + width - 2 + ph * stride, src + width - 1 + ph * stride, src + width - 1 + ph * stride};
+
+            s->filter(dst,             src,             1,         threshold, coordinateslb, s->coordinates);
+            s->filter(dst         + 1, src         + 1, width - 2, threshold, coordinates,   s->coordinates);
+            s->filter(dst + width - 1, src + width - 1, 1,         threshold, coordinatesrb, s->coordinates);
+
+            src += stride;
+            dst += dstride;
         }
     }
 



More information about the ffmpeg-cvslog mailing list