CVPixelBuffer Reference
| Derived from | |
| Framework | System/Library/Frameworks/CoreVideo.framework |
| Companion guide | Core Video Programming Guide |
| Declared in | CVPixelBuffer.h |
Overview
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.
Functions
CVPixelBufferCreate
Creates a single pixel buffer for a given size and pixel format.
CVReturn CVPixelBufferCreate ( CFAllocatorRef allocator, size_t width, size_t height, OSType pixelFormatType, CFDictionaryRef pixelBufferAttributes, CVPixelBufferRef *pixelBufferOut );
Parameters
- allocator
The allocator to use to create the pixel buffer. Pass
NULLto specify the default allocator.- width
Width of the pixel buffer, in pixels.
- height
Height of the pixel buffer, in pixels.
- pixelFormatType
The pixel format identified by its respective four-character code (type
OSType).- pixelBufferAttributes
A dictionary with additional attributes for a pixel buffer. This parameter is optional. See “Pixel Buffer Attribute Keys” for more details.
- pixelBufferOut
On output,
pixelBufferOutpoints to the newly created pixel buffer.
Return Value
A Core Video result code. See Core Video Constants Reference for possible values.
Discussion
This function allocates the necessary memory based on the pixel dimensions, format, and extended pixels described in the pixel buffer’s attributes.
Some of the parameters specified in this call override equivalent pixel buffer attributes. For example, if you define the kCVPixelBufferWidth and kCVPixelBufferHeight keys in the pixel buffer attributes parameter (pixelBufferAttributes), these values are overridden by the width and height parameters.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferCreateResolvedAttributesDictionary
Takes an array of CFDictionary objects describing various pixel buffer attributes and tries to resolve them into a single dictionary.
CVReturn CVPixelBufferCreateResolvedAttributesDictionary ( CFAllocatorRef allocator, CFArrayRef attributes, CFDictionaryRef *resolvedDictionaryOut );
Parameters
- allocator
The allocator to use to create the pixel buffer. Pass
NULLto specify the default allocator.- attributes
An array of Core Foundation dictionaries containing pixel buffer attribute key-value pairs.
- resolvedDictionaryOut
On output,
resolvedDictionaryOutpoints to the consolidated dictionary.
Return Value
A Core Video result code. See Core Video Constants Reference for possible values.
Discussion
This call is useful when you need to resolve requirements between several potential clients of a buffer.
If two or more dictionaries contain the same key but different values, errors may occur. For example, the width and height attributes must match, but if the bytes-per-row (rowBytes) attributes differ, the least common multiple is taken. Mismatches in pixel format allocators or callbacks also cause an error.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferCreateWithBytes
Creates a pixel buffer for a given size and pixel format containing data specified by a memory location.
CVReturn CVPixelBufferCreateWithBytes ( CFAllocatorRef allocator, size_t width, size_t height, OSType pixelFormatType, void *baseAddress, size_t bytesPerRow, CVPixelBufferReleaseBytesCallback releaseCallback, void *releaseRefCon, CFDictionaryRef pixelBufferAttributes, CVPixelBufferRef *pixelBufferOut );
Parameters
- allocator
The allocator to use to create this buffer. Pass
NULLto specify the default allocator.- width
The width of the pixel buffer, in pixels.
- height
The height of the pixel buffer, in pixels.
- pixelFormatType
The pixel format identified by its respective four character code (type
OSType).- baseAddress
A pointer to the base address of the memory storing the pixels.
- bytesPerRow
The row bytes of the pixel storage memory.
- releaseCallback
The callback function to be called when the pixel buffer is destroyed. This callback allows the owner of the pixels to free the memory. See
CVPixelBufferReleaseBytesCallbackfor more information.- releaseRefCon
The user data identifying the pixel buffer. This value is passed to your pixel buffer release callback.
- pixelBufferAttributes
A Core Foundation dictionary with additional attributes for a a pixel buffer. This parameter is optional. See “Pixel Buffer Attribute Keys” for more details.
- pixelBufferOut
On output,
pixelBufferOutpoints to the newly created pixel buffer.
Return Value
A Core Video result code. See Core Video Constants Reference for possible values.
Discussion
Some of the parameters specified in this call override equivalent pixel buffer attributes. For example, if you define the kCVPixelBufferWidth and kCVPixelBufferHeight keys in the pixel buffer attributes parameter (pixelBufferAttributes), these values are overridden by the width and height parameters.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferCreateWithPlanarBytes
Creates a single pixel buffer in planar format for a given size and pixel format containing data specified by a memory location.
CVReturn CVPixelBufferCreateWithPlanarBytes ( CFAllocatorRef allocator, size_t width, size_t height, OSType pixelFormatType, void *dataPtr, size_t dataSize, size_t numberOfPlanes, void *planeBaseAddress[], size_t planeWidth[], size_t planeHeight[], size_t planeBytesPerRow[], CVPixelBufferReleasePlanarBytesCallback releaseCallback, void *releaseRefCon, CFDictionaryRef pixelBufferAttributes, CVPixelBufferRef *pixelBufferOut );
Parameters
- allocator
The allocator to use to create this buffer. Pass
NULLto specify the default allocator.- width
The width of the pixel buffer, in pixels.
- height
The height of the pixel buffer, in pixels.
- pixelFormatType
The pixel format identified by its respective four-character code (type
OSType).- dataPtr
A pointer to a plane descriptor block if applicable, or
NULLif it is not.- dataSize
The size of the memory if the planes are contiguous, or
NULLif it is not.- numberOfPlanes
The number of planes.
- planeBaseAddress
The array of base addresses for the planes.
- planeWidth
The array of plane widths.
- planeHeight
The array of plane heights.
- planeBytesPerRow
The array of plane bytes-per-row values.
- releaseCallback
The callback function that gets called when the pixel buffer is destroyed. This callback allows the owner of the pixels to free the memory. See
CVPixelBufferReleaseBytesCallbackfor more information.- releaseRefCon
A pointer to user data identifying the pixel buffer. This value is passed to your pixel buffer release callback.
- pixelBufferAttributes
A dictionary with additional attributes for a a pixel buffer. This parameter is optional. See “Pixel Buffer Attribute Keys” for more details.
- pixelBufferOut
On output,
pixelBufferOutpoints to the newly created pixel buffer.
Return Value
A Core Video result code. See Core Video Constants Reference for possible values.
Discussion
Some of the parameters specified in this call override equivalent pixel buffer attributes. For example, if you define the kCVPixelBufferWidth and kCVPixelBufferHeight keys in the pixel buffer attributes parameter (pixelBufferAttributes), these values are overridden by the width and height parameters.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferFillExtendedPixels
Fills the extended pixels of the pixel buffer.
CVReturn CVPixelBufferFillExtendedPixels ( CVPixelBufferRef pixelBuffer );
Parameters
- pixelBuffer
The pixel buffer whose extended pixels you want to fill.
Return Value
A Core Video result code. See Core Video Constants Reference for possible values.
Discussion
This function replicates edge pixels to fill the entire extended region of the image.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetBaseAddress
Returns the base address of the pixel buffer.
void * CVPixelBufferGetBaseAddress ( CVPixelBufferRef pixelBuffer );
Parameters
- pixelBuffer
The pixel buffer whose base address you want to obtain.
Return Value
The base address of the pixels.
For chunky buffers, returns a pointer to the pixel at (0,0) in the buffer.
For planar buffers, returns a pointer to a
PlanarComponentInfostructure (as defined by QuickTime inImageCodec.h).
Discussion
Retrieving the base address for a pixel buffer requires that the buffer base address be locked via a successful call to CVPixelBufferLockBaseAddress.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetBaseAddressOfPlane
Returns the base address of the plane at the specified plane index.
void * CVPixelBufferGetBaseAddressOfPlane ( CVPixelBufferRef pixelBuffer, size_t planeIndex );
Parameters
- pixelBuffer
The pixel buffer containing the plane whose base address you want to obtain.
- planeIndex
The index of the plane.
Return Value
The base address of the plane, or NULL for nonplanar pixel buffers.
Discussion
Retrieving the base address for a pixel buffer requires that the buffer base address be locked by a successful call to CVPixelBufferLockBaseAddress.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetBytesPerRow
Returns the number of bytes per row of the pixel buffer.
size_t CVPixelBufferGetBytesPerRow ( CVPixelBufferRef pixelBuffer );
Parameters
- pixelBuffer
The pixel buffer whose bytes-per-row value you want to obtain.
Return Value
The number of bytes per row of the image data. For planar buffers, this function returns a rowBytes value such that bytesPerRow * height covers the entire image, including all planes.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetBytesPerRowOfPlane
Returns the number of bytes per row for a plane at the specified index in the pixel buffer.
size_t CVPixelBufferGetBytesPerRowOfPlane ( CVPixelBufferRef pixelBuffer, size_t planeIndex );
Parameters
- pixelBuffer
The pixel buffer containing the plane.
- planeIndex
The index of the plane whose bytes-per-row value you want to obtain.
Return Value
The number of row bytes of the plane, or NULL for nonplanar pixel buffers.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetDataSize
Returns the data size for contiguous planes of the pixel buffer.
size_t CVPixelBufferGetDataSize ( CVPixelBufferRef pixelBuffer );
Parameters
- pixelBuffer
The pixel buffer whose data size you want to obtain.
Return Value
The data size as specified in the call to CVPixelBufferCreateWithPlanarBytes.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetExtendedPixels
Returns the amount of extended pixel padding in the pixel buffer.
void CVPixelBufferGetExtendedPixels ( CVPixelBufferRef pixelBuffer, size_t *extraColumnsOnLeft, size_t *extraColumnsOnRight, size_t *extraRowsOnTop, size_t *extraRowsOnBottom );
Parameters
- pixelBuffer
The pixel buffer whose extended pixel size you want to obtain.
- extraColumnsOnLeft
On output, the pixel row padding to the left. May be
NULL.- extraColumnsOnRight
On output, the pixel row padding to the right. May be
NULL.- extraRowsOnTop
On output, the pixel row padding to the top. May be
NULL.- extraRowsOnBottom
On output, the pixel row padding to the bottom. May be
NULL.
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetHeight
Returns the height of the pixel buffer.
size_t CVPixelBufferGetHeight ( CVPixelBufferRef pixelBuffer );
Parameters
- pixelBuffer
The pixel buffer whose height you want to obtain.
Return Value
The buffer height, in pixels.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetHeightOfPlane
Returns the height of the plane at planeIndex in the pixel buffer.
size_t CVPixelBufferGetHeightOfPlane ( CVPixelBufferRef pixelBuffer, size_t planeIndex );
Parameters
- pixelBuffer
The pixel buffer whose plane height you want to obtain.
- planeIndex
The index of the plane.
Return Value
The height of the buffer, in pixels, or 0 for nonplanar pixel buffers.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetPixelFormatType
Returns the pixel format type of the pixel buffer.
OSType CVPixelBufferGetPixelFormatType ( CVPixelBufferRef pixelBuffer );
Parameters
- pixelBuffer
The pixel buffer whose format type you want to obtain.
Return Value
A four-character code OSType identifier for the pixel format.
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetPlaneCount
Returns number of planes of the pixel buffer.
size_t CVPixelBufferGetPlaneCount ( CVPixelBufferRef pixelBuffer );
Parameters
- pixelBuffer
The pixel buffer whose plane count you want to obtain.
Return Value
The number of planes. Returns 0 for nonplanar pixel buffers.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetTypeID
Returns the Core Foundation ID of the pixel buffer type.
CFTypeID CVPixelBufferGetTypeID ( void );
Return Value
The Core Foundation ID for this type.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetWidth
Returns the width of the pixel buffer.
size_t CVPixelBufferGetWidth ( CVPixelBufferRef pixelBuffer );
Parameters
- pixelBuffer
The pixel buffer whose width you want to obtain.
Return Value
The width of the buffer, in pixels.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferGetWidthOfPlane
Returns the width of the plane at a given index in the pixel buffer.
size_t CVPixelBufferGetWidthOfPlane ( CVPixelBufferRef pixelBuffer, size_t planeIndex );
Parameters
- pixelBuffer
The pixel buffer whose plane width you want to obtain.
- planeIndex
The plane index that contains the plane’s width value.
Return Value
The width of the plane, in pixels, or 0 for nonplanar pixel buffers.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferIsPlanar
Determines whether the pixel buffer is planar.
Boolean CVPixelBufferIsPlanar ( CVPixelBufferRef pixelBuffer );
Parameters
- pixelBuffer
The pixel buffer to check.
Return Value
Returns true if the pixel buffer was created using CVPixelBufferCreateWithPlanarBytes; otherwise, false.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferLockBaseAddress
Locks the base address of the pixel buffer.
CVReturn CVPixelBufferLockBaseAddress ( CVPixelBufferRef pixelBuffer, CVOptionFlags lockFlags );
Parameters
- pixelBuffer
The pixel buffer whose base address you want to lock.
- lockFlags
No options currently defined; pass
0.
Return Value
A Core Video result code. See Core Video Constants Reference for possible values.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferRelease
Releases a pixel buffer.
void CVPixelBufferRelease ( CVPixelBufferRef texture );
Parameters
- buffer
The pixel buffer that you want to release.
Discussion
This function is equivalent to CFRelease, but is NULL safe.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferRetain
Retains a pixel buffer.
CVPixelBufferRef CVPixelBufferRetain ( CVPixelBufferRef texture );
Parameters
- buffer
The pixel buffer that you want to retain.
Return Value
For convenience, the same pixel buffer you want to retain.
Discussion
This function is equivalent to CFRetain, but is NULL safe.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferUnlockBaseAddress
Unlocks the base address of the pixel buffer.
CVReturn CVPixelBufferUnlockBaseAddress ( CVPixelBufferRef pixelBuffer, CVOptionFlags unlockFlags );
Parameters
- pixelBuffer
The pixel buffer whose base address you want to unlock.
- unlockFlags
No options currently defined; pass
0.
Return Value
A Core Video result code. See Core Video Constants Reference for possible values.
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCallbacks
CVPixelBufferReleaseBytesCallback
Defines a pointer to a pixel buffer release callback function, which is called when a pixel buffer created by CVPixelBufferCreateWithBytes is released.
typedef void (*CVPixelBufferReleaseBytesCallback)( void *releaseRefCon, const void *baseAddress );
You would declare a pixel buffer release callback named MyPixelBufferReleaseCallback like this:
void MyPixelBufferReleaseCallback( void *releaseRefCon, const void *baseAddress );
Parameters
- releaseRefCon
A pointer to application-defined data. This pointer is the same as that passed in the
releaseRefConparameter ofCVPixelBufferCreateWithBytes.- baseAddress
A pointer to the base address of the memory holding the pixels. This pointer is the same as that passed in the
baseAddressparameter ofCVPixelBufferCreateWithBytes.
Discussion
You use this callback to release the pixels and perform any other cleanup when a pixel buffer is released.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hCVPixelBufferReleasePlanarBytesCallback
Defines a pointer to a pixel buffer release callback function, which is called when a pixel buffer created by CVPixelBufferCreateWithPlanarBytes is released.
typedef void (*CVPixelBufferReleasePlanarBytesCallback)( void *releaseRefCon, const void *dataPtr, size_t dataSize, size_t numberOfPlanes, const void *planeAddresses[] );
You would declare a callback named MyPixelBufferReleasePlanarBytes like this:
void MyPixelBufferReleasePlanarBytes)( void *releaseRefCon, const void *dataPtr, size_t dataSize, size_t numberOfPlanes, const void *planeAddresses[] );
Parameters
- releaseRefCon
A pointer to application-defined data. This pointer is the same as that passed in the
releaseRefConparameter ofCVPixelBufferCreateWithPlanarBytes.- dataPtr
A pointer to a plane descriptor block. This is the same pointer you passed to
CVPixelBufferCreateWithPlanarBytesin thedataPtrparameter.- dataSize
The size value you passed to
CVPixelBufferCreateWithPlanarBytesin thedataSizeparameter.- numberOfPlanes
The number of planes value you passed to
CVPixelBufferCreateWithPlanarBytesin thenumberOfPlanesparameter.- planeAddresses
A pointer to the base plane address you passed to
CVPixelBufferCreateWithPlanarBytesin thebasePlaneAddressparameter.
Discussion
You use this callback to release the pixels and perform any other cleanup when a pixel buffer is released.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hData Types
CVPixelBufferRef
A reference to a Core Video pixel buffer object.
typedef CVImageBufferRef CVPixelBufferRef;
Discussion
The pixel buffer stores an image in main memory.
Availability
- Available in iOS 4.0 and later.
Declared In
CVPixelBuffer.hConstants
Pixel Buffer Attribute Keys
The attributes associated with a pixel buffer.
const CFStringRef kCVPixelBufferPixelFormatTypeKey; const CFStringRef kCVPixelBufferMemoryAllocatorKey; const CFStringRef kCVPixelBufferWidthKey; const CFStringRef kCVPixelBufferHeightKey; const CFStringRef kCVPixelBufferExtendedPixelsLeftKey; const CFStringRef kCVPixelBufferExtendedPixelsTopKey; const CFStringRef kCVPixelBufferExtendedPixelsRightKey; const CFStringRef kCVPixelBufferExtendedPixelsBottomKey; const CFStringRef kCVPixelBufferBytesPerRowAlignmentKey; const CFStringRef kCVPixelBufferCGBitmapContextCompatibilityKey; const CFStringRef kCVPixelBufferCGImageCompatibilityKey; const CFStringRef kCVPixelBufferOpenGLCompatibilityKey; const CFStringRef kCVPixelBufferIOSurfacePropertiesKey; const CFStringRef kCVPixelBufferPlaneAlignmentKey;
Constants
kCVPixelBufferPixelFormatTypeKeyThe pixel format for this buffer (type
CFNumber, or typeCFArraycontaining an array ofCFNumbertypes (actually typeOSType)). For a listing of common pixel formats, see the QuickTime Ice Floe Dispatch 20.Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferMemoryAllocatorKeyThe allocator used with this buffer (type
CFAllocatorRef).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferWidthKeyThe width of the pixel buffer (type
CFNumber).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferHeightKeyThe height of the pixel buffer (type
CFNumber).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferExtendedPixelsLeftKeyThe number of pixels padding the left of the image (type
CFNumber).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferExtendedPixelsTopKeyThe number of pixels padding the top of the image (type
CFNumber).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferExtendedPixelsRightKeyThe number of pixels padding the right of the image (type
CFNumber).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferExtendedPixelsBottomKeyThe number of pixels padding the bottom of the image (type
CFNumber).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferBytesPerRowAlignmentKeyIndicates the number of bytes per row in the pixel buffer (type
CFNumber).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferCGBitmapContextCompatibilityKeyIndicates whether the pixel buffer is compatible with Core Graphics bitmap contexts (type
CFBoolean).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferCGImageCompatibilityKeyIndicates whether the pixel buffer is compatible with
CGImagetypes (typeCFBoolean).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferOpenGLCompatibilityKeyIndicates whether the pixel buffer is compatible with OpenGL contexts (type
CFBoolean).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferIOSurfacePropertiesKeyIndicates optional properties in the IOSurface framework (type
CFDictionary). An empty dictionary indicates default values.Presence of this key requests allocation via the IOSurface framework.
Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.kCVPixelBufferPlaneAlignmentKeySpecifies the alignment of the planes within the buffer. Planes will start on a byte number which is a multiple of this value. (type
CFNumber).Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.
Discussion
You specify these keys in a Core Foundation dictionary when calling functions such as CVPixelBufferCreate.
Pixel Buffer Locking Flags
The flags to pass to CVPixelBufferLockBaseAddress and CVPixelBufferUnlockBaseAddress.
enum CVPixelBufferLockFlags {
kCVPixelBufferLock_ReadOnly = 0x00000001,
};
Constants
kCVPixelBufferLock_ReadOnlyA read-only buffer.
If you are not going to modify the data while you hold the lock, you should set this flag to avoid potentially invalidating any existing caches of the buffer contents. This flag should be passed to both the lock and the unlock functions. Non symmetrical usage of this flag will result in undefined behavior.
Available in iOS 4.0 and later.
Declared in
CVPixelBuffer.h.
Discussion
You should set these attributes when adding attachments to a CVBuffer object.
© 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-08-03)