[FFmpeg-cvslog] lavfi/delogo: take SAR into account

Jean Delvare git at videolan.org
Wed Jul 3 23:19:18 CEST 2013


ffmpeg | branch: master | Jean Delvare <khali at linux-fr.org> | Mon Jul  1 16:28:59 2013 +0200| [99f1d7493349640a1489b6b42dec20a9b1326f9b] | committer: Michael Niedermayer

lavfi/delogo: take SAR into account

When interpolating, weights are based on relative distances, which
assume square pixels. If a non-1:1 sample aspect ratio is used, it
should be taken into account when comparing distances, because the
human eye and brain care about the picture as it is displayed, not
stored.

Signed-off-by: Jean Delvare <khali at linux-fr.org>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavfilter/vf_delogo.c |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
index 858595a..ba35cf5 100644
--- a/libavfilter/vf_delogo.c
+++ b/libavfilter/vf_delogo.c
@@ -56,7 +56,7 @@
  */
 static void apply_delogo(uint8_t *dst, int dst_linesize,
                          uint8_t *src, int src_linesize,
-                         int w, int h,
+                         int w, int h, AVRational sar,
                          int logo_x, int logo_y, int logo_w, int logo_h,
                          int band, int show, int direct)
 {
@@ -93,11 +93,11 @@ static void apply_delogo(uint8_t *dst, int dst_linesize,
              xdst = dst+logo_x1+1,
              xsrc = src+logo_x1+1; x < logo_x2-1; x++, xdst++, xsrc++) {
 
-            /* Weighted interpolation based on relative distances */
-            weightl = (uint64_t)              (logo_x2-1-x) * (y-logo_y1) * (logo_y2-1-y);
-            weightr = (uint64_t)(x-logo_x1)                 * (y-logo_y1) * (logo_y2-1-y);
-            weightt = (uint64_t)(x-logo_x1) * (logo_x2-1-x)               * (logo_y2-1-y);
-            weightb = (uint64_t)(x-logo_x1) * (logo_x2-1-x) * (y-logo_y1);
+            /* Weighted interpolation based on relative distances, taking SAR into account */
+            weightl = (uint64_t)              (logo_x2-1-x) * (y-logo_y1) * (logo_y2-1-y) * sar.den;
+            weightr = (uint64_t)(x-logo_x1)                 * (y-logo_y1) * (logo_y2-1-y) * sar.den;
+            weightt = (uint64_t)(x-logo_x1) * (logo_x2-1-x)               * (logo_y2-1-y) * sar.num;
+            weightb = (uint64_t)(x-logo_x1) * (logo_x2-1-x) * (y-logo_y1)                 * sar.num;
 
             interp =
                 (topleft[src_linesize*(y-logo_y  -yclipt)]   +
@@ -217,6 +217,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     int vsub0 = desc->log2_chroma_h;
     int direct = 0;
     int plane;
+    AVRational sar;
 
     if (av_frame_is_writable(in)) {
         direct = 1;
@@ -231,6 +232,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         av_frame_copy_props(out, in);
     }
 
+    sar = in->sample_aspect_ratio;
+    /* Assume square pixels if SAR is unknown */
+    if (!sar.num)
+        sar.num = sar.den = 1;
+
     for (plane = 0; plane < 4 && in->data[plane]; plane++) {
         int hsub = plane == 1 || plane == 2 ? hsub0 : 0;
         int vsub = plane == 1 || plane == 2 ? vsub0 : 0;
@@ -239,7 +245,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
                      in ->data[plane], in ->linesize[plane],
                      FF_CEIL_RSHIFT(inlink->w, hsub),
                      FF_CEIL_RSHIFT(inlink->h, vsub),
-                     s->x>>hsub, s->y>>vsub,
+                     sar, s->x>>hsub, s->y>>vsub,
                      FF_CEIL_RSHIFT(s->w, hsub),
                      FF_CEIL_RSHIFT(s->h, vsub),
                      s->band>>FFMIN(hsub, vsub),



More information about the ffmpeg-cvslog mailing list