Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 19, 2023
1 parent e1d5aac commit 6b74cc0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Actions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@
repositoryURL = "https://github.com/getsentry/sentry-cocoa";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 8.7.0;
minimumVersion = 8.7.2;
};
};
E337A3E227E8B66D0073E865 /* XCRemoteSwiftPackageReference "FuzzyFind" */ = {
Expand Down
3 changes: 2 additions & 1 deletion Intents Extension/Actions/GetAverageColorOfImage.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AppIntents
import CoreImage

struct GetAverageColorOfImage: AppIntent {
static let title: LocalizedStringResource = "Get Average Color of Image"
Expand All @@ -22,7 +23,7 @@ struct GetAverageColorOfImage: AppIntent {
}

func perform() async throws -> some IntentResult & ReturnsValue<ColorAppEntity> {
guard let image = XImage(data: image.data) else {
guard let image = CIImage(data: image.data) else {
throw "Invalid or unsupported image.".toError
}

Expand Down
26 changes: 19 additions & 7 deletions Shared/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2495,11 +2495,18 @@ extension NSImage {
func jpegData(compressionQuality: Double) -> Data? {
tiffRepresentation?.bitmap?.jpegData(compressionQuality: compressionQuality)
}
}
#endif


extension XImage {
/**
`UIImage` polyfill.
Convert a `UIImage`/`NSImage` to a `CIImage`.
*/
var ciImage: CIImage? {
var toCIImage: CIImage? {
#if os(iOS)
return CIImage(image: self, options: [.applyOrientationProperty: true])
#else
if let cgImage {
return CIImage(cgImage: cgImage, options: [.applyOrientationProperty: true])
}
Expand All @@ -2509,9 +2516,9 @@ extension NSImage {
}

return CIImage(data: tiffRepresentation, options: [.applyOrientationProperty: true])
#endif
}
}
#endif


extension URL {
Expand Down Expand Up @@ -6015,11 +6022,9 @@ extension NSNumber {
}


extension XImage {
extension CIImage {
func averageColor() -> XColor? {
guard let inputImage = ciImage else {
return nil
}
let inputImage = self

let filter = CIFilter.areaAverage()
filter.inputImage = inputImage
Expand Down Expand Up @@ -6049,6 +6054,13 @@ extension XImage {
}
}

extension XImage {
func averageColor() -> XColor? {
toCIImage?.averageColor()
}
}


// The inverse of `withAnimation()`.
func withoutAnimation<Result>(@_inheritActorContext _ body: () throws -> Result) rethrows -> Result {
var transaction = Transaction()
Expand Down

0 comments on commit 6b74cc0

Please sign in to comment.