1

Appleはそのドキュメントで、CoreImageを使用したリアルタイムフィルタリングについて次のように述べています。

アプリがリアルタイム画像処理をサポートしている場合は、contextWithOptions:を使用してGPUを指定するのではなく、EAGLコンテキストからCIContextオブジェクトを作成する必要があります。利点は、レンダリングされたイメージがGPUに残り、CPUメモリにコピーされないことです。まず、EAGLコンテキストを作成する必要があります。

次の実装を使用して、iOS6/iPhone5でこれを実現できました。

self.eaglContext = [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2] autorelease];
self.ciContext = [[CIContext contextWithEAGLContext:_eaglContext options:[[[NSMutableDictionary alloc] initWithObjectsAndKeys:[NSNull null], kCIContextWorkingColorSpace, nil] autorelease]] autorelease];
self.filteredImage = [[CIImage imageWithCGImage:_image.CGImage] autorelease];

    GLKView *glkView = [[GLKView alloc] initWithFrame:self.imageView.bounds context:self.eaglContext];
    self.glkView = glkView;
    [self.glkView bindDrawable];
    [self.mainView addSubview:self.glkView];
    [glkView release];

    CGRect filterViewBounds = CGRectZero;
    filterViewBounds.size.width = self.glkView.drawableWidth;
    filterViewBounds.size.height = self.glkView.drawableHeight;
    self.filterViewBounds = filterViewBounds;

    [self.context drawImage:self.filteredImage inRect:self.filterViewBounds fromRect:[self.filteredImage extent]];
    [self.glkView display];

次に、次のようにフィルターを適用します。

CIImage *filteredImage = [[CIImage alloc] initWithCGImage:self.image.CGImage options:nil];

for (Filter *filter in self.filters)
{
    if ([filter apply])
    {
        [filter.filter setValue:filteredImage forKey:kCIInputImageKey];
        [filteredImage release];
        filteredImage = [[filter.filter outputImage] retain];
    }
}

    [self.glkView bindDrawable];
    [self.ciContext drawImage:filteredImage inRect:self.filterViewBounds fromRect:[filteredImage extent]];
    [self.glkView display];

ただし、iOS5 / iPhone4でフィルターを適用すると、次のようになります。

CoreImage: EAGLContext framebuffer or renderbuffer incorrectly configured!

この後、フィルタリングは機能しますが、パフォーマンスは依然として非常に悪く、フィルタリングされた画像をCPUに保存して戻した場合とほぼ同じです。また、この特定のView Controllerを終了してから戻ってみると、クラッシュするという事実もあります。

誰でもこれについて何か助けを提供できますか?

4

0 に答える 0