blob: e7f3019c258722785798768c2c49c0970e2288fa (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
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 to 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⋅(1 − O) + C_fg⋅A_fg⋅O
A_out = A_bg⋅(1 − 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 foreground. This
algorithm is identical to the normal alpha blending
algorithm except that the opacity replaces the
foreground's alpha, and the alpha is treated as any
other colour except that all colours are still
premultiplied with it, since it is still an opacity.
However, since libskrift is a text drawing library
with subpixel rendering support, the opacity is
multiplied with the subpixel's value in the glyph,
and the highest subpixel's value is used for the
alpha channel (since it only supports surfaces
with per-pixel alpha and not per-subpixel alpha).
|