Repository navigation
fix(png): Preserve color and alpha in extended-range snapshots - #284
Merged
Merged
Conversation
jamieQ
added this pull request to stack #285
October 8, 2026 00:05
Sentry Snapshot Testing
|
Preserve UIImage orientation metadata when exporting through ImageIO. Use small color-aware regression fixtures and a strict expected-failure check to flag a future UIKit alpha fix. Refs #281
jamieQ
force-pushed
the
fix/png-alpha-export
branch
from
October 8, 2026 14:26
037f71a to
5c5ba3f
Compare
| return try XCTUnwrap(CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [CFString: Any]) | ||
| } | ||
|
|
||
| private func pngPixel(_ data: Data) throws -> [UInt16] { |
Contributor
There was a problem hiding this comment.
only one thing. i had an agent look at these tests and it called the following out:
pngPixelinUIImagePNGEncodingTests.swiftassumes a 16-bit PNG, but the bit depth depends on the simulator runtime. Extended-range sources come out 8-bit Display P3 on iOS 17.5 and 26.0, and 16-bit sRGB on 18.0.testExtendedRangePNGPreservesColorAndAlphaandtestUIKitPNGEncodingStillRequiresAlphaWorkaroundfail on 17.5, 18.5 and 26.0. CI is green only because of the runtime it currently picks, andunit-tests.ymldoesn't pin Xcode or the simulator OS.
- Suggested fix: drop
pngPixeland assert throughassertEqualPixels(decode(...), image.cgImage)instead, which removes the bit-depth dependence,import zliband the colour-space conversion block. Needs a check that this still fails againstimage.pngData().
Member
Author
There was a problem hiding this comment.
Sounds good, I think it will simplify the tests nicely.
NicoHinderling
approved these changes
Oct 8, 2026
Compare decoded pixels with the source image instead of parsing 16-bit PNG samples.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 372eb15. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

As reported in #281, there seems to be some odd interactions when rendering a
UIImageviaUIGraphicsImageRendererand then exporting it to PNG via itspngData()method. Specifically, if the renderer produces a 16-bit image, whichUIKitmay do in some cases, then the encoded PNG can include color values that are premultiplied by alpha, which violates the PNG spec. This results in exporting snapshot image that may not match the manner in which the "real" preview images are displayed. Work around this by using ImageIO to encode the PNG data, which appears to avoid the issue.Stacked on #283, which ensures our unit tests run in CI.
Refs EME-1331