Updated blend semantics so blending uses the following formula:

dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
    dstA = srcA + (dstA * (1-srcA))
This allows proper compositing semantics without requiring premultiplied alpha.

Needs full unit test coverage and bug fixes!
This commit is contained in:
Sam Lantinga 2013-07-23 08:06:49 -07:00
parent a99edf3519
commit 32188834b5
17 changed files with 362 additions and 1001 deletions

View file

@ -39,10 +39,17 @@ extern "C" {
*/
typedef enum
{
SDL_BLENDMODE_NONE = 0x00000000, /**< No blending */
SDL_BLENDMODE_BLEND = 0x00000001, /**< dst = (src * A) + (dst * (1-A)) */
SDL_BLENDMODE_ADD = 0x00000002, /**< dst = (src * A) + dst */
SDL_BLENDMODE_MOD = 0x00000004 /**< dst = src * dst */
SDL_BLENDMODE_NONE = 0x00000000, /**< no blending
dstRGBA = srcRGBA */
SDL_BLENDMODE_BLEND = 0x00000001, /**< alpha blending
dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
dstA = srcA + (dstA * (1-srcA)) */
SDL_BLENDMODE_ADD = 0x00000002, /**< additive blending
dstRGB = (srcRGB * srcA) + dstRGB
dstA = dstA */
SDL_BLENDMODE_MOD = 0x00000004 /**< color modulate
dstRGB = srcRGB * dstRGB
dstA = dstA */
} SDL_BlendMode;
/* Ends C function definitions when using C++ */

View file

@ -399,44 +399,42 @@ extern DECLSPEC int SDLCALL SDL_FillRects
*
* The blit function should not be called on a locked surface.
*
* The blit semantics for surfaces with and without alpha and colorkey
* The blit semantics for surfaces with and without blending and colorkey
* are defined as follows:
* \verbatim
RGBA->RGB:
SDL_SRCALPHA set:
alpha-blend (using alpha-channel).
Source surface blend mode set to SDL_BLENDMODE_BLEND:
alpha-blend (using the source alpha-channel and per-surface alpha)
SDL_SRCCOLORKEY ignored.
SDL_SRCALPHA not set:
Source surface blend mode set to SDL_BLENDMODE_NONE:
copy RGB.
if SDL_SRCCOLORKEY set, only copy the pixels matching the
RGB values of the source color 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:
Source surface blend mode set to SDL_BLENDMODE_BLEND:
alpha-blend (using the source per-surface alpha)
Source surface blend mode set to SDL_BLENDMODE_NONE:
copy RGB, set destination alpha to source per-surface alpha value.
both:
if SDL_SRCCOLORKEY set, only copy the pixels matching the
source color key.
RGBA->RGBA:
SDL_SRCALPHA set:
alpha-blend (using the source alpha channel) the RGB values;
leave destination alpha untouched. [Note: is this correct?]
Source surface blend mode set to SDL_BLENDMODE_BLEND:
alpha-blend (using the source alpha-channel and per-surface alpha)
SDL_SRCCOLORKEY ignored.
SDL_SRCALPHA not set:
Source surface blend mode set to SDL_BLENDMODE_NONE:
copy all of RGBA to the destination.
if SDL_SRCCOLORKEY set, only copy the pixels matching the
RGB values of the source color key, ignoring alpha in the
comparison.
comparison.
RGB->RGB:
SDL_SRCALPHA set:
alpha-blend (using the source per-surface alpha value).
SDL_SRCALPHA not set:
Source surface blend mode set to SDL_BLENDMODE_BLEND:
alpha-blend (using the source per-surface alpha)
Source surface blend mode set to SDL_BLENDMODE_NONE:
copy RGB.
both:
if SDL_SRCCOLORKEY set, only copy the pixels matching the