2011-12-16 16 views
3

私はiOS用のOpenGL ESについて研究しています。 YUV形式のデータはRGBを変換せずに表示できますか? ほとんどの場合、yuvデータは表示用にRGBを変換する必要があります。しかし、変換プロセスは非常に遅いです、その後、それは円滑に表示されません。 私はRGBに変換せずにYUVデータを表示しようとしたいと思います。 可能ですか?可能であれば、私は何ができますか? お願いします。OpenGL ESでrgbを変換せずにyuv形式のデータを表示する方法は?

答えて

5

OpenGL ESではRGBデータに変換せずにYUVデータを表示することはできないと思います。

5

これは、OpenGL ES 2.0シェーダを使用して非常に簡単に行うことができます。私はsuper-fast iOS camera app SnappyCamのためにこのテクニックを使用します。フラグメントシェーダは、行列の乗算を実行して、YCbCr( "YUV")からRGBに移動します。それぞれの{Y, Cb, Cr}チャンネルを別のGL_LUMINANCEテクスチャに設定するか、またはGL_LUMINANCE_ALPHAテクスチャを使用して{Cb, Cr}テクスチャを組み合わせて、クロミナンスデータが既にインターリーブされている場合(Appleはこれを2面フォーマットと呼びます)。

質問への私の関連する回答を参照してください。YUV to RGBA on Apple A4, should I use shaders or NEON?ここStackOverflowで。

また、ES 1.1の固定レンダリングパイプラインを使用してこれを行うこともできますが、試していません。私は、テクスチャブレンディング関数を見てみましょう。 given in this OpenGL Texture Combiners Wiki Page.

1

あなたはIOS、iPhoneアプリケーションのソリューションを探していますか?解決策はありますか?あなたは、私は他の人に提供することができ、モバイルデバイスを探している場合は、ビデオのピクセルタイプがkCVPixelFormatType_420YpCbCr8BiPlanarFullRange

-(UIImage *) imageFromSamplePlanerPixelBuffer:(CMSampleBufferRef) sampleBuffer{ 

    @autoreleasepool { 
     // Get a CMSampleBuffer's Core Video image buffer for the media data 
     CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 
     // Lock the base address of the pixel buffer 
     CVPixelBufferLockBaseAddress(imageBuffer, 0); 

     // Get the number of bytes per row for the plane pixel buffer 
     void *baseAddress = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0); 

     // Get the number of bytes per row for the plane pixel buffer 
     size_t bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer,0); 
     // Get the pixel buffer width and height 
     size_t width = CVPixelBufferGetWidth(imageBuffer); 
     size_t height = CVPixelBufferGetHeight(imageBuffer); 

     // Create a device-dependent gray color space 
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); 

     // Create a bitmap graphics context with the sample buffer data 
     CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8, 
                bytesPerRow, colorSpace, kCGImageAlphaNone); 
     // Create a Quartz image from the pixel data in the bitmap graphics context 
     CGImageRef quartzImage = CGBitmapContextCreateImage(context); 
     // Unlock the pixel buffer 
     CVPixelBufferUnlockBaseAddress(imageBuffer,0); 

     // Free up the context and color space 
     CGContextRelease(context); 
     CGColorSpaceRelease(colorSpace); 

     // Create an image object from the Quartz image 
     UIImage *image = [UIImage imageWithCGImage:quartzImage]; 

     // Release the Quartz image 
     CGImageRelease(quartzImage); 

     return (image); 
    } 
} 

として設定されている場合

これは仕方UIImageCMSampleBufferRefに変換されます。

関連する問題