CoreImage - запустить фильтр на процессоре

Я хотел бы запустить некоторые фильтры CoreImage на процессоре, а не на графическом процессоре. В документации по 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];

Проблема в том, что я не вижу, где и как установить контекст CI только для ЦП. Как это делается правильно?


person leecbaker    schedule 06.12.2011    source источник


Ответы (1)


Это вызывает рендеринг ЦП:

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

CIContext *theCIContext = [CIContext contextWithOptions:theCIContextOptions ];
person akaru    schedule 26.12.2011