Skip to content

Commit 4deabab

Browse files
committed
Fix accidentally dropping encoding quality on the floor sometimes
1 parent e9b2bb3 commit 4deabab

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableImageFormat+UTType.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,20 @@ extension AttachableImageFormat {
4646
/// @Available(Swift, introduced: 6.3)
4747
/// }
4848
public init(contentType: UTType, encodingQuality: Float = 1.0) {
49+
let kind: Kind
4950
switch contentType {
5051
case .png:
51-
self.init(kind: .png, encodingQuality: encodingQuality)
52+
kind = .png
5253
case .jpeg:
53-
self.init(kind: .jpeg, encodingQuality: encodingQuality)
54+
kind = .jpeg
5455
default:
5556
precondition(
5657
contentType.conforms(to: .image),
5758
"An image cannot be attached as an instance of type '\(contentType.identifier)'. Use a type that conforms to 'public.image' instead."
5859
)
59-
self.init(kind: .systemValue(contentType), encodingQuality: encodingQuality)
60+
kind = .systemValue(contentType)
6061
}
62+
self.init(kind: kind, encodingQuality: encodingQuality)
6163
}
6264

6365
/// Construct an instance of this type with the given path extension and

Sources/Overlays/_Testing_WinSDK/Attachments/AttachableImageFormat+CLSID.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,15 @@ extension AttachableImageFormat {
224224
@_spi(_)
225225
#endif
226226
public init(encoderCLSID: CLSID, encodingQuality: Float = 1.0) {
227-
switch CLSID.Wrapper(encoderCLSID) {
227+
let kind: Kind = switch CLSID.Wrapper(encoderCLSID) {
228228
case CLSID.Wrapper(CLSID_WICPngEncoder):
229-
self = .png
229+
.png
230230
case CLSID.Wrapper(CLSID_WICJpegEncoder):
231-
self = .jpeg
231+
.jpeg
232232
case let encoderCLSID:
233-
self.init(kind: .systemValue(encoderCLSID), encodingQuality: encodingQuality)
233+
.systemValue(encoderCLSID)
234234
}
235+
self.init(kind: kind, encodingQuality: encodingQuality)
235236
}
236237

237238
/// Construct an instance of this type with the given path extension and

0 commit comments

Comments
 (0)