Skip to main content

A library/tool to decode images in HEIC/HEIF format taken on Apple devices that contain HDR gain map.

Project description

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:

  1. A 16- or 32-bit per channel float representation in a given linear color space, which could be saved to an EXR file.
  2. 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+
  • exiftool 12.54+
    • For Ubuntu or Debian, do sudo apt install libimage-exiftool-perl
    • For other Linux distros, search exiftool using your package manager
    • For Mac or Windows, follow the instructions in website
    • For Windows, it is also available via Scoop

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apple_hdr_heic-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apple_hdr_heic-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file apple_hdr_heic-0.1.0.tar.gz.

File metadata

  • Download URL: apple_hdr_heic-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for apple_hdr_heic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 485e45571268226a528f8a53ae707c58d6273ec8c45b08ddd3ef20247fc3da35
MD5 30e89670bb9dab6066587e579f7799a3
BLAKE2b-256 3557ce939edb13c883ec76f61185f83740ab897a1d4300b8b6b4c715cabd2e3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for apple_hdr_heic-0.1.0.tar.gz:

Publisher: release.yml on johncf/apple-hdr-heic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file apple_hdr_heic-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: apple_hdr_heic-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for apple_hdr_heic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f25e8245d58bd47f015b895a283a829dd49284e40fe513b693b4f9d54a4800bf
MD5 31eb8888346c66c60c0f538c9049cf04
BLAKE2b-256 893940e1b212c6b7d48c164d2d147eee298e8d9c41073dcc00c86d8580dc079e

See more details on using hashes here.

Provenance

The following attestation bundles were made for apple_hdr_heic-0.1.0-py3-none-any.whl:

Publisher: release.yml on johncf/apple-hdr-heic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page