Contents

vImage_Buffer

An image buffer that stores an image’s pixel data, dimensions, and row stride.

Declaration

struct vImage_Buffer

Mentioned in

Overview

The vImage buffer is the fundamental data structure that the vImage library uses to represent image data. To ensure the best performance, the vImage buffer initialization functions may add extra padding to each row. For example, the following code declares an 8-bit per pixel buffer that’s 10 pixels wide:

var buffer = vImage_Buffer()

vImageBuffer_Init(&buffer,
                  5,    // height
                  10,   // width
                  8,    // bits per pixel
                  vImage_Flags(kvImageNoFlags))

Although the code defines a buffer with 10 bytes per row, to maximize performance, vImageBuffer_Init(_:_:_:_:_:) initializes a buffer with 16 bytes per row:

[Image]

If you provide your own buffer storage, call preferredAlignmentAndRowBytes(width:height:bitsPerPixel:) to get the row stride that ensures your buffer achieves the best performance.

let width = 10
let height = 5

let alignmentAndRowBytes = try vImage_Buffer.preferredAlignmentAndRowBytes(
    width: width,
    height: height,
    bitsPerPixel: 8)

// Prints "16".
print(alignmentAndRowBytes.rowBytes)

let data = UnsafeMutableRawPointer.allocate(
    byteCount: alignmentAndRowBytes.rowBytes * height,
    alignment: alignmentAndRowBytes.alignment)

let buffer = vImage_Buffer(data: data,
                           height: vImagePixelCount(height),
                           width: vImagePixelCount(width),
                           rowBytes: alignmentAndRowBytes.rowBytes)

Topics

Creating an empty vImage buffer

Creating a buffer that references existing data

Consuming and producing Core Graphics images

Inspecting a buffer’s properties

Copying a buffer’s contents

Deallocating a buffer

See Also

Data Types