我正在研究适用于iOS的OpenGL ES。 我想知道YUV格式的数据可以在不转换RGB的情况下显示。 在大多数情况下,yuv数据必须转换RGB才能显示。但是,转换过程非常缓慢,那就是不能顺利显示。 所以,我想尝试显示YUV数据而不转换为RGB。 可能吗?如果可能,我该怎么办? 请让我给出一个建议。
答案 0 :(得分:5)
我认为OpenGL ES无法在不转换为RGB数据的情况下显示YUV数据。
答案 1 :(得分:5)
使用OpenGL ES 2.0着色器可以非常轻松地完成此操作。我对super-fast iOS camera app SnappyCam使用这种技术。片段着色器将执行矩阵乘法,将您从YCbCr
(“YUV
”)带到RGB
。您可以将每个{Y, Cb, Cr}
频道放在单独的GL_LUMINANCE
纹理中,或者如果您的色度数据已经交错,则使用{Cb, Cr}
纹理将GL_LUMINANCE_ALPHA
纹理组合在一起(Apple称之为双平面格式。)
请参阅我在StackOverflow上的YUV to RGBA on Apple A4, should I use shaders or NEON?问题的相关答案。
您也可以使用ES 1.1的固定渲染管道执行此操作,但我还没有尝试过。我会看一下纹理混合函数,例如given in this OpenGL Texture Combiners Wiki Page.
答案 2 :(得分:1)
你正在寻找IOS,iPhone应用程序的解决方案,那么有解决方案。
当视频像素类型设置为 kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
时,这会将 CMSampleBufferRef 转换为 UIImage-(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);
}
}
如果您正在寻找移动设备,那么我可以提供其他人。