【问题标题】:CoreImage - run filter on CPUCoreImage - 在 CPU 上运行过滤器
【发布时间】:2011-12-27 02:19:16
【问题描述】:

我想在 CPU 而不是 GPU 上运行一些 CoreImage 过滤器。在 CI 文档中,我发现您可以通过创建类似这样的上下文 (see here) 来表达您对在 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 上下文。这是如何正确完成的?

【问题讨论】:

    标签: cocoa core-image


    【解决方案1】:

    这会强制 CPU 渲染:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-01
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 2020-03-19
      • 2013-05-01
      相关资源
      最近更新 更多