3

I am using “CGContextSetBlendMode” function in Quartz2D,but I don't understand the meaning of "kCGBlendModeColorDodge" constant.What's the formula of kCGBlendModeColorDodge?

djot
  • 2,952
  • 4
  • 19
  • 28
Jagie
  • 2,190
  • 3
  • 27
  • 25

2 Answers2

1

Here's the formula for "color dodge":

// v1 and v2 are the RGBA pixel values for the two pixels 
// "on top of each other" being blended
void someFunction(v1,v2) {
    return Math.min(v1 + v2, 255);
}

The source is this page:

http://jswidget.com/blog/2011/03/11/image-blending-algorithmpart-ii/

Edit:

There are two dodge functions. One is linear, the other is is simply called "dodge". Here's a more extensive list of the different blending modes:

How does photoshop blend two images together?

The blending mode formula is confirmed on this page:

http://www.pegtop.net/delphi/articles/blendmodes/dodge.htm

...but on this page they appear to get it right by reversing the formula:

http://www.simplefilter.de/en/basics/mixmods.html

You'll probably still have to figure out the special cases, and remember that '1' is actually '255'.

Community
  • 1
  • 1
Pedery
  • 3,632
  • 1
  • 27
  • 39
  • 1
    From the apple "QuartzDemo" sample, We can see if the source color is yellow (RGB=110) and the destination color is blue(RGB=001),the result of "kCGBlendModeColorDodge" is blue(RGB=001) .How to explain this:http://www.fileupyours.com/files/317337/abcde.png – Jagie May 02 '12 at 14:01
  • Thanks Pedery,I found the "inverse color dodge mode" of "http://www.pegtop.net/delphi/articles/blendmodes/dodge.htm" can explain the QuartzDemo case.Thank you very much! – Jagie May 03 '12 at 05:28
  • Can it? I was confused by the result myself since it was not what I expected based on the formulas. To double check I did the same test in Photoshop, and it too blended like in the QuartzDemo. – Pedery May 03 '12 at 10:49
  • Yes,it can.f(a,b) = b / (1 - a).(if b = 0 then the result = 0,regardless of "1-a". if b != 0 and 1 - a = 0,then result = 1) – Jagie May 07 '12 at 12:54
0

try:

// t_component's range is [0...1]
t_component dodge_component(const t_component& a, const t_component& b) {
  // note: saturate and limit to range
  return a / (1.0 - b);
}

t_color dodge_color(const t_color& a, const t_color& b) {
  t_color result;
  for (each component in color_model) {
    result.component[i] = dodge_component(a.component[i], b.component[i]);
  }
  return result;
}
justin
  • 104,054
  • 14
  • 179
  • 226