using System; using System.Collections.Generic; using System.Linq; using System.Text; using OwlCore.WinUI.ColorExtractor.ColorSpaces; namespace OwlCore.WinUI.ColorExtractor.Filters { /// /// A Collection of s that can be applied to a color or list of colors. /// public class FilterCollection : List { /// /// Filters the color list with a minimum of . /// /// The colors to filter. /// The minimum output of colors. /// The filtered color list. public RGBColor[] Filter(RGBColor[] colors, int minCount) { List colorList = colors.ToList(); foreach (var filter in this) { List filteredColors = new List(); foreach(var color in colorList) { if (filter.TakeColor(color)) { filteredColors.Add(color); } } if (filteredColors.Count < minCount) { return colorList.ToArray(); } colorList = filteredColors; } return colorList.ToArray(); } /// /// Filters the color list with a minimum of . /// /// The colors to filter. /// The minimum output of colors. /// The filtered color list. public HSVColor[] Filter(HSVColor[] colors, int minCount) { List colorList = colors.ToList(); foreach (var filter in this) { List filteredColors = new List(); foreach (var color in colorList) { if (filter.TakeColor(color)) { filteredColors.Add(color); } } if (filteredColors.Count < minCount) { return colorList.ToArray(); } colorList = filteredColors; } return colorList.ToArray(); } /// /// Adjusts a color to meet a filter. /// /// The color to clamp. /// The clamped color to match the filter. public RGBColor Clamp(RGBColor color) { foreach (var clamp in this) { color = clamp.Clamp(color); } return color; } } }