Hi,
I’m working on a demo for a program that will emulate
cel-animation layers, so it needs to stack a series
of partially transparent surfaces up and display them.
The obvious (I thought) way to do this is by making
all the surfaces alpha surfaces. Using SDL_Image, I
loaded PNG file resources to do this.
However, I have found that the PNG resources are not
all consistent (probably my use of ImageMagick) in that
some use the Alpha channel and some use Color Key to
do transparency. Alpha channel appears to work better
with the SGE rotations I’m using, so I’d like them
to all be in an Alpha channel format.
What I really want is to simply use the colorkey
information to reconstruct the missing alpha channel.
It’s probably possible to fix this by fixing the
resources themselves, but it’d be more robust if my
program could handle either type. But doing this
is not so transparent, if you’ll pardon the pun.
In principle, one ought to be able to do it by simply
setting the alpha value of every pixel to either
fully transparent or fully opaque based on whether
the RGB values match the color key. This seems
fairly tricky, though, especially since both
RGB and RGBA are represented as Uint32. I assume the
color key is probably just RGB?
I can imagine breaking each pixel into RGBA values and
comparing channel-by-channel, then reconstructing the
pixel and re-inserting it in the image. But that sounds
terminally slow. If I understood the internals of
the format, I’d do it with bitwise math of some kind,
but of course, I want the code to stay portable.
I’ve tried using the SDL_DisplayFormat() and
SDL_DisplayFormatAlpha() functions, but they seem to
be doing weird additional stuff, because they mess up
the colors of the images (and the alpha channel doesn’t
seem to be as expected, either). This might have
something to do with the 16 bpp screen mode it has to
be converted to for display, but I don’t have color
problems if I eliminate this step (but no transparency
either).
I’d really appreciate some advice about how to solve
this from someone who’s been using this longer than
I have (i.e. anyone ).
Thanks!–
Terry Hancock
@Terry_Hancock