Conversation
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.
This PR fixes #485.
Multichannel AVIF and HEIF gain maps currently use 4:2:0 sampling, which can cause visible artifacts in fine detail and gradients (such as blue skies). This change uses 4:4:4, matching the JPEG gain-map encoder.
The implementation changes two gain-map conversion calls. Base-image encoding, single-channel maps, gain-map math, and the public API are unchanged.
The examples in #485 show why this helps. On the Display P3 test image, lowering the 4:4:4 gain-map quality to Q62 for AVIF and Q73 for HEIF produced slightly smaller files than 4:2:0 at Q80, while reducing the one-pixel grid’s linear RGB reconstruction error by 84% and 91%, respectively.
Keeping Q80 increased total file sizes by 17.8% for AVIF and 11.5% for HEIF on that image. Results vary with content, and encoding took about 13–46% longer across the two images tested with both codecs.
Validation covered 35 matched pairs across eight test cases. The compressed base image and gain-map metadata were unchanged in every pair. Six outputs were also checked with macOS ImageIO.
The regression tests cover 4:4:4 multichannel maps and monochrome single-channel maps for both codecs, while retaining the existing odd-dimension check. All four cases pass with this change. On unchanged main, the two multichannel cases fail as expected and the single-channel cases pass.