I have tried to setup a simple GPUImage environment in a UIViewControler. However, I get a blank screen. I want to animate a property of the swirl filter whilst the source image is kept constant. How can I do this?
I want good performance (> 30 fps) for large-ish images so would ideally like to avoid unnecessary pixel copies back and forth from GPU to CPU.
- (void)viewDidLoad
{
UIImage *inputImage = [UIImage imageNamed:@"image.jpg"];
self.stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
self.swirlFilter = [[GPUImageSwirlFilter alloc] init];
self.swirlFilter.radius = 0.8;
self.filteredImageView =
[[GPUImageView alloc] initWithFrame:
CGRectMake(0.0, 0.0,
self.view.frame.size.width,
self.view.frame.size.height)];
[self.view addSubview:self.filteredImageView];
// GPUImagePicture -> GPUImageFilter -> GPUImageView
[self.stillImageSource addTarget:self.swirlFilter];
[self.swirlFilter addTarget:self.filteredImageView];
NSAssert(inputImage && _stillImageSource && _swirlFilter && _filteredImageView,
@"Something unexpected is nil");
}
// Set up a the display link in View Did appear
- (void) displayLinkDidFire:(CADisplayLink*)displayLink
{
CGFloat proportion =
[RSHelper proportionForTime:[[NSDate date] timeIntervalSinceReferenceDate]];
self.swirlFilter.angle = proportion;
// Do I need to call some kind of update call here?
}
Ok I found the answer - I was just missing a call to processImage
on the GPUImagePicture
- (void) displayLinkDidFire:(CADisplayLink*)displayLink
{
self.swirlFilter.angle = [Helper calcProportion];
[self.stillImageSource processImage];
}
GPUImage
is actually quite nice to setup and it seams to be faster than CoreImage
as it stated in the GPUImage docs. It pains me to use a 3rd party lib over some apple's technology, but I don't see any advantage or CoreImage.