withUnsafePixelBuffer(at:_:)
Calls the given closure with the pixel buffer that references the individual plane at the given index.
Declaration
func withUnsafePixelBuffer<R>(at index: Int, _ body: (vImage.PixelBuffer<Format.PlanarPixelFormat>) throws -> R) rethrows -> RParameters
- index:
The index of the plane.
- body:
A closure with a Pixelbuffer parameter that points to the underlying pixel buffer at the given index.
Return Value
The return value, if any, of the body closure parameter.
Discussion
Use this function to access a single planar pixel buffer from a multiple-plane pixel buffer. For example, the following code converts the 8-bit pixels at plane 2 to 32-bit and writes the result to dest:
let src = vImage.PixelBuffer<vImage.Planar8x4>(size: vImage.Size(width: 32,
height: 64))
let dest = vImage.PixelBuffer<vImage.PlanarF>(size: src.size)
src.withUnsafePixelBuffer(at: 2) { vImageBuffer in
vImageBuffer.convert(to: dest)
}