Skip to content
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

Allow Comparison of Optimized images with Unoptimized #140

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tinder-owenthomas
Copy link

@tinder-owenthomas tinder-owenthomas commented Dec 11, 2020

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.

@tinder-owenthomas
Copy link
Author

@reidmain As an outside contributor I the repo will not allow me to add requested reviewers. I'm curious to know if there's anything else needed from me in order to get this PR considered? Please let me know.

@alanzeino
Copy link
Collaborator

@reidmain As an outside contributor I the repo will not allow me to add requested reviewers. I'm curious to know if there's anything else needed from me in order to get this PR considered? Please let me know.

Happy to review, maybe you can rebase against latest so we can run the CI on this to see if it breaks the integration tests we have.

Optimized images may contain the same image, but fewer color components and therefore fewer bits per row. This causes the current image comparison to fail even though the image is otherwise identical.
@tinder-owenthomas tinder-owenthomas force-pushed the oht/allow-comparison-of-optimized-pngs-with-unoptimized-pngs branch from 934dc4f to 8e9c24f Compare October 22, 2021 20:34
@tinder-owenthomas
Copy link
Author

Sorry @alanzeino, just saw your comment now. I've updated from latest main. Hopefully everything will pass

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.

None yet

2 participants