I/O
hdrconv.io
HDR format I/O operations.
This module provides functions for reading and writing various HDR formats:
- ISO 21496-1 (Adaptive Gainmap):
read_21496,write_21496 - ISO 22028-5 (PQ/HLG AVIF):
read_22028_pq,write_22028_pq - Apple HEIC with gainmap:
read_apple_heic - iOS HDR screenshot:
read_ios_hdr_screenshot
read_21496(filepath)
Read ISO 21496-1 Gainmap JPEG file.
Parses a JPEG file containing an ISO 21496-1 compliant gainmap with Multi-Picture Format (MPF) container structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the ISO 21496-1 JPEG file. |
required |
Returns:
| Type | Description |
|---|---|
GainmapImage
|
GainmapImage dict containing: |
GainmapImage
|
|
GainmapImage
|
|
GainmapImage
|
|
GainmapImage
|
|
GainmapImage
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If gainmap is not found in MPF container. |
ValueError
|
If ISO 21496-1 metadata segment is missing. |
Note
The file must contain a valid MPF structure with the gainmap as the secondary image and ISO 21496-1 metadata in an APP2 segment.
See Also
write_21496: Write GainmapImage to ISO 21496-1 format.gainmap_to_hdr: Convert GainmapImage to linear HDR.
Source code in src/hdrconv/io/iso21496.py
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | |
write_21496(data, filepath)
Write ISO 21496-1 Gainmap JPEG file.
Creates a JPEG file with ISO 21496-1 compliant gainmap structure using Multi-Picture Format (MPF) container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GainmapImage
|
GainmapImage dict containing:
- |
required |
filepath
|
str
|
Output path for the JPEG file. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If file writing fails. |
Note
The output file structure places the baseline image first with an MPF index, followed by the gainmap with ISO 21496-1 metadata. JPEG quality is set to 95 with 4:4:4 chroma subsampling.
See Also
read_21496: Read ISO 21496-1 Gainmap JPEG.hdr_to_gainmap: Convert HDR image to GainmapImage.
Source code in src/hdrconv/io/iso21496.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | |
read_22028_pq(filepath)
Read ISO 22028-5 PQ AVIF file.
Decodes an AVIF file encoded with Perceptual Quantizer (PQ) transfer function as specified in ISO 22028-5 and SMPTE ST 2084.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the PQ AVIF file. |
required |
Returns:
| Type | Description |
|---|---|
HDRImage
|
HDRImage dict containing: |
HDRImage
|
|
HDRImage
|
|
HDRImage
|
|
HDRImage
|
|
Note
Currently assumes BT.2020 color primaries and 10-bit decode range. Future versions may extract actual color metadata from AVIF.
See Also
write_22028_pq: Write HDR image to PQ AVIF format.inverse_pq: Convert PQ-encoded data to linear light.
Source code in src/hdrconv/io/iso22028.py
write_22028_pq(data, filepath)
Write ISO 22028-5 PQ AVIF file.
Encodes an HDR image to AVIF format with Perceptual Quantizer (PQ) transfer function as specified in ISO 22028-5 and SMPTE ST 2084.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
HDRImage
|
HDRImage dict with PQ-encoded data. Must contain:
- |
required |
filepath
|
str
|
Output path for the AVIF file. |
required |
Note
Output is encoded at 10-bit depth with quality level 90. Color primaries and transfer characteristics are embedded in AVIF metadata.
See Also
read_22028_pq: Read PQ AVIF file.apply_pq: Convert linear HDR to PQ-encoded values.
Source code in src/hdrconv/io/iso22028.py
read_apple_heic(filepath)
Read Apple HEIC HDR file with gain map.
Extracts the base SDR image, HDR gain map, and headroom metadata from iPhone HEIC photos containing Apple's proprietary HDR format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the Apple HEIC file. |
required |
Returns:
| Type | Description |
|---|---|
AppleHeicData
|
AppleHeicData dict containing: |
AppleHeicData
|
|
AppleHeicData
|
|
AppleHeicData
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If base image, gainmap, or headroom cannot be extracted. |
Note
Requires exiftool to be installed and accessible in PATH for headroom extraction from EXIF/MakerNotes metadata.
See Also
apple_heic_to_hdr: Convert AppleHeicData to linear HDR.has_gain_map: Check if HEIC file contains gain map.
Source code in src/hdrconv/io/apple_heic.py
read_ios_hdr_screenshot(filepath, grid_cols=None, grid_rows=None, tile_size=512, real_width=None, real_height=None)
Read iOS HDR screenshot HEIC file.
Extracts the main image, gainmap, and metadata from iOS HDR screenshots
and returns a standard GainmapImage structure suitable for use with
gainmap_to_hdr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the iOS HDR screenshot HEIC file. |
required |
grid_cols
|
Optional[int]
|
Number of tile columns (auto-detected if None). |
None
|
grid_rows
|
Optional[int]
|
Number of tile rows (auto-detected if None). |
None
|
tile_size
|
int
|
Size of each square tile in pixels. Default: 512. |
512
|
real_width
|
Optional[int]
|
Actual image width (auto-detected if None). |
None
|
real_height
|
Optional[int]
|
Actual image height (auto-detected if None). |
None
|
Returns:
| Type | Description |
|---|---|
GainmapImage
|
GainmapImage dict containing: |
GainmapImage
|
|
GainmapImage
|
|
GainmapImage
|
|
GainmapImage
|
|
GainmapImage
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If external tools (MP4Box, ffmpeg) are not available. |
ValueError
|
If the file cannot be parsed or is not a valid iOS HDR screenshot. |
FileNotFoundError
|
If the input file does not exist. |
Note
Requires MP4Box (from GPAC) and ffmpeg to be installed and available in PATH.
The gainmap_min is always 0 and gainmap_gamma is always 1 for iOS HDR screenshots. Both baseline_offset and alternate_offset are set to the same value extracted from the tmap metadata.
See Also
gainmap_to_hdr: Convert the returned GainmapImage to linear HDR.
Source code in src/hdrconv/io/ios_hdr_screenshot.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
read_ultrahdr(filepath)
Read UltraHDR JPEG file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the UltraHDR JPEG file. |
required |
Returns:
| Type | Description |
|---|---|
GainmapImage
|
GainmapImage dict containing baseline, gainmap, metadata, and ICC data. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If gainmap stream or HDR gainmap metadata is missing. |
Source code in src/hdrconv/io/ultrahdr.py
write_ultrahdr(data, filepath)
Write UltraHDR JPEG file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GainmapImage
|
GainmapImage dict containing baseline, gainmap, and metadata. |
required |
filepath
|
str
|
Output path for the JPEG file. |
required |