Contents

vImageFlatten_ARGB16Q12(_:_:_:_:_:)

Performs an alpha composite of a fixed-point 16-bit-per-channel, 4-channel ARGB buffer over a solid background color.

Declaration

func vImageFlatten_ARGB16Q12(_ argbSrc: UnsafePointer<vImage_Buffer>, _ argbDst: UnsafePointer<vImage_Buffer>, _ argbBackgroundColorPtr: UnsafePointer<Int16>, _ isImagePremultiplied: Bool, _ flags: vImage_Flags) -> vImage_Error

Parameters

  • argbSrc:

    The source vImage buffer.

  • argbDst:

    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.

  • argbBackgroundColorPtr:

    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.

Return Value

kvImageNoError; otherwise, one of the error codes in Data Types and Constants.

Discussion

The function uses the following calculation to flatten the source image:

 pixelAlpha = CLAMP( 0, pixelAlpha, 4096);

 resultAlpha = (pixelAlpha * 4096 + (4096 - pixelAlpha) * backgroundAlpha + 2048) >> 12;
 
 if(isImagePremultiplied)
     resultColor = (pixelColor * 4096 + (4096 - pixelAlpha) * backgroundColor + 2048) >> 12
 else
     resultColor = (pixelColor * pixelAlpha + (4096 - pixelAlpha) * backgroundColor + 2048) >> 12

See Also

Flattening 4-channel,16-bit images