Allow Comparison of Optimized images with Unoptimized #140
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Optimized images (such as those generated by
pngcrush
) contain the same image in many fewer bytes of data. One of the optimizations can convert an image from the normal 4 color channels to only 2 if there are few enough colors in an image (such as images that only use black, white, and gray). This causes fewer color components therefore fewer bits per row. This in turn causes the current image comparison calculation to fail even though the images contain identical pixels because the amount of memory they consume is different.This update makes sure the CGBitmapContext is created with the same amount of memory for both images being compared, even though it is technically unnecessary for the optimized image. In this way, the raw memory of the resulting image pixels drawn into the contexts is still identical and easily comparable.
This change will allow us to crush all the snapshot images in our repo, saving us hundreds of MB of files on every clone into CI and CD.
This PR also adds 2 new tests to verify that optimized images can be compared with unoptimized, and the other way around. This requires the addition of one new image (rect_crushed.png) which is a crushed version of rect.png using default
pngcrush
options which reduces the file size by ~67% while retaining identical pixel information.