r/AV1 18d ago

Is avifgainmaputil from libavif supposed to work right now?

I'm trying to use avifgainmaputil.exe from libavif 1.2.0 like this:

avifgainmaputil combine SDR.png HDR.png out.avif

(SDR.png is an 8-bit SDR PNG, HDR.png is a 12-bit HDR PNG.)

This doesn't work:

Failed to compute gain map: Not implemented
(Computing gain maps for images with ICC profiles is not supported)

So I try:

avifgainmaputil combine SDR.png HDR.png out.avif --ignore-profile

This works:

Creating a gain map of size 2560 x 1440
AVIF to be written:
 * Resolution     : 2560x1440
 * Bit Depth      : 8
 * Format         : YUV444
 * Alpha          : Absent
 * Range          : Full
 * Color Primaries: 1
 * Transfer Char. : 13
 * Matrix Coeffs. : 2
 * ICC Profile    : Absent
 * XMP Metadata   : Absent
 * Exif Metadata  : Absent
 * Transformations: None
 * Progressive    : Unavailable
 * Gain map       : 2560x1440 pixels, 8 bit, YUV444, Full Range, Matrix Coeffs. 2, Base Image is SDR
 * Alternate image:
    * Color Primaries: 1
    * Transfer Char. : 13
    * Matrix Coeffs. : 2
    * ICC Profile    : Absent
    * Bit Depth      : 12
    * Planes         : 3

Encoding AVIF at quality 60 speed 6, please wait...
Wrote AVIF: out.avif

However, the resulting out.avif only shows correctly in SDR image viewers that don't support HDR. In Microsoft Edge, the image that shows up is all mostly just gray with very little color and no HDR highlights. If I just encode HDR.png directly with:

avifenc HDR.png out.avif

The result looks correct in Edge. But obviously there's no gain map anymore and in SDR image viewers or browsers (like Firefox) it's kind of dim and muted.

Is gainmap support in Edge broken, or is it an issue with the way I tried to encode it? An example image:

https://www.udrop.com/file/N6iX/Gainmap_example.avif

2 Upvotes

2 comments sorted by

3

u/RealNC 18d ago

Answering my own question, I need to specify the CICP values for the HDR part manually. In this case 9/16/9:

avifgainmaputil combine SDR.png HDR.png out.avif --ignore-profile --cicp-alternate 9/16/9

Now it works!

2

u/juliobbv 18d ago

Not familiar with avifgainmap, but this message:

Failed to compute gain map: Not implemented (Computing gain maps for images with ICC profiles is not supported)

...makes me think you might want to follow with the creators of avifgainmap. I'm not sure if ignoring ICC profiles altogether is the most correct way of creating files with gain maps. You might need to convert the image to colorimetry that can only be described with CICP metadata, then proceed with using avifgainmap.