summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2013-02-25 02:24:40 -0500
committerSøren Sandmann Pedersen <ssp@redhat.com>2013-02-25 02:24:40 -0500
commit671d68dc71dd28c570f92c925c270a7a81f5863d (patch)
tree3ee8928d3680e7c7baadf045ab801e3e054a5b4e
parent905997574e05f4471a54d647ede49f30a8336fb9 (diff)
asdf
-rw-r--r--blend.txt126
1 files changed, 76 insertions, 50 deletions
diff --git a/blend.txt b/blend.txt
index fede834..3ebd402 100644
--- a/blend.txt
+++ b/blend.txt
@@ -1,9 +1,4 @@
-Outstanding issues:
-
- - Find out what's up with HSL blend modes
- - Rethink structure of the document
-
-Porter/Duff and blend modes
+The Porter/Duff compositing algebra and blend modes
Porter/Duff
@@ -11,7 +6,7 @@ In the Porter/Duff compositing algebra, images are equipped with an
alpha channel that determines on a per-pixel basis whether the image
is there or not. When the alpha channel is 1, the image is fully
there, when it is 0, the image isn't there at all. When it is in
-between, the imgae is partially there. In other words, the alpha
+between, the image is partially there. In other words, the alpha
channel describes the the shape of the image, it does not describe
opacity. The way to think of images with an alpha channel is as
irregularly shaped pieces of cardboard, not as colored glass.
@@ -71,46 +66,28 @@ are given by these formulas:
A_dst = ad * (1 - as)
A_both = as * ad
-The resulting value corresponds to the amount of light reflected by
-the covered part of the pixel, so in order to get the right color
-value, we have to divide by alpha. Since divisions are expensive and
-since source and destination inputs have to be multiplied with their
-corresponding alpha values anyway, pixels are often stored in a format
-where all the color channels have been multiplied with the alpha
-channel.
+The alpha channel of the result is computed in a similar way. There is
+full coverage in all regions that are not blank:
-With this format, the formula becomes:
-
- (1 - ad) * [s] + (1 - as) * [d] + as * ad * [b]
+ A_src * [as] + A_dest * [ad] + A_both * [ab]
-where [s] and [d] are the premultiplied source and destination colors,
-and [b] is either 0, or one of the premultiplied source or destination
-colors divided by their corresponding alpha channel (this division is
-then canceled by either the /as/ or the /ad/ in front of [b]).
-
-The alpha channel is computed with the same formula. In this case [s]
-is either 0 or as, [d] is either 0 or ad, and [b] is either 0, or
-as/as = 1, or ad/ad = 1.
-
-In other words, with premultiplied pixels, this formula:
-
- (1 - ad) * [s] + (1 - as) * [d] + as * ad * [b]
-
-works for all four channels of a premultiplied pixel.
+where [as] and [ad] are either 0 or 1 depending on whether the source
+and destination regions are present, and where [ab] is 0 when the
+'both' region is blank, and 1 otherwise.
Here is a table of all the Porter/Duff operators:
[s] [d] [b]
- Src s 0 s/as
- Atop 0 d s/as
- Over s d s/as
- In 0 0 s/as
+ Src s 0 s
+ Atop 0 d s
+ Over s d s
+ In 0 0 s
Out s 0 0
- Dest 0 d d/ad
- DestAtop s 0 d/ad
- DestOver s d d/as
- DestIn 0 0 d/ad
+ Dest 0 d d
+ DestAtop s 0 d
+ DestOver s d d
+ DestIn 0 0 d
DestOut 0 d 0
Clear 0 0 0
Xor s d 0
@@ -150,14 +127,15 @@ source and destination according to this formula:
The pixel diagram is this:
- Zoomed Color Dodge
+ Color Dodge diagram
And the result looks like this:
src ColorDodge dest
-Unlike with the regular Over operator, the source and destination
-image are actually blended in the area where both are present.
+Unlike with the regular Over operator, in this case there is
+substantial chunk of the output where the source and destination are
+actually mixed together.
Layers in Photoshop and Gimp are not tailored to each other (except
for layer masks, which we will ignore here), so the compositing of the
@@ -172,11 +150,15 @@ ColorDodge:
colordodge-dest-diagram.png
-Which looks like this:
+The result looks like this:
ColorDodge dest
-With three very simple blend modes:
+Here are all the possibilities:
+
+ dodge-neither dodge-src, dodge-dest, dodge-both,
+
+With three trival blend modes:
Source: B(s, d) = s
Dest: B(s, d) = d
@@ -190,25 +172,68 @@ formulas. Each such formula gives rise to four new compositing
operators characterized by whether the source and destination are
blank or contain the corresponding pixel color.
-The general formula is still an area weighted average with
-premultiplied pixels:
+The general formula is still an area weighted average:
- (1 - ad) * [s] + (1 - as) * [d] + as * ad * B(s / as, d / ad)
+ A_src * [s] + A_dest * [d] + as * ad * B(s, d)
where [s] and [d] are 0 or the source and destination color
-respectively, but where B(s, d) is no longer restricted to 0, s, and
-d.
+respectively, but where B(s, d) is no longer restricted to one of 0,
+s, and d but can instead be chosen from a large set of formulas.
+
+In this way, each new blend mode gives rise to four new compositing
+operators defined by whether or the source and destination regions are
+present or blank.
+
+The output of the alpha channel is the same as before:
+
+ A_src * [as] + A_dest * [ad] + as * ad * [ab]
+
+except that [ab] is now determined by the blend mode. For the Zero
+blend mode there is no coverage in the both region, so [ab] is 0; for
+most other, there is full coverage, so [ab] is 1.
Here is a table of the operators that are generated by various blend
modes:
- [ blend table.png ]
+ [ blend table.png ]
The three first rows are the original Porter/Duff operators.
+<!--
+
Alpha Channels
+
+The resulting value corresponds to the amount of light reflected by
+the covered part of the pixel, so in order to get the right color
+value, we have to divide by alpha. Since divisions are expensive and
+since source and destination inputs have to be multiplied with their
+corresponding alpha values anyway, pixels are often stored in a format
+where all the color channels have been multiplied with the alpha
+channel.
+
+With this format, the formula becomes:
+
+ (1 - ad) * [s] + (1 - as) * [d] + as * ad * [b]
+
+where [s] and [d] are the premultiplied source and destination colors,
+and [b] is either 0, or one of the premultiplied source or destination
+colors divided by their corresponding alpha channel (this division is
+then canceled by either the /as/ or the /ad/ in front of [b]).
+
+The alpha channel is computed with the same formula. In this case [s]
+is either 0 or as, [d] is either 0 or ad, and [b] is either 0, or
+as/as = 1, or ad/ad = 1.
+
+In other words, with premultiplied pixels, this formula:
+
+ (1 - ad) * [s] + (1 - as) * [d] + as * ad * [b]
+
+works for all four channels of a premultiplied pixel.
+
+
+
With the classic Porter/Duff operators the output alpha channel is
computed by plugging 1 into the area weighted average whenever a
region is filled with either source or destination, and 0 whenever a
@@ -289,6 +314,7 @@ destination are drawn, and B is the blend mode. When B(s,d) is chosen
to be 0, s, or d, the formula reduces to the twelve original
Porter/Duff operators.
+-->
<!--