Open o-l-a-v opened 8 months ago
Thank you for the bug report. See https://github.com/AOMediaCodec/libavif/issues/1421 for an open entry about the issue: avifdec
now writes CICP metadata (here 9/16/9) to PNG as a cHRM chunk, but JPEG does not support that.
The AVIF file has no ICC color profile by the way but I tried stuffing ITUR_2100_PQ_FULL.ICC into the output JPG using avifdec input.avif --icc colorprofile.icc output.jpg
(requires https://github.com/AOMediaCodec/libavif/pull/2042):
It does not seem to be the correct ICC but it could be a working approach.
Even if --icc
is not specified I still expect avifdec.exe input.avif output.jpg
to create an SDR JPG image looking close to the original.
One more alternative approach/idea: If input is HDR => Use JPEG XL jpegli to encode to JPEG with XYB colorspace, which supports HDR.
Even if
--icc
is not specified I still expectavifdec.exe input.avif output.jpg
to create an SDR JPG image looking close to the original.
Unfortunately libavif cannot handle all format and color space combinations, with workarounds for every situation. Detecting special cases such as common CICP combinations and outputting a matching ICC profile in JPG seems doable though.
If this is impossible for various reasons, or in the meantime, would an error or warning in avifdec
console output be better?
Have you tried other conversion tools than avifdec
for going from AVIF to JPG? Maybe there is some acceptable behavior we could match.
One more alternative approach/idea: If input is HDR => Use JPEG XL jpegli to encode to JPEG with XYB colorspace, which supports HDR.
So the input AVIF file would be in XYB colorspace?
If so, why not directly embed an HDR PQ ICC profile in the input AVIF file? It would be forwarded to the output JPG by avifdec
.
Error if input has CICP and output is set to JPG until this might get fixed in the future makes sense.
I'm no image expert, I might've gotten the XYB part of jpegli wrong.
I don't know of other tools that handle this scenario, no.
If so, why not directly embed an HDR PQ ICC profile in the input AVIF file? It would be forwarded to the output JPG by
avifdec
.
This not a good idea for 8-bit encoding like JPEG (I guess until, and if avifdec decides to support 12-bit JPEG as well).
IMHO, I think it should be enough detect anything other than sRGB/Rec709 (as either CICP or ICC), and throw a warning in the console that the image cannot really be preserved in a JPEG (or any other 8-bit container), unless the input was 8-bit to begin with of course.
I still expect avifdec.exe input.avif output.jpg to create an SDR JPG image looking close to the original.
Gamut and tone mapping should be left to a different abstraction level/library, as there are a few compromises and creative choices to be made there, it's not really a job of the codec library IMHO.
Btw, if -d
is not specified, will avifdec
correctly choose PNG bit depth depending on input?
Btw, if
-d
is not specified, willavifdec
correctly choose PNG bit depth depending on input?
Yes.
Gamut and tone mapping should be left to a different abstraction level/library, as there are a few compromises and creative choices to be made there, it's not really a job of the codec library IMHO.
Completely agree. libavif could add the ITU-R recommended way of tone mapping from HDR to SDR as a convenience, but it doesn't necessarily produce great results.
libavif v1.0.4.
Following image:
Decodes to JPG but colors end up looking dull/washed out.
I used following command:
Output always looks like this, in GIMP, Paint.NET, Windows Photos, XnView MP.
AVIF - PNG - JPG