/// <summary> /// Adds a range to the saturation filter that could cause pixels whose saturation it covers to be replaced if their respective values are also covered by the hue and vibrance filters. /// </summary> /// <param name="minSaturation">The minimum saturation to be considered for this condition. Values greater than 1 will be divided by 100.</param> /// <param name="maxSaturation">The maximum saturation to be considered for this condition. Values greater than 1 will be divided by 100.</param> public void AddSaturationRange(float minSaturation, float maxSaturation) { float newFilterMinValue = minSaturation <= 1f ? minSaturation : minSaturation / 100f; float newFilterMaxValue = maxSaturation <= 1f ? maxSaturation : maxSaturation / 100f; SaturationValueRanges.Add(new ColorValueRange(newFilterMinValue, newFilterMaxValue)); }
public Color FilterColor(Color color) { float hue; float saturation; float vibrance; float alpha = color.a; Color.RGBToHSV(color, out hue, out saturation, out vibrance); if (HueValueRanges.TrueForAll(valueRange => valueRange.Covers(hue)) && SaturationValueRanges.TrueForAll(valueRange => valueRange.Covers(saturation)) && VibranceValueRanges.TrueForAll(valueRange => valueRange.Covers(vibrance)) && AlphaValueRanges.TrueForAll(valueRange => valueRange.Covers(alpha))) { float newHue = replacementHue >= 0f ? replacementHue : hue; float newSaturation = replacementSaturation >= 0f ? replacementSaturation : saturation; float newVibrance = replacementVibrance >= 0f ? replacementVibrance : vibrance; float newAplha = replacementAlpha >= 0f ? replacementAlpha : alpha; return(Color .HSVToRGB(newHue, newSaturation, newVibrance) .WithAlpha(newAplha)); } return(color); }