Skip to content

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

Description

@gregbenz

AVIF and HEIF currently subsample generated multichannel gain maps to 4:2:0. This visibly damages fine color detail in the rendered HDR, as can be seen in the image samples linked below. The JPEG encoder already uses 4:4:4 for generated multichannel gain maps.

420 vs 444.zip

The clearest example is the one-pixel red/green and red/blue grid in the test image. Switching only the gain-map conversion to 4:4:4 substantially improves it. The adjacent gradients also look smoother. Raising the 4:2:0 map quality to 100 does not recover the grid detail.

Ultimately, the assumptions used for subsampling are based around human visual perception of an image and relate to direct reproduction of color where the RGB values are in a consistent range/encoding. However, a gain map is not a real image, it is just encoding per-channel weights in an image format. Each channel is intended to be completely independent of the others for a given pixel (they may not even use the same min/max range or gammas). As a result 420 subsampling causes incorrect weights and therefore visible artifacts because it breaks the assumptions necessary to use the gain map correctly.

While subsampling is attractive for size reduction, 444 works very well here. It allows encoding with a quality to achieve similar (or better) results than 420. So the example here shows similar size with substantially better 1x1 grid / gradient fidelity. On the Display P3 test image, lowering the 4:4:4 quality produced a slightly smaller file than 4:2:0 at Q80, while retaining much more of the grid:

Format 4:2:0 map Q80 4:4:4 map Total file size change Grid error reduction
AVIF 377,335 bytes Q62: 374,628 bytes -0.7% 84%
HEIF 960,736 bytes Q73: 959,592 bytes -0.1% 91%

Base quality was 90 throughout. The error figures are linear RGB RMSE over the 64×64 grid, not a perceptual score or a whole-image improvement. Sizes are for the complete 1080×1080 files. The AVIF comparison includes 4:2:0 Q80, 4:4:4 Q80, and 4:4:4 Q62, with a viewer showing just the grid and neighboring gradients without re-encoding the files.

There is a tradeoff at unchanged quality settings: Q80 4:4:4 increased this image's total size by 17.8% for AVIF and 11.5% for HEIF. Across three photographs, increases ranged from 2.8–18.3% and 10.6–22.0%, respectively, and reconstruction improvements varied. Warm encode-only measurements on two images were about 13–46% slower, depending on the image and codec.

These tests used main at f3e36226914289cfefcf0d81a6471cf6266c79fb, patched libheif 1.19.7, libaom 3.14.1, and x265 4.2 on macOS. The generated maps were 8-bit, full resolution, multichannel, with gamma 1. Within each 4:2:0/4:4:4 pair, the compressed base and gain-map metadata were identical. The original JPEG was decoded to HDR and SDR inputs and the gain map regenerated; this was not a compressed-map passthrough test.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions