aboutsummaryrefslogtreecommitdiff
path: root/Captura/Core Extensions
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2023-07-28 08:53:26 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2023-07-28 08:53:26 +0200
commitf5d16c1c8c259966338b23afd407d142f72784aa (patch)
treed8ef63436af5c954dac262b4766ece363ac10ac9 /Captura/Core Extensions
parenta4e804275517af683afa1733e2db7c383c306f2b (diff)
Separate some logic out of main app
Diffstat (limited to 'Captura/Core Extensions')
-rw-r--r--Captura/Core Extensions/CGImage+resize.swift21
-rw-r--r--Captura/Core Extensions/Notification+AppEvents.swift9
2 files changed, 30 insertions, 0 deletions
diff --git a/Captura/Core Extensions/CGImage+resize.swift b/Captura/Core Extensions/CGImage+resize.swift
new file mode 100644
index 0000000..110e85b
--- /dev/null
+++ b/Captura/Core Extensions/CGImage+resize.swift
@@ -0,0 +1,21 @@
+import CoreGraphics
+
+extension CGImage {
+ func resize(by scale: CGFloat) -> CGImage? {
+ let width = Int(CGFloat(self.width) / scale)
+ let height = Int(CGFloat(self.height) / scale)
+
+ let bitsPerComponent = self.bitsPerComponent
+ let colorSpace = self.colorSpace ?? CGColorSpace(name: CGColorSpace.sRGB)!
+ let bitmapInfo = self.bitmapInfo.rawValue
+
+ guard let context = CGContext(data: nil, width: width, height: height, bitsPerComponent: bitsPerComponent, bytesPerRow: 0, space: colorSpace, bitmapInfo: bitmapInfo) else {
+ return nil
+ }
+
+ context.interpolationQuality = .high
+ context.draw(self, in: CGRect(x: 0, y: 0, width: width, height: height))
+
+ return context.makeImage()
+ }
+}
diff --git a/Captura/Core Extensions/Notification+AppEvents.swift b/Captura/Core Extensions/Notification+AppEvents.swift
new file mode 100644
index 0000000..809c00e
--- /dev/null
+++ b/Captura/Core Extensions/Notification+AppEvents.swift
@@ -0,0 +1,9 @@
+import Foundation
+
+extension Notification.Name {
+ static let startAreaSelection = Notification.Name("startSelectingArea")
+ static let startRecording = Notification.Name("startRecording")
+ static let stopRecording = Notification.Name("stopRecording")
+ static let finalizeRecording = Notification.Name("finalizeRecording")
+ static let reset = Notification.Name("reset")
+}