I’m finally sitting down to convert some of our graphics libraries to use CoreImage to render images (for things like blending two images) and I’ve got it working but its slow (iOS5.01 iPhone 4S). I thought the promise of CoreImage was hardware acceleration, here is what I’m doing:
CIImage *intputBackgroundImage = [[CIImage alloc] initWithCGImage:backgroundImageRef];
CIImage *inputImage = [[CIImage alloc] initWithCGImage:inputImageRef];
CIFilter *multiply = [CIFilter filterWithName:@"CIMultiplyBlendMode"];
[multiply setDefaults];
[multiply setValue:intputBackgroundImage forKey:@"inputBackgroundImage"];
[multiply setValue:inputImage forKey:@"inputImage"];
CIImage *result = multiply.outputImage;
CIContext *ctx = [CIContext contextWithOptions:nil];
CGImageRef resultRef = [ctx createCGImage:result fromRect:CGRectMake(0, 0, imgFrame.size.width, imgFrame.size.height)];
UIImage *resultImage = [UIImage imageWithCGImage:resultRef];
CGImageRelease(resultRef);
It works, I get an image which has the inputImage blended into the backgroundImage but it actually takes longer than if I had just done it using CoreGraphics and a CGContext(). Is there a way to check if this work isn’t being done on the GPU, is there a reason it wouldn’t be?
Thanks,
Things that you need rerender are best for ci, or things that need to do multiple filters.
It’s currently slower because the items have to be copied from cpu memory to gpu memory (no opengl unified memory support on ios).
This means that since you are only doing one effect, it will take more time due to the double copy.