premultiply()
Transforms a floating-point 16-bit RGBA pixel buffer in-place from nonpremultiplied alpha format to premultiplied alpha format.
Declaration
func premultiply()Discussion
This function multiplies the color values in each pixel self by the corresponding alpha value and copies the alpha value to the destination unchanged.
For example, the following code multiplies the RGB values [0.125, 0.25, 0.5] by the alpha value 0.5:
let pixelValues = [0.125, 0.25, 0.5,
Float(0.5)].map {
return vImage.Planar16F.makePixel($0)
}
let src = vImage.PixelBuffer<vImage.Interleaved16Fx4>(
pixelValues: pixelValues,
size: vImage.Size(width: 1, height: 1))
src.premultiply()
let result = src.array.map {
return vImage.PlanarF.makePixel($0)
}
// Prints "[0.0625, 0.125, 0.25, 0.5]".
print(result)