Blitting RGBA -> RGBA with per-surface alpha

I have a 32 bit RGBA surface that I want to blit to another 32 bit
RGBA surface (the screen buffer), but I want to use the per-surface
alpha setting, not the alpha channel. Is this possible?

According to the docs, you can only blit per-surface with RGB -> RGBA.
Can you switch a RGBA to RGB for the blit and then back again without
copying data (i.e speed slowdown)?

Calling SDL_SetAlpha() doesn’t do this. Does it? According to the
docs, it does not, it is setting some other flag. The SDL_SRCALPHA
flags the the RGBA setting of a surface are not the same thing.

The issue is sometimes this surface will get blitted with alpha
channel and other times with a per-surface alpha value. I have an
image that I want to fade away, but it needs to be drawn alpha
channeled other times.

Tankko

Tankko Omaskio wrote:

I have a 32 bit RGBA surface that I want to blit to another 32 bit
RGBA surface (the screen buffer), but I want to use the per-surface
alpha setting, not the alpha channel. Is this possible?

No.–
Rainer Deyke - rainerd at eldwood.com - http://eldwood.com

So what is the preferred method of converting a surface from RGBA ->
RGB so a per-surface blit can happen (RGB->RGBA)? What is the bit in
the header that tells the surface it is RGB? Or is it just the size
of the BytesPerPixel goes to 3? The original image is coming from a
.png loading via SDL_Image, so I’ll need to convert it. Do I just
send it though ConvertSurface? I know this will work, but it is the
"best/right" solution? Or is SDL_DisplayFormat better?

It seems like a RGBA -> RGBA with per-surface alpha would be a very
useful bitter to have (slower, yes, but very useful). The other very
useful blitter would be a RGBA -> RGBA that resulted in a combined
alpha so images could be precomposited.

TankkoOn 4/21/05, Rainer Deyke wrote:

Tankko Omaskio wrote:

I have a 32 bit RGBA surface that I want to blit to another 32 bit
RGBA surface (the screen buffer), but I want to use the per-surface
alpha setting, not the alpha channel. Is this possible?

No.


Rainer Deyke - rainerd at eldwood.com - http://eldwood.com


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

Tankko Omaskio wrote:

So what is the preferred method of converting a surface from RGBA ->
RGB so a per-surface blit can happen (RGB->RGBA)? What is the bit in
the header that tells the surface it is RGB? Or is it just the size
of the BytesPerPixel goes to 3? The original image is coming from a
.png loading via SDL_Image, so I’ll need to convert it. Do I just
send it though ConvertSurface? I know this will work, but it is the
"best/right" solution? Or is SDL_DisplayFormat better?

for what i know, DisplayFormat uses ConvertSurface internally.

It seems like a RGBA -> RGBA with per-surface alpha would be a very
useful bitter to have (slower, yes, but very useful). The other very
useful blitter would be a RGBA -> RGBA that resulted in a combined
alpha so images could be precomposited.

ACK. but SDL does not provide these and there was not much demand for it
on this list since i follow it. for a combination of alpha channel and
per surface alpha value, i have written some custom code that saves a
surfaces alpha channel in a unsigned char array before i iterate through
all pixels and multiply its alpha value with PerSurfaceAlpha/255. not
fast but works.

i would prefere if, at least SDL2 would provide similar blitflags as
directfb does.

clemens