Compositing and blending
- Builds upon existing SVG spec
- Collaboration between Adobe and Canon
- Contains all of blend modes. Widely use by graphic designers
- Matches all the compositing modes in Canvas
Why add this?
- SVG filters are not as easy to use
- Not all blending modes are available in the filters spec
- Existing compositing spec only applied to SVG
- New spec breaks compositing and blending into 2 steps:
- blend-mode
- alpha-compositing
What is blending?
- Takes the colors of the shape and the background
- Combine the colors using a 'mixing' formula
- Use the alpha of the background to create a new color
Step 1 + 2: apply blending formula
Alpha of source and background are ignored
step 3: account for background alpha
Image is on top of the 2 rectangles
Result = α x blendedColor + (1 - α) x original
Different blend modes
- normal
- multiply
- screen
- overlay
- darken
- lighten
- color-dodge
- color-burn
- hard-light
- soft-light
- difference
- exclusion
- hue
- saturation
- color
- luminosity
Additions to canvas
Extend globalCompositeOperation to take blend modes
Wait, there's more!
We got many requests to
add the 'missing' Photoshop blend modes
So, we will add them as well:
- Linear dodge
- Linear burn
- Vivid light
- Linear light
- Pin light
- Hard mix
- Divide
- Subtract
Compositing
- combines graphical objects (also known as shapes)
- Works with the alpha channel and premultiplied colors
- Is a low level primitive for graphical effects
- Already part of the canvas specification
Simple alpha Compositing
Result = source + (1 - αs) x backdrop
Different blend modes
- clear
- src
- dst
- src-over
- dst-over
- src-in
- dst-in
- src-out
- dst-out
- src-atop
- dst-atop
- xor
- plus
Group compositing
01 <rect ...>
02 <g id="gsave">
03 <circle ...>
04 <circle style="alpha-compositing: clear" ...>
.gsave: hover {opacity: .5};
The shape buffer
This is an extra channel that keeps track of the shape
Group isolation and knockout
Current status
- Working draft since August 16
- Partially implemented in WebKit
- Working prototype available