Alpha + colorkey

Hello,

I have a PNG image (with per pixel alpha) and I want to blit it on a

surface with colorkey (at first, without alpha). The image has all over the
edge some transparent pixels so it displays at its own as a "rounded"
surface. The problem comes when I try to blit it over a surface with
colorkey set. This surface should be fully transparent (it’s a surface made
of a single color, and that color is the colorkey), but when I make the blit
from the image to the transparent surface, all over the “new image”, where
the pixels where transparent at first, now I see the colorkey of the
transparent surface!

I've looked up for alpha and color issues, but I don't manage to

understand it completely :((

Could you help me please?

I've tried disabling the alpha of the image (SDL_SetAlpha( image, 0, 0

)) but then I completely loose the alpa information of the image after
blitting.++++++++++++++++++++++++++++++++

ALBERT FERNANDEZ MARSAL

CIRSA INTERACTIVE CORP. SL

Analista senior y programador

mail: @Albert_Fernandez_Mar

++++++++++++++++++++++++++++++++

Albert Fern?ndez Marsal wrote:

The problem comes when I try to blit it over a surface with
colorkey set. This surface should be fully transparent (it’s
a surface made of a single color, and that color is the colorkey),
but when I make the blit from the image to the transparent
surface, all over the “new image”, where the pixels where
transparent at first, now I see the colorkey of the transparent
surface!

See if the target surface has the SDL_SRCCOLORKEY (0x00001000) flag set in
the SDL_Surface.flags member after you do the blit. If it does not, try
setting the colorkey again on that surface.

-Alex.

Albert Fern?ndez Marsal wrote:

I have a PNG image (with per pixel alpha) and I want to blit it on a
surface with colorkey (at first, without alpha). The image has all
over the edge some transparent pixels so it displays at its own as a
"rounded" surface. The problem comes when I try to blit it over a
surface with colorkey set. This surface should be fully transparent
(it’s a surface made of a single color, and that color is the
colorkey), but when I make the blit from the image to the transparent
surface, all over the “new image”, where the pixels where transparent
at first, now I see the colorkey of the transparent surface!

this is to be expected. the alpha pixels alter the “first colorkey
colored” pixels of the destination surface slightly, so they do not
match the colorkey anymore. you can check this by reading the pixel
values after the blit using get_pixel() (from the SDL docs).

there is nothing you can do about this. but why do you want to blit an
alpha channeled surface to a surface filled with the colorkey in the
first place?

clemens

the idea is that the “colorkeyed” surface acts as a container for
the image and other elements. I need to put a lot of images with per-pixel
alpha channel onto a “transparent” surface, and store that composed surface
for further uses. Is there not a way to overwrite the pixel data of the
destination surface with both the pixel data and the alpha channel of the
source surface (but taking into account the colorkey of the destination)? I
guess that would be the solution for what I want to do…

Thank you-----Mensaje original-----

De: sdl-bounces+afmarsal=cirsa.com at libsdl.org
[mailto:sdl-bounces+afmarsal=cirsa.com at libsdl.org] En nombre de Clemens
Kirchgatterer
Enviado el: viernes, 14 de octubre de 2005 7:51
Para: A list for developers using the SDL library. (includes SDL-announce)
Asunto: Re: [SDL] Alpha + colorkey

Albert Fern?ndez Marsal <@Albert_Fernandez_Mar> wrote:

I have a PNG image (with per pixel alpha) and I want to blit it on a
surface with colorkey (at first, without alpha). The image has all
over the edge some transparent pixels so it displays at its own as a
"rounded" surface. The problem comes when I try to blit it over a
surface with colorkey set. This surface should be fully transparent
(it’s a surface made of a single color, and that color is the
colorkey), but when I make the blit from the image to the transparent
surface, all over the “new image”, where the pixels where transparent
at first, now I see the colorkey of the transparent surface!

this is to be expected. the alpha pixels alter the “first colorkey
colored” pixels of the destination surface slightly, so they do not
match the colorkey anymore. you can check this by reading the pixel
values after the blit using get_pixel() (from the SDL docs).

there is nothing you can do about this. but why do you want to blit an
alpha channeled surface to a surface filled with the colorkey in the
first place?

clemens


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

I will answer myself:

per pixel alpha must be used on both surfaces, so the "transparent"

surface must be created with an RBGA, i.e, the amask must be non-zero.

Then the alpha must be disabled in the loaded image:

SDL_SetAlpha( image, 0, 0 )

And then, just blit. As the docs explain, it makes the RGBA info copied to
the destination surface because it matches the case RGBA->RGBA without
SRCALPHA.

Thanks for the help!________________________________

De: sdl-bounces+afmarsal=cirsa.com at libsdl.org
[mailto:sdl-bounces+afmarsal=cirsa.com at libsdl.org] En nombre de Albert
Fern?ndez Marsal
Enviado el: jueves, 13 de octubre de 2005 18:46
Para: 'A list for developers using the SDL library. (includes SDL-announce)'
Asunto: [SDL] Alpha + colorkey

Hello,

I have a PNG image (with per pixel alpha) and I want to blit it on a

surface with colorkey (at first, without alpha). The image has all over the
edge some transparent pixels so it displays at its own as a "rounded"
surface. The problem comes when I try to blit it over a surface with
colorkey set. This surface should be fully transparent (it’s a surface made
of a single color, and that color is the colorkey), but when I make the blit
from the image to the transparent surface, all over the “new image”, where
the pixels where transparent at first, now I see the colorkey of the
transparent surface!

I've looked up for alpha and color issues, but I don't manage to

understand it completely :((

Could you help me please?

I've tried disabling the alpha of the image (SDL_SetAlpha( image, 0, 0

)) but then I completely loose the alpa information of the image after
blitting.

++++++++++++++++++++++++++++++++

ALBERT FERNANDEZ MARSAL

CIRSA INTERACTIVE CORP. SL

Analista senior y programador

mail: @Albert_Fernandez_Mar

++++++++++++++++++++++++++++++++

Albert Fern?ndez Marsal wrote:

the idea is that the “colorkeyed” surface acts as a container for
the image and other elements. I need to put a lot of images with
per-pixel alpha channel onto a “transparent” surface, and store that
composed surface for further uses. Is there not a way to overwrite the
pixel data of the destination surface with both the pixel data and the
alpha channel of the source surface (but taking into account the
colorkey of the destination)? I guess that would be the solution for
what I want to do…

SDL as it is, is rather limited for this kind of surface composition. It
is not possible to do the things you describe here with SDL alone. you
have to provide your own custom blitter to do this, that is able to
combine the alpha channels of both, the source and the destination
surface. even then it’s rather difficult to allways get it right.
there are just so many possibilities to combine the alphas.

clemens

Albert Fern?ndez Marsal wrote:

per pixel alpha must be used on both surfaces, so the "transparent"
surface must be created with an RBGA, i.e, the amask must be non-zero.

Then the alpha must be disabled in the loaded image:

SDL_SetAlpha( image, 0, 0 )

And then, just blit. As the docs explain, it makes the RGBA info
copied to the destination surface because it matches the case
RGBA->RGBA without SRCALPHA.

true, but what if you blit a surface over a region you have already
copied another surface into? you will completely loose the alpha
information there. this is why i suggested an “alpha combining” blitter
in my other mail. as long as you touch every pixel in the destination
surface only once, you are fine without, though.

clemens

you’re right… It works as long as I don’t try to blit more than 1
surface overlapping any of the others… Well, I’ll keep trying and I will
notify if I find any workaround for that.

Thanks for the reply-----Mensaje original-----

De: sdl-bounces+afmarsal=cirsa.com at libsdl.org
[mailto:sdl-bounces+afmarsal=cirsa.com at libsdl.org] En nombre de Clemens
Kirchgatterer
Enviado el: viernes, 14 de octubre de 2005 14:42
Para: A list for developers using the SDL library. (includes SDL-announce)
Asunto: Re: [SDL] Alpha + colorkey

Albert Fern?ndez Marsal <@Albert_Fernandez_Mar> wrote:

per pixel alpha must be used on both surfaces, so the "transparent"
surface must be created with an RBGA, i.e, the amask must be non-zero.

Then the alpha must be disabled in the loaded image:

SDL_SetAlpha( image, 0, 0 )

And then, just blit. As the docs explain, it makes the RGBA info
copied to the destination surface because it matches the case
RGBA->RGBA without SRCALPHA.

true, but what if you blit a surface over a region you have already
copied another surface into? you will completely loose the alpha
information there. this is why i suggested an “alpha combining” blitter
in my other mail. as long as you touch every pixel in the destination
surface only once, you are fine without, though.

clemens


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