Skip to content

Commit

Permalink
OpenEXR support
Browse files Browse the repository at this point in the history
  • Loading branch information
starkdmi committed May 4, 2024
1 parent 79b06dd commit c19ad74
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ __Supported image formats:__
- TIFF
- BMP
- JPEG 2000
- OpenEXR
- ICO
- PDF

Expand Down
7 changes: 6 additions & 1 deletion Sources/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public struct ImageTool {
case .jpeg2000:
fallthrough
#endif
case .jpeg, .gif, .bmp, .ico, .png, .tiff, .heic, .heics, .pdf:
case .jpeg, .gif, .bmp, .ico, .png, .tiff, .heic, .heics, .exr, .pdf:
guard let utType = format.utType, let destination = CGImageDestinationCreateWithURL(url as CFURL, utType, frames.count, nil) else {
// debugPrint(CGImageDestinationCopyTypeIdentifiers()) // supported output image formats when using `CGImageDestination` methods
throw CompressionError.failedToCreateImageFile
Expand Down Expand Up @@ -630,6 +630,11 @@ public struct ImageTool {
if let iptc = metadata[kCGImagePropertyIPTCDictionary] {
imageOptions[kCGImagePropertyIPTCDictionary] = iptc
}

// OpenEXR
if let exr = metadata[kCGImagePropertyOpenEXRDictionary] {
imageOptions[kCGImagePropertyOpenEXRDictionary] = exr
}
}

// Orientation
Expand Down
10 changes: 8 additions & 2 deletions Sources/Types/Image/ImageFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public enum ImageFormat: Hashable, Equatable {
/// Bitmap image format
case bmp

/// OpenEXR
case exr

/// Icon image format, squared only with 6, 32, 48, 128, or 256 pixels wide
case ico

Expand All @@ -78,11 +81,11 @@ public enum ImageFormat: Hashable, Equatable {
/// Predefined formats
#if os(macOS)
internal static var allFormats: [ImageFormat] = [
.heif, .heif10, .heic, .heics, .png, .jpeg, .jpeg2000, .gif, .tiff, .bmp, .ico, .pdf
.heif, .heif10, .heic, .heics, .png, .jpeg, .jpeg2000, .gif, .tiff, .bmp, .exr, .ico, .pdf
]
#else
internal static var allFormats: [ImageFormat] = [
.heif, .heif10, .heic, .heics, .png, .jpeg, .gif, .tiff, .bmp, .ico, .pdf
.heif, .heif10, .heic, .heics, .png, .jpeg, .gif, .tiff, .bmp, .exr, .ico, .pdf
]
#endif

Expand Down Expand Up @@ -116,6 +119,7 @@ public enum ImageFormat: Hashable, Equatable {
case (.gif, .gif): return true
case (.tiff, .tiff): return true
case (.bmp, .bmp): return true
case (.exr, .exr): return true
case (.ico, .ico): return true
case (.pdf, .pdf): return true
case (.custom(let lhsFormatId), .custom(let rhsFormatId)):
Expand Down Expand Up @@ -170,6 +174,8 @@ public enum ImageFormat: Hashable, Equatable {
} else {
return kUTTypeBMP
}
case .exr:
return "com.ilm.openexr-image" as CFString
case .ico:
if #available(macOS 11, iOS 14, tvOS 14, visionOS 1, *) {
return UTType.ico.identifier as CFString
Expand Down

0 comments on commit c19ad74

Please sign in to comment.