diff options
author | Mattias Andrée <maandree@kth.se> | 2020-04-28 20:46:56 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2020-04-28 20:46:56 +0200 |
commit | 18a1da68841e1f22cf1a942c3e7f7deb160f7ed0 (patch) | |
tree | 9d6c5f63be4774b6c2077ec8fc096d40719f9aa9 /algorithms/dual-alpha_blending | |
parent | Fix blending function error for non-premultiplied surfaces (diff) | |
download | libskrift-18a1da68841e1f22cf1a942c3e7f7deb160f7ed0.tar.gz libskrift-18a1da68841e1f22cf1a942c3e7f7deb160f7ed0.tar.bz2 libskrift-18a1da68841e1f22cf1a942c3e7f7deb160f7ed0.tar.xz |
Document alpha blending algorithm
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | algorithms/dual-alpha_blending | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/algorithms/dual-alpha_blending b/algorithms/dual-alpha_blending new file mode 100644 index 0000000..ef16f3e --- /dev/null +++ b/algorithms/dual-alpha_blending @@ -0,0 +1,47 @@ +Some variable names: + + C_out = some colour channel in the output + C_bg = some colour channel in the background + C_fg = some colour channel in the foreground + + A_out = the alpha channel in the output + A_bg = the alpha channel in the background + A_fg = the alpha channel in the foreground + + +The normal alpha blending algorithm is used render +a translucent object over another translucent object. +The alpha blending algorithm is: + + C_out⋅A_out = C_bg⋅A_bg⋅(1 − A_fg) + C_fg⋅A_fg + + A_out = A_bg⋅(1 − A_fg) + A_fg + + +libskrift expands this algorithm to allow the alpha +channel of the foreground object to be applied unto +the background, replacing the alpha channel, +effectively cutting out part of the background and +the adding the foreground, and it can do this partially, +so that even if the background is opaque, the result +can be translucent where the text is. This requires +a new parameter for the foreground object (but not +the background object): opacity (we will call this +variable O). The new alpha blending algorithm +(“dual-alpha blending”) is: + + C_out⋅A_out = C_bg⋅A_bg⋅O⋅(1 − A_fg⋅O) + C_fg⋅A_fg⋅O + + A_out = A_bg⋅O⋅(1 − A_fg⋅O) + A_fg⋅O + +This algorithm works as the normal alpha blending +algorithm if the opacity is used instead of alpha, +and alpha is set to 1, on the foregrund. + + +However, since libskrift is a text drawing library, +which subpixel rendering support, the opacity is +multiply with the subpixel's value in the glyph, and +they highest subpixel's value for the alpha channel +(since it only support surfaces with per-pixel alpha +and not per-subpixel alpha). |