mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-02 18:32:55 +00:00
Create and use pngData() method for Mac to get data from image as PNG instead of TIFF — use less memory.
This commit is contained in:
1 parent
8916c3024f
commit
b784abbec1
2 files changed
+17
-12
No files matched your search
@@ -83,16 +83,25 @@ public extension RSImage {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
/// Returns data as PNG. May be nil in some circumstances.
|
||||
func pngData() -> Data? {
|
||||
guard let cgImage = cgImage(forProposedRect: nil, context: nil, hints: nil) else {
|
||||
return nil
|
||||
}
|
||||
let bitmapRep = NSBitmapImageRep(cgImage: cgImage)
|
||||
return bitmapRep.representation(using: .png, properties: [:])
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Returns a data representation of the image.
|
||||
///
|
||||
/// The resultant data is TIFF data on macOS, and PNG data on iOS.
|
||||
/// - Returns: Data representing the image.
|
||||
/// - Returns: Image data. Normally PNG, though in rare cases it might TIFF on macOS.
|
||||
func dataRepresentation() -> Data? {
|
||||
#if os(macOS)
|
||||
return tiffRepresentation
|
||||
#else
|
||||
return pngData()
|
||||
#endif
|
||||
#if os(macOS)
|
||||
pngData() ?? tiffRepresentation
|
||||
#else
|
||||
return pngData()
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Asynchronously initializes an image from data.
|
||||
|
||||
@@ -126,11 +126,7 @@ extension Article {
|
||||
let fm = FileManager.default
|
||||
var path = fm.urls(for: .cachesDirectory, in: .userDomainMask)[0]
|
||||
let feedID = webFeed.webFeedID.replacingOccurrences(of: "/", with: "_")
|
||||
#if os(macOS)
|
||||
path.appendPathComponent(feedID + "_smallIcon.tiff")
|
||||
#else
|
||||
path.appendPathComponent(feedID + "_smallIcon.png")
|
||||
#endif
|
||||
fm.createFile(atPath: path.path, contents: image.image.dataRepresentation()!, attributes: nil)
|
||||
return path
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user