Performs an alpha composite of an RGBA8888 image over a solid background color.


func vImageFlatten_RGBA8888(_ rgbaSrc: UnsafePointer<vImage_Buffer>, _ rgbaDst: UnsafePointer<vImage_Buffer>, _ rgbaBackgroundColorPtr: UnsafePointer<UInt8>, _ isImagePremultiplied: Bool, _ flags: vImage_Flags) -> vImage_Error



A pointer to a vImage buffer that references floating-point RGBA interleaved source pixels.


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 must deallocate the memory.


A pointer to Pixel_FFFF that references floating-point RGBA premultiplied background color.


True if the source image is premultiplied; otherwise, false.


The options to use when performing the operation. If you plan to perform your own tiling or use multithreading, pass kvImageDoNotTile.

Return Value

kvImageNoError; otherwise, one of the error codes described in Data Types and Constants.


The per-pixel operation is:

if( isImagePremultiplied )
    color = (color * 255 + (255 - alpha) * backgroundColor + 127) / 255else
color = (color * alpha + (255 - alpha) * backgroundColor + 127) / 255

The source and destination buffers must have the same height and width.

See Also

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software