apple-hdr-heic
A library/tool to decode photos (HEIC files) taken on an iPhone that contain HDR gain map, and convert it to standard HDR representations such as:
- A 16- or 32-bit per channel float representation in a given linear color space, which could be saved to an EXR file.
- A 48-bit (16-bit per channel) representation as per Rec. 2100 with PQ transfer function, which could be saved to a PNG file.
Disclaimer: This project is not affiliated with, or endorsed by, Apple Inc. or any of its subsidiaries.
Pre-requisites
- Python 3.10+
exiftool12.54+- For Ubuntu or Debian, do
sudo apt install libimage-exiftool-perl - For other Linux distros, search
exiftoolusing your package manager - For Mac or Windows, follow the instructions in website
- For Windows, it is also available via Scoop
- For Ubuntu or Debian, do
Installation
To install the latest published version, do (preferrably in a virtual environment):
pip install apple-hdr-heic
Or if you want the latest development version, install using a Github archive link:
pip install https://github.com/johncf/apple-hdr-heic/archive/master.tar.gz
Usage
CLI Tool
apple-hdr-heic-decode input.heic output.png
apple-hdr-heic-decode input.heic output.heic -q 95
Near-lossless conversion:
apple-hdr-heic-decode input.heic output.avif -b 12 -y 444
Note: With 12-bit channels (in AVIF or HEIC), it's not truly lossless compared to 16-bit channels in PNG or 32-bit channels in EXR, but it's close enough.
Truly lossless conversion:
apple-hdr-heic-decode input.heic output.exr -b 32 --colorspace "ROMM RGB"
Note: Even though this preserves all the HDR information in the original image, the HDR-to-SDR tone-mapping information will be lost. To preserve that, an additional layer of information is required (like the HDR gain map in the original image, which is an inverse tone-map).
Library Usage
from apple_hdr_heic import load_as_bt2020_linear, quantize_bt2020_to_bt2100_pq
bt2020_linear = load_as_bt2020_linear("input.heic")
bt2100_pq = quantize_bt2020_to_bt2100_pq(bt2020_linear)
cv2.imwrite("output.png", bt2100_pq[:, :, ::-1])
Note: The output file output.png (in examples above) does not contain the necessary cICP metadata that denotes it to have bt2020 (9) color primaries and smpte2084 (16) transfer characteristics. Therefore, all image viewers will display them incorrectly.
Development
Environment Set Up
Install uv.
Install nox using uv:
uv tool install nox
Unit Testing
nox -s test
Type Checking
nox -s typeck
Linting
nox -s lint
Formatting
nox -s style
Building
uv tool install flit
flit build --no-use-vcs
Miscellaneous Notes
About 12-bit HEIC Files
Although this tool supports 12-bit HEIC output, it doesn't seem to be widely supported, even in Apple softwares.
About AVIF Output
If you want to use a different AVIF encoder, first use this tool to produce a PNG file, then use libavif with --cicp set to 9/16/9 to convert the PNG to AVIF:
avifenc -s 4 -j 4 --min 1 --max 56 -a end-usage=q -a cq-level=10 -a tune=ssim -a color:enable-qm=1 \
-a color:enable-chroma-deltaq=1 -d 12 --cicp 9/16/9 output.png output.avif
About EXR Output
Although the EXR file created by apple-hdr-heic-decoder tool contains colorspace information (specifically, color primaries and white point), it is not read/used by most softwares out there. Therefore it's recommended to use the --colorspace argument to make the EXR file's color space match what the software consuming the file expects.
For example, Affinity Photo 2 expects "ROMM RGB" by default when opening an EXR file. This default colorspace for 32-bit HDR can be changed from Settings > Color options in Affinity Photo 2.
Release files for apple-hdr-heic 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| apple_hdr_heic-0.1.0.tar.gz | 8.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| apple_hdr_heic-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.1 kB
Release files / apple_hdr_heic-0.1.0.tar.gz
| Download URL | apple_hdr_heic-0.1.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
485e45571268226a528f8a53ae707c58d6273ec8c45b08ddd3ef20247fc3da35
|
|
BLAKE2b-256 checksum How to use checksums |
3557ce939edb13c883ec76f61185f83740ab897a1d4300b8b6b4c715cabd2e3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 11, 2024.
Transparency logRelease files / apple_hdr_heic-0.1.0-py3-none-any.whl
| Download URL | apple_hdr_heic-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f25e8245d58bd47f015b895a283a829dd49284e40fe513b693b4f9d54a4800bf
|
|
BLAKE2b-256 checksum How to use checksums |
893940e1b212c6b7d48c164d2d147eee298e8d9c41073dcc00c86d8580dc079e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 11, 2024.
Transparency log