Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canon HIF (10 bit) Conversion to JPG : Tone Mapping & EXIF #1183

Open
paswai opened this issue Jun 9, 2024 · 11 comments
Open

Canon HIF (10 bit) Conversion to JPG : Tone Mapping & EXIF #1183

paswai opened this issue Jun 9, 2024 · 11 comments

Comments

@paswai
Copy link

paswai commented Jun 9, 2024

Hello all, I tried the demo (version 1.16.2) to convert a HIF file (10 bit) to JPG. The conversion went smoothly, however, I noticed two things : 1) No tone mapping has been applied (JPG image looks flat) and 2) All EXIF have been lost.
Is this an expected behaviour and is it still present in the newest release?

@bradh
Copy link
Contributor

bradh commented Jun 10, 2024

Can you attach the file instead? Zip it if needed.

@farindk
Copy link
Contributor

farindk commented Jun 10, 2024

I have downloaded the image: issue-1183-data.zip

The image contains no auxiliary tone-mapping image, just standard EXIF and XMP metadata.

The NCLX color profile says that it uses a PQ transfer characteristic, which is probably the reason that the image looks dull when it is not taken care of. During the conversion to JPEG, libheif does not modify the image data itself. The EXIF is preserved, but the NCLX data is lost.

The question is: should libheif handle the color profile conversion? This may still be doable for simple things like here, but when we want to also convert between attached ICC profiles, we would need to use lcms2 as an additional dependency.

@paswai
Copy link
Author

paswai commented Jun 10, 2024

Please find it attached :
20240525_162308_IMG_0009.zip

@kmilos
Copy link
Contributor

kmilos commented Jun 10, 2024

The question is: should libheif handle the color profile conversion?

There are so many creative choices and trade-offs to be made when doing the tone and gamut mapping, that makes it IMHO out of scope for a file format library.

libjxl is actually doing this (I guess there might be a "recommended" tone mapper in some ITU/Dolby/etc. doc), but I still feel this should be abstracted out of a file format library and shared as a separate black box library... Otherwise, we'll end up w/ a tone/gamut mapper each in libjxl, libheif, libavif, and libpng (also now supports CICP HDR profiles for >8bpp).

P.S. Also note that libjxl is doing this internally in float representation...

@kmilos
Copy link
Contributor

kmilos commented Jun 10, 2024

If anything, libheif should just throw a warning if saving to JPEG w/ anything other than sRGB if ICC is not available. Long term, perhaps support Ultra HDR JPEGs via libultrahdr...

@farindk
Copy link
Contributor

farindk commented Jun 10, 2024

Yes, I agree on the tone mapping and ICC side. This should just be passed through and we can output a warning in heif-convert when the auxiliary tone-mapping image is lost in the conversion.
However, it might be useful to at least convert the transfer-characteristic stored in the NCLX to the standard used in JPEG. That is a non-opinionated mathematical formula and if we don't do it, the information will be lost in the conversion. I don't know of a way to specify the transfer characteristic in JPEG.

@kmilos
Copy link
Contributor

kmilos commented Jun 10, 2024

However, it might be useful to at least convert the transfer-characteristic stored in the NCLX to the standard used in JPEG. That is a non-opinionated mathematical formula and if we don't do it, the information will be lost in the conversion. I don't know of a way to specify the transfer characteristic in JPEG.

AFAIK, there is none (other than the TRC inside an ICC). That's why I said, if there is no ICC in the original HEIF, one should just give up (and suggest converting to PNG instead, which does support CICP). Alternatively you have to make a translator from CICP/NCLX codes to ICC yourself, which means pulling in a dependency on a color engine like LCMS2, or hard-code some common CICP->ICC combos into libheif.

See also e.g. ImageMagick/ImageMagick#7308, ImageMagick/ImageMagick#6642 and ImageMagick/ImageMagick#7302

@kmilos
Copy link
Contributor

kmilos commented Jun 11, 2024

As far as Exif goes, I see no problem using v1.17.6 heif-convert...

@paswai
Copy link
Author

paswai commented Jun 13, 2024

I was curiously following the discussion - Many thanks for the insights! @farindk If the tone mapping is out-of-scope for this project, please close this issue.

@farindk
Copy link
Contributor

farindk commented Jun 13, 2024

For the library itself, this should not include any color management other than basic nclx handling. However, I would consider doing some (optional) color profile conversion in heif-convert if we would otherwise lose that information.

I'll leave this issue open.

@kmilos
Copy link
Contributor

kmilos commented Jun 13, 2024

However, I would consider doing some (optional) color profile conversion in heif-convert if we would otherwise lose that information.

Could indeed be an option: keep the heif-dec as the "barebones" decoder, and possibly evolve heif-convert into something more...

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

No branches or pull requests

4 participants