2011-12-06 87 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 ];