/*! 为给定大小和像素格式创建单个像素缓冲区 @function CVPixelBufferCreate @abstract Call to create a single PixelBuffer for a given size and pixelFormatType. @discussion Creates a single PixelBuffer for a given size and pixelFormatType. It allocates the necessary memory based on the pixel dimensions, pixelFormatType and extended pixels described in the pixelBufferAttributes. Not all parameters of the pixelBufferAttributes will be used here. @param width Width of the PixelBuffer in pixels. @param height Height of the PixelBuffer in pixels. @param pixelFormatType Pixel format indentified by its respective OSType. @param pixelBufferAttributes A dictionary with additional attributes for a pixel buffer. This parameter is optional. See BufferAttributeKeys for more details. @param pixelBufferOut The new pixel buffer will be returned here @result returns kCVReturnSuccess on success. */ CV_EXPORT CVReturn CVPixelBufferCreate( CFAllocatorRef CV_NULLABLE allocator, size_t width, size_t height, OSType pixelFormatType, CFDictionaryRef CV_NULLABLE pixelBufferAttributes, CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL pixelBufferOut) __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);
/*! 为给定大小和像素格式创建一个像素缓冲区,其中包含由内存位置指定的数据 @function CVPixelBufferCreateWithBytes @abstract Call to create a single PixelBuffer for a given size and pixelFormatType based on a passed in piece of memory. @discussion Creates a single PixelBuffer for a given size and pixelFormatType. Not all parameters of the pixelBufferAttributes will be used here. It requires a release callback function that will be called, when the PixelBuffer gets destroyed so that the owner of the pixels can free the memory. @param width Width of the PixelBuffer in pixels @param height Height of the PixelBuffer in pixels @param pixelFormatType Pixel format indentified by its respective OSType. @param baseAddress Address of the memory storing the pixels. @param bytesPerRow Row bytes of the pixel storage memory. @param releaseCallback CVPixelBufferReleaseBytePointerCallback function that gets called when the PixelBuffer gets destroyed. @param releaseRefCon User data identifying the PixelBuffer for the release callback. @param pixelBufferAttributes A dictionary with additional attributes for a a pixel buffer. This parameter is optional. See PixelBufferAttributes for more details. @param pixelBufferOut The new pixel buffer will be returned here @result returns kCVReturnSuccess on success.
/*! @function CVPixelBufferCreateWithPlanarBytes @abstract Call to create a single PixelBuffer in planar format for a given size and pixelFormatType based on a passed in piece of memory. @discussion Creates a single PixelBuffer for a given size and pixelFormatType. Not all parameters of the pixelBufferAttributes will be used here. It requires a release callback function that will be called, when the PixelBuffer gets destroyed so that the owner of the pixels can free the memory. @param width Width of the PixelBuffer in pixels @param height Height of the PixelBuffer in pixels @param pixelFormatType Pixel format indentified by its respective OSType. @param dataPtr Pass a pointer to a plane descriptor block, or NULL. @param dataSize pass size if planes are contiguous, NULL if not. @param numberOfPlanes Number of planes. @param planeBaseAddress Array of base addresses for the planes. @param planeWidth Array of plane widths. @param planeHeight Array of plane heights. @param planeBytesPerRow Array of plane bytesPerRow values. @param releaseCallback CVPixelBufferReleaseBytePointerCallback function that gets called when the PixelBuffer gets destroyed. @param releaseRefCon User data identifying the PixelBuffer for the release callback. @param pixelBufferAttributes A dictionary with additional attributes for a a pixel buffer. This parameter is optional. See PixelBufferAttributes for more details. @param pixelBufferOut The new pixel buffer will be returned here @result returns kCVReturnSuccess on success. */ CV_EXPORT CVReturn CVPixelBufferCreateWithPlanarBytes( CFAllocatorRef CV_NULLABLE allocator, size_t width, size_t height, OSType pixelFormatType, void * CV_NULLABLE dataPtr, // pass a pointer to a plane descriptor block, or NULL size_t dataSize, // pass size if planes are contiguous, NULL if not size_t numberOfPlanes, void * CV_NULLABLE planeBaseAddress[CV_NONNULL ], size_t planeWidth[CV_NONNULL ], size_t planeHeight[CV_NONNULL ], size_t planeBytesPerRow[CV_NONNULL ], CVPixelBufferReleasePlanarBytesCallback CV_NULLABLE releaseCallback, void * CV_NULLABLE releaseRefCon, CFDictionaryRef CV_NULLABLE pixelBufferAttributes, CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL pixelBufferOut) __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);
修改
在使用 CPU 访问像素数据之前必须调用CVPixelBufferLockBaseAddress,然后再调用CVPixelBufferUnlockBaseAddress。 而使用 GPU 访问像素数据时,就没有这个必要了。
填充扩展的PixelBuffer
1 2 3 4 5 6 7 8 9
/*! 填充扩展的PixelBuffer @function CVPixelBufferFillExtendedPixels @abstract Fills the extended pixels of the PixelBuffer. This function replicates edge pixels to fill the entire extended region of the image. @param pixelBuffer Target PixelBuffer.
/*! 锁定PixelBuffer地址 @function CVPixelBufferLockBaseAddress @abstract Description Locks the BaseAddress of the PixelBuffer to ensure that the memory is accessible. @discussion This API ensures that the CVPixelBuffer is accessible in system memory. This should only be called if the base address is going to be used and the pixel data will be accessed by the CPU. @param pixelBuffer Target PixelBuffer. @param lockFlags See CVPixelBufferLockFlags. @result kCVReturnSuccess if the lock succeeded, or error code on failure
@function CVPixelBufferUnlockBaseAddress @abstract Description Unlocks the BaseAddress of the PixelBuffer. @param pixelBuffer Target PixelBuffer. @param unlockFlags See CVPixelBufferLockFlags. @result kCVReturnSuccess if the unlock succeeded, or error code on failure */
/*! 引用计数+1 @function CVPixelBufferRetain @abstract Retains a CVPixelBuffer object @discussion Equivalent to CFRetain, but NULL safe @param buffer A CVPixelBuffer object that you want to retain. @result A CVPixelBuffer object that is the same as the passed in buffer. */ CV_EXPORT CVPixelBufferRef CV_NULLABLE CVPixelBufferRetain( CVPixelBufferRef CV_NULLABLE texture ) __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);
释放
1 2 3 4 5 6 7 8
/*! 引用计数-1 @function CVPixelBufferRelease @abstract Releases a CVPixelBuffer object @discussion Equivalent to CFRelease, but NULL safe @param buffer A CVPixelBuffer object that you want to release. */ CV_EXPORT void CVPixelBufferRelease( CV_RELEASES_ARGUMENT CVPixelBufferRef CV_NULLABLE texture ) __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);