> 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
_______________________________________________
Pixman mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/pixman