mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-22 15:20:00 +01:00
Remove no-longer-needed functions for compositing the avatar on a background.
This commit is contained in:
parent
a225d52ba3
commit
2d22f061a5
@ -27,64 +27,13 @@ extension RSImage {
|
|||||||
guard var cgImage = RSImage.scaleImage(data, maxPixelSize: scaledMaxPixelSize) else {
|
guard var cgImage = RSImage.scaleImage(data, maxPixelSize: scaledMaxPixelSize) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// if cgImage.width < avatarSize || cgImage.height < avatarSize {
|
|
||||||
// cgImage = RSImage.compositeAvatar(cgImage)
|
|
||||||
// }
|
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
return RSImage(cgImage: cgImage)
|
return RSImage(cgImage: cgImage)
|
||||||
#else
|
#else
|
||||||
let size = NSSize(width: cgImage.width, height: cgImage.height)
|
let size = NSSize(width: cgImage.width, height: cgImage.height)
|
||||||
return RSImage(cgImage: cgImage, size: size)
|
return RSImage(cgImage: cgImage, size: size)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension RSImage {
|
|
||||||
|
|
||||||
#if os(iOS)
|
|
||||||
|
|
||||||
static func compositeAvatar(_ avatar: CGImage) -> CGImage {
|
|
||||||
let rect = CGRect(x: 0, y: 0, width: avatarSize, height: avatarSize)
|
|
||||||
UIGraphicsBeginImageContext(rect.size)
|
|
||||||
if let context = UIGraphicsGetCurrentContext() {
|
|
||||||
context.setFillColor(AppAssets.avatarLightBackgroundColor.cgColor)
|
|
||||||
context.fill(rect)
|
|
||||||
context.translateBy(x: 0.0, y: CGFloat(integerLiteral: avatarSize));
|
|
||||||
context.scaleBy(x: 1.0, y: -1.0)
|
|
||||||
let avatarRect = CGRect(x: (avatarSize - avatar.width) / 2, y: (avatarSize - avatar.height) / 2, width: avatar.width, height: avatar.height)
|
|
||||||
context.draw(avatar, in: avatarRect)
|
|
||||||
}
|
|
||||||
let img = UIGraphicsGetImageFromCurrentImageContext()
|
|
||||||
UIGraphicsEndImageContext()
|
|
||||||
return img!.cgImage!
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
static func compositeAvatar(_ avatar: CGImage) -> CGImage {
|
|
||||||
var resultRect = CGRect(x: 0, y: 0, width: avatarSize, height: avatarSize)
|
|
||||||
let resultImage = NSImage(size: resultRect.size)
|
|
||||||
|
|
||||||
resultImage.lockFocus()
|
|
||||||
if let context = NSGraphicsContext.current?.cgContext {
|
|
||||||
if NSApplication.shared.effectiveAppearance.isDarkMode {
|
|
||||||
context.setFillColor(AppAssets.avatarDarkBackgroundColor.cgColor)
|
|
||||||
} else {
|
|
||||||
context.setFillColor(AppAssets.avatarLightBackgroundColor.cgColor)
|
|
||||||
}
|
|
||||||
context.fill(resultRect)
|
|
||||||
let avatarRect = CGRect(x: (avatarSize - avatar.width) / 2, y: (avatarSize - avatar.height) / 2, width: avatar.width, height: avatar.height)
|
|
||||||
context.draw(avatar, in: avatarRect)
|
|
||||||
}
|
|
||||||
resultImage.unlockFocus()
|
|
||||||
|
|
||||||
return resultImage.cgImage(forProposedRect: &resultRect, context: nil, hints: nil)!
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user