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
CGImage property of an image. In the following example, the image is named
init(cg function initializes a
v structure with the image data using the format discussed in Creating a Core Graphics Image Format.
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
init(width: 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: