From 2d22f061a5f0eda49a79bf1547671a06a6c3d21b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 16 Sep 2019 20:07:07 -0700 Subject: [PATCH] Remove no-longer-needed functions for compositing the avatar on a background. --- Shared/Extensions/RSImage-Extensions.swift | 55 +--------------------- 1 file changed, 2 insertions(+), 53 deletions(-) diff --git a/Shared/Extensions/RSImage-Extensions.swift b/Shared/Extensions/RSImage-Extensions.swift index 0b566b632..a09cafeb7 100644 --- a/Shared/Extensions/RSImage-Extensions.swift +++ b/Shared/Extensions/RSImage-Extensions.swift @@ -27,64 +27,13 @@ extension RSImage { guard var cgImage = RSImage.scaleImage(data, maxPixelSize: scaledMaxPixelSize) else { 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 - + #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 - -}