vImageFlatten_ARGB8888ToRGB888(_:_:_:_:_:)
Flattens an 8-bit-per-channel ARGB buffer against a solid background to produce an 8-bit-per-channel RGB result.
Declaration
func vImageFlatten_ARGB8888ToRGB888(_: UnsafePointer<vImage_Buffer>, _: UnsafePointer<vImage_Buffer>, _: UnsafePointer<UInt8>, _: Bool, _: vImage_Flags) -> vImage_ErrorReturn Value
kvImageNoError; otherwise, one of the error codes in Data Types and Constants.
Discussion
Parameters
- argb8888Src
The source vImage buffer.
- rgb888dest
A pointer to the destination vImage buffer 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, deallocate the memory to prevent memory leaks.
- backgroundColor
A pixel value that defines the solid background color.
- isImagePremultiplied
A Boolean value that specifes whether the source image has premultiplied alpha.
- flags
The options to use when performing the operation. If your code implements its own tiling or its own multithreading, pass kvImageDoNotTile; otherwise, pass kvImageNoFlags.
The function uses the following calculation to flatten the source image:
if( isImagePremultiplied )
color = (color * 255 + (255 - alpha) * backgroundColor + 127) / 255
else
color = (color * alpha + (255 - alpha) * backgroundColor + 127) / 255