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

1

12

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?

Devy answered 6/11, 2011 at 18:55 Comment(0)
S
11

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.

Supervisor answered 6/11, 2011 at 19:19 Comment(5)
It's strange. Because I need this buffer format for the new CVOpenGLESTextureCacheCreateTextureFromImage function. In the RosyWriter apple example they use this very format (although they obtain this buffer from the camera).Devy
RosyWriter doesn't mention kCVPixelFormatType_32RGBA. In the call to CVOpenGLESTextureCacheCreateTextureFromImage, it uses GL_RGBA as the internalFormat parameter, but it uses GL_BGRA as the format parameter, which "Specifies the format of the pixel data."Supervisor
In fact RosyWriter uses kCVPixelFormatType_32BGRA (not ...32RGBA).Supervisor
yes! it's working! Thanks so much! Staring too long at all these parameters can make you parameter blind apparently.Devy
@robmayoff Hi, would you plz have a glance at my issue. thx.#37612093Brevet

© 2022 - 2024 — McMap. All rights reserved.