Initialize vImage buffers from Core Graphics images.
v structures are the basic data structures that vImage uses for working with images. They describe an image's dimensions and contain the pixel data that vImage routines operate on.
Typically, you'll initialize a source buffer from an image and initialize and allocate a destination buffer to receive the result of a vImage operation.
Initialize a Source Buffer from a Core Graphics Image
The vImage functions that initialize a buffer's size and data require an instantiated
v structure. Typically, you declare a buffer as a variable because these functions mutate the buffer:
You can initialize a vImage buffer from a
CGImage instance that's acquired from the
cg property of an image. In the following example, the image is named
v function initializes a
v structure with the image data using the format discussed in Creating a Core Graphics Image Format.
Many vImage functions return an error value. For example, if you pass an image that doesn't contain four 8-bit channels,
kv. To verify that the operation completed correctly, check the error value that the function returns.
Initialize and Allocate a Destination Buffer
Typically, in addition to creating a buffer to represent your source image, you create a destination buffer to receive the result of the vImage operation. In this case, you use the
v function to initialize a buffer of a specified size and the correct memory allocation for the bit-depth of the image:
Free the Buffer Memory
After you're finished with buffers that have have their own memory allocation, it's important that you free the memory allocated to them: