[FFmpeg-cvslog] avfilter/interlace: simplify code

Thomas Mundt git at videolan.org
Sat Sep 16 02:07:45 EEST 2017


ffmpeg | branch: master | Thomas Mundt <tmundt75 at gmail.com> | Thu Sep 14 21:20:24 2017 +0200| [ed48e22748ee199ce4790ed29da8cef937347f17] | committer: Michael Niedermayer

avfilter/interlace: simplify code

Signed-off-by: Thomas Mundt <tmundt75 at gmail.com>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

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

 libavfilter/vf_interlace.c  | 31 +++++++++----------------------
 libavfilter/vf_tinterlace.c | 29 +++++++++--------------------
 2 files changed, 18 insertions(+), 42 deletions(-)

diff --git a/libavfilter/vf_interlace.c b/libavfilter/vf_interlace.c
index 1a9278082a..55bf782af8 100644
--- a/libavfilter/vf_interlace.c
+++ b/libavfilter/vf_interlace.c
@@ -181,6 +181,8 @@ static void copy_picture_field(InterlaceContext *s,
         int lines = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->h, vsub) : inlink->h;
         uint8_t *dstp = dst_frame->data[plane];
         const uint8_t *srcp = src_frame->data[plane];
+        int srcp_linesize = src_frame->linesize[plane] * 2;
+        int dstp_linesize = dst_frame->linesize[plane] * 2;
 
         av_assert0(cols >= 0 || lines >= 0);
 
@@ -189,38 +191,23 @@ static void copy_picture_field(InterlaceContext *s,
             srcp += src_frame->linesize[plane];
             dstp += dst_frame->linesize[plane];
         }
-        if (lowpass == VLPF_LIN) {
-            int srcp_linesize = src_frame->linesize[plane] * 2;
-            int dstp_linesize = dst_frame->linesize[plane] * 2;
+        if (lowpass) {
+            int x = 0;
+            if (lowpass == VLPF_CMP)
+                x = 1;
             for (j = lines; j > 0; j--) {
                 ptrdiff_t pref = src_frame->linesize[plane];
                 ptrdiff_t mref = -pref;
-                if (j == lines)
-                    mref = 0;    // there is no line above
-                else if (j == 1)
-                    pref = 0;    // there is no line below
-                s->lowpass_line(dstp, cols, srcp, mref, pref);
-                dstp += dstp_linesize;
-                srcp += srcp_linesize;
-            }
-        } else if (lowpass == VLPF_CMP) {
-            int srcp_linesize = src_frame->linesize[plane] * 2;
-            int dstp_linesize = dst_frame->linesize[plane] * 2;
-            for (j = lines; j > 0; j--) {
-                ptrdiff_t pref = src_frame->linesize[plane];
-                ptrdiff_t mref = -pref;
-                if (j >= (lines - 1))
+                if (j >= (lines - x))
                     mref = 0;
-                else if (j <= 2)
+                else if (j <= (1 + x))
                     pref = 0;
                 s->lowpass_line(dstp, cols, srcp, mref, pref);
                 dstp += dstp_linesize;
                 srcp += srcp_linesize;
             }
         } else {
-            av_image_copy_plane(dstp, dst_frame->linesize[plane] * 2,
-                                srcp, src_frame->linesize[plane] * 2,
-                                cols, lines);
+            av_image_copy_plane(dstp, dstp_linesize, srcp, srcp_linesize, cols, lines);
         }
     }
 }
diff --git a/libavfilter/vf_tinterlace.c b/libavfilter/vf_tinterlace.c
index 81d2d773e0..66c6d17ed9 100644
--- a/libavfilter/vf_tinterlace.c
+++ b/libavfilter/vf_tinterlace.c
@@ -252,6 +252,8 @@ void copy_picture_field(TInterlaceContext *tinterlace,
         int cols  = plane == 1 || plane == 2 ? AV_CEIL_RSHIFT(    w, hsub) : w;
         uint8_t *dstp = dst[plane];
         const uint8_t *srcp = src[plane];
+        int srcp_linesize = src_linesize[plane] * k;
+        int dstp_linesize = dst_linesize[plane] * (interleave ? 2 : 1);
 
         lines = (lines + (src_field == FIELD_UPPER)) / k;
         if (src_field == FIELD_LOWER)
@@ -261,35 +263,22 @@ void copy_picture_field(TInterlaceContext *tinterlace,
         // Low-pass filtering is required when creating an interlaced destination from
         // a progressive source which contains high-frequency vertical detail.
         // Filtering will reduce interlace 'twitter' and Moire patterning.
-        if (flags & TINTERLACE_FLAG_CVLPF) {
-            int srcp_linesize = src_linesize[plane] * k;
-            int dstp_linesize = dst_linesize[plane] * (interleave ? 2 : 1);
+        if (flags & TINTERLACE_FLAG_VLPF || flags & TINTERLACE_FLAG_CVLPF) {
+            int x = 0;
+            if (flags & TINTERLACE_FLAG_CVLPF)
+                x = 1;
             for (h = lines; h > 0; h--) {
                 ptrdiff_t pref = src_linesize[plane];
                 ptrdiff_t mref = -pref;
-                if (h >= (lines - 1)) mref = 0;
-                else if (h <= 2)      pref = 0;
-
-                tinterlace->lowpass_line(dstp, cols, srcp, mref, pref);
-                dstp += dstp_linesize;
-                srcp += srcp_linesize;
-            }
-        } else if (flags & TINTERLACE_FLAG_VLPF) {
-            int srcp_linesize = src_linesize[plane] * k;
-            int dstp_linesize = dst_linesize[plane] * (interleave ? 2 : 1);
-            for (h = lines; h > 0; h--) {
-                ptrdiff_t pref = src_linesize[plane];
-                ptrdiff_t mref = -pref;
-                if (h == lines)  mref = 0; // there is no line above
-                else if (h == 1) pref = 0; // there is no line below
+                if (h >= (lines - x))  mref = 0; // there is no line above
+                else if (h <= (1 + x)) pref = 0; // there is no line below
 
                 tinterlace->lowpass_line(dstp, cols, srcp, mref, pref);
                 dstp += dstp_linesize;
                 srcp += srcp_linesize;
             }
         } else {
-            av_image_copy_plane(dstp, dst_linesize[plane] * (interleave ? 2 : 1),
-                                srcp, src_linesize[plane]*k, cols, lines);
+            av_image_copy_plane(dstp, dstp_linesize, srcp, srcp_linesize, cols, lines);
         }
     }
 }



More information about the ffmpeg-cvslog mailing list