-
Notifications
You must be signed in to change notification settings - Fork 215
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
Added support for optimised reference image PNGs #80
base: main
Are you sure you want to change the base?
Added support for optimised reference image PNGs #80
Conversation
@reidmain is anyone still maintaining this project / any chance to get this merged please? |
ee17d57
to
42f6e2d
Compare
@reidmain Any chance for this to being merged? Is the project still being maintained please? PRs seems to be abandoned (this one is opened 10 months with no response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can no longer approve any changes to this repository. I'm going to request changes to this PR so it can be removed from my queue.
How does this compare to #140? |
Thanks @alanzeino for having a look. I believe both this and #140 have the same goal and almost identical implementation. This was just waiting and ready here 1.5y before #140 😀 Looking at the code the solution is almost the same as well. |
// Find image which requires more bytes in memory. We have to normalise both images to context requiring "bigger" memory representation. | ||
// This allows comparing 2 visually identic images even if their bit representation in file can be different | ||
// (for example reference images optimised using ImageOptim app). | ||
// Because both images have the same pixel size, image with more bytes per row is the image dictating the context confix for comparison. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: config
// Because both images have the same pixel size, image with more bytes per row is the image dictating the context confix for comparison. | |
// Because both images have the same pixel size, image with more bytes per row is the image dictating the context config for comparison. |
size_t minBytesPerRow = MIN(CGImageGetBytesPerRow(self.CGImage), CGImageGetBytesPerRow(image.CGImage)); | ||
size_t referenceImageSizeBytes = referenceImageSize.height * minBytesPerRow; | ||
// Find image which requires more bytes in memory. We have to normalise both images to context requiring "bigger" memory representation. | ||
// This allows comparing 2 visually identic images even if their bit representation in file can be different |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: identical
// This allows comparing 2 visually identic images even if their bit representation in file can be different | |
// This allows comparing 2 visually identical images even if their bit representation in file can be different |
This allows to use apps like ImageOptim.app to optimise recorded reference images. Optimising reference image can heavily reduce its size, meaning we need to store less binary data in repo.
42f6e2d
to
3fa343c
Compare
Hey. I faced the same problem as the author and ended up with the same fix. The only concern is that it may fail when one image has more bits per component while the other has more bits per pixel and bytes per row. But this is probably very rare. |
TL;DR: Don't fail test / comparison if recorded saved reference image PNG is optimized using tools like ImageOptim.
Overview
This allows to use apps like ImageOptim.app to optimise recorded reference images. Optimising reference image can heavily reduce its size, meaning we need to store less binary data in repo.
Technical details
The core of this change is the way how
CGContextRef
are initialized.Before (original code)
Each context was using
minBytesPerRow
to calculate buffer size. However, this was reason of the failure in case of optimized images. ImageOptim will for example reduce color space of the PNG from 32bit to 8bit (monochromatic) where possible. This results inminBytesPerRow
being wrong value (not big enough to fit runtime rendered snapshot).After (this change)
Contexts are always built based on "bigger" (the one needing more memory) context of the two images (saved reference vs rendered). This means context will always be built based on runtime rendered image. When rendering
CGContextDrawImage
to context, both runtime snapshot and loaded optimized reference images are "normalized" to the same context (colorspace etc.).Backwards compatibility
✅ 100% backwards compatible
Optimizing reference images is opt-in, optional and fully backwards compatible. This PR will not impact existing projects which don't use optimized reference images.
Performance impact
✅ None (negligible)
memcmp
works the same.minBytesPerRow
padding optimization, which should have almost no impact.