2

I'm just starting to learn about Quartz Composer and the first thing I would like to create is a composition that could eventually be used in a Cocoa application which would accept a black and white image and two NSColor's and change the black pixels to NSColor #1 and the white pixels to NSColor #2.

I've spent some time playing with QC, but cannot seem to figure out how to put all of the pieces together.

About the only thing I have figured out is that I need to use the Image Filter template and I do see there is a Image Pixel patch that can get pixels from an image...however, I don't see a patch to set a pixel. It also seems possible the Pixellate patch might be necessary...although, I shouldn't have to worry about it producing an image with infinite dimensions since my source images will only be fixed size PNG images.

skaffman
  • 398,947
  • 96
  • 818
  • 769
ericg
  • 8,413
  • 9
  • 43
  • 77

1 Answers1

1

Take a look at the False Color patch — it takes an image and remaps it with a pair of colors.

In fact, since the False Color patch is just a wrapper around the Core Image filter with the same name (CIFalseColor), you could do this without involving Quartz Composer at all --- just set up and apply a CIFilter instance to your NSImage.

Edit — or write your own Core Image filter, starting with something like this:

kernel vec4 remapBasedOnRed(sampler image,__color colorForDark,__color colorForLight)
{
    return mix(colorForDark,colorForLight,sample(image, samplerCoord(image)).r);
}

...which takes the brightness of the red channel of the input image (sample(image, samplerCoord(image)).r), and uses it as a coefficient for linear interpolation between colorForDark and colorForLight.

smokris
  • 11,740
  • 2
  • 39
  • 59
  • 1
    Thanks. I will have to look into CIFalseColor in more detail. However, I would still be interested in learning how to essentially write the False Color patch from scratch...if that is possible. I figure it might be a good way of learning some interesting techniques. If it is not possible, that would be equally interesting. – ericg Mar 15 '11 at 01:32
  • +1 for the "write your own Core Image filter" suggestion. You're not likely to be able to build a QC composition where the composition itself transforms every individual pixels. (Well, it might be possible, but it won't be efficient.) If you want to transform images, you need to use patches that take images as input and produce images as output. If there isn't a patch that does what you want, then it's not too hard to write it as a Core Image filter. – Daniel Yankowsky Mar 12 '12 at 02:38