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

avfilter/vf_delogo: round to the closest value

When the interpolated value is divided by the sum of weights, no
rounding is done, which means the value is truncated. This results in
a slight bias towards dark green in the interpolated area. Rounding
properly removes the bias.

I measured this change to reduce the interpolation error by 1 to 2 %
on average on a number of sample input and logo area combinations.
Signed-off-by: 's avatarJean Delvare <jdelvare@suse.de>
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent c8905e0d
......@@ -61,7 +61,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize,
unsigned int band, int show, int direct)
{
int x, y;
uint64_t interp, weightl, weightr, weightt, weightb;
uint64_t interp, weightl, weightr, weightt, weightb, weight;
uint8_t *xdst, *xsrc;
uint8_t *topleft, *botleft, *topright;
......@@ -125,7 +125,8 @@ static void apply_delogo(uint8_t *dst, int dst_linesize,
(botleft[x-logo_x1] +
botleft[x-logo_x1-1] +
botleft[x-logo_x1+1]) * weightb;
interp /= (weightl + weightr + weightt + weightb) * 3U;
weight = (weightl + weightr + weightt + weightb) * 3U;
interp = ROUNDED_DIV(interp, weight);
if (y >= logo_y+band && y < logo_y+logo_h-band &&
x >= logo_x+band && x < logo_x+logo_w-band) {
......
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