Jagie
Jagie

Reputation: 2220

What's the formula of kCGBlendModeColorDodge

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

Upvotes: 3

Views: 743

Answers (2)

Pedery
Pedery

Reputation: 3636

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'.

Upvotes: 1

justin
justin

Reputation: 104718

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;
}

Upvotes: 0

Related Questions