Add extension function to get dominant colors of an image#19
Open
Add extension function to get dominant colors of an image#19
Conversation
unixzii
requested changes
Oct 28, 2022
Member
unixzii
left a comment
There was a problem hiding this comment.
Looks great but there are some small issues need to be solved before a merge.
| @@ -0,0 +1,41 @@ | |||
| // | |||
Member
There was a problem hiding this comment.
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] { |
Member
There was a problem hiding this comment.
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 { |
Member
There was a problem hiding this comment.
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) |
Member
There was a problem hiding this comment.
Some line breaks would be nice to have.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.