CoreImage - 在 CPU 上运行过滤器

发布于 2024-12-19 21:25:15 字数 1079 浏览 2 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如梦亦如幻 2024-12-26 21:25:15

这会强制 CPU 渲染:

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

CIContext *theCIContext = [CIContext contextWithOptions:theCIContextOptions ];

This forces CPU rendering:

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

CIContext *theCIContext = [CIContext contextWithOptions:theCIContextOptions ];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文