Skip to content

Instantly share code, notes, and snippets.

@randomsequence
Created May 12, 2014 12:20
Show Gist options
  • Save randomsequence/c3a0666a4bb0c7624a84 to your computer and use it in GitHub Desktop.
Save randomsequence/c3a0666a4bb0c7624a84 to your computer and use it in GitHub Desktop.
CoreImage - Render a CIImage to an Intermediate CVPixelBuffer Backed Image

#CoreImage - Render a CIImage to an Intermediate CVPixelBuffer Backed Image

This is useful if you're previewing several core image effects on the same image.

@implementation CIContext (IntermediateImage)
- (CIImage *)rsq_renderToIntermediateImage:(CIImage *)image {
CIImage *intermediateImage = nil;
CGSize size = image.extent.size;
CVPixelBufferRef pixelBuffer = NULL;
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault,
size.width,
size.height,
kCVPixelFormatType_32ARGB,
(__bridge CFDictionaryRef) @{(__bridge NSString *) kCVPixelBufferIOSurfacePropertiesKey: @{}},
&pixelBuffer);
if (status == kCVReturnSuccess) {
[self render:image toCVPixelBuffer:pixelBuffer];
intermediateImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
}
CVPixelBufferRelease(pixelBuffer);
return intermediateImage;
}
@end
@akfheaven
Copy link

akfheaven commented Oct 30, 2018

I get a slightly blinking result on replaykit SampleBuffer CallBack after applying the [render:image toCVPixelBuffer:pixelBuffer] function

Device: iphone 7 Plus ,IOS 12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment