title: Multiplying colors when compositing with Quartz
body: <p>I'm trying to draw an image with a certain color. To get this effect, first I draw the image (consisting of mostly white and black), and then I draw a rectangle over it in a specified color (let's say red). There are various compositing options available, but none are exactly what I want.</p>
  
  <p>I want the colors (and alpha values) to be multiplied together. I think this is sometimes called a "Modulate" operation in other graphics systems. So, the white values in the image will be multiplied by the red values in the overlay rectangle to produce red. The black values in the image will be multiplied with black to product black.</p>
  
  <p>In other words, R = S * D (result equals source multiplied by destination).</p>
  
  <p>This is the code I'm working with now:</p>
  
  <pre><code>[image drawInRect:[self bounds] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
  
  NSColor * blend = [NSColor colorWithCalibratedRed:1 green:0 blue:0 alpha:1.0];
  
  [blend setFill];
  NSRectFillUsingOperation(self.bounds, NSCompositePlusDarker);
  </code></pre>
  
  <p>NSCompositePlusDarker is NOT what I want, but it's close. (It's addition instead of multiplication).</p>
  
  <p>Is there a way to do this in Quartz? It's very easy to do in OpenGL for instance. I've looked at CIFilter's but they seem a bit cumbersome for this. But if that's the only way, I would appreciate any sample code to get me in the right direction.</p>