gpt4 book ai didi

cocoa - CoreImage - 在 CPU 上运行过滤器

转载 作者:行者123 更新时间:2023-12-03 17:25:09 24 4
gpt4 key购买 nike

我想在 CPU 上运行一些 CoreImage 滤镜,而不是 GPU。在 CI 文档中,我发现您可以通过创建类似这样的上下文来表达您对在 CPU 上执行过滤器的偏好 ( 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];

要应用过滤器,我目前正在执行以下操作:

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 上下文。如何正确完成此操作?

最佳答案

这会强制 CPU 渲染:

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

CIContext *theCIContext = [CIContext contextWithOptions:theCIContextOptions ];

关于cocoa - CoreImage - 在 CPU 上运行过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8407496/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com