Add real HDR headroom to an image
Encodes a gain-map JPEG (Ultra HDR style) — the one HDR output format Phase 0 proved works end-to-end, entirely locally. Every export is round-trip validated before you can download it.
How Encode actually works
Encode runs a two-pass pipeline, entirely in a Web Worker so the tab stays responsive. Pass one computes a gain map against your original image — for each pixel, how much brighter it should get based on the mode and settings you picked, expressed as a log2 ratio. That gets fed through the same tone-mapping math Preview uses to produce a boosted primary image: the actual visual result you see in the live preview.
Pass two recomputes the gain map — this time against that boosted primary, not the original. That's deliberate: an HDR-capable viewer reconstructs brightness as primary × 2^gain. If the gain map were still computed against the unboosted original while the primary already carries the boost, a real HDR viewer would apply the boost twice and blow out the highlights. Recomputing against the actual shipped primary keeps the math self-consistent.
The primary and the gain map are both encoded as real JPEGs, then spliced together with hdrgm XMP metadata via an MPF container — the same structure Ultra HDR and Adobe's Gain Map spec describe. Before the download link ever becomes clickable, the resulting file is decoded back apart and checked: does the whole file still open at the right dimensions, does the embedded gain map decode at the right dimensions too. Only a genuine pass unlocks the download.