Commit f0bcb13a authored by Jean Delvare's avatar Jean Delvare Committed by Michael Niedermayer

lavfi/delogo: avoid propagation of rounding errors in chroma planes

When operating on subsampled chroma planes, some rounding is taking
place. The left and top borders are rounded down while the width and
height are rounded up, so all rounding is done outward to guarantee the
logo area is fully covered.

The problem is that the width and height are counted from the
unrounded left and top borders, respectively. So if the left or top
border position has indeed been rounded down, and the width or height
needs no rounding (up), the position of the the right or bottom border
will be effectively rounded down, i.e. inward.

The issue can easily be seen with a yuv240p input and
  -vf delogo=45:45:60:40:show=1 -vframes 1 delogo-bug.png
(or virtually any logo area with odd x and y and even width and
height.) The right and bottom chroma borders (in green) are clearly
off.

In order to fix this, the width and height must be adjusted to include
the bits lost in the rounding of the left and top border positions,
respectively, prior to being themselves rounded up.
Signed-off-by: 's avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 99f1d749
......@@ -246,8 +246,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
FF_CEIL_RSHIFT(inlink->w, hsub),
FF_CEIL_RSHIFT(inlink->h, vsub),
sar, s->x>>hsub, s->y>>vsub,
FF_CEIL_RSHIFT(s->w, hsub),
FF_CEIL_RSHIFT(s->h, vsub),
/* Up and left borders were rounded down, inject lost bits
* into width and height to avoid error accumulation */
FF_CEIL_RSHIFT(s->w + (s->x & ((1<<hsub)-1)), hsub),
FF_CEIL_RSHIFT(s->h + (s->y & ((1<<vsub)-1)), vsub),
s->band>>FFMIN(hsub, vsub),
s->show, direct);
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment