2011-12-06 42 views
1

我想在CPU上运行一些CoreImage过滤器,而不是GPU。在CI的文档,我发现,你可以表达自己的喜好,其过滤CPU上创建一个背景是这样的(see here)执行:CoreImage - 在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

这迫使CPU渲染:

NSDictionary *theCIContextOptions = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], kCIContextUseSoftwareRenderer, NULL]; 

CIContext *theCIContext = [CIContext contextWithOptions:theCIContextOptions ];