Skip to content

Add optional color precision for UIImage diffing strategy #580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed

Add optional color precision for UIImage diffing strategy #580

wants to merge 4 commits into from

Conversation

maxheld
Copy link

@maxheld maxheld commented Mar 4, 2022

This PR introduces the extra functionality to define the color precision of each individual pixel when asserting UIImages. Our experience is that varying iOS version render colors slightly differently which causes a slight shift in certain color tones. This addition lets you fine tune how far off the colors are allowed to be. When asserting UIView/UIViewController snapshots with e.g. non-deterministic rendering of shadows this can also come in handy.

The colorPrecision defines the leeway each individual RGBA value has before it is considered a mismatching pixel. If any of the values overstep the threshold the respective pixel is considered a mismatch and fails the test.

The precision parameter is still used to determine the proportion of pixels that are allowed to fail.

This has a knock-on effect for UIView and UIViewController strategies.

@maxheld maxheld marked this pull request as ready for review March 4, 2022 11:03
@esemusa
Copy link

esemusa commented Mar 18, 2022

Works like a charm!

@stephencelis
Copy link
Member

@maxheld Thanks for this! We've had several versions of this kind of fix open for a bit now, but finally decided to go with #628. Please let us know if that solution does not help, and if there is something about "color precision" that works better for you. In the future, when we begin to design a 2.0, we'll be able to take into consideration the flexible needs of plugging into these diffing algorithms.

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.

3 participants