6.5.3.3.5 Alpha Blending
The general alpha blending equations are:
- Cd = Fs * Cs’ + Fd * Cd’
- Ad = Fs * As’’ + Fd * Ad’’
Where
- Cs’ is the source color component (adjusted for NPM if necessary)
- Cd’ is the destination color component (adjusted for NPM if necessary)
- As’’ is the modified source alpha component
- Ad’’ is the modified destination alpha component
- Fs is fraction of the source that contributes to the final value
- Fd is fraction of the destination that contributes to the final value
The blending is done in four logical stages (not real implementation stages):
- Transparent/opaque conversion
The incoming alpha (source or destination independently) can be inverted if needed to match the internal alpha rule. Internally, an alpha of 0 means transparent, while an alpha of “0xFF” means opaque. External content might follow the opposite rule. The output of the block is either As (Ad for destination) or 1-As (1-Ad for destination).
- Global value substitution
A global alpha value from a register can be used to substitute or scaled the incoming alpha. An incoming alpha As can pass-through, be directly substituted by Ags (global alpha) or scaled by the global alpha value (As * Ags). The source and destination have distinct global alpha values.
- Blending factor generation
The blending factors are generated (refer to table below). Each alpha can take the values 0, 1, A or 1-A depending on the blending mode.
- Final blending
This final stage implements the operations described by equations (1) and (2),
The different stages are illustrated in the following figure.
The fractions take the values described in the following table, depending on the blending mode.
Blending Mode | Fs | Fd |
---|---|---|
Clear | 0 | 0 |
SRC | 1 | 0 |
DST | 0 | 1 |
SRC_OVER | 1 | 1 – As’’ |
DST_OVER | 1 – Ad’’ | 1 |
SRC_IN | Ad’’ | 0 |
DST_IN | 0 | As’’ |
SRC_OUT | 1 – Ad’’ | 0 |
DST_OUT | 0 | 1 – As’’ |
SRC_ATOP | Ad’’ | 1 – As’’ |
DST_ATOP | 1 – Ad’’ | As’’ |
XOR | 1 – Ad’’ | 1 – As’’ |
The register fields that control the blending modes are:
- 1 bit for transparent/opaque conversion for source alpha
- 1 bit for transparent/opaque conversion for destination alpha
- 2 bits for source alpha modifications, to specify the 3 cases (As, Ags, As*Ags)
- 2 bits for destination alpha modifications, to specify the 3 cases (Ad, Agd, Ad*Agd)
- 4 bits to select between the 12 blending modes
- 8 bits for global source alpha
- 8 bits for global destination alpha
Alpha blending is supported on bit blit and filter blit primitives.