aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README3
-rw-r--r--algorithms/dual-alpha_blending47
2 files changed, 49 insertions, 1 deletions
diff --git a/README b/README
index 8ab597f..bfa17bf 100644
--- a/README
+++ b/README
@@ -18,7 +18,8 @@ Currently implemented:
Drawing coloured text with 3 primaries, alpha and opacity,
(100% opacity but 0% alpha will cut out the text so it is
- transparent instead of opaque where the text is.)
+ transparent, rather than at least as opaque as the background,
+ where the text is.)
Drawing on RGB, XRGB, ARGB, and RGBA with 8-bit, 16-bit,
32-bit, and 64-bit subpixels, RGB, ARGB, and RGBA with
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).