[FFmpeg-cvslog] avfilter/vf_estdif: simplify finding minimum score

Paul B Mahol git at videolan.org
Tue May 9 13:20:24 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue May  9 10:20:03 2023 +0200| [57f264e78cb06fd8686b78f93b057122afdb3d44] | committer: Paul B Mahol

avfilter/vf_estdif: simplify finding minimum score

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

 libavfilter/vf_estdif.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/libavfilter/vf_estdif.c b/libavfilter/vf_estdif.c
index 452361d717..91e8431e35 100644
--- a/libavfilter/vf_estdif.c
+++ b/libavfilter/vf_estdif.c
@@ -266,11 +266,12 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst,                  \
     const type *const next3_line = (const type *const)nnext3_line;             \
     const int interp = s->interp;                                              \
     const int ecost = s->ecost;                                                \
-    const int dcost = s->dcost * s->max;                                       \
-    const int end = width - 1;                                                 \
+    const int dcost = s->dcost;                                                \
     const int mcost = s->mcost;                                                \
     atype sd[S], sD[S], di = 0;                                                \
+    const int end = width - 1;                                                 \
     atype dmin = amax;                                                         \
+    int id = 0, iD = 0;                                                        \
     int k = *K;                                                                \
                                                                                \
     for (int i = -rslope; i <= rslope && abs(k) > rslope; i++) {               \
@@ -288,7 +289,11 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst,                  \
         sD[i + rslope] += mcost * cost_##ss(prev_line,  next_line,  end, x, i);\
         sD[i + rslope] += dcost * abs(i);                                      \
                                                                                \
-        dmin = FFMIN(sD[i + rslope], dmin);                                    \
+        if (dmin > sD[i + rslope]) {                                           \
+            dmin = sD[i + rslope];                                             \
+            di = 1;                                                            \
+            iD = i;                                                            \
+        }                                                                      \
     }                                                                          \
                                                                                \
     for (int i = -rslope; i <= rslope; i++) {                                  \
@@ -306,23 +311,14 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst,                  \
         sd[i + rslope] += mcost * cost_##ss(prev_line, next_line, end, x, k+i);\
         sd[i + rslope] += dcost * abs(k + i);                                  \
                                                                                \
-        dmin = FFMIN(sd[i + rslope], dmin);                                    \
-    }                                                                          \
-                                                                               \
-    for (int i = -rslope; i <= rslope && abs(k) > rslope; i++) {               \
-        if (dmin == sD[i + rslope]) {                                          \
-            di = 1;                                                            \
-            k = i;                                                             \
-            break;                                                             \
+        if (dmin > sd[i + rslope]) {                                           \
+            dmin = sd[i + rslope];                                             \
+            di = 0;                                                            \
+            id = i;                                                            \
         }                                                                      \
     }                                                                          \
                                                                                \
-    for (int i = -rslope; i <= rslope && !di; i++) {                           \
-        if (dmin == sd[i + rslope]) {                                          \
-            k += i;                                                            \
-            break;                                                             \
-        }                                                                      \
-    }                                                                          \
+    k = di ? iD : k + id;                                                      \
                                                                                \
     dst[x] = s->mid_##ss[interp](prev_line, next_line,                         \
                                  prev2_line, next2_line,                       \



More information about the ffmpeg-cvslog mailing list