Performs alpha compositing of two RGBA8888 images using the multiply blend mode to produce a premultiplied result.


func vImagePremultipliedAlphaBlendMultiply_RGBA8888(_ srcTop: UnsafePointer<vImage_Buffer>, _ srcBottom: UnsafePointer<vImage_Buffer>, _ dest: UnsafePointer<vImage_Buffer>, _ flags: vImage_Flags) -> vImage_Error



A pointer to a vImage buffer structure that contains data for the top source image.


A pointer to a vImage buffer structure that contains data for the bottom source image.


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.


The options to use when performing the compositing. 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.


For each pixel:

// For color channels:
uint8_t destColor =((255 -    srcTopAlpha) * srcBottomColor +
                    (255 - srcBottomAlpha) * srcTopColor + 
                     srcTopColor * srcBottomColor + 127)/255;
// For the alpha channel:
uint8_t alpha =  srcTopAlpha + ((255 - srcTopAlpha) * srcBottomAlpha + 127)/255;

This function can work in place provided the following are true:

  • For each buffer, buf, that overlaps with dest, buf->data is equal to dest->data.

  • If an overlapping buffer has a different rowBytes from dest, kvImageDoNotTile is also passed in the flags

See Also

Performing Premultiplied Alpha Compositing With Blend Modes