Skip to content

Encode multichannel AVIF and HEIF gain maps as 4:4:4 - #486

Open
gregbenz wants to merge 1 commit into
google:mainfrom
gregbenz:codex/gainmap-444
Open

gregbenz wants to merge 1 commit into
google:mainfrom
gregbenz:codex/gainmap-444

Conversation

@gregbenz

Copy link
Copy Markdown
Contributor

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.

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.

Use 4:4:4 for multichannel AVIF and HEIF gain maps

1 participant