diff --git a/Sources/SnapshotTesting/Snapshotting/NSImage.swift b/Sources/SnapshotTesting/Snapshotting/NSImage.swift index 9b1989f6d..2336b6da4 100644 --- a/Sources/SnapshotTesting/Snapshotting/NSImage.swift +++ b/Sources/SnapshotTesting/Snapshotting/NSImage.swift @@ -108,6 +108,7 @@ private func compare(_ old: NSImage, _ new: NSImage, precision: Float, perceptua if oldRep[offset] != newRep[offset] { differentByteCount += 1 } + return differentByteCount <= byteCountThreshold } if differentByteCount > byteCountThreshold { let actualPrecision = 1 - Float(differentByteCount) / Float(byteCount) diff --git a/Sources/SnapshotTesting/Snapshotting/UIImage.swift b/Sources/SnapshotTesting/Snapshotting/UIImage.swift index 7bf74253d..cfe59de20 100644 --- a/Sources/SnapshotTesting/Snapshotting/UIImage.swift +++ b/Sources/SnapshotTesting/Snapshotting/UIImage.swift @@ -127,6 +127,7 @@ private func compare(_ old: UIImage, _ new: UIImage, precision: Float, perceptua if oldBytes[offset] != newerBytes[offset] { differentByteCount += 1 } + return differentByteCount <= byteCountThreshold } if differentByteCount > byteCountThreshold { let actualPrecision = 1 - Float(differentByteCount) / Float(byteCount) @@ -186,6 +187,7 @@ func perceptuallyCompare(_ old: CIImage, _ new: CIImage, pixelPrecision: Float, let deltaThreshold = (1 - perceptualPrecision) * 100 var failingPixelCount: Int = 0 var maximumDeltaE: Float = 0 + let maxFailingPixelCountAllowed = Float(1 - pixelPrecision) * Float(deltaOutputImage.extent.width * deltaOutputImage.extent.height) // rowBytes must be a multiple of 8, so vImage_Buffer pads the end of each row with bytes to meet the multiple of 0 requirement. // We must do 2D iteration of the vImage_Buffer in order to avoid loading the padding garbage bytes at the end of each row. fastForEach(in: 0.., _ body: (Int) -> Void) { +func fastForEach(in range: Range, _ body: (Int) -> Bool) { var index = range.lowerBound while index < range.upperBound { - body(index) + guard body(index) else { + return + } index += 1 } }