Layer Blending Algorithms
By solid-matrix
Prerequisite
- The formulas are only fitted for RGB color system.
- In the formulas
- $ A $: the color vector in the bottom layer
- $ B $: the color vector in the top layer
- $ C $: the color vector in the blended layer
Algorithms
Darken $$ C=\min(A,B) $$
Lighten $$ C = \max(A,B) $$
Multiply $$ C=\frac{A\times B}{255} $$
Screen $$ C = 255-\frac{(255-A)\times(255-B)}{255} = A+B-\frac{A\times B}{255} $$
Color Burn $$ C=A-\frac{(255-A)\times(255-B)}{B} = 255\times \frac{A+B-255}{B} $$
Color Dodge $$ C=A+\frac{A\times B}{255-B} = \frac{255\times A}{255-B} $$
Linear Burn $$ C=A+B-255 $$
Linear Dodge $$ C=A+B $$
Overlay $$ C = \begin{cases} \frac{A\times B}{128} & \text{if }A\le128 \ 255-\frac{(255-A)\times(255-B)}{128} & \text{if }A\gt128 \end{cases} $$
Hard Light $$ C = \begin{cases} \frac{A\times B}{128} & \text{if }B\le128 \ 255-\frac{(255-A)\times(255-B)}{128} & \text{if }B\gt128 \end{cases} $$
Soft Light $$ C = \begin{cases} \frac{A\times B}{128}+\frac{A}{255}^2 \times(255-2B) & \text{if }B\le128 \ \frac{A\times(255-B)}{128} + \sqrt{\frac{A}{255}}\times(2B-255) & \text{if }B\gt128 \end{cases} $$
Vivid Light $$ C = \begin{cases} A-\frac{(255-A)\times(255-2B)}{2B} & \text{if }B\le128 \ A+\frac{A\times(2B-255)}{2\times(255-B)} & \text{if }B\gt128 \end{cases} $$
Linear Light $$ C=A+2B-255 $$
Pin Light $$ C = \begin{cases} C=\min(A,2B) & \text{if }B\le128 \ C=\min(A,2B-255) & \text{if }B\gt128 \end{cases} $$
Hard Mix $$ C= \begin{cases} 255 & \text{if }A+B\ge255 \ 0 & \text{if } A+B\lt 255 \end{cases} $$
Difference $$ C = |A-B| $$
Exclusion $$ C=A+B-\frac{A\times B}{128} $$