Function

CVPixelBufferCreateWithBytes(_:_:_:_:_:_:_:_:_:_:)

Creates a pixel buffer for a given size and pixel format containing data specified by a memory location.

Declaration

func CVPixelBufferCreateWithBytes(_ allocator: CFAllocator?, _ width: Int, _ height: Int, _ pixelFormatType: OSType, _ baseAddress: UnsafeMutableRawPointer, _ bytesPerRow: Int, _ releaseCallback: CVPixelBufferReleaseBytesCallback?, _ releaseRefCon: UnsafeMutableRawPointer?, _ pixelBufferAttributes: CFDictionary?, _ pixelBufferOut: UnsafeMutablePointer<CVPixelBuffer?>) -> CVReturn

Parameters

allocator

The allocator to use to create this buffer. Pass NULL to 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 CVPixelBufferReleaseBytesCallback for 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 pixel buffer. This parameter is optional. See Pixel Buffer Attribute Keys for more details.

pixelBufferOut

On output, the newly created pixel buffer. Ownership follows the The Create Rule.

Return Value

A Core Video result code. See Core Video Constants 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.