public ColorScale GetPaletteScale()
        {
            var baseColorRGB        = _baseColor.ActiveColor;
            var baseColorHSL        = ColorUtils.RGBToHSL(baseColorRGB);
            var baseColorNormalized = new NormalizedRGB(baseColorRGB);

            var baseScale = new ColorScale(new Color[] { _scaleColorLight, baseColorRGB, _scaleColorDark, });

            var trimmedScale = baseScale.Trim(_clipLight, 1.0 - _clipDark);
            var trimmedLight = new NormalizedRGB(trimmedScale.GetColor(0, _interpolationMode));
            var trimmedDark  = new NormalizedRGB(trimmedScale.GetColor(1, _interpolationMode));

            var adjustedLight = trimmedLight;
            var adjustedDark  = trimmedDark;

            if (baseColorHSL.S >= _saturationAdjustmentCutoff)
            {
                adjustedLight = ColorBlending.SaturateViaLCH(adjustedLight, _saturationLight);
                adjustedDark  = ColorBlending.SaturateViaLCH(adjustedDark, _saturationDark);
            }

            if (_multiplyLight != 0)
            {
                var multiply = ColorBlending.Blend(baseColorNormalized, adjustedLight, ColorBlendMode.Multiply);
                adjustedLight = ColorUtils.InterpolateColor(adjustedLight, multiply, _multiplyLight, _interpolationMode);
            }

            if (_multiplyDark != 0)
            {
                var multiply = ColorBlending.Blend(baseColorNormalized, adjustedDark, ColorBlendMode.Multiply);
                adjustedDark = ColorUtils.InterpolateColor(adjustedDark, multiply, _multiplyDark, _interpolationMode);
            }

            if (_overlayLight != 0)
            {
                var overlay = ColorBlending.Blend(baseColorNormalized, adjustedLight, ColorBlendMode.Overlay);
                adjustedLight = ColorUtils.InterpolateColor(adjustedLight, overlay, _overlayLight, _interpolationMode);
            }

            if (_overlayDark != 0)
            {
                var overlay = ColorBlending.Blend(baseColorNormalized, adjustedDark, ColorBlendMode.Overlay);
                adjustedDark = ColorUtils.InterpolateColor(adjustedDark, overlay, _overlayDark, _interpolationMode);
            }

            var finalScale = new ColorScale(new Color[] { adjustedLight.Denormalize(), baseColorRGB, adjustedDark.Denormalize() });

            return(finalScale);
        }
예제 #2
0
        public static string FormatColorString(Color input, ColorStringFormat format, int precision = 4)
        {
            switch (format)
            {
            case ColorStringFormat.RGB:
                return(string.Format("{0}{1}{2}", input.R.ToString("x2"), input.G.ToString("x2"), input.B.ToString("x2")));

            case ColorStringFormat.PoundRGB:
                return(string.Format("#{0}{1}{2}", input.R.ToString("X2"), input.G.ToString("X2"), input.B.ToString("X2")));

            case ColorStringFormat.ARGB:
                return(string.Format("{0}{1}{2}{3}", input.A.ToString("x2"), input.R.ToString("x2"), input.G.ToString("x2"), input.B.ToString("x2")));

            case ColorStringFormat.NormalizedRGB:
                var normalizedRGB = new NormalizedRGB(input, true, precision);
                return(string.Format("{0},{1},{2}", normalizedRGB.R, normalizedRGB.G, normalizedRGB.B));

            case ColorStringFormat.HSL:
                var hsl = RGBToHSL(input, true, precision);
                return(string.Format("{0},{1},{2}", hsl.H, hsl.S, hsl.L));

            case ColorStringFormat.HSV:
                var hsv = RGBToHSV(input, true, precision);
                return(string.Format("{0},{1},{2}", hsv.H, hsv.S, hsv.V));

            case ColorStringFormat.LAB:
                var lab = RGBToLAB(input, true, precision);
                return(string.Format("{0},{1},{2}", lab.L, lab.A, lab.B));

            case ColorStringFormat.LCH:
                var lch = RGBToLCH(input, true, precision);
                return(string.Format("{0},{1},{2}", lch.L, lch.C, lch.H));

            case ColorStringFormat.XYZ:
                var xyz = RGBToXYZ(input, true, precision);
                return(string.Format("{0},{1},{2}", xyz.X, xyz.Y, xyz.Z));

            case ColorStringFormat.Luminance:
                var lum = RGBToLuminance(input, true, precision);
                return(lum.ToString());

            case ColorStringFormat.Temperature:
                var temp = RGBToTemperature(input, true, 0);
                return(temp.ToString());
            }
            return(null);
        }