Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a CVPixelBuffer with 32RGBA format for iPhone?

When trying to create a 32 bits RGBA CVPixelBuffer, I constantly get errors.

Most notably error -6680 which means: "The buffer does not support the specified pixel format."

This is the code fragment: (Width and height are specified as 256*256)

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
//                         [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
//                         [NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
//                         [NSNumber numberWithBool:YES], kCVPixelBufferOpenGLCompatibilityKey,
                         nil];
CVPixelBufferRef pxbuffer = NULL;
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, WIDTH,
                                      HEIGHT, kCVPixelFormatType_32RGBA, (CFDictionaryRef) options, 
                                      &pxbuffer);
NSParameterAssert(status == kCVReturnSuccess && pxbuffer != NULL);

Can anyone give a hint as to what I'm doing wrong?

like image 668
Toad Avatar asked Nov 06 '11 18:11

Toad


People also ask

What format is an image in a CVPixelBuffer rgb_32?

A CVPixelBuffer usually contains pixels in RGBA format where each color channel is 8 bits. That means the pixel values in this image are between 0 and 255.

What is a CVPixelBuffer?

A Core Video pixel buffer is an image buffer that holds pixels in main memory. Applications generating frames, compressing or decompressing video, or using Core Image can all make use of Core Video pixel buffers.


1 Answers

You'll need to use a different pixel format. Just because there's a constant defined for 32RGBA doesn't mean it's supported. This tech note lists the supported formats (as of when it was written) and the functions you can use to find out what formats are currently supported:

Technical Q&A QA1501 Core Video - Available Pixel Formats

The most similar formats that are supported are 32ARGB and 32BGRA.

like image 50
rob mayoff Avatar answered Sep 28 '22 02:09

rob mayoff