/// <summary> /// Adds a range to the hue filter that could cause pixels whose hue it covers to be replaced if their respective values are also covered by the saturation and vibrance filters. /// </summary> /// <param name="minHue">The minimum hue to be considered for this condition. Values greater than or equal to 1 will be divided by 360.</param> /// <param name="maxHue">The maximum hue to be considered for this condition. Values greater than 1 will be divided by 360.</param> public void AddHueRange(float minHue, float maxHue) { float newFilterMinValue = minHue < 1f ? minHue : minHue / 360f; float newFilterMaxValue = maxHue < 1f ? maxHue : maxHue / 360f; HueValueRanges.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); }