Remove no-longer-needed functions for compositing the avatar on a background.

This commit is contained in:
Brent Simmons 2019-09-16 20:07:07 -07:00
parent a225d52ba3
commit 2d22f061a5
1 changed files with 2 additions and 53 deletions

View File

@ -28,63 +28,12 @@ extension RSImage {
return nil
}
// if cgImage.width < avatarSize || cgImage.height < avatarSize {
// cgImage = RSImage.compositeAvatar(cgImage)
// }
#if os(iOS)
return RSImage(cgImage: cgImage)
#else
let size = NSSize(width: cgImage.width, height: cgImage.height)
return RSImage(cgImage: cgImage, size: size)
#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
}