Using iOS 10 beta I want to capture a RAW and render it into a Metal texture.
This is what I am currently doing and it takes about 500ms using an iPhone 6S, I was hoping it would be faster:
// Create DNG from RAW
NSData* imageData = [AVCapturePhotoOutput DNGPhotoDataRepresentationForRawSampleBuffer:stillBuffer previewPhotoSampleBuffer:nil];
// Process DNG with no adjustments
CIFilter* rawFilter = [CIFilter filterWithImageData:imageData options:@{ (NSString*)kCGImageSourceTypeIdentifierHint : @"com.adobe.raw-image" }];
CIVector* nativesize = [rawFilter valueForKey:kCIOutputNativeSizeKey];
CIImage* result = rawFilter.outputImage;
// Create a Metal texture
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
MTLTextureDescriptor* td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Unorm width:nativesize.X height:nativesize.Y mipmapped:NO];
td.usage = MTLTextureUsageShaderWrite;
id<MTLTexture> texture = [device newTextureWithDescriptor:td];
// Render result into Metal texture
CIContext* context = [CIContext contextWithMTLDevice:device options:@{ kCIContextWorkingFormat : [NSNumber numberWithInteger:kCIFormatRGBAh] }];
[context render:result toMTLTexture:texture commandBuffer:nil bounds:(CGRect){ 0, 0, nativesize.Y, nativesize.X } colorSpace:CGColorSpaceCreateWithName( kCGColorSpaceLinearSRGB )];
Is this the best way to do it?