예제 #1
0
		/// <summary>
		/// Tries to change one color to not be so similar to others
		/// </summary>
		/// <param name="input">array of colors to process</param>
		/// <param name="index">index of current color to check against others</param>
		/// <param name="bestCol">output color (most far from others)</param>
		/// <returns>minimum distance of best colors to others</returns>
		public static int GetBestRelocation(MyCol[] input, int index, out MyCol bestCol)
		{
			int bestVal;
			bestCol = new MyCol(0, 0, 0);
			bestVal = int.MinValue;

			var temp = new MyCol();
			for (short r = 20; r <= 255; r += 3) {
				for (short g = 20; g <= 255; g += 3) {
					for (short b = 50; b <= 255; b += 3) {
						temp.R = (byte) r;
						temp.G = (byte) g;
						temp.B = (byte) b;

						int minDist = int.MaxValue;
						for (int i = 0; i < input.Length; ++i) {
							if (i == index) continue;
							int cDistance = temp%input[i];
							if (cDistance <= bestVal) {
								minDist = int.MinValue;
								break;
							}
							if (cDistance < minDist) minDist = cDistance;
						}

						if (minDist > bestVal) {
							bestVal = minDist;
							bestCol = temp;
						}
					}
				}
			}
			return bestVal;
		}
예제 #2
0
 /// <summary>
 /// This method calculates visual apparent "distance" of colors
 /// </summary>
 /// <param name="e1">first color to compare</param>
 /// <param name="e2">second color to compare</param>
 /// <returns>Return number representing distance .. values under 30 000 or so seems similar</returns>
 public static int Distance(MyCol e1, MyCol e2)
 {
   int r, g, b;
   int rmean;
   rmean = ((int)e1.R + (int)e2.R)/2;
   r = (int)e1.R - (int)e2.R;
   g = (int)e1.G - (int)e2.G;
   b = (int)e1.B - (int)e2.B;
   return (((512 + rmean)*r*r) >> 8) + 4*g*g + (((767 - rmean)*b*b) >> 8);
 }
예제 #3
0
        /// <summary>
        /// This method calculates visual apparent "distance" of colors
        /// </summary>
        /// <param name="e1">first color to compare</param>
        /// <param name="e2">second color to compare</param>
        /// <returns>Return number representing distance .. values under 30 000 or so seems similar</returns>
        public static int Distance(MyCol e1, MyCol e2)
        {
            int r, g, b;
            int rmean;

            rmean = ((int)e1.R + (int)e2.R) / 2;
            r     = (int)e1.R - (int)e2.R;
            g     = (int)e1.G - (int)e2.G;
            b     = (int)e1.B - (int)e2.B;
            return((((512 + rmean) * r * r) >> 8) + 4 * g * g + (((767 - rmean) * b * b) >> 8));
        }
예제 #4
0
        /// <summary>
        /// Tries to change one color to not be so similar to others
        /// </summary>
        /// <param name="input">array of colors to process</param>
        /// <param name="index">index of current color to check against others</param>
        /// <param name="bestCol">output color (most far from others)</param>
        /// <returns>minimum distance of best colors to others</returns>
        public static int GetBestRelocation(MyCol[] input, int index, out MyCol bestCol)
        {
            int bestVal;

            bestCol = new MyCol(0, 0, 0);
            bestVal = int.MinValue;

            MyCol temp = new MyCol();

            for (short r = 0; r <= 255; r += 3)
            {
                for (short g = 0; g <= 255; g += 3)
                {
                    for (short b = 0; b <= 255; b += 3)
                    {
                        temp.R = (byte)r;
                        temp.G = (byte)g;
                        temp.B = (byte)b;

                        int minDist = int.MaxValue;
                        for (int i = 0; i < input.Length; ++i)
                        {
                            if (i == index)
                            {
                                continue;
                            }
                            int cDistance = temp % input[i];
                            if (cDistance <= bestVal)
                            {
                                minDist = int.MinValue;
                                break;
                            }
                            if (cDistance < minDist)
                            {
                                minDist = cDistance;
                            }
                        }

                        if (minDist > bestVal)
                        {
                            bestVal = minDist;
                            bestCol = temp;
                        }
                    }
                }
            }
            return(bestVal);
        }
예제 #5
0
 public int Distance(MyCol e2)
 {
     return(Distance(this, e2));
 }
예제 #6
0
 public int Distance(MyCol e2)
 {
   return Distance(this, e2);
 }
예제 #7
0
 /// <summary>
 /// Processes input array of colors and if some colors are too similar, it changes them to be more different
 /// </summary>
 /// <param name="input">Array of colors to process</param>
 /// <param name="balanceDistance">Treshold distance, if two colors are more similar than this, it changes one of them</param>
 public static void FixColors(MyCol[] input, int balanceDistance)
 {
   for (int i = 0; i < input.Length - 1; ++i) for (int j = i + 1; j < input.Length; ++j) if (input[i]%input[j] < balanceDistance) GetBestRelocation(input, i, out input[i]);
 }