Function

vImageFlatten_BGRA8888ToRGB888(_:_:_:_:_:)

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

Declaration

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

Parameters

bgra8888Src

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

A floating-point 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.

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