コード例 #1
0
            public Color Darker(float percDarker)
            {
                if (!_isSystemColors_Control)
                {
                    int zeroLum = NewLuma(ShadowAdjustment, true);
                    return(ColorFromHLS(_hue, zeroLum - (int)(zeroLum * percDarker), _saturation));
                }
                else
                {
                    // With the usual color scheme, ControlDark/DarkDark is not exactly
                    // what we would otherwise calculate
                    if (percDarker == 0.0f)
                    {
                        return(SystemColors.ControlDark);
                    }
                    else if (percDarker == 1.0f)
                    {
                        return(SystemColors.ControlDarkDark);
                    }
                    else
                    {
                        ARGB dark     = SystemColors.ControlDark;
                        ARGB darkDark = SystemColors.ControlDarkDark;

                        return(Color.FromArgb(
                                   (byte)(dark.R - (byte)((dark.R - darkDark.R) * percDarker)),
                                   (byte)(dark.G - (byte)((dark.G - darkDark.G) * percDarker)),
                                   (byte)(dark.B - (byte)((dark.B - darkDark.B) * percDarker))));
                    }
                }
            }
コード例 #2
0
            public Color Lighter(float percentLighter)
            {
                if (_isSystemColors_Control)
                {
                    // With the usual color scheme, ControlLight/LightLight is not exactly
                    // what we would otherwise calculate
                    if (percentLighter == 0.0f)
                    {
                        return(SystemColors.ControlLight);
                    }
                    else if (percentLighter == 1.0f)
                    {
                        return(SystemColors.ControlLightLight);
                    }
                    else
                    {
                        ARGB light      = SystemColors.ControlLight;
                        ARGB lightLight = SystemColors.ControlLightLight;

                        return(Color.FromArgb(
                                   (byte)(light.R - (byte)((light.R - lightLight.R) * percentLighter)),
                                   (byte)(light.G - (byte)((light.G - lightLight.G) * percentLighter)),
                                   (byte)(light.B - (byte)((light.B - lightLight.B) * percentLighter))));
                    }
                }
                else
                {
                    int zeroLum = Luminosity;
                    int oneLum  = NewLuma(HighlightAdjustment, true);
                    return(ColorFromHLS(_hue, zeroLum + (int)((oneLum - zeroLum) * percentLighter), _saturation));
                }
            }
コード例 #3
0
        internal static Color MixColor(this Color color1, Color color2)
        {
            // Some colors look up their values on every property access so we'll get the value out
            ARGB argb1 = color1;
            ARGB argb2 = color2;

            return(Color.FromArgb(
                       (argb1.A + argb2.A) / 2,
                       (argb1.R + argb2.R) / 2,
                       (argb1.G + argb2.G) / 2,
                       (argb1.B + argb2.B) / 2));
        }
コード例 #4
0
        /// <summary>
        ///  Inverts the color.
        /// </summary>
        internal static Color InvertColor(this Color color)
        {
            ARGB argb = color;

            return(Color.FromArgb(argb.A, (byte)~argb.R, (byte)~argb.G, (byte)~argb.B));
        }
コード例 #5
0
            public HLSColor(Color color)
            {
                _isSystemColors_Control = color.ToKnownColor() == SystemColors.Control.ToKnownColor();

                ARGB argb = color;
                int  r = argb.R;
                int  g = argb.G;
                int  b = argb.B;
                int  max, min;
                int  sum, dif;
                int  Rdelta, Gdelta, Bdelta; // intermediate value: % of spread from max

                // calculate lightness
                max = Math.Max(Math.Max(r, g), b);
                min = Math.Min(Math.Min(r, g), b);
                sum = max + min;

                Luminosity = ((sum * HLSMax) + RGBMax) / (2 * RGBMax);

                dif = max - min;
                if (dif == 0)
                {
                    // r=g=b --> achromatic case
                    _saturation = 0;
                    _hue        = Undefined;
                }
                else
                {
                    // chromatic case
                    _saturation = Luminosity <= (HLSMax / 2)
                        ? ((dif * HLSMax) + (sum / 2)) / sum
                        : ((dif * HLSMax) + (2 * RGBMax - sum) / 2) / (2 * RGBMax - sum);

                    Rdelta = (((max - r) * (HLSMax / 6)) + (dif / 2)) / dif;
                    Gdelta = (((max - g) * (HLSMax / 6)) + (dif / 2)) / dif;
                    Bdelta = (((max - b) * (HLSMax / 6)) + (dif / 2)) / dif;

                    if (r == max)
                    {
                        _hue = Bdelta - Gdelta;
                    }
                    else if (g == max)
                    {
                        _hue = (HLSMax / 3) + Rdelta - Bdelta;
                    }
                    else
                    {
                        // B == cMax
                        _hue = (2 * HLSMax / 3) + Gdelta - Rdelta;
                    }

                    if (_hue < 0)
                    {
                        _hue += HLSMax;
                    }

                    if (_hue > HLSMax)
                    {
                        _hue -= HLSMax;
                    }
                }
            }