vImageHistogramCalculation_ARGB8888(_:_:_:)
Calculates the histogram of an 8-bit-per-channel, 4-channel interleaved buffer.
Declaration
func vImageHistogramCalculation_ARGB8888(_ src: UnsafePointer<vImage_Buffer>, _ histogram: UnsafeMutablePointer<UnsafeMutablePointer<vImagePixelCount>?>, _ flags: vImage_Flags) -> vImage_ErrorParameters
- src:
The source vImage buffer.
- histogram:
An array of four collections that contain 256 elements that receive the histogram data.
- 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.
To specify that the function doesn’t calculate the alpha channel histogram, set the Kvimageleavealphaunchanged flag.
Return Value
kvImageNoError; otherwise, one of the error codes in Data Types and Constants.
Discussion
The following code populates the histogramAlpha , histogramRed, histogramGreen, and histogramBlue arrays with the histograms for each channel of the specified vImage_Buffer structure.
var histogramAlpha = [vImagePixelCount](repeating: 0, count: 256)
var histogramRed = [vImagePixelCount](repeating: 0, count: 256)
var histogramGreen = [vImagePixelCount](repeating: 0, count: 256)
var histogramBlue = [vImagePixelCount](repeating: 0, count: 256)
histogramAlpha.withUnsafeMutableBufferPointer { zeroPtr in
histogramRed.withUnsafeMutableBufferPointer { onePtr in
histogramGreen.withUnsafeMutableBufferPointer { twoPtr in
histogramBlue.withUnsafeMutableBufferPointer { threePtr in
var histogramBins = [zeroPtr.baseAddress, onePtr.baseAddress,
twoPtr.baseAddress, threePtr.baseAddress]
histogramBins.withUnsafeMutableBufferPointer { histogramBinsPtr in
// `buffer` is a `vImage_Buffer` structure.
_ = vImageHistogramCalculation_ARGB8888(&buffer,
histogramBinsPtr.baseAddress!,
vImage_Flags(kvImageNoFlags))
}
}
}
}
}