[FFmpeg-cvslog] avfilter/vf_estdif: do some clip calculations only once in loop

Paul B Mahol git at videolan.org
Tue Nov 9 10:50:48 EET 2021


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue Nov  9 09:32:20 2021 +0100| [a13646639fcddb1de3bf08c25a243218cec39a0b] | committer: Paul B Mahol

avfilter/vf_estdif: do some clip calculations only once in loop

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

 libavfilter/vf_estdif.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/libavfilter/vf_estdif.c b/libavfilter/vf_estdif.c
index 4469cb11bf..c7a80425f0 100644
--- a/libavfilter/vf_estdif.c
+++ b/libavfilter/vf_estdif.c
@@ -217,10 +217,9 @@ MID6(uint16_t, 16)
 #define DIFF(type, ss)                                         \
 static unsigned diff_##ss(const type *const prev,              \
                           const type *const next,              \
-                          int end, int x, int k, int j)        \
+                          int x, int y)                        \
 {                                                              \
-    return FFABS(prev[av_clip(x + k + j, 0, end)] -            \
-                 next[av_clip(x - k + j, 0, end)]);            \
+    return FFABS(prev[x] -  next[y]);                          \
 }
 
 DIFF(uint8_t, 8)
@@ -272,9 +271,11 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst,                  \
         atype sum = 0;                                                         \
                                                                                \
         for (int j = -redge; j <= redge; j++) {                                \
-            sum += diff_##ss(prev_line,  next_line,  end, x, i, j);            \
-            sum += diff_##ss(prev2_line, prev_line,  end, x, i, j);            \
-            sum += diff_##ss(next_line,  next2_line, end, x, i, j);            \
+            const int xx = av_clip(x + i + j, 0, end);                         \
+            const int yy = av_clip(x - i + j, 0, end);                         \
+            sum += diff_##ss(prev_line,  next_line,  xx, yy);                  \
+            sum += diff_##ss(prev2_line, prev_line,  xx, yy);                  \
+            sum += diff_##ss(next_line,  next2_line, xx, yy);                  \
         }                                                                      \
                                                                                \
         sD[i + rslope]  =     sum;                                             \
@@ -288,9 +289,11 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst,                  \
         atype sum = 0;                                                         \
                                                                                \
         for (int j = -redge; j <= redge; j++) {                                \
-            sum += diff_##ss(prev_line,  next_line,  end, x, k + i, j);        \
-            sum += diff_##ss(prev2_line, prev_line,  end, x, k + i, j);        \
-            sum += diff_##ss(next_line,  next2_line, end, x, k + i, j);        \
+            const int xx = av_clip(x + k + i + j, 0, end);                     \
+            const int yy = av_clip(x - k - i + j, 0, end);                     \
+            sum += diff_##ss(prev_line,  next_line,  xx, yy);                  \
+            sum += diff_##ss(prev2_line, prev_line,  xx, yy);                  \
+            sum += diff_##ss(next_line,  next2_line, xx, yy);                  \
         }                                                                      \
                                                                                \
         sd[i + rslope]  =     sum;                                             \



More information about the ffmpeg-cvslog mailing list