AOMediaCodec / libavif

libavif - Library for encoding and decoding .avif files
Other
1.53k stars 195 forks source link

CICP information lost when decoding to png/jpeg #1421

Open maryla-uc opened 1 year ago

maryla-uc commented 1 year ago

According to https://github.com/AOMediaCodec/libavif/wiki/CICP if an avif image does not contain an ICC profile, then the first two values of the CICP triplet, i.e. the color primaries and the transfer characteristics should be used to decide how to interpret the RGB values. However, this information is not stored in the decoded png/jpeg and will cause color differences if the values differ from sRGB.

For png it's possible to use the cHRM, gAMA and/or cICP chunks. For jpeg I'm not aware of a equivalent mechanism, the solution might be to generate an icc profile.

See an example avif image, and the decoded versions with avifdec original.avif decoded.png, at revision c74526f

wantehchang commented 1 year ago

Maryla: Should we open an issue when we save a decoded AVIF image as JPEG?

maryla-uc commented 1 year ago

H I didn't realize I'd closed it. Reopening it since it was meant to cover both png and jpeg.

wantehchang commented 1 year ago

I think it's closed by the sentence "Fixes #1421 for png." in https://github.com/AOMediaCodec/libavif/pull/1422.

The commit message of the (squashed) commit of that pull request doesn't have that sentence, so apparently GitHub uses only the first comment in the pull request.

svgeesus commented 6 months ago

For png it's possible to use the cHRM, gAMA and/or cICP chunks.

For PNG it is preferable to just use cICP. That avoids information loss, and covers all of CICP while gAMA can only be used for a simple gamma exponent and not a more complex transfer curve such as PQ, HLG, or even the sRGB curve used by Display P3.

wantehchang commented 6 months ago

@svgeesus Chris: Could you please review our PNG fix https://github.com/AOMediaCodec/libavif/pull/1422 and see if it is correct? You can post your comments in that pull request. Thanks.

svgeesus commented 6 months ago

@wantehchang The eventual decisions in that PR (in terms of what to write and when) all look correct to me. Thanks!