-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add extension function to get dominant colors of an image #19
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great but there are some small issues need to be solved before a merge.
@@ -0,0 +1,41 @@ | |||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we use Image+Color.swift
as the file name to imply that this is an extension?
extension UIImage { | ||
|
||
@inlinable | ||
public func dominantColors(clusterCount: Int = 5) -> [UIColor] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add a PlatformImage
typealias to unify these APIs.
extension CIImage { | ||
|
||
public func dominantColor(clusterCount: Int = 5) -> [PlatformColor] { | ||
guard let kMeansFilter = CIFilter(name: "CIKMeans") else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The k
prefix is for constants I believe, we should just remove it.
var dominantColors = [PlatformColor]() | ||
|
||
for i in 0..<clusterCount { | ||
let color = PlatformColor(red: CGFloat(bitmap[i * 4 + 0]) / 255.0, green: CGFloat(bitmap[i * 4 + 1]) / 255.0, blue: CGFloat(bitmap[i * 4 + 2]) / 255.0, alpha: CGFloat(bitmap[i * 4 + 3]) / 255.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some line breaks would be nice to have.
No description provided.