public static Color HSVToRGB(HSXColor hsvColor)
 {
     return ConvertColor.HSVToRGB(hsvColor.Hue, hsvColor.Saturation, hsvColor.X);
 }
示例#2
0
 public HSXColor(HSXColor clone)
     : this(clone.Hue, clone.Saturation, clone.X)
 {
 }
        //public IEnumerable<Color> GetColoredPallet(float hue, float hueConstraint, float saturation, float x)
        public Color[] GetColoredPallet(float hue, float hueConstraint, float saturation, float x)
        {
            if (this._ColorType != ColorType.HSL && this._ColorType != ColorType.HSV)
            {
                throw new NotImplementedException(string.Format(
                      "Not implemented color type: \"{0}\"", this._ColorType));
            }

            #region Linq

            //if (!this._ColorType.In(ColorType.HSL, ColorType.HSV))
            //{
            //    throw new NotImplementedException(string.Format(
            //          "Not implemented color type: \"{0}\"", this._ColorType));
            //}

            #endregion

            // Hue
            float hueDiff = this._PalletInfo.HueAvg - hue;

            // Saturation
            float satDiff;
            float satConstraint;
            float satAux;

            this.CalculateParameters(saturation, this._PalletInfo.SatMin,
                this._PalletInfo.SatMax, out satDiff, out satConstraint, out satAux);

            // X
            float xDiff;
            float xConstraint;
            float xAux;

            this.CalculateParameters(x, this._PalletInfo.XMin,
                this._PalletInfo.XMax, out xDiff, out xConstraint, out xAux);

            Color[] result = new Color[this._SourcePallet.Length];
            HSXColor sourceColor;
            HSXColor resultColor;

            //Not Tested yet

            for(int i = 0; i < this._SourcePallet.Length; i++)
            {
                sourceColor = this._SourcePallet[i];
                resultColor = new HSXColor(
                        sourceColor.Hue + (this._PalletInfo.HueAvg - sourceColor.Hue) * hueConstraint - hueDiff,
                        sourceColor.Saturation + (satAux - sourceColor.Saturation) * satConstraint + satDiff,
                        sourceColor.X + (xAux - sourceColor.X) * xConstraint + xDiff);

                result[i] = (this.IsHSL ? ConvertColor.HSLToRGB(resultColor) : ConvertColor.HSVToRGB(resultColor));
            }

            #region Linq

            //Color[] result = (
            //    from
            //        c in this._SourcePallet
            //    select
            //        new HSXColor(
            //            c.Hue + (this._PalletInfo.HueAvg - c.Hue) * hueConstraint - hueDiff,
            //            c.Saturation + (satAux - c.Saturation) * satConstraint + satDiff,
            //            c.X + (xAux - c.X) * xConstraint + xDiff)
            //    into n
            //        select
            //            IsHSL ? ConvertColor.HSLToRGB(n) : ConvertColor.HSVToRGB(n)
            //    ).ToArray();

            #endregion

            return result;
        }