Contents

vImageAffineWarpCG_ARGBFFFF(_:_:_:_:_:_:)

Applies a Core Graphics affine transformation to an ARGBFFFF source image.

Declaration

func vImageAffineWarpCG_ARGBFFFF(_ src: UnsafePointer<vImage_Buffer>, _ dest: UnsafePointer<vImage_Buffer>, _ tempBuffer: UnsafeMutableRawPointer!, _ transform: UnsafePointer<vImage_CGAffineTransform>, _ backColor: UnsafePointer<Float>!, _ flags: vImage_Flags) -> vImage_Error

Parameters

  • src:

    A pointer to a vImage buffer structure that contains the source image whose data you want to transform.

  • dest:

    A pointer to a vImage buffer data structure. You’re responsible for filling out the height, width, and rowBytes fields of this structure, and for allocating a data buffer of the appropriate size. On return, the data buffer this structure points to contains the destination image data. When you no longer need the data buffer, you need to deallocate the memory.

  • tempBuffer:

    A pointer to workspace memory the function uses as it operates on an image. Pass nil to instruct the function to allocate, use, and then free its own temporary buffer.

  • transform:

    The affine transformation matrix to apply to the source image.

  • backColor:

    A background color. Pass a pixel value only if you also set the kvImageBackgroundColorFill flag.

  • flags:

    The options to use when applying the rotation.

    To instruct the function to return the minimum size of the workspace memory, set the Kvimagegettempbuffersize flag.

    To specify how vImage handles pixel locations beyond the edge of the source image, you must set exactly one of the following flags: Kvimagebackgroundcolorfill or Kvimageedgeextend.

    If you want vImage to use a higher quality, but slower resampling filter, set the Kvimagehighqualityresampling flag.

    If your code implements its own tiling or its own multithreading, pass Kvimagedonottile.

    This function ignores the Kvimageleavealphaunchanged flag.

Return Value

kvImageNoError; otherwise, a negative value indicates one of the error codes that Data Types and Constants describes, and a positive value indicates the required size for the temporary buffer.

Discussion

Core Graphics types use float values in 32-bit and double values in 64-bit. This convenience method takes the Core Graphics affine transform type directly so that you don’t have to use a different function for 64-bit applications.

This function maps each pixel in the source image [x, y] to a new position [x’, y’] in the destination image, using this formula:

(x', y') = (x, y) * transform

where transform is the 3x3 affine transformation matrix.

Optimize performance with temporary buffers

This function uses a multiple-pass algorithm that saves intermediate pixel values between passes. In some cases, the destination buffer may not be large enough to store that intermediate data, so the operation requires additional storage.

Pass nil to the tempBuffer parameter to have vImage create and manage this temporary storage for you.

In cases where your code calls the function frequently (for example, when processing video), create and manage this temporary buffer yourself and reuse it across function calls. Reusing a buffer avoids vImage allocating the temporary storage with each call.

To use your own temporary buffer, first call the function with the same values for all other parameters that you intend to use for subsequent calls. In addition, pass the kvImageGetTempBufferSize flag. The kvImageGetTempBufferSize instructs the function not to perform any processing, and to return a positive value that represents the minimum size, in bytes, of the temporary buffer. A negative return value represents an error.

After you allocate the memory for the temporary buffer, pass that to the tempBuffer parameter for subsequent calls to the function, and don’t pass the kvImageGetTempBufferSize flag.

You can use the same workspace memory for a group of images that are different sizes. To do this, create a vImage buffer structure with a size that shares the maximum width and maximum height of the images that you’re working with. For example, to create a workspace memory that’s suitable for 4x4, 5x4, and 4x5 images, pass a buffer with the size 5x5.

See Also

Core Graphics Affine Transformation