📄
Colors/src/ColorAnalyzer.cs
using System.Linq; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; namespace Mosaic.Colors; public static class ColorAnalyzer { extension(Image<Rgba32> image) { public (Rgba32 color, float proportion)[] GetPalette() { var quantized = image.Quantize(6); var total = quantized.Values.Aggregate(0.0f, (t, v) => t + v); return [.. quantized.Select(kvp => (kvp.Key, kvp.Value / total)).OrderByDescending(p => p.Item2)]; } } }