@@ -24,29 +24,15 @@ private let imageCompressionQuality: CGFloat = 0.8
2424/// An enum describing failures that can occur when converting image types to model content data.
2525/// For some image types like `CIImage`, creating valid model content requires creating a JPEG
2626/// 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 {
4128 /// The image (the receiver of the call `toModelContentParts()`) was invalid.
4229 case invalidUnderlyingImage
4330
4431 /// A valid image destination could not be allocated.
4532 case couldNotAllocateDestination
4633
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
5036}
5137
5238#if canImport(UIKit)
@@ -55,7 +41,7 @@ public enum ImageConversionError: Error {
5541 extension UIImage : ThrowingPartsRepresentable {
5642 public func tryPartsValue( ) throws -> [ ModelContent . Part ] {
5743 guard let data = jpegData ( compressionQuality: imageCompressionQuality) else {
58- throw ImageConversionError . couldNotConvertToJPEG ( . uiImage ( self ) )
44+ throw ImageConversionError . couldNotConvertToJPEG
5945 }
6046 return [ ModelContent . Part. inlineData ( mimetype: " image/jpeg " , data) ]
6147 }
@@ -72,7 +58,7 @@ public enum ImageConversionError: Error {
7258 let bmp = NSBitmapImageRep ( cgImage: cgImage)
7359 guard let data = bmp. representation ( using: . jpeg, properties: [ . compressionFactor: 0.8 ] )
7460 else {
75- throw ImageConversionError . couldNotConvertToJPEG ( . nsImage ( self ) )
61+ throw ImageConversionError . couldNotConvertToJPEG
7662 }
7763 return [ ModelContent . Part. inlineData ( mimetype: " image/jpeg " , data) ]
7864 }
@@ -97,7 +83,7 @@ public enum ImageConversionError: Error {
9783 if CGImageDestinationFinalize ( imageDestination) {
9884 return [ . inlineData( mimetype: " image/jpeg " , output as Data ) ]
9985 }
100- throw ImageConversionError . couldNotConvertToJPEG ( . cgImage ( self ) )
86+ throw ImageConversionError . couldNotConvertToJPEG
10187 }
10288 }
10389#endif // !os(watchOS)
@@ -118,7 +104,7 @@ public enum ImageConversionError: Error {
118104 if let jpegData = jpegData {
119105 return [ . inlineData( mimetype: " image/jpeg " , jpegData) ]
120106 }
121- throw ImageConversionError . couldNotConvertToJPEG ( . ciImage ( self ) )
107+ throw ImageConversionError . couldNotConvertToJPEG
122108 }
123109 }
124110#endif // canImport(CoreImage)
0 commit comments