Beispiel #1
0
        ///////////////////////////////////////////////////////////////////////////////
        // Public methods                                                            //
        ///////////////////////////////////////////////////////////////////////////////
        #region Public Methods and Operators

        /// <summary>
        /// Returns a colored pallet for the given hue and saturation.
        /// </summary>
        /// <param name="hue">
        /// A <see cref="float"/> with the hue to use.
        /// </param>
        /// <param name="hueConstraint">
        /// A <see cref="float"/> with the hue constraint to use.
        /// </param>
        /// <param name="saturation">
        /// A <see cref="float"/> with the saturation to use.
        /// </param>
        /// <param name="x">
        /// A <see cref="float"/> with ???
        /// </param>
        /// <returns>
        /// An array of colors defining the pallet.
        /// </returns>
        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));
            }

            // 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 diffX;
            float constraintX;
            float auxX;

            this.CalculateParameters(x, this.palletInfo.XMin, this.palletInfo.XMax, out diffX, out constraintX, out auxX);

            var      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.ValueLuminanceBrightness + ((auxX - sourceColor.ValueLuminanceBrightness) * constraintX) + diffX);

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

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Fills coloration class with color array to
        ///   build pallet info.
        /// </summary>
        /// <param name="pallet">
        /// An array of <see cref="Color"/> defining the pallet
        /// </param>
        private void SetSourcePallet(Color[] pallet)
        {
            // if (!this._ColorType.In(ColorType.HSL, ColorType.HSV)) // C# 3.0
            if (this.colorType != ColorType.HSL && this.colorType != ColorType.HSV)
            {
                throw new NotImplementedException(string.Format("Not implemented color type: \"{0}\"", this.colorType));
            }

            this.palletInfo.HueMin = float.MaxValue;
            this.palletInfo.SatMin = float.MaxValue;
            this.palletInfo.XMin   = float.MaxValue;

            this.sourcePallet = new HSXColor[pallet.Length];

            this.palletInfo.HueAvg = 0F;

            for (int i = 0; i < pallet.Length; i++)
            {
                HSXColor hsx;

                if (this.IsHSL)
                {
                    hsx = ConvertColor.RBGToHSL(pallet[i]);
                }
                else
                {
                    hsx = ConvertColor.RBGToHSV(pallet[i]);
                }

                this.sourcePallet[i] = hsx;

                if (hsx.Hue.HasValue)
                {
                    if (hsx.Hue < this.palletInfo.HueMin)
                    {
                        this.palletInfo.HueMin = hsx.Hue.Value;
                    }

                    if (hsx.Hue > this.palletInfo.HueMax)
                    {
                        this.palletInfo.HueMax = hsx.Hue.Value;
                    }

                    this.palletInfo.HueAvg += hsx.Hue.Value;
                }

                if (hsx.Saturation < this.palletInfo.SatMin)
                {
                    this.palletInfo.SatMin = hsx.Saturation;
                }

                if (hsx.Saturation > this.palletInfo.SatMax)
                {
                    this.palletInfo.SatMax = hsx.Saturation;
                }

                if (hsx.ValueLuminanceBrightness < this.palletInfo.XMin)
                {
                    this.palletInfo.XMin = hsx.ValueLuminanceBrightness;
                }

                if (hsx.ValueLuminanceBrightness > this.palletInfo.XMax)
                {
                    this.palletInfo.XMax = hsx.ValueLuminanceBrightness;
                }
            }

            this.palletInfo.HueAvg /= pallet.Length;
        }