Compute histogram for 10 bit YCbCr samples

I have CVPixelBuffers in YCbCr (422 or 420 biplanar 10 bit video range) coming from camera. I see vImage framework is sophisticated enough to handle a variety of image formats (including pixel buffers in various YCbCr formats). I was looking to compute histograms for both Y (luma) and RGB. For the 8 bit YCbCr samples, I could use this code to compute histogram of Y component.

           CVPixelBufferLockBaseAddress(pixelBuffer, .readOnly)
                
                let bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0)
                let baseAddress = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0)
                let height = CVPixelBufferGetHeightOfPlane(pixelBuffer, 0)
                let width = CVPixelBufferGetWidthOfPlane(pixelBuffer, 0)
                
                CVPixelBufferUnlockBaseAddress(pixelBuffer, .readOnly)
                
                var buffer = vImage_Buffer(data: baseAddress, height: vImagePixelCount( height), width: vImagePixelCount(width), rowBytes: bytesPerRow)
                
                alphaBin.withUnsafeMutableBufferPointer { alphaPtr in
                    let error = vImageHistogramCalculation_Planar8(&buffer, alphaPtr.baseAddress!, UInt32(kvImageNoFlags))
                    
                    guard error == kvImageNoError else {
                        fatalError("Error calculating histogram luma: \(error)")
                    }
                    
                }

How does one implement the same for 10 bit HDR pixel buffers, preferably using new iOS 16 vImage APIs that provide lot more flexibility (for instance, getting RGB histogram as well from YCbCr sample without explicitly performing pixel format conversion)?

Hi,

vImage supports 8- and 32-bit histogram calculation for planar and interleaved 4-channel images.You'll need to perform a conversion before calling the appropriate histogram calculation routine.

Compute histogram for 10 bit YCbCr samples
 
 
Q