Skip to content

About

HLG / HDR PQ photos to Apple adaptive HDR (gain-map HDR): conversion library + hlg2hdr CLI

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HLGtoHDRKit

Convert HLG / HDR PQ photos into Apple adaptive HDR (gain-map HDR) — locally, on your own machine, with no upload and no third-party service.

This is the conversion engine behind the HLG to HDR app, packaged on its own:

  • HLGtoHDRKit — the conversion core as a Swift library (detection, HDR decode, tone mapping, gain-map generation, metadata handling, verification).
  • hlg2hdr — a command line front end over the same pipeline, for scripting and batch work.

Quick start

git clone https://github.com/webto/HLGtoHDRKit.git && cd HLGtoHDRKit
swift run hlg2hdr selftest                          # generate → convert → verify, one command
swift run hlg2hdr convert --recursive ~/Pictures/HLG  # outputs are written beside the inputs

Prebuilt universal binaries are on the Releases page — see Install.

What it produces

A HEIF file with a 10-bit SDR base image plus an ISO 21496-1 gain map, which Apple platforms render as adaptive HDR. The output keeps the source's EXIF / GPS / XMP / TIFF metadata, carries hdr:converter / hdr:converterVersion / hdr:settings XMP and an EXIF UserComment, and adds dc:subject = ShotinHLG so converted files can be found by a keyword in Photos. Orientation is baked into the pixels.

An input that is already adaptive HDR is reported as skipped — that is a success, not an error.

Requirements

  • Library: macOS 15 or later, iOS 26 or later (the app's own deployment targets).
  • CLI: built and validated on macOS 26 / Apple Silicon with the Swift 6.2 toolchain (Xcode 27 or the matching toolchain). Release binaries are universal: arm64 + x86_64.
  • Apple frameworks only (CoreGraphics / CoreImage / ImageIO). No third-party dependencies.

Install

Download

Take hlg2hdr-1.0.1-macos-universal.zip from Releases, unpack it, and put hlg2hdr on your PATH. The binary is signed with a Developer ID and notarised; a disk image that can carry the notarisation ticket is attached when available.

unzip hlg2hdr-1.0.1-macos-universal.zip
sudo mv hlg2hdr /usr/local/bin/
hlg2hdr --version

From source

swift build -c release
.build/release/hlg2hdr --version

Commands

Command What it does
convert <input>... Convert HLG / HDR PQ images to adaptive HDR. At least one input; directories need --recursive.
inspect <file> Show what an image is (encoding, HDR type, gain map), without converting.
verify <file> Check that a file really is adaptive HDR: gain map present, metadata sane. Exit code 1 when it is not, so it works as a gate.
gen-test <out> Write a synthetic HLG test image.
selftest [outdir] Generate, convert and verify in one go — the fastest way to check a machine.
help [command] Usage, or the detail for one command.

hlg2hdr --help prints the same overview.

Options

Option Meaning
--out, -o <dir|file> Destination directory, or a file when there is exactly one input. Default: beside each input.
--recursive, -r Walk directories given in the input list.
--ext <list> Extensions picked up when walking. Default heic,heif,hif,jpg,jpeg.
--skip-existing Skip an output that already exists (the default).
--force Overwrite an existing output (mutually exclusive with --skip-existing).
--dry-run Report what would happen and write nothing.
--working-space p3|2020|srgb Internal linear HDR working space. Default p3.
--tone auto|rolloff SDR tone mapping. Default auto.
--headroom <float> HDR headroom override. Default: measured from the source.
--json Machine-readable output on stdout; human text goes to stderr.
--quiet, -q / --verbose, -v Less / more output.
--no-color No ANSI colour (NO_COLOR is honoured too).

Exit codes

Code Meaning
0 Everything succeeded. Inputs reported as skipped count as success.
1 Nothing worked (every input failed — or verify says the file is not adaptive HDR).
2 Usage error: unknown command or option, missing value, bad value, wrong number of arguments, conflicting flags. stdout stays clean.
3 Partial: some inputs succeeded, some failed.

Examples

# Convert a whole tree, writing each output beside its input
hlg2hdr convert --recursive ~/Pictures/HLG

# Convert into one destination directory
hlg2hdr convert --recursive ~/Pictures/HLG --out ~/Pictures/HDR

# Re-run only unfinished work, then force a re-render
hlg2hdr convert ~/Pictures/HLG --out ~/Pictures/HDR --skip-existing
hlg2hdr convert ~/Pictures/HLG/sample.HIF --force

# Look before you convert (script friendly)
hlg2hdr inspect ~/Pictures/HLG/sample.HIF --json

# Drive it yourself and act on the per-invocation result
find ~/Pictures/HLG -type f \( -iname '*.hif' -o -iname '*.heic' -o -iname '*.jpg' \) |
while IFS= read -r f; do
  hlg2hdr convert "$f" --out ~/Pictures/HDR/ || echo "failed: $f"
done

# Gate a pipeline on a converted file
hlg2hdr verify ~/Pictures/HDR/sample.heic || echo "not adaptive HDR"

How it works

  1. Detect what the input actually is (HLG / PQ, HEIF / JPEG), rather than trusting the file extension.
  2. Decode the HDR image in the chosen linear working space (p3 by default).
  3. Render a 10-bit SDR base with tone mapping, and generate the ISO 21496-1 gain map from the measured headroom.
  4. Write HEIF with both, restore the source metadata, tag the output, and bake the orientation into the pixels.
  5. Verify the result (gain map present and consistent) before reporting success.

Library

Add the package to your Package.swift:

.package(url: "https://github.com/webto/HLGtoHDRKit.git", from: "1.0.0")

The library is the same code the app ships; hlg2hdr is its reference consumer. The public types live in Sources/HLGtoHDRKit, and the tests in Tests/HLGtoHDRKitTests show the supported paths. This project is at 1.0.1: the CLI flags are the stable contract, the library surface may still change in minor releases.

Known test gaps on iOS

The package builds for iOS and the CLI suite passes there, but the library test suite does not run green on the iOS simulator yet (measured on a current build: 135 tests, 22 skipped, 22 failures). The failures are in the test helpers: the synthetic-image generator cannot finalise EXIF injection on iOS (20 cases), and two clamp tests use tolerances that the simulator's floating-point path exceeds. None of it affects linking or the conversion contract; the app's own iOS probe suite passes. Fixing the helpers is on the list, not a blocker for using the library on iOS.

GUI app

Want a graphical app instead of the CLI? HLG to HDR is available on the Mac App Store and the iOS App Store — one universal purchase for both. The app adds Photo Library integration, batch selection, in-place write-back and diagnostics on top of this engine.

Contributing

Issues and pull requests are welcome. Please run swift test before opening a PR, and keep the CLI argument contract and exit codes backwards compatible. Bug reports that include hlg2hdr inspect output (or the app's exported diagnostic log) are much easier to act on.

License

MIT — see LICENSE.

Support

About

HLG / HDR PQ photos to Apple adaptive HDR (gain-map HDR): conversion library + hlg2hdr CLI

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages