GithubHelp home page GithubHelp logo

Comments (24)

jcupitt avatar jcupitt commented on May 28, 2024 2

Let's make this into an enhancement issue and make a test PR.

from libvips.

jcupitt avatar jcupitt commented on May 28, 2024 1

Oh, that's a good find! It looks like they have this code:

https://github.com/mnaydenov/FreeImage-Sidecar/blob/master/src/PluginHEIF.cpp#L98-L169

Which is pretty simple and should be easy to add to libvips.

Testing would be a PITA though. I have a mac mini, which has quite good HDR support, but of course it's plugged into a non-HDR display. Perhaps I can persuade libvips.org to buy me a HDR monitor ...

from libvips.

Starbix avatar Starbix commented on May 28, 2024 1

I've started coding a bit and wanted to share my findings.

Setting the correct ICC profile (Display P3; SMPTE ST 2084 PQ) using this in vips_foreign_load_heif_set_header works great and you get a JPG that looks very close to how it should. I used the ICC profile Apple provides.

vips_image_set_blob(out, VIPS_META_ICC_NAME,
			(VipsCallbackFn) vips_area_free_cb, data, length);

Thus generating an ICC profile from the NCLX data seems to be the way to go. colorist does exactly that. Simply using colorist convert in.avif out.jpg results in a veeeery dark image, due to forcing the max luminance to 10'000 nits (only for PQ, not sure why). However force-omitting it (or a lower value around 100 nits) results in very good results.
EDIT: according to this presentation, 203 nits should be used

libheif presents a nice API to read out the relevant information of the nclx triplet. The values of this triplet are defined in H.273.

I can look into implementing this more cleanly than what I have right now.
The code in already looks really good, but it's not handling HDR cases (PQ or HLG curves). For these, colorist has the curves in the source code as binary data. Either we copy this (I'm not quite sure where those curves come from initially) or we use a parametric curve like in the Apple profile. However the Apple profile also includes "Intent-0, device to PCS conversion table" tags which may be required in conjunction with the simple parametric tone response curve and I don't know how to replicate those with LCMS2.

I've included a zip file with some relevant results and ICC profiles.
nclx_shenanigans.zip

EDIT: I've emailed the author of colorist and his response was very helpful to understanding more about the choices colorist made. The curves definitely need to be in the repo. He created them himself from the spec.

from libvips.

jcupitt avatar jcupitt commented on May 28, 2024

Hi @mertalev,

You two images above ^^ look identical on firefox on linux, but different in firefox on macos, interestingly.

libvips uses ICC profiles for colour management, but your image has no ICC profile. I would guess it is using nclx for encoding HDR, and that is (as far as I know) only supported by heif. I tried in imagemagick6 and 7, and they both gave the same result as libvips.

We could add nclx support, but that would be a huge amount of work. Maybe you could save your image with an ICC profile? It might at least be less work to support.

from libvips.

jcupitt avatar jcupitt commented on May 28, 2024

... you're right, we could also add an sdr (for example) option to heifload which enabled convert_hdr_to_8bit. That might be a simple fix.

from libvips.

mertalev avatar mertalev commented on May 28, 2024

It does apparently use nclx:

Color Representation            : nclx 12 16 6

A flag to enable convert_hdr_to_8bit sounds good! The only thing this doesn't handle is HDR -> HDR, but we can avoid converting in that case and just strip metadata.

from libvips.

mertalev avatar mertalev commented on May 28, 2024

Oh, but would this still let us use a Display P3 profile in the output image? Or would it have to be sRGB?

from libvips.

jcupitt avatar jcupitt commented on May 28, 2024

It'd become a regular SDR image, yes. All the extra HDR bits would be removed.

I think you'd need to switch to an ICC workflow and encode with 10 or 12 bits to get HDR with a P3 profile. Your test image has no profile attached.

Though I'm a bit unclear on the details -- I've never actually tried this. I ought to get an HDR display.

from libvips.

mertalev avatar mertalev commented on May 28, 2024

For context, this is for a photo backup / library app where users import images that get compressed, resized and stripped to serve more quickly. On our end, the goal is to make the most of what we're given when converting these images.

Looking into this a bit more, NCLX seems to be popular for this format - all the online examples for HDR HEIC/AVIF images I could find use it. I wonder if there's a straightforward way to convert NCLX to ICC? I could find this that uses liblcms2, but it's beyond my knowledge haha

from libvips.

mertalev avatar mertalev commented on May 28, 2024

If it helps, I'm happy to test a branch with the changes!

from libvips.

jcupitt avatar jcupitt commented on May 28, 2024

Oh very nice @Starbix, I'll try to have a look this weekend!

from libvips.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.