Exemple #1
0
        /// <summary>
        /// Returns the euclidean distance squared (DeltaE CIE 1976 squared) between this color and other color.
        /// </summary>
        /// <param name="Color2"></param>
        /// <returns></returns>
        public double DistanceSquared(TLabColor Color2)
        {
            double a = (a0 * Color2.a0 <= 0) ? 100000 : 1; //avoid opposite colors appearing
            double b = (b0 * Color2.b0 <= 0) ? 100000 : 1;

            return(Math.Pow(Color2.L0 - L0, 2) + a * Math.Pow(Color2.a0 - a0, 2) + b * Math.Pow(Color2.b0 - b0, 2));
        }
Exemple #2
0
        /// <summary>
        /// Returns the CMC color distance between this color and color2 (distance returned is squared, so you need to get the sqrt if you want the real CMC value). Note that CMC is not symetric (Color1.CMC(Color2) != Color2.CMC(Color1), so this color is the one used as reference.
        /// </summary>
        /// <param name="Color2">Color that will be compared against this reference.</param>
        /// <param name="l">L parameter for CMC calculation. For acceptability (CMC2:1) this is normally 2, and for perceptibility (CMC1:1) this should be 1.</param>
        /// <param name="c">C parameter for CMC calculation. This is normally 1.</param>
        /// <returns></returns>
        public double CMCSquared(TLabColor Color2, int l, int c)
        {
            double C1Squared = Math.Pow(a0, 2) + Math.Pow(b0, 2);

            double C1            = Math.Sqrt(C1Squared);
            double C2            = Math.Sqrt(Math.Pow(Color2.a0, 2) + Math.Pow(Color2.b0, 2));
            double DeltaCSquared = (C1 - C2) * (C1 - C2);

            double DeltaHSquared = Math.Pow(a0 - Color2.a0, 2) + Math.Pow(b0 - Color2.b0, 2) - DeltaCSquared;
            double DeltaL        = L0 - Color2.L0;

            double H1 = Math.Atan2(b0, a0) * 180 / Math.PI;

            if (H1 < 0)
            {
                H1 += 360;
            }
            if (H1 >= 360)
            {
                H1 -= 360;
            }

            double C1SquaredSquared = C1Squared * C1Squared;
            double F = Math.Sqrt(C1SquaredSquared / (C1SquaredSquared + 1900));

            double T = H1 >= 164 && H1 <= 345 ?
                       0.56 + 0.2 * Math.Abs(Math.Cos((H1 + 168) * Math.PI / 180)) :
                       0.36 + 0.4 * Math.Abs(Math.Cos((H1 + 35) * Math.PI / 180));

            double Sl = L0 < 16 ? 0.511 : 0.040975 * L0 / (1 + 0.01765 * L0);
            double Sc = 0.0638 * C1 / (1 + 0.0131 * C1) + 0.638;
            double Sh = Sc * (F * T + 1 - F);

            return(Math.Pow(DeltaL / (l * Sl), 2) + DeltaCSquared / Math.Pow(c * Sc, 2) + DeltaHSquared / Math.Pow(Sh, 2));
        }
Exemple #3
0
        /// <summary>
        /// Returns true if both colors are the same.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (!(obj is TLabColor))
            {
                return(false);
            }
            TLabColor o = (TLabColor)obj;

            return(FL0 == o.FL0 && Fa0 == o.Fa0 && Fb0 == o.Fb0);
        }
Exemple #4
0
        /// <summary>
        /// Returns -1 if obj is more than color, 0 if both colors are the same, and 1 if obj is less than color.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int CompareTo(object obj)
        {
            if (!(obj is TLabColor))
            {
                return(-1);
            }
            TLabColor o2 = (TLabColor)obj;
            int       c;

            c = FL0.CompareTo(o2.FL0); if (c != 0)
            {
                return(c);
            }
            c = Fa0.CompareTo(o2.Fa0); if (c != 0)
            {
                return(c);
            }
            c = Fb0.CompareTo(o2.Fb0); if (c != 0)
            {
                return(c);
            }

            return(0);
        }