Alpha surface creation

Hello.

I want to create a per-pixel alpha SDL_Surface,
with if possible hardware acceleration.

1)Here is the way I found without possible hardware acceleration:
picture=SDL_CreateRGBSurface(SDL_SRCALPHA, pictureRect.w,
pictureRect.h,format->BitsPerPixel,
0xFF,0xFF00,0xFF0000,0xFF000000);

2)Here is the way with a temporary surface:
temp_picture=SDL_CreateRGBSurface(SDL_SRCALPHA, pictureRect.w,
pictureRect.h,format->BitsPerPixel,
format->Rmask,format->Gmask,format->Bmask,format->Amask);
picture=SDL_DisplayFormatAlpha(temp_picture);

Is there a way to create directly a surface, without a temporary surface,
and with possible acceleration ?
That’s would be cleaner.

Thanks.

Luc Olivier & Stephane

1)Here is the way I found without possible hardware acceleration:
picture=SDL_CreateRGBSurface(SDL_SRCALPHA, pictureRect.w,
pictureRect.h,format->BitsPerPixel,
0xFF,0xFF00,0xFF0000,0xFF000000);

SDL_SRCALPHA is set automatically when you give a nonzero Amask

2)Here is the way with a temporary surface:
temp_picture=SDL_CreateRGBSurface(SDL_SRCALPHA, pictureRect.w,
pictureRect.h,format->BitsPerPixel,
format->Rmask,format->Gmask,format->Bmask,format->Amask);
picture=SDL_DisplayFormatAlpha(temp_picture);

specify SDL_HWSURFACE to take advantage of acceleration. I don’t think any
SDL display target currently accelerates alpha blits however, so you are
better off doing it between software surfaces to avoid the latency hit
from using video ram.

What SDL_DisplayFormatAlpha() really does is the following:

If the screen pixel format is 32-bit, then the created surface will have
the alpha channel in the unused 8 bits. Otherwise (any other depth), it
will just pick the 8888ARGB format. There is special code for blitting
that format efficiently to 565RGB and 555RGB.

You could do the same thing, or just use SDL_DisplayFormatAlpha() on a
test surface and see what format it prefers.

If you want better performance, consider using RLE encoding for your alpha
surfaces. Then it doesn’t matter what format you use (as long as it’s
sane), since the RLE translation will use the most efficient pixel format
automatically