[Pixman] [PATCH v14 16/22] pixman-filter: distribute normalization error over filter
Søren Sandmann
soren.sandmann at gmail.com
Sat Mar 19 01:54:40 UTC 2016
On Sun, Mar 6, 2016 at 8:06 PM, <spitzak at gmail.com> wrote:
> From: Bill Spitzak <spitzak at gmail.com>
>
> This removes a high-frequency spike in the middle of some filters that is
> caused by math errors all being in the same direction.
>
> Signed-off-by: Bill Spitzak <spitzak at gmail.com>
> ---
> pixman/pixman-filter.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/pixman/pixman-filter.c b/pixman/pixman-filter.c
> index 36dd811..ab62e0a 100644
> --- a/pixman/pixman-filter.c
> +++ b/pixman/pixman-filter.c
> @@ -282,8 +282,18 @@ create_1d_filter (int width,
> p[x] = t;
> }
>
> + /* Distribute any remaining error over all samples */
> if (new_total != pixman_fixed_1)
> - p[width / 2] += (pixman_fixed_1 - new_total);
> + {
> + pixman_fixed_t delta = new_total - pixman_fixed_1;
> + pixman_fixed_t t = 0;
> + for (x = 0; x < width; ++x)
> + {
> + pixman_fixed_t new_t = delta * (x + 1) / width;
> + p[x] += new_t - t;
> + t = new_t;
> + }
> + }
>
I think there is a sign error in this code: delta is new_total - 1, which
is positive when new_total is bigger than 1. But this positive delta is
then added to the samples, making the total even bigger.
Also, I would write the code like this:
pixman_fixed_t error = pixman_fixed_1 - new_total;
for (x = 0; x < width; ++x)
{
pixman_fixed_t d = error * (x + 1) / width;
p[x] += d;
error -= d;
}
to get rid of the temporary and to make it more obvious that there is an
error that is being distributed.
Another possibility is to do error diffusion in the /* Normalize */ loop.
Søren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pixman/attachments/20160318/00bd337b/attachment-0001.html>
More information about the Pixman
mailing list