[Pixman] [PATCH v14 16/22] pixman-filter: distribute normalization error over filter

Søren Sandmann soren.sandmann at gmail.com
Sun Mar 20 01:19:56 UTC 2016


> 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.
>

I meant

    ...
    pixman_fixed_t d = error / (width - x);
    ...

of course, but I guess the rounding-towards-zero behavior of division in C
makes this less desirable since it tends to put all the rounding error
towards one side of the kernel. Rounding-to-nearest would make it similar
to your code:

    ...
    pixman_fixed_t d = DIV(error + (width - x - 1) / 2, width - x)
    ...

but then it would be slightly cleaner to make the loop count down:

    for (x = width; x > 0; --x)
    {
        pixman_fixed_t d = DIV(error + (x - 1) / 2, x)
        p[x] += d;
        error -= d;
    }


Søren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pixman/attachments/20160319/144a6f70/attachment.html>


More information about the Pixman mailing list