Skip to content

Commit

Permalink
Improve color extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmuslos committed Sep 5, 2024
1 parent c4020f4 commit 305add4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
ReferencedContainer = "container:AmpFin.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "CORESVG_VERBOSE"
value = "YES"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
2 changes: 1 addition & 1 deletion Multiplatform/Album/AlbumViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ extension AlbumViewModel {
private func determineButtonColor() async {
if let image = await album.cover?.systemImage,
let colors = try? await RFKVisuals.extractDominantColors(4, image: image),
let result = RFKVisuals.determineMostSaturated(colors.map { $0.color }) {
let result = RFKVisuals.determineMostSaturated(RFKVisuals.brightnessExtremeFilter(colors.map { $0.color }, threshold: 0.25)) {
await MainActor.withAnimation {
self.buttonColor = result
}
Expand Down
2 changes: 1 addition & 1 deletion Multiplatform/NowPlaying/Background.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal extension NowPlaying {
@State private var baseSpeed = CGFloat.random(in: 0.1...0.2)

private var speed: CGFloat {
guard viewModel.playing && !haltNowPlayingBackground else {
guard viewModel.expanded && viewModel.playing && !haltNowPlayingBackground else {
return 0
}

Expand Down
4 changes: 2 additions & 2 deletions Multiplatform/NowPlaying/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ private extension NowPlaying.ViewModel {
}

let colors = RFKVisuals.brightnessExtremeFilter(dominantColors.map { $0.color }, threshold: 0.25)
var highlights = RFKVisuals
let highlights = RFKVisuals
.contrastRatios(RFKVisuals.brightnessExtremeFilter(colors, threshold: 0.35))
.sorted { $0.value < $1.value }
.filter { $0.value > 15 }
.filter { $0.value > 1 }
.map { $0.key }

let extractedCoverItemID = await self?.extractedCoverItemID
Expand Down

0 comments on commit 305add4

Please sign in to comment.