Contents

vImage.PixelBuffer

An image buffer that stores an image’s pixel data, dimensions, bit depth, and number of channels.

Declaration

struct PixelBuffer<Format> where Format : PixelFormat

Mentioned in

Overview

Use a vImage.PixelBuffer to represent an image from a CGImage instance, a CVPixelBuffer structure, or a collection of raw pixel values. Pixel buffers are typed by their bits per channel and number of channels. For example, vImage.Interleaved8x4 indicates a 4-channel, 8-bit-per-channel pixel buffer that contains image data such as RGBA or CMYK.

Pixel buffers expose methods that are available for the buffer’s pixel format. For example, the fast box convolution functions are only available for one- and four-channel 8-bit per channel buffers:

 let src = vImage.PixelBuffer<vImage.Interleaved8x4>(cgImage: cgImage,
                                                     cgImageFormat: &cgImageFormat)
 let dest = vImage.PixelBuffer<vImage.Interleaved8x4>(src.size)

 src.boxConvolve(kernelSize: vImage.Size(width: 64, height: 64),
                 edgeMode: .truncateKernel,
                 destination: dest)

Typed pixel buffers provide a simple API to convert between pixel formats. For example, the following code converts 8-bit unsigned integer pixels to 32-bit floating point pixels:

 let src = vImage.PixelBuffer<vImage.Interleaved8x4>(cgImage: cgImage,
                                                     cgImageFormat: &cgImageFormat)
 let dest = vImage.PixelBuffer<vImage.InterleavedFx4>(size: src.size)

 src.convert(to: dest)

vImage pixel buffers manage their memory, therefore, you don’t need to call deallocate() when you’re finished with the buffer.

Topics

Pixel buffer essentials

Inspecting a pixel buffer

Pixel buffer methods

Pixel buffer operations

Instance Properties

Instance Methods

Default Implementations

See Also

vImage Pixel Buffers