Alpha blending transparent PNGs

Hello everybody!First, I’m sorry if this question was asked already, I’ve searched, but looks like nobody encountered this problem.In my program, I’m using SDL_DisplayFormatAlpha to convert the loaded image, because I’m using transparent PNGs. I also want to fade in/out these images, but I can’t find a way to do that. SDL_SetAlpha works only if I convert the image with SDL_DisplayFormat, so ignoring the PNG’s built-in alpha information, but it doesn’t seems to work at all if I try to set the alpha value of an image which has built-in transparency. Is there a way to do that? I think it can be done somehow with SDL_GetRGBA/SDL_MapRGBA, but I have no idea.Best Regards,

--------------------------Hirdet?s-----------------------------

Egy milli? forintos aj?nlat?tlagosan ennyit vesz?t?nk 10 ?v alatt rossz befektet?seinken. Hogyan ker?lheti el ?n?
http://www.portfoliomoney.hu/befektetes.html

Cracker wrote:

Hello everybody!First, I’m sorry if this question was asked already,
I’ve searched, but looks like nobody encountered this problem.In my
program, I’m using SDL_DisplayFormatAlpha to convert the loaded image,
because I’m using transparent PNGs. I also want to fade in/out these
images, but I can’t find a way to do that. SDL_SetAlpha works only if
I convert the image with SDL_DisplayFormat, so ignoring the PNG’s built-in
alpha information, but it doesn’t seems to work at all if I try to set the
alpha value of an image which has built-in transparency. Is there a way to
do that? I think it can be done somehow with SDL_GetRGBA/SDL_MapRGBA, but
I have no idea.Best Regards,

Using the PNG alpha = per pixel alpha. Fading a surface = per surface alpha. You
can’t mix the two in SDL 1.2 (I don’t know if it’s possible in SDL 1.3).

Hey,

If you didn’t read the other response: The SDL docs say no mixing per-pixel and per-surface alpha.

But if you’d like to do this, you’ll just have to do it yourself. That means sacrificing a lot of speed, but in many cases it’s still worth it. I always pop up when this topic is raised, so I’ll direct you to download U32_SDL at http://pubpages.unh.edu/~jmb97. In that library, you’ll find U32_Blit(), which by default calls U32_BlitClip() and then U32_BlendBlit(). I can’t be sure that it works perfectly, but it should do the job… You may need to adjust the color-packing bit-shift part if you have problems with it.

Good luck,
Jonny D

Hello everybody!First, I’m sorry if this question was asked already, I’ve searched, but looks like nobody encountered this problem.In my program, I’m using SDL_DisplayFormatAlpha to convert the loaded image, because I’m using transparent PNGs. I also want to fade in/out these images, but I can’t find a way to do that. SDL_SetAlpha works only if I convert the image with SDL_DisplayFormat, so ignoring the PNG’s built-in alpha information, but it doesn’t seems to work at all if I try to set the alpha value of an image which has built-in transparency. Is there a way to do that? I think it can be done somehow with SDL_GetRGBA/SDL_MapRGBA, but I have no idea.Best Regards,
--------------------------Hirdet?s-----------------------------Egy milli? forintos aj?nlat?tlagosan ennyit vesz?t?nk 10 ?v alatt rossz befektet?seinken. Hogyan ker?lheti el ?n?http://www.portfoliomoney.hu/befektetes.htmlTo: sdl at lists.libsdl.orgFrom: tcracker at vipmail.huDate: Sat, 20 Oct 2007 01:40:39 -0600Subject: [SDL] Alpha blending transparent PNGs


Peek-a-boo FREE Tricks & Treats for You!
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us

Ilya Olevsky wrote:"Using the PNG alpha = per pixel alpha. Fading a surface = per surface alpha. Youcan’t mix the two in SDL 1.2 (I don’t know if it’s possible in SDL 1.3)."Jonathan Dearborn wrote:"If you didn’t read the other response: The SDL docs say no mixing per-pixel and per-surface alpha. But if you’d like to do this, you’ll just have to do it yourself. That means sacrificing a lot of speed, but in many cases it’s still worth it. I always pop up when this topic is raised, so I’ll direct you to download U32_SDL at http://pubpages.unh.edu/~jmb97. In that library, you’ll find U32_Blit(), which by default calls U32_BlitClip() and then U32_BlendBlit(). I can’t be sure that it works perfectly, but it should do the job… You may need to adjust the color-packing bit-shift part if you have problems with it."Hello again!Thanks for your answers. Speed is important in my program, so nothing left but to write my own image loading/displaying system and use SDL for input/timer handling only, or to not use transparent PNGs.But is it possible to blend a PNG which has no transparency, but instead of a background color, it has completely transparent alpha?Thanks again for your help.By the way: is this feature will be added to SDL 1.3?

--------------------------Hirdet?s-----------------------------

Egy milli? forintos aj?nlat?tlagosan ennyit vesz?t?nk 10 ?v alatt rossz befektet?seinken. Hogyan ker?lheti el ?n?
http://www.portfoliomoney.hu/befektetes.html

(What’s the matter with your mail client…? The text version comes
out as a single line of text.)

[…]

        Hello again!Thanks for your answers. Speed is important

in my program, so nothing left but to write my own image
loading/displaying system and use SDL for input/timer handling only,
or to not use transparent PNGs.

Well, you should still be able to use SDL for pretty much everything
but the actual “alpha*alpha” blending, at least for software
rendering.

Alternatively, glSDL (as of 0.8) will do what you need, using an
extended blending API, and also has rotation and scaling - but as of
now, these features are only available when actually rendering over
OpenGL.
http://olofson.net/mixed.html

But is it possible to blend a PNG which has no transparency, but
instead of a background color, it has completely transparent
alpha?

Yes, you can use colorkeying together with full surface alpha.

Thanks again for your help.By the way: is this feature will be added
to SDL 1.3?

Not sure what the plan is there. 1.3 uses Direct3D or OpenGL where
available, and there it’s trivial to implement. “Alpha*alpha” in
software means more work and slower blitting, though.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Saturday 20 October 2007, Cracker wrote:

Hey,

I would agree with David here. Try out glSDL. I want to point out, though, that there is no sacrifice in ‘game’ speed if you’re able to pre-render the surfaces that you’re using. If you can do what you’re trying to do with sprites that themselves are accurate and don’t change, you can blit them normally onto the screen and retain normal speed.

Jonny D> From: david at olofson.net> To: sdl at lists.libsdl.org> Date: Sat, 20 Oct 2007 15:02:08 +0200> Subject: Re: [SDL] Alpha blending transparent PNGs> > On Saturday 20 October 2007, Cracker wrote:> […]> > Hello again!Thanks for your answers. Speed is important> > in my program, so nothing left but to write my own image> > loading/displaying system and use SDL for input/timer handling only,> > or to not use transparent PNGs.> > Well, you should still be able to use SDL for pretty much everything > but the actual “alphaalpha" blending, at least for software > rendering.> > Alternatively, glSDL (as of 0.8) will do what you need, using an > extended blending API, and also has rotation and scaling - but as of > now, these features are only available when actually rendering over > OpenGL.> http://olofson.net/mixed.html> > > > But is it possible to blend a PNG which has no transparency, but> > instead of a background color, it has completely transparent> > alpha?> > Yes, you can use colorkeying together with full surface alpha.> > > > Thanks again for your help.By the way: is this feature will be added> > to SDL 1.3?> > Not sure what the plan is there. 1.3 uses Direct3D or OpenGL where > available, and there it’s trivial to implement. "Alphaalpha” in > software means more work and slower blitting, though.> > > //David Olofson - Programmer, Composer, Open Source Advocate>


Peek-a-boo FREE Tricks & Treats for You!
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us

David Olofson wrote:"(What’s the matter with your mail client…? The text version comes out as a single line of text.)"Well, I’m sorry about that, I’m using a really stupid web-based mailing system…"Yes, you can use colorkeying together with full surface alpha."And is it possible without colorkey-ing? I don’t want to set a colorkey color, I just want to use the alpha as the background.Best regards,

--------------------------Hirdet?s-----------------------------

Egy milli? forintos aj?nlat?tlagosan ennyit vesz?t?nk 10 ?v alatt rossz befektet?seinken. Hogyan ker?lheti el ?n?
http://www.portfoliomoney.hu/befektetes.html

[…]

David Olofson wrote:
[…]
"Yes, you can use colorkeying together with full surface alpha."
And is it possible without colorkey-ing? I don’t want to set a
colorkey color, I just want to use the alpha as the background.

Not directly, AFAIK. You’d have to decide on a key color in the code
and then scan the surface, writing that color to pixels that are
supposed to be transparent, so you can use SDL colorkeying.

BTW, an easy way of doing this kind of (pre-)processing is to
SDL_ConvertSurface() surfaces into a specific 32 bit RGBA format, do
your processing, and then SDL_DisplayFormat() or
SDL_DisplayFormatAlpha() when done. This way, you don’t have to worry
about pixel formats, so you only need one implementation of each
processing filter. SDL conversions are pretty fast, so the extra
conversions are no big deal, at least not for load/init time
processing.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Saturday 20 October 2007, Cracker wrote:

It looks like his emails come as HTML (which looks formatted sensibly)
and plain text. For whatever reason, the latter is totally unformatted
and nearly impossible to read (like you said, one line). Perhaps time to
tweak or change mail clients?

-bill!On Sat, Oct 20, 2007 at 03:02:08PM +0200, David Olofson wrote:

(What’s the matter with your mail client…? The text version comes
out as a single line of text.)