Alpha blits

Hi all,

I’ve just upgraded from 1.1.3 to 1.1.6, and my app shows a
significant slowdown when it comes to alpha blits.
I’ve already noticed that I can call SDL_DisplayFormatAlpha,
which however doesn’t help the situation very much. (neither
does SDL_RLEACCEL, btw)

My question is: Is this supposed to be the case, i.e. were
some highly-optimized routines discarded in favor of the new
"flipped" alpha code, or am I missing something, possibly
a new optimization that I have to turn on?

Thanks for any help,

Andreas–
What do you have if you have 6 mathematicians buried up to
their necks in pig shit? - Not enough pig shit.

I’ve just upgraded from 1.1.3 to 1.1.6, and my app shows a
significant slowdown when it comes to alpha blits.
I’ve already noticed that I can call SDL_DisplayFormatAlpha,
which however doesn’t help the situation very much. (neither
does SDL_RLEACCEL, btw)

Exactly what are you doing? Posting a minimal (but complete)
example program that shows the slowdown would help. Also please tell
us what platform you are using

hi

is it possible to blit surfaces with SDL that contain different alpha
values? e.g. to have a sprite that has alpha values of 0 for regions
that should not be visible. i know this could be done with openGL but i
can’t count on hardware acceleration for my program.
if alpha blitting is possible, how must the pixel format be specified?

thx
eik

hi

is it possible to blit surfaces with SDL that contain different alpha
values? e.g. to have a sprite that has alpha values of 0 for regions
that should not be visible.

Yes. But do you really need alpha? You could use colorkeying instead,
at least on slow machines, as that’s much faster.

Or just take the route I did in Kobo Deluxe; my SDL port of XKobo:

http://olofson.net/skobo

I convert everything into 32 bit RGBA, run it through scaling filters
and stuff, and eventually run a “contrast/brightness” filter and then a
"max/min threshold" filter on the alpha channels. This enables me to
tweak the blending effects (such as that of the game window frame), and
remove any “alpha noise” that could cause the alpha blitter to be used
more than necessary. It would also be possible to set the filters up to
practically eliminate alpha blending, but I’m currently not doing this,
as it made little difference when I tried it. (Maybe it matters more on
machines with very slow multiplications… Haven’t tested that
thoroughly.)

i know this could be done with openGL but i
can’t count on hardware acceleration for my program.

Ok - but keep in mind that it’s pretty slow, compared to opaque and
colorkey blits. Also keep in mind that fully opaque and fully transparent
areas are optimized by the RLE blitter of SDL, so those areas don’t cost
more than opaque blits, or just skipping, even if there are alpha blended
areas on the surface.

Further, 50% alpha is a special case that faster than other alpha levels

  • you could try using that as much as possible if you’re low on CPU
    power, but still need alpha blending.

if alpha blitting is possible, how must the pixel format be specified?

RGBA, basically. Just pass the surfaces through SDL_SetAlpha() or
SDL_SetColorKey() with the SDL_RLEACCEL flag set, and then
SDL_DisplayFormatAlpha() or SDL_DisplayFormat() respectively, and you
should get what you want.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Monday 04 February 2002 23:14, Eike Umlauf wrote:

Eike Umlauf wrote:

is it possible to blit surfaces with SDL that contain different alpha
values? e.g. to have a sprite that has alpha values of 0 for regions
that should not be visible.

yes

if alpha blitting is possible, how must the pixel format be specified?

with an alpha channel. For sprites it’s recommended to use RLE to speed
things up, and it will convert pixels to a suitable format automatically.
Thus you can load the sprites in any RGB+A format