Combining Filters and Images


When you retrieve the outputImage property of a CIFilter object, the result is a CIImage. There is nothing that prevents you from taking that CIImage and passing it as the input parameter of another filter. By carefully combining filters, your application can create very complex effects.

Core Image also makes it easy to combine the results of different filter chains. In fact, some of the filters in Core Image are little more than collecting points, meeting places if you will, where you can tie together different filter chains and combine their results. The filters in the Compositing Filter category are interesting examples of this kind of filter.

One particularly useful class that Core Image provides is the CIImageAccumulator. Unfortunately the documentation of CIImageAccumulator invokes some rather heady concepts involving "dynamical systems," which makes it difficult to understand what this class is for. The actual class itself, however, is pretty simple. The CIImageAccumulator is a handy tool to use when you want to create an image by collecting the results of applying small, incremental image filters. The CIAnnotation sample at Apple's web site demonstrates how this is done:

http://developer.apple.com/samplecode/CIAnnotation/CIAnnotation.html

The canonical example of a CIImageAccumulator in action is a program that lets the user paint on a canvas. The basic idea is that the user selects a paintbrush tool that has a particular brush shape. As the user drags the brush across the canvas, the computer draws an image by tracking the mouse and repeatedly drawing the brush shape on the canvas.

In this example, the computer may have a CIFilter that accepts the mouse location as an input parameter and generates a CIImage of paintbrush's shape drawn at that location. By drawing many copies of this filter with different locations and collecting the results into a final image, the end result is as if the user had dragged the brush to those locations. The CIImageAccumulator is the tool that knows how to collect the results of running the brush shape filter at each mouse location.

If you think of the CIImage as an image program, rather than as a collection of pixels, it may be easier to understand the role of the CIImageAccumulator. The image program that draws the results of the user painting on the canvas could, potentially, have a large number of similar steps. Each step would take the "current" image, use it as the input to a small filter, and the new "current image" would be the results of applying that filter. Expressed in pseudocode the image program would contain statements like this

currentImage = ApplySomeFilter(currentImage) 


If you want to create a CIImage (write an image program) that contains several steps that follow this pattern, using an CIImageAccumulator will help Core Image optimize the execution of this image program.




Quartz 2D Graphics for Mac OS X Developers
Quartz 2D Graphics for Mac OS X Developers
ISBN: 0321336631
EAN: 2147483647
Year: 2006
Pages: 100

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net