Parmanoir

Photoshop-like compositing with Core Animation

If you've ever tried Core Image's compositing filters, you've seen the BIG gotcha : the images are composited one of top of each other and you can't change their position. That means they're stuck at the same position, both cramped at (0, 0) — not very useful unless you're blending same size images. To position two images where you want them and have the top one composited on top of the other one, you have to compute the common rectangle they share, extract sub images from that rectangle, and composite them with the compositing filter. Ugh. Luckily, Core Animation has a compositingFilter property that will handle just that.

Image:Photoshop-like compositing with Core Animation.jpg

All it takes is myLayer.compositingFilter = [CIFilter filterWithName:@"CIAdditionCompositing"]; and myLayer will be compositing on top of the previous layer in the layer tree. Varying myLayer.opacity will give the same result as in photoshop, changing the opacity of the composited image.

There still is the limitation of the GPU texture size, so this won't handle big (2000+x2000+ ?) images. Maybe CATiledLayer can be of some help there ?

Sample code

Image:iconZip.png Blending Modes.zip

Core Animation


Follow me on Twitter
Planet Cocoa
Cocoa.fr

2011 02 22Distance field
2010 07 202Binding through NSApp
2010 05 122Forwarding invocations
2010 02 272Core Image black fringes
2010 02 21Quickest Way to Shell
2010 02 08Who's calling ?
2009 09 2138 ways to use Blocks in Snow Leopard
2009 08 182Bracket Mess
2009 08 124Taming JavascriptCore within and without WebView
2009 04 15Debugging with Activity Monitor
2009 03 25How Core Image Color Tracking works
2009 03 1510Custom NSThemeFrame
2009 03 10Which framework is running ?
2009 03 074CoreUI can paint pretty big
2009 02 18Localization with functions
2009 01 30Did you forget to nest alloc and init?
2009 01 16JSCocoa on the iPhone
2009 01 11Mixing WebView and JavascriptCore
2009 01 09Badge overflow
2009 01 09Find your Garbage Collection leaks with Instruments

Powered by MediaWiki