![](https://secure.gravatar.com/avatar/b47d036b8f12e712f4960ba78404c3b2.jpg?s=120&d=mm&r=g)
2010/11/26 LucaDC <dicappello@...2144...>:
Jasper van de Gronde wrote:
In any case, there is no good reason to multiply the coefficients by 255, just use 256 (or some other, higher, power of 2), that way the divide can be done with a single shift (and that should definitely be somewhat faster).
Maybe I'm gonna say something obvious for you, if so forgive me. When you do integer math there is a difference between multiplying by 255 or 256 and it's in what is '1'.
In this case it doesn't matter because the input values are limited to 0...255. We can use any multiplier we want - as long as the coeffs sum up to the value we use as the divisor, it will work correctly. There are many other cases where it won't, precisely because of the reason you mentioned (e.g. in blending, or when alpha is used as a coefficient) and then we can't avoid the division.
Regards, Krzysztof