Search code examples
iosperformancecore-graphicscore-imagecifilter

CIImage and CIFilter implementation specifics


I have a question about the underlying implementation of the Core Image system. I'm adding some CIImages on top of each other. Not that much, about 5 or 6 of them. To save memory and performance, they all have their transparent pixels cropped. They are then drawn at offsets, so I'm using a @"CIAffineTransform" filter to position them.

CIFilter* moveFilter = [CIFilter filterWithName:@"CIAffineTransform"];

My question is: does the moveFilter.outputImage REALLY generate a new image, or does it generate "render settings" that are later on used to draw the actual image?

(If it is the first, that would mean I'm effectively rendering the image twice. It would be a huge flaw in the Core Image API and hard to believe Apple created it this way.)


Solution

  • Filters do not generate anything. outputImage does not generate anything. CIImage does not generate anything. All you are doing is constructing a chain of filters.

    Rendering to a bitmap doesn't happen until you explicitly ask for it to happen. You do this in one of two ways:

    • Call CIContext createCGImage:fromRect:.

    • Actually draw a CIImage-based UIImage into a graphics context.