What Is Core Image?


Core Image is a collection of Objectve-C classes for managing and applying image filters. Although it has an Objective-C API, it is important to realize that Core Image is not a part of Cocoa! Carbon applications are free to use Core Image in their drawings as well. The first code sample in this chapter has been developed as a Carbon application that uses Core Image.

The classes of Core Image let you chain multiple filters together into a single effect and can optimize the application of those filters. In fact, on a moderate system, Core Image is fast enough that the computer can apply an effect chain to full-frame motion video as it plays. The filters are very accurate. The computer carries out the pixel calculations in floating point arithmetic. This avoids the component clamping, which might occur with lower precision pixel formats and allows Core Image to maintain the color fidelity of the image throughout processing.

The power of Core Image comes from its filters. Filters can be written to execute code on the both the system's main CPU and the graphics card's GPU if an appropriate programmable GPU is available. When the computer filters an image, the computer executes the code of the filter on all the pixels in the image. Given that even small images contain thousands of pixels, the filter's code must run very quickly.

The advantage of using the GPU for filter calculations is twofold. First, the parallel pixel channels of the GPU allow the video card to apply the filter to many pixels of the image at once. By processing the image on the GPU, the computer also frees up the CPU for other tasks. In the event that your computer is not equipped with a programmable video card, however, Core Image can translate the code for the GPU into instructions that can run on general purpose vector processing units, like AltiVec or SSE, or even on the CPU if no vector units are available.

The technology that enables this flexibility is embodied in a concept known as the Core Image kernel. The Kernel of a filter is a bit of code, written in a special language know as the Core Image Kernel Language. This language is inspired by another language, the OpenGL Shading Language, that the OpenGL community designed specifically for programming the GPUs of modern video cards. The additional features of the Core Image Kernel Language allow the computer to repurpose the code for a variety of combinations of GPUs and CPUs. This allows the same filter kernel to run on a variety of video cards from different manufacturers. Similarly, Core Image itself frees your application from the tedious details of interacting with OpenGL, and the video card to get the kernel programs downloaded to the GPU.

These filters in Core Image are grouped together into categories. Some of the categories found in the built-in set of filters include

  • Blend Mode Filters These are filters that create a new image by combining two or more images with particular pixel blending operation. These filters include effects found in popular image processing applications like color dodge and color burn.

  • Color Adjustment Filters Filters that alter the color characteristics of an image as a whole. This includes photo processing effects like hue shifting and exposure adjustments, as well as color environment adjustments like changing the white point or gamma curve of an image.

  • Color Effect Filters Filters in this category operate on the colors of individual pixels. A common color effect filter will invert the colors of the pixels in an image. Another popular color effect reproduces an image as monotone images, including sepia tones.

  • Compositing Filters These filters allow you to composite two or more images together using a variety of compositing operators.

  • Distortion Effect Filters Distortion filters modify an image in interesting ways. Applications can use distortion filters to apply special effects like fisheye lens effects and wavy ripple effects.

  • Focus Filters The focus filter category derives its name from the idea of focusing an image through a camera. This category of effects include Gaussian blur filters and motion blur effects.

  • Generator Filters Generator filters are unique in that they are actually create images instead of modifying existing ones. For example, the Lenticular Halo generator creates an image that looks like the halo caused by bright light striking the lens of a camera. The more mundane checkerboard filter generates an image with a two-tone checkerboard pattern on it.

  • Geometry Adjustment Filters These filters adjust the geometry of an image. We've seen how Core Graphics can apply an affine transformation to an image, and indeed there is a Core Image filter that applies an affine transformation to an image. Another popular geometry filter is one that crops an image. The Perspective Transform effect allows you to go beyond the limits of what an affine transformation can accomplish.

  • Gradient Filters This category includes filters that generate smooth blends between one color and another. The effects of these filters include the same kinds of effects you can generate using CGShading objects, but there are filters that can create images beyond those that come from CGShadings.

  • Halftone Effects Filters Halftoning is the technique of using small dots (or other shapes) to reproduce continuous tone images. Perhaps the most common example of halftoning are those used to print pictures in newspapers. The filters in this category reproduce similar effects on the computer screen.

  • Stylize Filters The effect of stylize filters are all interesting and distinct. These filters allow your application to apply a number of artistic effects to an image.

  • Tile Effect Filters These filters take an image and treat it as a single tile and then generate another image by repeating the tile in various ways. In some ways tile effects are very similar to Quartz 2D patterns.

  • Transition Filters Transition filters generate a sequence of images that are designed to be run as an animation. The idea is that you are moving from one image to another over some length of time and want a smooth way of drawing a transition from one image to the other. Common transition effects include cross fades, and wipes.

Obviously there is quite a lot of functionality contained in the basic filters that ship with the system. The full breadth of built-in filters is thoroughly covered by the Core Image documentation. Rather than discuss the particular details of individual filters, our efforts here are concentrated on understanding how to create and manipulate the parameters of a filter. Once you understand the basics, you should be able to use any Core Image filter you like.

The Development Tools in Tiger contain two applications you may find helpful when exploring Core Image. The first is called Core Image Fun House (/Developer/Applications/Graphics Tools/Core Image Fun House). This application allows you to pass an image through a chain of the Core Image filters and view the results. It is an excellent tool for exploring the parameters of filters and examining their effects. It is also encouraging to see the power functionality a program can call into play through a simple application of the Core Image API.

The development tools also contain an application called Quartz Composer. Quartz Composer is is a powerful tool for putting together Core Image filters and other graphics components in complex ways. Quartz Composer not only lets you see the results of the graphics processing pipelines, it generate files that your application can load when it runs. Those files can reconstruct the image processing pipeline you've created in Quartz Composer and play it back, potentially with different parameters, inside your application. For more information please consult the Quartz Composer documentation:

http://developer.apple.com/documentation/GraphicsImaging/Conceptual/QuartzComposer/qc_intro/chapter_1_section_1.html





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