3

I am trying to simulate the Adobe Photoshop's blending mode - Darken.

I understand the basic Darken principle : Darken(a,b) = min(a,b). E.g.:

Darken( (.2, .3, .8), (.5, .1, .4) ) = (.2, .1, .4)   // (r, g, b)

But I have transparency in it. In Photoshop, Darken works this way:

Darken( (0, 1, 0, .5), (0, 0, 0, .5) ) = (0, .3, 0, .75)   // (r, g, b, a)

Darkening green over black is green. I see, that output alpha is computed in classic way: ao = aa + ab * (1-aa). Do you know how the other values are computed?

BTW. Darken mode is commutative.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Ivan Kuckir
  • 2,327
  • 3
  • 27
  • 46

2 Answers2

2

So finally I found it out.

In Darken mode, composition is the same as in Normal mode, but if back channel is darker, front-back channels are flipped.

For each channel: Darken(a, b) = a < b ? Norm(a, b) : Norm(b, a);

So in my top example, for green and alpha:

Darken( (1, .5), (0, .5) ) =  Norm( (0, .5), (1, .5) ) 
alpha = (.5 + .5*(1-.5)) = .75
green = (0*.5 + 1*.5*(1-.5)) / .75 = (0 + .25) / .75 = 0.333333
Ivan Kuckir
  • 2,327
  • 3
  • 27
  • 46
0

Well, it's slightly more involved, actually. There are other, similar questions on here, which answer this. The best one to use is probably the aptly named:

Algorithm for Additive Color Mixing for RGB Values

Community
  • 1
  • 1
Nik Bougalis
  • 10,495
  • 1
  • 21
  • 37
  • They are talking about "Normal" blending mode, not Darken. I have been searching for similar questions already, but I couldn't find anything similar. – Ivan Kuckir Nov 18 '12 at 23:23
  • You could alpha-blend your chosen color with white to lighten and black to darken. The alpha channel can control how lighter or darker you want the resulting color to be. – Nik Bougalis Nov 18 '12 at 23:26
  • But I need transparency in my output, just like in Photoshop. – Ivan Kuckir Nov 18 '12 at 23:28
  • And what makes you think this method won't provide this? – Nik Bougalis Nov 18 '12 at 23:50
  • I already have implemented Normal and Dissolve modes, I see it. But I think I am getting a clue... I think Darken(a,b) is some "average" of min(a,b) and Normal(a,b), depending on transparencies... – Ivan Kuckir Nov 18 '12 at 23:52
  • Great, but I still think you should at least try the method I outlined above. Alpha-blend with white to lighten, black to darken, and adjust the alpha channel of the resulting color to whatever you want. – Nik Bougalis Nov 19 '12 at 00:13
  • What do you mean by your method? can you write some formula? – Ivan Kuckir Nov 19 '12 at 16:27