Exemple #1
0
        /// <summary>
        /// The conversion method
        /// </summary>
        /// <param name="inColor">The pointer to the input color values</param>
        /// <param name="outColor">The pointer to the output color values</param>
        /// <param name="data">The data that is used to perform the conversion</param>
        public static void Convert(double *inColor, double *outColor, ConversionData data)
        {
            double *vs = data.Vars;

            //Max = vs[0] and Min = vs[1]
            UMath.MinMax_3(inColor, vs);

            vs[2]       = vs[0] - vs[1];
            vs[3]       = vs[0] + vs[1];
            outColor[2] = vs[3] * 0.5;

            if (Math.Round(vs[0], 6) == Math.Round(vs[1], 6))
            {
                outColor[1] = outColor[0] = 0;
            }
            else
            {
                if (outColor[2] <= 0.5d)
                {
                    outColor[1] = vs[2] / vs[3];
                }
                else
                {
                    outColor[1] = vs[2] / (2 - vs[2]);
                }

                if (inColor[0] == vs[0])
                {
                    outColor[0] = (inColor[1] - inColor[2]) / vs[2];
                }
                else if (inColor[1] == vs[0])
                {
                    outColor[0] = 2d + (inColor[2] - inColor[0]) / vs[2];
                }
                else
                {
                    outColor[0] = 4d + (inColor[0] - inColor[1]) / vs[2];
                }                                                                 //inColor[2] == max
                outColor[0] *= 60d;
            }
        }
Exemple #2
0
        /// <summary>
        /// The conversion method
        /// </summary>
        /// <param name="inColor">The pointer to the input color values</param>
        /// <param name="outColor">The pointer to the output color values</param>
        /// <param name="data">The data that is used to perform the conversion</param>
        public static void Convert(double *inColor, double *outColor, ConversionData data)
        {
            double *vs = data.Vars;

            //Max = vs[0] and Min = vs[1]
            UMath.MinMax_3(inColor, vs);

            if (Math.Round(vs[0], 6) == Math.Round(vs[1], 6))
            {
                outColor[2] = vs[1]; outColor[0] = 0;
            }
            else
            {
                if (inColor[0] == vs[1])
                {
                    vs[2] = inColor[1] - inColor[2];
                    vs[3] = 3d;
                }
                else if (inColor[2] == vs[1])
                {
                    vs[2] = inColor[0] - inColor[1];
                    vs[3] = 1d;
                }
                else //inColor[0] == vs[1] (== min)
                {
                    vs[2] = inColor[2] - inColor[0];
                    vs[3] = 5d;
                }

                outColor[0] = 60d * (vs[3] - vs[2] / (vs[0] - vs[1]));
                outColor[2] = vs[0];
            }
            if (Math.Abs(vs[0]) < Const.Delta)
            {
                outColor[1] = 0;
            }
            else
            {
                outColor[1] = (vs[0] - vs[1]) / vs[0];
            }
        }