Learn / Gain Maps

What is a gain map?

The trick behind most HDR photos you've actually seen — on a phone, in Google Photos, in a browser. One file, two images, and a normal-looking fallback built in.

A dramatic golden-hour sunset over the ocean with birds flying across a bright sun
Photo by frank mckenna on Unsplash

Open an HDR photo on a phone that supports it, and the sky looks genuinely brighter than the rest of the screen — not just more contrasty, but like there's more light coming from it. Open that same file on an older device, and you just see a normal, perfectly reasonable photo. Both of those are the same file. The mechanism that makes that possible, in most cases you'll actually run into, is called a gain map.

Two images in one file

A gain-map HDR file isn't one image with extra-bright pixels. It's two images bundled together: a normal, standard-dynamic-range (SDR) photo — the primary — and a second, smaller grayscale image — the gain map — where each pixel says how much brighter the corresponding pixel in the primary should get, on a display that can show it.

White in the gain map means "boost this pixel as much as this photo ever needs." Black means "leave it alone." Everything in between is a partial boost. A handful of extra numbers in the file's metadata (things like how much the brightest boost actually corresponds to, in real terms) tell a decoder exactly how to turn that grayscale map into real extra brightness.

This is exactly what you're looking at in Headroom's Encode tool: toggle to "Gain map" in the live preview and you'll see that literal grayscale boost mask, computed from your actual image.

Why bother with two images instead of one?

Backward compatibility. Any app, browser, or device that has never heard of gain maps can still open the file — it just reads the primary image and shows a normal SDR photo. Nothing breaks, nothing looks wrong. Only software that specifically knows to look for the gain map recombines the two and shows you the boosted version. That's a meaningfully different bet than formats that require a decoder to understand HDR at all just to render the file correctly.

How the boost actually gets computed

For each pixel, an encoder compares how bright that pixel currently is (in the SDR primary) to how bright it's supposed to end up (the HDR target, based on the mapping mode and settings you choose). The ratio between those two — expressed as a log2 value, since brightness perception is roughly logarithmic — becomes that pixel's value in the gain map. A pixel that shouldn't change at all gets a gain of zero; a pixel that should hit the file's maximum boost gets the gain map's brightest value.

This is also exactly where it's easy to get wrong: if a tool bakes a boosted look into the primary image and ships a gain map computed against the original, unboosted image, an HDR-capable viewer will apply that gain map on top of an already-brightened primary — double boosting it into blown-out highlights. A correct pipeline computes the gain map against whatever the primary image actually ships as, not what it used to be.

Where you've actually encountered this

Ultra HDR (Google's format, used by Android's camera and Google Photos), Adobe's Gain Map specification, and Apple's HDR photo pipeline are all variations on this same idea. If you've taken an HDR photo on a recent phone, it's very likely a gain-map file under the hood — see What is Ultra HDR? for the specific format most Android photos use.

Try it on a real file

Encode builds this exact kind of file from any photo you give it — primary image, computed gain map, and the metadata a decoder needs, all spliced into one real JPEG and round-trip validated before you can download it. Inspect reads any image you give it and tells you honestly whether it actually has a gain map embedded, rather than guessing from the filename or extension.

Questions people actually ask

Is a gain map the same thing as HDR?
It's one way of delivering HDR, not the only one. A gain map is a specific technique — an extra grayscale image plus metadata — used by formats like Ultra HDR and Adobe's Gain Map spec. Other HDR approaches (like HDR video's PQ or HLG) encode brightness directly in the pixel values instead, with no second image involved.
Why not just make the main image brighter?
Because most screens and apps still only understand standard (SDR) brightness. If the primary image itself were blown out past SDR white, it would just look overexposed everywhere that doesn't apply the gain map. Keeping the primary image SDR-safe and storing the extra brightness separately is what makes the file degrade gracefully instead of breaking.
Does a gain map make the file much bigger?
Not usually. The gain map is typically encoded at lower resolution and quality than the primary image, since it only needs to carry a smooth boost signal, not fine detail. It adds some size, but nowhere near doubling the file.
Can I see the gain map itself, not just the boosted result?
Yes — Headroom's Encode tool shows you the raw gain map (white = full boost, black = none) alongside the boosted result while you're creating one, and Inspect will tell you whether an uploaded file has one embedded.