Quick start: HDR photos in darktable with HLG and JPEG XL, plus xl-view (a cross-platform HDR viewer)

Hi all,

I’ve been editing more and more of my photos for HDR displays lately and have settled on a darktable setup that works well for me. I wanted to share it as a quick start guide, along with the image viewer I’ve been building to look at the results.

The Processing RAWs for HDR displays in Darktable thread has a ton of great background. This is my condensed, practical take using HLG and JPEG XL. Corrections and suggestions are very welcome.

Why HLG and not PQ?

  • PQ export in darktable is broken for this use right now. The PQ profile maps 1.0 to 10,000 nits, so middle gray ends up around 1,800 nits unless you pull exposure down by several stops.

  • HLG is easier to work with. It’s relative rather than absolute, so the display adapts the image to its own peak brightness instead of you targeting fixed nit values.

  • Most camera makers use HLG for their in-camera HDR stills, so the files fit in with what’s already out there.

darktable setup

1. Output color profile

Set the export profile to HLG Rec2020 RGB.

2. Disable sigmoid (or filmic, or AgX)

HLG has a lot more dynamic range than SDR, so tone mapping usually isn’t necessary. A tone mapper would compress the image back down to SDR range, which defeats the purpose. Without one, anything above the top of the HLG range clips, so keep an eye on the brightest highlights.

3. Exposure: -1.05 EV

This places exposure according to the ITU-R BT.2408 guidelines for HLG. The value has two parts:

  • -1.75 EV to account for the HLG transfer function. I measured this with my own Sony body and a ColorChecker.

  • +0.7 EV, darktable’s default compensation for typical raw underexposure.

Since this was measured with my camera, it may not be exactly right for yours or for every situation, just like any default exposure in SDR. In practice I’ve found it works well as a starting point.

4. Expect a dark preview

darktable can’t display HDR yet, so with this setup the darkroom preview looks too dark. That’s expected. Judge the final brightness on an HDR display with a proper image viewer.

JPEG XL export

Why JPEG XL? It has first-party HDR support (HLG and PQ are part of the format itself), and in my opinion it’s the most promising successor to JPEG. As of this month, Chrome 155 and Firefox 158 both decode it by default, joining Safari.

Setting Value
File format JPEG XL
Bit depth 12 bit
Quality 98
Encoding effort 8
Decoding speed 0
Profile HLG Rec2020 RGB
  • Quality 98, effort 8, decoding speed 0 for the best possible quality.
  • 12 bit. For lossy JPEG XL (quality below 100), darktable hands libjxl float data and the bit depth only sets a header field that tells decoders what precision to expect. 10 and 12 bit give the same file size and quality. Avoid 8 bit though, since some apps then decode to 8-bit buffers.

Metadata
Open the export module’s preferences (hamburger menu) and tick all the checkboxes. For privacy reasons, darktable doesn’t write any metadata to JPEG XL until every box is checked.

Viewing the results: xl-view

To look at these files I’ve been building xl-view over the last couple of months. It’s a small JPEG XL viewer for Linux, Windows and macOS, focused on showing HDR files correctly and staying responsive with large images like panoramas. It’s written in Rust and licensed GPL-3.0.

On an HDR display it outputs PQ, and on an SDR display it tone-maps to sRGB. HLG, PQ and SDR files all work. On Linux it needs a native Wayland session, and HDR also needs compositor support for HDR and Wayland color management.

Builds are on the releases page.

I put a lot of effort into testing and validating the HDR pipeline, but there are many OS, GPU and display combinations out there, so reports are very welcome.

Thanks for reading! Happy to answer questions about any of this.

DSC00564_downscaled_no_metadata.jxl (887.6 KB)

4 Likes

Thanks for sharing your workflow and viewer…I am going to have to go buy a new monitor… :slight_smile:

Like @priort , I’d love to try this but I need a new monitor first! I’ve been looking at them for a couple of years, waiting for the sweet spot of price and technology. A mini-LED HDR1000 32" 4K monitor with enough dimming zones is still too expensive currently.

1 Like

For fun I will give it a try later and look at the output on my phone…

I have little knowledge/understanding of all the relevant profiles, protocols etc, but isn’t this also what will happen if we simply apply the SDR workflow to a HDR screen: 1.0 being mapped to the screen’s peak brightness?

@priort PC displays with good HDR are sadly still rare and expensive. However, if you own an OLED TV (also expensive, but more common), I suggest giving it a try on that.

@europlatus Yes, aim for at least “DisplayHDR 1000” certification if you’re buying an LCD. Otherwise, HDR won’t give you a good experience (sometimes it’s even worse than staying in SDR). Mini-LED and OLED seem to be the most promising technologies right now.

2 Likes

@EspE1 Partly yes. HLG is relative like SDR, so the top of the signal goes to the screen’s peak brightness. The lower half of the HLG curve is close to SDR gamma, and the upper half is logarithmic.

The difference is where the image sits in that range. In SDR, 1.0 is diffuse white, so stretching it to the panel peak just makes the whole image brighter. In HLG, diffuse white sits at 75% of the signal (about 203 nits on a 1000 nit screen), and everything above that is headroom for highlights. That’s why the workflow lowers exposure and turns off sigmoid: normal content stays at SDR-like brightness, and only the highlights go higher.

On the PC side, most HDR output is PQ, which is what xl-view uses. PQ is absolute, so an HLG file first has to be converted to nits, usually with the standard 1000 nit reference so diffuse white lands at 203 nits. If the screen can’t reach that, the brightest highlights need tone mapping. The same goes for PQ files with values brighter than the screen.

1 Like

Thank you, for the explanation.

I’ve thought more about this, and I begin to wonder if this is a good example of where we limit our considerations to physics and technology, and forget to take psychology and vision into consideration.

Companies which sell monitors will like us to think they can sell us something new and improved and get reactions like:

but are they really?

Where does that “diffuse” come from??
Our brain constantly interprets what we se at 1.0 as “white”.
“White” and “black” are relative, psychological entities, and we interpret them from the total context, irrespective of the actual brightness level.

This has been demonstrated over and over again, f. ex. with the well-know drawing of a shadow crossing a checker board. Another striking example is a projection screen, likely being the whitest area within a room, where we suddenly interprets part of it as black because we throw some additional light on other parts of the screen, as when we project a document with some text or drawings.

Our vision don’t care much about brightness, but about contrast.

So, that 1.0 is “white”, “bright white” or “diffuse white” as we “need” it.

Who has ever looked at a photo of a polished steel sphere with the sun reflecting from it and immediately thought “Nja, what is that diffuse white dot in the middle there? Is somebody trying to attempt us think that it is a specular reflection of the sun? Well, we are not so easily fooled …”?

For, yes, our vision is so easily fooled because we already know something about specular lights and we have some expectations from a photo and it is the contrasts that counts.

Or who has ever looked at a picture on a screen and thought “That dark parts there are likely 0.0 and what the screen looks like when it doesn’t emit any light – and likely meant to be “black”. But we all know and see that the screen in this darkened state is not truly black as black can otherwise be, far from it, so I cannot se it as anything but dark gray.”?

Have any ordinary user of monitors (who hasn’t read a lot on screen technology and display standards) ever reacted that “my screen is not black/white enough”? (That we all may have reacted that the screen is not bright enough if we try to use our pc’s in strong sunlight, is another matter …).

That we can see a difference between SDR white/black and HDR white/black when we put two screen beside each other, is clear, but we don’t look at pictures in this way – our attention is on one screen at the time.

I can understand that for movies/videos it may be useful to have some “white power” in the display “in reserve” , because what we see is a dynamic picture and our vision’s relative contrast considerations are constantly changing. So if we want to show a blink like a flash or an explosion we need something more than that which we immediately before and after the blink interpret as bright white.

But for photo? I tend to think that I can save that money for a better purpose.

1 Like

Paper, i.e. photo prints. A white piece of paper can only be as bright as the ambient light it diffuses.

Sure.
But does paper have any relevance when I look at a monitor emitting light (1.0) in low ambient light?

What monitor? You’re looking at a print. :wink:

The point is - SDR monitors mimic/match prints, i.e. 1.0 on an SDR screen is “white” of the print. Neither can go brighter and (truly) represent specular highlights.

No, they don’t. They have a much larger dynamic range than paper.
And HDR monitors have an even larger DR.
But our vision in any case interprets what we see as needed (f. ex. white in various shades).

This is where the misunderstandings imm manifests itself.
There is nothing “truly” in our vision – in particular when we talk about representations.
Photo has represented specular highlights at all times both on paper and screens.

Sure, but relative to the stimulus.

Yes. Badly.

Yes, and my main point is that our vision works on a relative basis.

If we are making photographs for scientific measuring purposes, the actual brightness/reflection level may be of interest, but anywhere else the point is what our vision/brain perceives from a photo – and our brain is such a fantastic organ that this perception is not really dependent on the maximum brightness level of a screen.

Mostly good enough for us humans to see/understand from the relative levels and our knowledge of the world and photography that it represents specular highlights – and hence to see/perceive specular highlights.

Can you please explain why you said this, when we are talking about a screen that, contrary to paper, emits light and has a larger dynamic range?
Can you also please explain what is the fundamental difference between a photo displayed on a HDR screen and on a SDR screen – beyond that the extended dynamic range (compared to paper) is somewhat larger on a HDR screen?

And as for:

the word “represent”, that you use yourself, is a key, because a photo is in any case a plane with some shaded/colored sectors on it. It represents some part of the real life, but there is nothing “true” with it.

We know of light sources that are about a thousand times stronger than our sun – there is no limit to how “white” light can be. But if we stay with the sun, (and look away from sensor limitations …), what will the HDR representation of a specular highlight actually be in brightness level, compared to an actual reading of the highlight?

That’s very subjective. Many would disagree and loathe the “radioactive HDR look” of aggressive tone mapping and dynamic range compression that SDR screen technology and prints were forcing upon us.

Whatever the HDR monitor can do - e.g. 4000 nits (for very expensive ones) compared to 200 nits of diffuse white. So your tone mapper does not have to compress as aggressively. Again it’s the relative that matters here. You can provide a 20x brighter stimulus for the highlight (although it is not physically accurate as it indeed might be way brighter), but that is still a huge improvement to having to map diffuse white to e.g. 0.88 and then most of your highlights compress to 1.0.

I really don’t want to dwell on this further - we agreed that perception is relative. SDR tech and prints simply cannot provide a wide enough dynamic range of stimli to produce the same effect inside one’s brain as a natural scene or HDR tech, no matter what you want to imagine/recall inside it. It might be a “good enough” experience most of the time for you, but that doesn’t mean someone shouldn’t look for better.

Thanks for this writeup, and for xl-view!

If I start with a 16 bit file that is already mapped 0-1 (i.e. SDR), does the HLG transfer actually do much of anything? Pushing the whites brighter could be a form of enhancement relative to the original, I guess.

A quick test on my MacBook Pro M1 looks about right (DR stretched correctly), but still seems sort of like faux HDR, almost like I would manually boost brightness only on the image area and not the entire screen. Whites are brighter than white outside the image area.

Among the several questions you did not respond to is what is the actual brightness level of specular highlight displayed on a HDR screen compared to a reading of the actual highlight?

Sorry, added above in the meantime.

Again, think relative. Any extra light you can emit >“1.0” helps in contrast perception. It doesn’t have to be “actual”, just (noticeably) better.

Thanks for the clarification.

As for the relative, I think it is important to take into consideration that our vision and perception is not only relative to the stimulus but to our whole context. Therefore what you have said does not convince me to buy a new monitor for the sake of the specular highlights in particular, (and they will often meet a limitation in the camera sensor anyway). But you point to less need for compression in general, which has a certain attraction for pictures with large dynamic range.