Contents

premultiply(alpha:)

Transforms a 32-bit planar pixel buffer in-place from nonpremultiplied alpha format to premultiplied alpha format.

Declaration

func premultiply(alpha: vImage.PixelBuffer<Format>)

Parameters

  • alpha:

    An 32-bit planar pixel buffer that contains the alpha.

Discussion

This function multiplies the color values in self by the corresponding alpha values. For example, the following code premultiplies a 4 x 1 planar pixel buffer with the corresponding pixels in a separate planar alpha buffer:

let src = vImage.PixelBuffer<vImage.PlanarF>(
    pixelValues: [0.125, 0.25, 0.5, 1],
    size: vImage.Size(width: 4, height: 1))

let alpha = vImage.PixelBuffer<vImage.PlanarF>(
    pixelValues: [0, 0.25, 0.5, 1],
    size: vImage.Size(width: 4, height: 1))

src.premultiply(alpha: alpha)

// Prints "[0, 0.0625, 0.25, 1]".
print(src.array)

See Also

Premultiply