Contents

applyGamma(_:intermediateBuffer:destination:)

Applies a gamma function to an 8-bit planar pixel buffer.

Declaration

func applyGamma(_ gamma: vImage.Gamma, intermediateBuffer: vImage.PixelBuffer<vImage.PlanarF>? = nil, destination: vImage.PixelBuffer<vImage.Planar8>)

Parameters

  • gamma:

    An enumeration that specifies either a used-defined or constant gamma.

  • intermediateBuffer:

    An optional intermediate buffer.

  • destination:

    The destination pixel buffer.

Discussion

This operation applies gamma to an vImage.Planar8 buffer by calling the underlying function vImageGamma_Planar8toPlanarF(_:_:_:_:). Therefore, it requires an intermediate vImage.PlanarF buffer. For the best performance, pass an existing vImage.PlanarF buffer to intermediateBuffer, alternatively, pass `nil` to specify that the function creates the intermediate buffer.

For example, the following code applies a gamma of 2.0 to a one-pixel pixel buffer:

let buffer = vImage.PixelBuffer<vImage.Planar8>(
    pixelValues: [128],
    size: vImage.Size(width: 1,
                      height: 1))

buffer.applyGamma(.fullPrecision(2),
                  destination: buffer)

// Prints "[64]" ≅ [255 * 0.5²].
print(buffer.array)

See Also

Applying gamma