Improvements to the generated difference image (#520)#1028
Improvements to the generated difference image (#520)#1028stephencelis merged 1 commit intopointfreeco:mainfrom
Conversation
- 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
|
@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. |
|
@stephencelis Please please, get this merged, it's been forever and current version is just wrong. |
## 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>
stephencelis
left a comment
There was a problem hiding this comment.
@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.
|
@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. |
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
differenceblend mode.After
The "difference" image now highlights pixels with changes to their the alpha component.
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.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.