Reputation: 1341
My app applies filters to a picture after it has been selected/captured using Core Image. It works fine on small picture however if i take pictures by camera it takes about 3-4 seconds in order to process the picture and apply the filter. I read through the Core Image Programming Guide performance topics and i came across being able to decide if i want to use the CPU or GPU. So i applied what is written and it's still slow plus an error occurring in the console. I'll post the original code, the changes i applied to switch to GPU, and the error occurring.
Original code:
CIContext *context = [CIContext contextWithEAGLContext:nil]; //[CIContext contextWithOptions:@{kCIContextUseSoftwareRenderer: [NSNumber numberWithBool:NO]}];
CIImage *image = [CIImage imageWithData:UIImagePNGRepresentation(_originalImage)];
CIFilter *filter = [CIFilter filterWithName:_filters[filterName]];
if ([filterName isEqualToString:@"Sepia"]) {
[filter setValue:image forKey:kCIInputImageKey];
[filter setValue:@0.8f forKey:kCIInputIntensityKey];
}
if ([filterName isEqualToString:@"B/W"]) {
[filter setValue:image forKey:kCIInputImageKey];
}
if ([filterName isEqualToString:@"Bloom"]) {
[filter setValue:image forKey:kCIInputImageKey];
[filter setValue:@1.0f forKey:kCIInputRadiusKey];
[filter setValue:@1.0f forKey:kCIInputIntensityKey];
}
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGRect extent = [result extent];
CGImageRef cgimage = [context createCGImage:result fromRect:extent];
UIImage *filteredImage = [UIImage imageWithCGImage:cgimage];
[_filteredImageView setImage:filteredImage];
tempFilteredImage = filteredImage;
Modified code for the context:
CIContext *context = [CIContext contextWithEAGLContext:nil];
Error occurring after changing the CIContext code:
CIContexts can only be created with ES 2.0 EAGLContexts
Is there something wrong in code ? am i doing the right thing to accelerate the process of rendering ? Thank you.
Upvotes: 0
Views: 1291
Reputation: 1070
Try making the context like this...
EAGLContext *myEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
CIContext *myContext = [CIContext contextWithEAGLContext:myEAGLContext options:nil];
Upvotes: 1