private float GenerateScore(Swatch swatch, Target target) { float[] hsl = swatch.GetHsl(); float saturationScore = 0; float luminanceScore = 0; float populationScore = 0; int maxPopulation = mDominantSwatch != null?mDominantSwatch.GetPopulation() : 1; if (target.GetSaturationWeight() > 0) { saturationScore = target.GetSaturationWeight() * (1f - Math.Abs(hsl[1] - target.GetTargetSaturation())); } if (target.GetLightnessWeight() > 0) { luminanceScore = target.GetLightnessWeight() * (1f - Math.Abs(hsl[2] - target.GetTargetLightness())); } if (target.GetPopulationWeight() > 0) { populationScore = target.GetPopulationWeight() * (swatch.GetPopulation() / (float)maxPopulation); } return(saturationScore + luminanceScore + populationScore); }
private bool ShouldBeScoredForTarget(Swatch swatch, Target target) { // Check whether the HSL values are within the correct ranges, and this color hasn't // been used yet. float[] hsl = swatch.GetHsl(); bool a = false; mUsedColors.TryGetValue(swatch.GetRgb(), out a); return(hsl[1] >= target.GetMinimumSaturation() && hsl[1] <= target.GetMaximumSaturation() && hsl[2] >= target.GetMinimumLightness() && hsl[2] <= target.GetMaximumLightness() && !a); }
private bool ShouldIgnoreColor(Swatch color) { return(ShouldIgnoreColor(color.GetRgb(), color.GetHsl())); }