The Great Alpha Flip!

The latest CVS snapshot has the initial code for “The Great Alpha Flip”:
http://www.libsdl.org/cvs.html

Many thanks go to Mattias Engdeg?rd for essentially doing this single-handedly.

The currently released version of SDL_image will not work with the latest
CVS code, and an updated version will be available very shortly.

Please let us know if anything is broken, but be sure to read Mattias’
earlier message about converting over to the new code.

Here’s a full list of the API and semantic changes, including the new
gamma control API:

The Big Alpha Flip: SDL now treats alpha as opacity like everybody
else, and not as transparency:

A new cpp symbol: SDL_ALPHA_OPAQUE is defined as 255
A new cpp symbol: SDL_ALPHA_TRANSPARENT is defined as 0
Values between 0 and 255 vary from fully transparent to fully opaque.

New functions:
SDL_DisplayFormatAlpha()
    Returns a surface converted to a format with alpha-channel
    that can be blit efficiently to the screen. (In other words,
    like SDL_DisplayFormat() but the resulting surface has
    an alpha channel.)  This is useful for surfaces with alpha.
SDL_MapRGBA()
    Works as SDL_MapRGB() but takes an additional alpha parameter.
SDL_GetRGBA()
    Works as SDL_GetRGB() but also returns the alpha value
    (SDL_ALPHA_OPAQUE for formats without an alpha channel)


Both SDL_GetRGB() and SDL_GetRGBA() now always return values in
the [0..255] interval. Previously, SDL_GetRGB() would return
(0xf8, 0xfc, 0xf8) for a completely white pixel in RGB565 format.
(N.B.: This is broken for bit fields < 3 bits.)

SDL_MapRGB() returns pixels in which the alpha channel is set opaque.

SDL_SetAlpha() can now be used for both setting the per-surface
alpha, using the new way of thinking of alpha, and also to enable
and disable per-pixel alpha blending for surfaces with an alpha
channel:
        To disable alpha blending:
                SDL_SetAlpha(surface, 0, 0);
        To re-enable alpha blending:
                SDL_SetAlpha(surface, SDL_SRCALPHA, 0);
Surfaces with an alpha channel have blending enabled by default.

SDL_SetAlpha() now accepts SDL_RLEACCEL as a flag, which requests
RLE acceleration of blits, just as like with SDL_SetColorKey().
This flag can be set for both surfaces with an alpha channel
and surfaces with an alpha value set by SDL_SetAlpha().
As always, RLE surfaces must be locked before pixel access is
allowed, and unlocked before any other SDL operations are done
on it.

The blit semantics for surfaces with and without alpha and colorkey
have now been defined:

RGBA->RGB:
    SDL_SRCALPHA set:
        alpha-blend (using alpha-channel).
        SDL_SRCCOLORKEY ignored.
    SDL_SRCALPHA not set:
        copy RGB.
        if SDL_SRCCOLORKEY set, only copy the pixels matching the
        RGB values of the source colour key, ignoring alpha in the
        comparison.

RGB->RGBA:
    SDL_SRCALPHA set:
        alpha-blend (using the source per-surface alpha value);
        set destination alpha to opaque.
    SDL_SRCALPHA not set:
        copy RGB, set destination alpha to opaque.
    both:
        if SDL_SRCCOLORKEY set, only copy the pixels matching the
        source colour key.

RGBA->RGBA:
    SDL_SRCALPHA set:
        alpha-blend (using the source alpha channel) the RGB values;
        leave destination alpha untouched. [Note: is this correct?]
        SDL_SRCCOLORKEY ignored.
    SDL_SRCALPHA not set:
        copy all of RGBA to the destination.
        if SDL_SRCCOLORKEY set, only copy the pixels matching the
        RGB values of the source colour key, ignoring alpha in the
        comparison.

RGB->RGB:
    SDL_SRCALPHA set:
        alpha-blend (using the source per-surface alpha value).
    SDL_SRCALPHA not set:
        copy RGB.
    both:
        if SDL_SRCCOLORKEY set, only copy the pixels matching the
        source colour key.
As a special case, blits from surfaces with per-surface alpha
value of 128 (50% transparency) are optimised and much faster
than other alpha values. This does not apply to surfaces with
alpha channels (per-pixel alpha).

New functions for manipulating the gamma of the display have
been added:
        int SDL_SetGamma(float red, float green, float blue);
        int SDL_SetGammaRamp(Uint8 *red, Uint8 *green, Uint8 *blue);
        int SDL_GetGammaRamp(Uint8 *red, Uint8 *green, Uint8 *blue);
Gamma ramps are tables with 256 entries which map the screen color
components into actually displayed colors.  For an example of
implementing gamma correction and gamma fades, see test/testgamma.c
Gamma control is not supported on all hardware.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software