Changed my applyEffects to this:
dispatch_queue_t myQueue = dispatch_queue_create("My Queue",NULL);
if (!running) {
running = true;
dispatch_async(myQueue, ^{
UIGraphicsBeginImageContext();
//CGContextTranslateCTM, CGContextScaleCTM, CGContextDrawImage and stuff like that
UIImage *blendedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dispatch_async(dispatch_get_main_queue(), ^{
// Update the UI
preview.image = blendedImage;
running = false;
});
});
}
Now it will create a separate thread to apply the effect, and update the UI when it's ready. This way I'm not clogging up the UI touch event processing.
The if (!running) is a dumb control to make it only run once at a time.
The ideal way is to throw away all that code and reimplement it with GPUImage, but it will require much more time, so it's a temporary solution.