@@ -24,29 +24,15 @@ private let imageCompressionQuality: CGFloat = 0.8
24
24
/// An enum describing failures that can occur when converting image types to model content data.
25
25
/// For some image types like `CIImage`, creating valid model content requires creating a JPEG
26
26
/// representation of the image that may not yet exist, which may be computationally expensive.
27
- public enum ImageConversionError : Error {
28
- /// The image that could not be converted.
29
- public enum SourceImage {
30
- #if canImport(UIKit)
31
- case uiImage( UIImage )
32
- #elseif canImport(AppKit)
33
- case nsImage( NSImage )
34
- #endif // canImport(UIKit)
35
- case cgImage( CGImage )
36
- #if canImport(CoreImage)
37
- case ciImage( CIImage )
38
- #endif // canImport(CoreImage)
39
- }
40
-
27
+ enum ImageConversionError : Error {
41
28
/// The image (the receiver of the call `toModelContentParts()`) was invalid.
42
29
case invalidUnderlyingImage
43
30
44
31
/// A valid image destination could not be allocated.
45
32
case couldNotAllocateDestination
46
33
47
- /// JPEG image data conversion failed, accompanied by the original image, which may be an
48
- /// instance of `NSImage`, `UIImage`, `CGImage`, or `CIImage`.
49
- case couldNotConvertToJPEG( SourceImage )
34
+ /// JPEG image data conversion failed.
35
+ case couldNotConvertToJPEG
50
36
}
51
37
52
38
#if canImport(UIKit)
@@ -55,7 +41,7 @@ public enum ImageConversionError: Error {
55
41
extension UIImage : ThrowingPartsRepresentable {
56
42
public func tryPartsValue( ) throws -> [ ModelContent . Part ] {
57
43
guard let data = jpegData ( compressionQuality: imageCompressionQuality) else {
58
- throw ImageConversionError . couldNotConvertToJPEG ( . uiImage ( self ) )
44
+ throw ImageConversionError . couldNotConvertToJPEG
59
45
}
60
46
return [ ModelContent . Part. inlineData ( mimetype: " image/jpeg " , data) ]
61
47
}
@@ -72,7 +58,7 @@ public enum ImageConversionError: Error {
72
58
let bmp = NSBitmapImageRep ( cgImage: cgImage)
73
59
guard let data = bmp. representation ( using: . jpeg, properties: [ . compressionFactor: 0.8 ] )
74
60
else {
75
- throw ImageConversionError . couldNotConvertToJPEG ( . nsImage ( self ) )
61
+ throw ImageConversionError . couldNotConvertToJPEG
76
62
}
77
63
return [ ModelContent . Part. inlineData ( mimetype: " image/jpeg " , data) ]
78
64
}
@@ -97,7 +83,7 @@ public enum ImageConversionError: Error {
97
83
if CGImageDestinationFinalize ( imageDestination) {
98
84
return [ . inlineData( mimetype: " image/jpeg " , output as Data ) ]
99
85
}
100
- throw ImageConversionError . couldNotConvertToJPEG ( . cgImage ( self ) )
86
+ throw ImageConversionError . couldNotConvertToJPEG
101
87
}
102
88
}
103
89
#endif // !os(watchOS)
@@ -118,7 +104,7 @@ public enum ImageConversionError: Error {
118
104
if let jpegData = jpegData {
119
105
return [ . inlineData( mimetype: " image/jpeg " , jpegData) ]
120
106
}
121
- throw ImageConversionError . couldNotConvertToJPEG ( . ciImage ( self ) )
107
+ throw ImageConversionError . couldNotConvertToJPEG
122
108
}
123
109
}
124
110
#endif // canImport(CoreImage)
0 commit comments