CoreImage - 在 CPU 上运行过滤器
我想在 CPU 上运行一些 CoreImage 过滤器,而不是 GPU。在 CI 文档中,我发现您可以通过创建类似这样的上下文(参见此处):
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 上下文。如何正确完成此操作?
I'd like to run some CoreImage filters on the CPU, instead of the GPU. In the CI documentation, I've discovered that you can express your preference that filters be executed on the CPU by creating a context something like this (see here):
NSDictionary * cpuonlycontextOptions = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool: YES],kCIContextUseSoftwareRenderer,nil];
CGContextRef cgcontext = [[NSGraphicsContext graphicsContextWithBitmapImageRep:rep] graphicsPort];
CIContext * cpu_context = [CIContext contextWithCGContext:cgcontext options: cpuonlycontextOptions];
To apply a filter, I'm currently doing this:
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];
The problem is, I can't see where or how to set the CPU only CI context. How is this done properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这会强制 CPU 渲染:
This forces CPU rendering: