You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add an optional perceptualPrecision parameter for image snapshot comparisons
The perceptual precision number is between 0 & 1 that gets translated to a CIE94 tolerance https://en.wikipedia.org/wiki/Color_difference
* Use CIColorThreshold and CIAreaAverage for a 70% faster image diff on iOS 14, tvOS 14, and macOS 11
* Add a unit test demonstrating the difference between pixel precision and perceptual precision
* Update the reference image for the image precision test
* Backport the threshold filter to macOS 10.13 by creating a CIImageProcessorKernel implementation
* Update Sources/SnapshotTesting/Snapshotting/UIImage.swift
* Update NSImage.swift
Co-authored-by: Stephen Celis <[email protected]>
Co-authored-by: Stephen Celis <[email protected]>
returnSimplySnapshotting.image(precision: precision).pullback{ layer in
12
+
/// - Parameters:
13
+
/// - precision: The percentage of pixels that must match.
14
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
returnSimplySnapshotting.image(precision: precision, perceptualPrecision: perceptualPrecision).pullback{ layer in
15
17
letimage=NSImage(size: layer.bounds.size)
16
18
image.lockFocus()
17
19
letcontext=NSGraphicsContext.current!.cgContext
@@ -36,10 +38,11 @@ extension Snapshotting where Value == CALayer, Format == UIImage {
36
38
///
37
39
/// - Parameters:
38
40
/// - precision: The percentage of pixels that must match.
41
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
returnSimplySnapshotting.image(precision: precision).pullback{ path in
12
+
/// - Parameters:
13
+
/// - precision: The percentage of pixels that must match.
14
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
returnSimplySnapshotting.image(precision: precision, scale: scale).pullback{ path in
43
+
/// - Parameters:
44
+
/// - precision: The percentage of pixels that must match.
45
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
returnSimplySnapshotting.image(precision: precision).pullback{ path in
12
+
/// - Parameters:
13
+
/// - precision: The percentage of pixels that must match.
14
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
Copy file name to clipboardExpand all lines: Sources/SnapshotTesting/Snapshotting/NSImage.swift
+61-23
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,24 @@
1
1
#if os(macOS)
2
+
import CoreImage.CIFilterBuiltins
2
3
import Cocoa
3
4
import XCTest
4
5
5
6
extensionDiffingwhere Value ==NSImage{
6
7
/// A pixel-diffing strategy for NSImage's which requires a 100% match.
7
-
publicstaticletimage=Diffing.image(precision:1)
8
+
publicstaticletimage=Diffing.image()
8
9
9
10
/// A pixel-diffing strategy for NSImage that allows customizing how precise the matching must be.
10
11
///
11
-
/// - Parameter precision: A value between 0 and 1, where 1 means the images must match 100% of their pixels.
12
+
/// - Parameters:
13
+
/// - precision: The percentage of pixels that must match.
14
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
/// - precision: The percentage of pixels that must match.
44
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
Copy file name to clipboardExpand all lines: Sources/SnapshotTesting/Snapshotting/NSView.swift
+3-2
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,10 @@ extension Snapshotting where Value == NSView, Format == NSImage {
11
11
///
12
12
/// - Parameters:
13
13
/// - precision: The percentage of pixels that must match.
14
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
Copy file name to clipboardExpand all lines: Sources/SnapshotTesting/Snapshotting/NSViewController.swift
+3-2
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,10 @@ extension Snapshotting where Value == NSViewController, Format == NSImage {
11
11
///
12
12
/// - Parameters:
13
13
/// - precision: The percentage of pixels that must match.
14
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
Copy file name to clipboardExpand all lines: Sources/SnapshotTesting/Snapshotting/SceneKit.swift
+8-6
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,10 @@ extension Snapshotting where Value == SCNScene, Format == NSImage {
12
12
///
13
13
/// - Parameters:
14
14
/// - precision: The percentage of pixels that must match.
15
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
@@ -23,16 +24,17 @@ extension Snapshotting where Value == SCNScene, Format == UIImage {
23
24
///
24
25
/// - Parameters:
25
26
/// - precision: The percentage of pixels that must match.
27
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
Copy file name to clipboardExpand all lines: Sources/SnapshotTesting/Snapshotting/SpriteKit.swift
+8-6
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,10 @@ extension Snapshotting where Value == SKScene, Format == NSImage {
12
12
///
13
13
/// - Parameters:
14
14
/// - precision: The percentage of pixels that must match.
15
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
@@ -23,16 +24,17 @@ extension Snapshotting where Value == SKScene, Format == UIImage {
23
24
///
24
25
/// - Parameters:
25
26
/// - precision: The percentage of pixels that must match.
27
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
Copy file name to clipboardExpand all lines: Sources/SnapshotTesting/Snapshotting/SwiftUIView.swift
+3-1
Original file line number
Diff line number
Diff line change
@@ -28,11 +28,13 @@ extension Snapshotting where Value: SwiftUI.View, Format == UIImage {
28
28
/// - Parameters:
29
29
/// - drawHierarchyInKeyWindow: Utilize the simulator's key window in order to render `UIAppearance` and `UIVisualEffect`s. This option requires a host application for your tests and will _not_ work for framework test targets.
30
30
/// - precision: The percentage of pixels that must match.
31
+
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. [98-99% mimics the precision of the human eye.](http://zschuessler.github.io/DeltaE/learn/#toc-defining-delta-e)
31
32
/// - layout: A view layout override.
32
33
/// - traits: A trait collection override.
33
34
publicstaticfunc image(
34
35
drawHierarchyInKeyWindow:Bool=false,
35
36
precision:Float=1,
37
+
perceptualPrecision:Float=1,
36
38
layout:SwiftUISnapshotLayout=.sizeThatFits,
37
39
traits:UITraitCollection=.init()
38
40
)
@@ -51,7 +53,7 @@ extension Snapshotting where Value: SwiftUI.View, Format == UIImage {
0 commit comments