capturegraph.adapters.apple_dng_convert
#
Apple DNG Conversion Utilities (Internal)#
.. warning:: Do not use these functions directly.
Use the cross-platform wrappers from ``dng_convert`` instead::
from capturegraph.adapters import dng_to_jpeg, dng_to_heif, dng_to_png, dng_to_pil
These wrappers automatically use Apple Core Image when available on macOS,
and fall back to rawpy on other platforms.
macOS-specific utilities for converting DNG (Digital Negative) raw files to JPEG, HEIF, and PNG formats using Apple's Core Image (Quartz) framework.
This preserves Apple's native tone mapping and color science, producing results consistent with Preview.app and Photos.app. EXIF metadata from the source DNG is preserved in the output files.
Thread Safety
These functions are thread-safe and can be called concurrently from multiple threads. Each thread uses its own CIContext and operations are wrapped in autorelease pools to prevent memory issues with Objective-C objects.
Requires
- macOS
- PyObjC (pyobjc-framework-Quartz, pyobjc-framework-Cocoa)
apple_dng_to_jpeg(dng_path, output_path, quality=1.0, max_axis=None)
#
Convert a DNG file to JPEG using Apple's Core Image (Quartz) framework.
This preserves Apple's native tone mapping and color science, producing results consistent with Preview.app. EXIF metadata from the source DNG is preserved in the output JPEG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dng_path
|
str | Path
|
Path to the input DNG file. |
required |
output_path
|
str | Path
|
Path for the output JPEG file. |
required |
quality
|
float
|
JPEG compression quality (0.0-1.0). Default is 1.0 for maximum quality. |
1.0
|
max_axis
|
int
|
If provided, resize so the largest dimension equals this value. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created JPEG file. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If not running on macOS or PyObjC is not installed. |
FileNotFoundError
|
If the DNG file does not exist. |
RuntimeError
|
If the conversion fails. |
Example
from capturegraph.adapters import apple_dng_to_jpeg
# Maximum quality conversion
apple_dng_to_jpeg("DSC_0001.dng", "output.jpg")
# Slightly compressed for smaller file size
apple_dng_to_jpeg("DSC_0001.dng", "output.jpg", quality=0.95)
# Save a smaller version for analysis
apple_dng_to_jpeg("DSC_0001.dng", "thumb.jpg", max_axis=1024)
Source code in capturegraph-lib/capturegraph/adapters/apple_dng_convert.py
apple_dng_to_heif(dng_path, output_path, quality=1.0, max_axis=None)
#
Convert a DNG file to HEIF using Apple's Core Image (Quartz) framework.
This preserves Apple's native tone mapping and color science. HEIF provides better compression than JPEG at equivalent quality levels (typically 40-50% smaller files). EXIF metadata from the source DNG is preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dng_path
|
str | Path
|
Path to the input DNG file. |
required |
output_path
|
str | Path
|
Path for the output HEIF file (typically .heic extension). |
required |
quality
|
float
|
HEIF compression quality (0.0-1.0). Default is 1.0 for maximum quality. |
1.0
|
max_axis
|
int
|
If provided, resize so the largest dimension equals this value. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created HEIF file. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If not running on macOS or PyObjC is not installed. |
FileNotFoundError
|
If the DNG file does not exist. |
RuntimeError
|
If the conversion fails. |
Example
from capturegraph.adapters import apple_dng_to_heif
# Maximum quality conversion
apple_dng_to_heif("DSC_0001.dng", "output.heic")
# Good quality with better compression
apple_dng_to_heif("DSC_0001.dng", "output.heic", quality=0.9)
# Save a smaller version for analysis
apple_dng_to_heif("DSC_0001.dng", "thumb.heic", max_axis=1024)
Source code in capturegraph-lib/capturegraph/adapters/apple_dng_convert.py
apple_dng_to_png(dng_path, output_path, max_axis=None)
#
Convert a DNG file to PNG using Apple's Core Image (Quartz) framework.
This preserves Apple's native tone mapping and color science. PNG is lossless, so no quality parameter is needed. Note that PNG has limited EXIF support, but basic metadata will be preserved where possible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dng_path
|
str | Path
|
Path to the input DNG file. |
required |
output_path
|
str | Path
|
Path for the output PNG file. |
required |
max_axis
|
int
|
If provided, resize so the largest dimension equals this value. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created PNG file. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If not running on macOS or PyObjC is not installed. |
FileNotFoundError
|
If the DNG file does not exist. |
RuntimeError
|
If the conversion fails. |
Example
Source code in capturegraph-lib/capturegraph/adapters/apple_dng_convert.py
apple_dng_to_pil(dng_path)
#
Open a DNG file and return it as a PIL Image using Apple's Core Image.
Uses Apple's native RAW processing with proper tone mapping and color science, producing results consistent with Preview.app and Photos.app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dng_path
|
str | Path
|
Path to the input DNG file. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
PIL.Image.Image: The processed image. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If not running on macOS, PyObjC not installed, or Pillow not installed. |
FileNotFoundError
|
If the DNG file does not exist. |
RuntimeError
|
If the conversion fails. |
Note
Remember to call .close() on the returned image when done.
Example
Source code in capturegraph-lib/capturegraph/adapters/apple_dng_convert.py
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 | |