vImageExtractChannel_ARGB16U(_:_:_:_:)
Extracts a single channel from an unsigned 16-bit-per-channel, 4-channel interleaved buffer and writes the result to an unsigned 16-bit planar buffer.
Declaration
func vImageExtractChannel_ARGB16U(_ src: UnsafePointer<vImage_Buffer>, _ dest: UnsafePointer<vImage_Buffer>, _ channelIndex: Int, _ flags: vImage_Flags) -> vImage_ErrorParameters
- src:
The source vImage buffer.
- dest:
A pointer to the destination vImage buffer structure. You’re responsible for filling out the Height, Width, and Rowbytes fields of this structure, and for allocating a data buffer of the appropriate size. On return, the data buffer this structure points to contains the destination image data. When you no longer need the data buffer, deallocate the memory to prevent memory leaks.
- channelIndex:
The index of the channel that the function extracts.
- flags:
The options to use when performing the operation. If your code implements its own tiling or its own multithreading, pass Kvimagedonottile; otherwise, pass Kvimagenoflags.
Return Value
kvImageNoError; otherwise, one of the error codes in Data Types and Constants.
Discussion
The following code extracts channel 1 from the source buffer and writes the result to the destination buffer:
let source = vImage.PixelBuffer<vImage.Interleaved16Ux4>(
pixelValues: [10, 20, 30, 40,
50, 60, 70, 80],
size: .init(width: 1, height: 2))
let destination = vImage.PixelBuffer<vImage.Planar16U>(
size: source.size
)
source.withUnsafePointerToVImageBuffer { src in
destination.withUnsafePointerToVImageBuffer { dst in
_ = vImageExtractChannel_ARGB16U(src,
dst,
1,
vImage_Flags(kvImageNoFlags))
}
}
// Prints:
// "[20,
// 60]"
print(destination.array)