我想在CPU上运行一些CoreImage过滤器,而不是GPU。在CI文档中,我发现您可以通过创建类似这样的上下文(see here)来表达您在CPU上执行过滤器的偏好:
NSDictionary * cpuonlycontextOptions = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool: YES],kCIContextUseSoftwareRenderer,nil];
CGContextRef cgcontext = [[NSGraphicsContext graphicsContextWithBitmapImageRep:rep] graphicsPort];
CIContext * cpu_context = [CIContext contextWithCGContext:cgcontext options: cpuonlycontextOptions];
要应用过滤器,我目前正在这样做:
NSBitmapImageRep * bitmaprep_in;
CGImageRef cg_image_in = [bitmaprep_in CGImage];
CIImage * ci_image_in = [CIImage imageWithCGImage:cg_image_in];
CIFilter * edge_filter = [CIFilter filterWithName:@"CIEdges"];
[edge_filter setDefaults];
[edge_filter setValue:ci_image_in forKey: @"inputImage"];
CIImage * result = [edge_filter valueForKey: @"outputImage"];
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithCIImage:result];
问题是,我看不到在哪里或如何设置仅CPU的CI上下文。这怎么做得好?
答案 0 :(得分:0)
这会强制CPU渲染:
NSDictionary *theCIContextOptions = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], kCIContextUseSoftwareRenderer, NULL];
CIContext *theCIContext = [CIContext contextWithOptions:theCIContextOptions ];