Пример #1
0
        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);
        }
Пример #2
0
        /// <summary>
        /// Adds a range to the vibrance filter that could cause pixels whose vibrance it covers to be replaced if their respective values are also covered by the hue and saturation filters.
        /// </summary>
        /// <param name="minVibrance">The minimum vibrance to be considered for this condition. Values greater than 1 will be divided by 100.</param>
        /// <param name="maxVibrance">The maximum vibrance to be considered for this condition. Values greater than 1 will be divided by 100.</param>
        public void AddVibranceRange(float minVibrance, float maxVibrance)
        {
            float newFilterMinValue = minVibrance <= 1f ? minVibrance : minVibrance / 100f;
            float newFilterMaxValue = maxVibrance <= 1f ? maxVibrance : maxVibrance / 100f;

            VibranceValueRanges.Add(new ColorValueRange(newFilterMinValue, newFilterMaxValue));
        }