Function

vImageFlatten_ARGB8888ToRGB888(_:_:_:_:_:)

Transforms an ARGB8888 image to an RGB888 image against an opaque background of the provided color.

Declaration

func vImageFlatten_ARGB8888ToRGB888(_: UnsafePointer<vImage_Buffer>, _: UnsafePointer<vImage_Buffer>, _: UnsafePointer<UInt8>, _: Bool, _: vImage_Flags) -> vImage_Error

Parameters

argb8888Src

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

rgb888dest

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.

backgroundColor

An 8-bit interleaved pixel value.

isImagePremultiplied

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

flags

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.

Discussion

If the source image uses premultiplied data, the function calculates each channel value for a pixel in the destination image as follows (where i is the source value for the channel):

    new value = (i * 255 + (255 - alpha) * backgroundColor + 127) / 255

If the source image does not use premultiplied data, the function calculates each channel value for a pixel in the destination image as follows (where i is the source value for the channel):

    new value = (i * alpha + (255 - alpha) * backgroundColor + 127) / 255

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