Skip to content

Commit

Permalink
Avoid bridge to CFMutableData in ImageEncoders.ImageIO
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Apr 21, 2024
1 parent 1f1fc21 commit 3b513dd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Sources/Nuke/Encoding/ImageEncoders+ImageIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ extension ImageEncoders {
}

public func encode(_ image: PlatformImage) -> Data? {
let data = NSMutableData()
guard let source = image.cgImage,
let data = CFDataCreateMutable(nil, 0),
let destination = CGImageDestinationCreateWithData(data, type.rawValue as CFString, 1, nil) else {
return nil
}
var options: [CFString: Any] = [
kCGImageDestinationLossyCompressionQuality: compressionRatio
]
#if canImport(UIKit)
options[kCGImagePropertyOrientation] = CGImagePropertyOrientation(image.imageOrientation).rawValue
#endif
guard let source = image.cgImage,
let destination = CGImageDestinationCreateWithData(data as CFMutableData, type.rawValue as CFString, 1, nil) else {
return nil
}
CGImageDestinationAddImage(destination, source, options as CFDictionary)
guard CGImageDestinationFinalize(destination) else {
return nil
Expand Down

0 comments on commit 3b513dd

Please sign in to comment.