Some Bits: Nelson's log

Working with Ultra HDR JPGs

My Pixel phone takes nice HDR images and saves them as UltraHDR. (aka ISO 21496-1 or Adaptive HDR). These files look and act mostly like normal JPEGs but HDR-aware software can find a second raster image in there with a “gain map” which has extra brightness information for boosting the image into 10 bit HDR.

It’s a bit of a kludge but seems to work well in practice. Chrome and a lot of Android software works with them as true HDR images. Microsoft and Apple both support them, as do all the browsers. Any old software without UltraHDR falls back to an 8 bit SDR image: not great but better than nothing.

GUI HDR programs

I’d like to view and edit HDR images on my Linux desktop. I have a nice HDR monitor that is working! Unfortunately I can’t find a single mainstream Linux image viewer or editor that supports Ultra HDR JPGs. A little surprised at that. The only thing that will show them correctly is Chrome, you can drag a local file to it and it displays in HDR.

There are a couple of specialist viewers that sort of work. tev seems to handle the HDR data but I couldn’t easily get a display that looked right although fiddling with the tone mapping the image looked intact. HDRView displays the image great but I think is only rendering at 8 bits, just nicely tonemapped. Also it doesn’t scale the UI to my display so it’s unusable.

CLI HDR programs

Even worse, I can’t find a good command line program to work with UltraHDRs or even convert them intact to other HDR formats like AVIF or EXR. At least, nothing simple seems to work. I tried out a bunch of Gemini suggestions on a Pixel photo and didn’t get very far.

The winner is hdrify-cli, a pure Javascript node program. It is easy to install and use. I can convert the UltraHDR-JPG to a EXR file that when opened in Okulus looks... different than the source SDR. Like a badly tone mapped image, but maybe that’s Okulus’ display algorithm fault. If I convert it back to a JPEG and view it in Chrome it looks like the original, so actual round trip conversion! hdrify also supports writing 8 bit SDR files like WebPs, it seems to just extract the SDR from the source.

ImageMagick now has some HDR support but I can’t honestly tell how much. The build on my Nobara Linux system doesn’t include the support. I tried a precompiled build from the project but didn’t get much success with the converter. I got somewhere using this elaborate command, but the resulting tone mapping was too dark. Also this is way too complicated, why doesn’t convert foo.jpg foo.avif just work?

uhdr2avif seemed promising but the program just spun and ate 2 CPUs.

Google’s reference libultrahdr has a demo program but it’s more of a swiss army knife for working with UltraHDR images, not a simple converter.

A lot of these tools all seem very much aimed at experts who understand tone mapping curves and color spaces and gamuts. Not intended for civilian use.

File formats

Part of my confusion is what image format I should be using for HDR images.

UltraHDR JPG is what Google is giving me when I download my photos. It’s a kludgey format but has a lot of support, it seems OK.

AVIF seems like the “best” choice for a clean image format that happens to also do HDR. Unfortunately hdrify doesn’t support writing it.

EXR is a very low level HDR format that has some broad support. Main issue is there’s no lossy compression so files are huge.

JPEG-XL in theory should work but in practice is still a dead-on-arrival format.

HEIC/HEIF is what Apple has been doing but I don’t think much else supports it.