Skip to content

Improvements to the generated difference image (#520)#1028

Merged
stephencelis merged 1 commit intopointfreeco:mainfrom
CraigSiemens:520-diff-image-improvement
Mar 18, 2026
Merged

Improvements to the generated difference image (#520)#1028
stephencelis merged 1 commit intopointfreeco:mainfrom
CraigSiemens:520-diff-image-improvement

Conversation

@CraigSiemens
Copy link
Copy Markdown
Contributor

@CraigSiemens CraigSiemens commented Sep 25, 2025

This PR improves the generated difference image to make differences much clearer in cases where the alpha component changes or there's only a subtle change in color.

Examples

All the images below contain the "reference" "failure" and "difference" images from one test run.

Alpha only changes

The "reference" is a transparent image containing the word "Hello"
The "failure" is a transparent image with the same size containing the word "World"

Before

The "difference" image is all black because the alpha component is not considered by the difference blend mode.

before

After

The "difference" image now highlights pixels with changes to their the alpha component.

after

Subtle color changes

The "reference" image is the color Color(white: 128.0 / 255.0)
The "failure" image adds the text "Changed" with the foreground style Color(white: 129.0 / 255.0)

Before

The "difference" appears all black. The text is so close to the background color in the "failure", the "difference" has the color Color(white: 1.0 / 255.0) which is not perceptible. You need to adjust the levels in an image editor to really make them visible.

before

After

The "difference" image now clearly shows the difference by normalizing the difference values in the image based on the max component difference per pixel. White is the most different pixel in the image, and black is unchanged pixels.

after

- now shows differences when only the alpha component changes
- normalizes the difference values to improve contrast in the image
- falls back to using the difference blend mode when the image size has changed
@CraigSiemens
Copy link
Copy Markdown
Contributor Author

@stephencelis @mbrandonw Is there anything I can do to help get this merged? I've been using this for the past couple months and it's been very helpful.

@Kaspik
Copy link
Copy Markdown

Kaspik commented Feb 6, 2026

@stephencelis Please please, get this merged, it's been forever and current version is just wrong.

o-nnerb added a commit to snapshot-testing/xc-snapshot-testing that referenced this pull request Feb 13, 2026
## Description

<!--- 
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context.
-->

Improves the generated difference image to make differences much clearer
in cases where the alpha component changes or there's only a subtle
change in color.

Reference:
pointfreeco/swift-snapshot-testing#1028

Co-authored-by: brennobemoura <37243584+brennobemoura@users.noreply.github.com>
Copy link
Copy Markdown
Member

@stephencelis stephencelis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CraigSiemens Thanks for this! We think it should be an improvement. I was a little worried about performance changes but it's probably not a big deal for the unhappy path.

@stephencelis
Copy link
Copy Markdown
Member

@Kaspik Many, many developers depend on this library so we have to be careful bringing in changes that may break things. The good news is the library is extensible, so you can always define custom strategies that bring logic like this diffing logic in without changes to the core library.

2.0 of the library will give us an opportunity to shed off some of the friction involved in releases, but we're not sure the timeline on that.

@stephencelis stephencelis merged commit cfa6cc9 into pointfreeco:main Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Difference image doesn't show difference in opacity.

3 participants