Exact algorithms for blend modes

General discussions about Inkscape.
ink_user
Posts: 2
Joined: Tue Oct 04, 2016 6:24 pm

Exact algorithms for blend modes

Postby ink_user » Tue Oct 04, 2016 6:41 pm

Inkscape has blend modes: Normal, Multiply, Screen, Darken, Lighten.
How could I know the algorithms for the blending modes in Inkscape per pixel?
For example, if we discuss a blending mode in Gimp, its manual provides description and mathematical formulas.
Top

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Exact algorithms for blend modes

Postby Lazur » Tue Oct 04, 2016 9:33 pm

Hi.

Good call, compositing is the basic of the rendering.
By a quick search I found this.

multiply
The source color is multiplied by the destination color and replaces the destination. The resultant color is always at least as dark as either the source or destination color. Multiplying any color with black results in black. Multiplying any color with white preserves the original color.


f(Sc,Dc) = Sc × Dc
X = 1
Y = 1
Z = 1

Dca' = Sca × Dca + Sca × (1 - Da) + Dca × (1 - Sa)
Da' = Sa × Da + Sa × (1 - Da) + Da × (1 - Sa)
= Sa + Da - Sa × Da



screen
The source and destination colors are complemented, multiplied and the resultant color replaces the destination. The resultant color is always at least as light as either the source or destination colour. Screening any color with white results in white. Screening any color with black preserves the original color.


f(Sc,Dc) = Sc + Dc - (Sc × Dc)

X = 1
Y = 1
Z = 1

Dca' = (Sca × Da + Dca × Sa - Sca × Dca) + Sca × (1 - Da) + Dca × (1 - Sa)
= Sca + Dca - Sca × Dca
Da' = Sa + Da - Sa × Da



darken
The resultant color is the darker of source or destination colors. If the source is darker, it replaces the destination. Otherwise, the destination is preserved.


f(Sc,Dc) = min(Sc,Dc)
X = 1
Y = 1
Z = 1

Dca' = min(Sca × Da, Dca × Sa) + Sca × (1 - Da) + Dca × (1 - Sa)
Da' = Sa + Da - Sa × Da

or

if Sca × Da < Dca × Sa
src-over()
otherwise
dst-over()



lighten
The resultant color is the lighter of source or destination colors. If the source is lighter, it replaces the destination. Otherwise, the destination is preserved.


f(Sc,Dc) = max(Sc,Dc)
X = 1
Y = 1
Z = 1

Dca' = max(Sca × Da, Dca × Sa) + Sca × (1 - Da) + Dca × (1 - Sa)
Da' = Sa + Da - Sa × Da

or

if Sca × Da > Dca × Sa
src-over()
otherwise
dst-over()

ink_user
Posts: 2
Joined: Tue Oct 04, 2016 6:24 pm

Re: Exact algorithms for blend modes

Postby ink_user » Thu Oct 06, 2016 2:12 am

Lazur wrote:Good call, compositing is the basic of the rendering.
By a quick search I found this

So Gimp's and Inkscape's blend modes have the same names but different mathematical algorithms.
Right ?

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Exact algorithms for blend modes

Postby Lazur » Thu Oct 06, 2016 2:52 am

Haven't gone through the details myself. Inkscape uses the svg specs&cairo. I'd expect the same behave.


Return to “General Discussions”