[SDL] BUG?: RGBA->screen blit has 1-off error with opaque colors
Markus Laire
malaire at gmail.com
Wed Jun 6 05:54:02 PDT 2007
On 6/6/07, David Olofson <david at olofson.net> wrote:
> I think this is the result of the blitters multiplying by the alpha
> value, and then dividing by 256 (8 bit right shift) rather than 255.
> (Actual division is *very* expensive, compared to shift operations!)
What about checking whether the alpha value is 255, and in that case
just copying the color instead of multiply and bit-shift?
I find this bug to be quite annnoying as currently I can't have fully
opaque colors when using the alpha-channel.
> One way around this is to scale the alpha value from [0, 255] to [0,
> 256]. In the case of full surface alpha, this costs virtually
> nothing, but it would probably slow down alpha channel (RGBA) blits
> quite a bit - although not nearly as much as actually dividing by 255
> for each channel.
>
> One could cheat by scaling the alpha channel to [0, 128] and shifting
> 7 bits, but obviosuly, that results in a "funny" pixel format, and
> less accurate blending... Another hack is to add 1 somewhere, but
> then you just get 1 instead of 0 for "fully" transparent.
>
> I'm afraid there is no easy, low cost solution - which is why it is
> the way it is, I would think.
--
Markus Laire
More information about the SDL
mailing list