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 an ISO 21496-1 Gainmap image.
Routes JPEG files to the MPF parser and HEIF/AVIF files to the ISOBMFF parser.
Source code in src/hdrconv/io/iso21496.py
write_21496(data, filepath, baseline_quality=95, gainmap_quality=95)
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 |
baseline_quality
|
int
|
JPEG quality for baseline image (1-100, default 95). |
95
|
gainmap_quality
|
int
|
JPEG quality for gainmap image (1-100, default 95). |
95
|
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
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 | |
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
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 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | |
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
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 | |
write_ultrahdr(data, filepath, baseline_quality=95, gainmap_quality=95)
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 |
baseline_quality
|
int
|
JPEG quality for baseline image (1-100, default 95). |
95
|
gainmap_quality
|
int
|
JPEG quality for gainmap image (1-100, default 95). |
95
|