summaryrefslogtreecommitdiff
path: root/libavfilter
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2013-07-01 16:28:59 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-07-03 23:10:46 +0200
commit99f1d7493349640a1489b6b42dec20a9b1326f9b (patch)
treeb60f149a1eb6902ded17ace92c4cbae1ffb9d960 /libavfilter
parenta64248d1ec154779473be90ce1608702cc4a6496 (diff)
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@linux-fr.org> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/vf_delogo.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
index 858595af92..ba35cf5c8d 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),