Low framerate when using alpha channel

Hello,

For some reason I’m getting a 50% drop in framerate when I blit surfaces
with an alpha channel instead of a color key (pixels are either fully
transparent or fully opaque in both cases). Basically, when I use
SDL_DisplayFormat() on the surface everything works fine. When I use
SDL_DisplayFormatAlpha(), it converts the color key to an alpha channel
and the framerate drops to half of what it is without the alpha channel.
The screen and surfaces are created in system memory, so that’s not the
problem. Shouldn’t a surface with an alpha channel blit at the same
speed as one with a color key if no blending needs to be done?

Thanks,
Ilya

Hello,

For some reason I’m getting a 50% drop in framerate when I blit surfaces
with an alpha channel instead of a color key (pixels are either fully
transparent or fully opaque in both cases). Basically, when I use
SDL_DisplayFormat() on the surface everything works fine. When I use
SDL_DisplayFormatAlpha(), it converts the color key to an alpha channel
and the framerate drops to half of what it is without the alpha channel.
The screen and surfaces are created in system memory, so that’s not the
problem. Shouldn’t a surface with an alpha channel blit at the same
speed as one with a color key if no blending needs to be done?

Are you using RLE acceleration with your color keyed images? That will
make a significant difference in performance. If not, then it could just
be the cost of inspecting the alpha channel versus a quick equality test
for the color key.

When blitting with a color key the inner loop of the blit has to test
each pixel against a single value, the color key, to decide whether or
not to draw the pixel. But, assuming the blitter recognizes your special
case, when you are using an alpha channel the inner loop of the blit has
to isolate the alpha channel and then test its value. The extra cost of
isolating the alpha channel can add a lot to the total time needed to
process the blit. If it doesn’t recognize your special case then the
blitter has to read both the source and destination pixels, to alpha
blending, and then write the destination pixel.

No matter how you look at it, operations on alpha channels have the
potential to be slower than a simple color key test because alpha
blending is more complex. I say, “has the potential” because you might
run into a strange situation where color key blitting is implemented in
software while there is hardware support for alpha blitting and then
using the alpha channel is going to be faster.

It is damn hard to make an absolute statement about anything having to
do with computers these days. :slight_smile:

	Bob PendletonOn Fri, 2005-04-29 at 14:21 -0400, Ilya Olevsky wrote:

Thanks,
Ilya


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


±-------------------------------------+

Are you using RLE acceleration with your color keyed images? That will
make a significant difference in performance. If not, then it could just
be the cost of inspecting the alpha channel versus a quick equality test
for the color key.

I am using RLE but removing it doesn’t make much of a difference in my
case.

When blitting with a color key the inner loop of the blit has to test
each pixel against a single value, the color key, to decide whether or
not to draw the pixel. But, assuming the blitter recognizes your special
case, when you are using an alpha channel the inner loop of the blit has
to isolate the alpha channel and then test its value. The extra cost of
isolating the alpha channel can add a lot to the total time needed to
process the blit. If it doesn’t recognize your special case then the
blitter has to read both the source and destination pixels, to alpha
blending, and then write the destination pixel.

Hmm, yeah I can see how it could be slower based on what you’re saying.
I’m playing around with it a bit right now, and it seems that it slows
down when there’s a large number of surfaces being blitted. None of
these have partially transparent pixels, so what you’re saying is
probably true. Looks like blitting a surface with an alpha channel is
slow in general, which kind of sucks. I was hoping that fully
transparent areas would be treated like a color key.

Thanks the info,
Ilya