Contents

unpremultiply(channelOrdering:)

Transforms an 8-bit ARGB or RGBA pixel buffer in-place from premultiplied alpha format to nonpremultiplied alpha format.

Declaration

func unpremultiply(channelOrdering: vImage.ChannelOrdering)

Parameters

  • channelOrdering:

    The channel ordering of the source buffer.

Discussion

This function divides the color values in each pixel self by the corresponding alpha value and copies the alpha value to the destination unchanged. The function treats the values 0 ... 255 in the pixel buffer as the values 0 ... 1.

For example, the following code divides the RGB values [32, 64, 128] by the alpha value 128 (interpreted as 0.5):

let src = vImage.PixelBuffer<vImage.Interleaved8x4>(
    pixelValues: [127, 32, 64, 128],
    size: vImage.Size(width: 1, height: 1))

src.unpremultiply(channelOrdering: .ARGB)

// Prints "[127, 64, 129, 255]".
print(src.array)

See Also

Unpremultiply