示例#1
0
 /// <summary>
 /// Toggles brightness between light mode and dark mode.
 /// </summary>
 /// <param name="value">The source color value collection.</param>
 /// <param name="level">The relative saturation level.</param>
 /// <returns>The color toggled.</returns>
 public static IEnumerable <Color> ToggleBrightness(IEnumerable <Color> value, RelativeBrightnessLevels level)
 => value?.Select(ele => ToggleBrightness(ele));
示例#2
0
    /// <summary>
    /// Toggles brightness between light mode and dark mode.
    /// </summary>
    /// <param name="value">The source color value.</param>
    /// <param name="level">The relative saturation level.</param>
    /// <returns>The color toggled.</returns>
    public static Color ToggleBrightness(Color value, RelativeBrightnessLevels level)
    {
        var max   = Maths.Arithmetic.Max(value.R, value.G, value.B);
        var min   = Maths.Arithmetic.Min(value.R, value.G, value.B);
        var high  = 255 - max;
        var delta = high - min;

        switch (level)
        {
        case RelativeBrightnessLevels.Switch:
            break;

        case RelativeBrightnessLevels.High:
            if (high <= min)
            {
                return(value);
            }
            break;

        case RelativeBrightnessLevels.Low:
            if (high >= min)
            {
                return(value);
            }
            break;

        case RelativeBrightnessLevels.Middle:
        {
            if (high == min)
            {
                return(value);
            }
            return(Color.FromArgb(
                       value.A,
                       ToChannel(value.R + delta / 2f),
                       ToChannel(value.G + delta / 2f),
                       ToChannel(value.B + delta / 2f)));
        }

        case RelativeBrightnessLevels.Exposure:
            if (high == 0)
            {
                return(value);
            }
            delta = high;
            break;

        case RelativeBrightnessLevels.Shadow:
            if (min == 0)
            {
                return(value);
            }
            delta = -min;
            break;

        default:
            return(value);
        }

        return(Color.FromArgb(value.A, value.R + delta, value.G + delta, value.B + delta));
    }