vImage_Buffer
An image buffer that stores an image’s pixel data, dimensions, and row stride.
Declaration
struct vImage_BufferMentioned in
- Enhancing image contrast with histogram manipulation
- Applying vImage operations to regions of interest
- Creating and Populating Buffers from Core Graphics Images
- Building a basic image conversion workflow
- Building a Basic Image-Processing Workflow
- Compositing images with vImage blend modes
- Converting bitmap data between Core Graphics images and vImage buffers
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)