Easy optimisation to speed up the bitmap rendering

As I'm also following on a laptop I sped up the bitmap rendering trivially by immediately rejecting pixels with zero alpha and not doing any alpha blending calculations for pixels with full alpha.

i.e something like;

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
if ( alpha > 0 )
{
    if ( alpha == 255 )
    {
        *destinationPixel = *sourcePixel;
    }
    else
    {
        // Do full alpha blending calculations here
    }
}
++destinationPixel;
++sourcePixel;


Hope this helps someone
Mike

Edited by Mike Nimmo on Reason: Fixing the typo in the code block (thanks mmozeiko)
I hope you don't have "if (alpha=255)" in your code and its a typo, because that will make all bitmaps opaque (but it will be faster of course). Basically use compare "alpha==255" not assign "alpha=255" in if condition.
mmozeiko: You are right, that was a typo in my post.
Corrected the example now.

Thanks
Some people are so afraid of bugs of that kind, they write the comparisons in reverse order (which will cause the compiler to give an error).

1
if (255 = alpha)


..Personally I feel that's bending backwards a bit too much. Modern compilers will typically give you a warning if you do an assignment where a comparison is expected.