Alpha Compositing

Composite images together.

Overview

Alpha compositing (also known as alpha blending) is the process of layering multiple images, with the alpha value for a pixel in a given layer indicating what fraction of the colors from lower layers are seen through the color at the given level. The functions described in this reference operate on the alpha values of pixels either by blending alpha values or clipping them.

Most of the alpha compositing functions blend two input images—a top image and a bottom image—to create a composite image. The vImage framework computes the alpha values of the composite image from the alpha values of the input images. Some functions operate on interleaved formats (ARGB8888, ARGBFFFF, RGBA8888, RGBAFFFF) while others operate on planar formats. Interleaved formats contain an alpha value for each pixel, but planar formats do not. To perform alpha compositing with planar images, you need to supply the alpha information separately.

Alpha compositing functions by default perform tiling internally and may multithread internally as well. If you plan to perform your own tiling or multithreading, you must turn off vImage internal tiling and multithreading by supplying the kvImageDoNotTile flag as an option to the functions you use.

The vImage framework provides functions for alpha compositing for both the premultiplied alpha case and the nonpremultiplied alpha case, and includes alpha compositing functions for common mixed cases. Premultiplying pixel color values by the associated alpha value results in greater computational efficiency than providing nonpremultiplied data, especially when you composite more than two images. When you use premultiplied alpha, you still need to maintain the original alpha information, so that you can retrieve the original, nonpremultiplied values of the pixels when you need them. You also need to supply the original alpha value for the bottom layer in a compositing operation.

For floating-point formats, you can multiply the color value by the alpha value directly. For integer formats in which both values are in the range of 0 to 255, you multiply the color and alpha values, then you must scale the result so that it is in the 0 to 255 range. The scaling calculation is:

scaledColor = (alpha * color + 127) / 255

Alpha compositing functions use a vImage buffer structure (vImage_Buffer—see Data Types and Constants) to receive and supply image data. This buffer contains a pointer to image data, the height and width (in pixels) of the image data, and the number of row bytes. You actually pass a pointer to a vImage buffer structure. You can provide a pointer to the same vImage buffer structure for one of the source images and the destination image because alpha compositing functions “work in place”. That is , the source and destination images can occupy the same memory if the they are strictly aligned pixel for pixel.

Topics

Performing Premultiplied Alpha Compositing

func vImagePremultipliedAlphaBlend_ARGB8888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Performs premultiplied alpha compositing of two ARGB8888 images, placing the result in a destination buffer.

func vImagePremultipliedAlphaBlend_BGRAFFFF(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Performs premultiplied alpha compositing of two BGRAFFFF images, placing the result in a destination buffer.

func vImagePremultipliedAlphaBlend_BGRA8888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Performs premultiplied alpha compositing of two BGRA8888 images, placing the result in a destination buffer.

Performing Premultiplied Alpha Compositing With Blend Modes

Performing Premultiplied Alpha Compositing With a Permute

func vImagePremultipliedAlphaBlendWithPermute_ARGB8888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<UInt8>, Bool, vImage_Flags) -> vImage_Error

Reorders the channels of the top 8-bit, 4-channel, premultiplied image, and blends the image into a bottom premultiplied, ARGB8888 image.

func vImagePremultipliedAlphaBlendWithPermute_RGBA8888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<UInt8>, Bool, vImage_Flags) -> vImage_Error

Reorders the channels of the top 8-bit, 4-channel, premultiplied image, and blends the image into a bottom premultiplied, RGBA8888 image.

Performing Premultiplied Alpha Compositing With a Single Alpha Value

func vImagePremultipliedConstAlphaBlend_ARGBFFFF(UnsafePointer<vImage_Buffer>, Pixel_F, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Performs premultiplied alpha compositing of two ARGBFFFF images, using a single alpha value for the whole image and placing the result in a destination buffer.

func vImagePremultipliedConstAlphaBlend_ARGB8888(UnsafePointer<vImage_Buffer>, Pixel_8, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Performs premultiplied alpha compositing of two ARGB8888 images, using a single alpha value for the whole image and placing the result in a destination buffer.

func vImagePremultipliedConstAlphaBlend_PlanarF(UnsafePointer<vImage_Buffer>, Pixel_F, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Performs premultiplied alpha compositing of a two PlanarF images, using a single alpha value for the whole image and placing the result in a destination buffer.

func vImagePremultipliedConstAlphaBlend_Planar8(UnsafePointer<vImage_Buffer>, Pixel_8, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Performs premultiplied alpha compositing of two Planar8 images, using a single alpha value for the entire image and placing the result in a destination buffer.

Performing Nonpremultiplied to Premultiplied Alpha Compositing

func vImageAlphaBlend_NonpremultipliedToPremultiplied_ARGBFFFF(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Performs mixed alpha compositing of a nonpremultiplied ARGBFFFF image over a premultiplied ARGBFFFF image, to produce a premultiplied result.

func vImageAlphaBlend_NonpremultipliedToPremultiplied_ARGB8888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Performs mixed alpha compositing of a nonpremultiplied ARGB8888 image over a premultiplied ARGB8888 image, to produce a premultiplied result.

Converting from Unpremultiplied to Premultiplied Format

func vImagePremultiplyData_ARGBFFFF(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an ARGBFFFF image in nonpremultiplied alpha format into an image in premultiplied alpha format.

func vImagePremultiplyData_ARGB8888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an ARGB8888 image in nonpremultiplied alpha format into an image in premultiplied alpha format.

func vImagePremultiplyData_ARGB16U(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an ARGB16U image in nonpremultiplied alpha format, along with alpha information, into an image in premultiplied alpha format.

func vImagePremultiplyData_ARGB16Q12(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an ARGB16Q12 image in nonpremultiplied alpha format, along with alpha information, into an image in premultiplied alpha format.

func vImagePremultiplyData_RGBAFFFF(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an RGBAFFFF image in nonpremultiplied alpha format into an image in premultiplied alpha format.

func vImagePremultiplyData_RGBA8888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an RGBA8888 image in nonpremultiplied alpha format into an image in premultiplied alpha format.

func vImagePremultiplyData_RGBA16U(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an RGBA16U image in nonpremultiplied alpha format, along with alpha information, into an image in premultiplied alpha format.

func vImagePremultiplyData_RGBA16Q12(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an RGBA16Q12U image in nonpremultiplied alpha format, along with alpha information, into an image in premultiplied alpha format.

func vImagePremultiplyData_PlanarF(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms a PlanarF image in nonpremultiplied alpha format, along with alpha information, into an image in premultiplied alpha format.

func vImagePremultiplyData_Planar8(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms a Planar8 image in nonpremultiplied alpha format, along with alpha information, into an image in premultiplied alpha format.

Converting from Premultiplied to Unpremultiplied Format

func vImageUnpremultiplyData_ARGBFFFF(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an ARGBFFFF image in premultiplied alpha format into an image in nonpremultiplied alpha format.

func vImageUnpremultiplyData_ARGB8888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an ARGB8888 image in premultiplied alpha format into an image in nonpremultiplied alpha format.

func vImageUnpremultiplyData_ARGB16U(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an ARGB16U image in premultiplied alpha format into an image in nonpremultiplied alpha format.

func vImageUnpremultiplyData_ARGB16Q12(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms an ARGB16Q12 image in premultiplied alpha format into an image in nonpremultiplied alpha format.

func vImageUnpremultiplyData_RGBAFFFF(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms a RGBAFFFF image in premultiplied alpha format into an image in nonpremultiplied alpha format.

func vImageUnpremultiplyData_RGBA8888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms a RGBA8888 image in premultiplied alpha format into an image in nonpremultiplied alpha format.

func vImageUnpremultiplyData_RGBA16U(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms a RGBA16U image in premultiplied alpha format into an image in nonpremultiplied alpha format.

func vImageUnpremultiplyData_RGBA16Q12(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms a RGBA16Q12 image in premultiplied alpha format it into an image in nonpremultiplied alpha format.

func vImageUnpremultiplyData_PlanarF(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms a PlanarF image in premultiplied alpha format, along with alpha information, into an image in nonpremultiplied alpha format.

func vImageUnpremultiplyData_Planar8(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Transforms a Planar8 image in premultiplied alpha format, along with alpha information, into an image in nonpremultiplied alpha format.

Clipping Color Values to Alpha

See Also