Avatar,
I'll just give my thoughts on all three approaches:
- Scanning each pixel and scaling the transparency according to the bytes in the alpha map: This may seem slow, but consider this:
1. If the alpha map value is 0 or 255, you can skip expensive calculus. This will be the case most of the time, as you noticed yourself.
2. You can pre-scale the sprite data using the alpha map, so you only have to scale the background colors and add the prescaled sprite pixels.
I am not sure what you mean by 'this has to be done for each frame of animation of each sprite'? I assume you want to do this at run time, so yeah, you do it for each sprite, but just for one frame at a time.
- Second idea, edge checking: Read my tutorial 7, and split your sprite in horizontal spans.
Assume that only the first pixel and the last pixel of a span can have an alpha value (this will be a pretty good approximation of the first approach). Again, prescale the sprite with the alpha data.
Using this approach you can skip the 'if' that you needed in the first approach to test for '0' or '255'. Conditional code is usually very expensive (although I doubt that the StrongARM does branch prediction), so this could speed up your code a lot (I would assume this trick would double the speed). It does take some preprocessing, more complex drawing, and some memory to store all this extra data. On the other hand, you can probably dump the alpha map once you constructed the spans, so memory should not be an issue.
- Table lookup: The problem here is that you want it the other way round. You are drawing the pixels of the sprite one by one, so to lookup whether or not a pixel has a different alpha than '255' (or '0'), you have to look through the entire lookup table. Not a good idea, I think.
Hope this helps.
- Jacco.
I'll just give my thoughts on all three approaches:
- Scanning each pixel and scaling the transparency according to the bytes in the alpha map: This may seem slow, but consider this:
1. If the alpha map value is 0 or 255, you can skip expensive calculus. This will be the case most of the time, as you noticed yourself.
2. You can pre-scale the sprite data using the alpha map, so you only have to scale the background colors and add the prescaled sprite pixels.
I am not sure what you mean by 'this has to be done for each frame of animation of each sprite'? I assume you want to do this at run time, so yeah, you do it for each sprite, but just for one frame at a time.
- Second idea, edge checking: Read my tutorial 7, and split your sprite in horizontal spans.
Using this approach you can skip the 'if' that you needed in the first approach to test for '0' or '255'. Conditional code is usually very expensive (although I doubt that the StrongARM does branch prediction), so this could speed up your code a lot (I would assume this trick would double the speed). It does take some preprocessing, more complex drawing, and some memory to store all this extra data. On the other hand, you can probably dump the alpha map once you constructed the spans, so memory should not be an issue.
- Table lookup: The problem here is that you want it the other way round. You are drawing the pixels of the sprite one by one, so to lookup whether or not a pixel has a different alpha than '255' (or '0'), you have to look through the entire lookup table. Not a good idea, I think.
Hope this helps.
- Jacco.