vImageMatrixMultiply_ARGB8888(_:_:_:_:_:_:_:)
Multiplies each pixel in an interleaved four-channel, 8-bit source image by a matrix to produce an interleaved four-channel, 8-bit destination image.
Declaration
func vImageMatrixMultiply_ARGB8888(_ src: UnsafePointer<vImage_Buffer>, _ dest: UnsafePointer<vImage_Buffer>, _ matrix: UnsafePointer<Int16>, _ divisor: Int32, _ pre_bias: UnsafePointer<Int16>!, _ post_bias: UnsafePointer<Int32>!, _ 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, androwBytesfields 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. - matrix:
An array of values that contains the 4 x 4 matrix elements.
- divisor:
A value that the function divides the matrix multiplication result by after adding postbias.
- pre_bias:
An array that contains four bias values. The function adds the corresponding bias value to each source value before the matrix multiplication step. Pass
nilto specify zero prebias. - post_bias:
An array that contains four bias values. The function adds the corresponding bias value to each destination value after the matrix multiplication step. Pass
nilto specify zero postbias. - 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.
Mentioned in
Return Value
kvImageNoError; otherwise, one of the error codes in Data Types and Constants.
Discussion
This function treats the four-channel source and destination pixels as four-element vectors. The operation multiplies each source pixel by the 4 x 4 matrix to produce the destination pixel.
The following code shows a single-pixel image that contains the ARGB value (10, 20, 30, 40). The matrix permutes the channel values to produce a single-pixel destination image that contains the ARGB value (40, 30, 20, 10).
let size = vImage.Size(width: 1, height: 1)
let source = vImage.PixelBuffer<vImage.Interleaved8x4>(
pixelValues: [10, 20, 30, 40],
size: size)
let destination = vImage.PixelBuffer<vImage.Interleaved8x4>(
size: size)
let matrix: [Int16] = [
0, 0, 0, 1,
0, 0, 1, 0,
0, 1, 0, 0,
1, 0, 0, 0
]
source.withUnsafePointerToVImageBuffer { src in
destination.withUnsafePointerToVImageBuffer { dest in
_ = vImageMatrixMultiply_ARGB8888(
src,
dest,
matrix,
1,
nil,
nil,
vImage_Flags(kvImageNoFlags))
}
}
// Prints "[40, 30, 20, 10]".
print(destination.array)