Skip to content

Commit 46dd841

Browse files
committed
Better color generation: increase brightness
1 parent 0cd0c77 commit 46dd841

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

LyricFever/Support Files/ImageColorGeneration.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@ extension NSImage {
1616
}
1717
for color in dominantColors {
1818
if color.brightnessComponent > 0.1 {
19-
let red = Int(color.redComponent * 255)
20-
let green = Int(color.greenComponent * 255)
21-
let blue = Int(color.blueComponent * 255)
22-
19+
var hue: CGFloat = 0
20+
var saturation: CGFloat = 0
21+
var brightness: CGFloat = 0
22+
var alpha: CGFloat = 0
23+
color.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha)
24+
let clampedBrightness: CGFloat = max(brightness, 0.6)
25+
let clampedColor = NSColor(hue: hue, saturation: saturation, brightness: clampedBrightness, alpha: alpha)
26+
let red = Int(clampedColor.redComponent * 255)
27+
let green = Int(clampedColor.greenComponent * 255)
28+
let blue = Int(clampedColor.blueComponent * 255)
29+
2330
let combinedValue = (max(0,red) << 16) | (max(0,green) << 8) | max(0,blue)
31+
print("Color Generation: using color \(clampedColor.hexString) generated from color \(color.hexString)")
2432
return Int32(bitPattern: UInt32(combinedValue))
2533
}
2634
}

0 commit comments

Comments
 (0)