func getCGImageMatchPercentage()

in AmazonChimeSDK/AmazonChimeSDKTests/audiovideo/video/backgroundfilter/BackgroundFilterTest.swift [311:330]


    func getCGImageMatchPercentage(
        expectedCgImage: CGImage, gotCgImage: CGImage,
        expectedCgImageBytes: UnsafePointer<UInt8>, gotCgImageBytes: UnsafePointer<UInt8>
    ) -> Double {
        var matchCount = 0
        let totalPixels = gotCgImage.height * gotCgImage.width
        let bytesPerPixel = gotCgImage.bitsPerPixel / gotCgImage.bitsPerComponent
        for row in 0 ..< gotCgImage.height {
            for col in 0 ..< gotCgImage.width {
                let offset = (row * gotCgImage.bytesPerRow) + (col * bytesPerPixel)
                let match = self.getRGBMatch(offset: offset,
                                             expectedImageBytes: expectedCgImageBytes, gotImageBytes: gotCgImageBytes)
                if match {
                    matchCount += 1
                }
            }
        }
        let matchPercentage = Double(matchCount) / Double(totalPixels)
        return matchPercentage
    }