void Perform <TColor>() where TColor : IColor { Console.WriteLine(typeof(TColor).FullName); double accuracy = 0; double length = 0; var stopwatch = new Stopwatch(); stopwatch.Start(); for (double r = 0; r < 255; r++) { ConsoleExtensions.ClearLine(); Console.Write("Step {0}/255 ({1})".F(r.ToString().PadLeft(3, '0'), stopwatch.Elapsed.GetRemaining(255, r.ToInt64()).ToShortTime())); for (double g = 0; g < 255; g++) { for (double b = 0; b < 255; b++) { //The first color var color_a = new RGB(r / 255.0, g / 255.0, b / 255.0); //The first color, converted var color_b = color_a.To <TColor>(_converter); //The converted color, converted back var color_c = color_b.To <RGB>(_converter); //The accuracy of the conversion var _accuracy = GetAccuracy(color_a, color_c); _accuracy = double.IsNaN(_accuracy) ? 100 : _accuracy; accuracy += _accuracy; length++; } } } stopwatch.Stop(); accuracy /= length; ConsoleExtensions.ClearLine(); Console.WriteLine("Accuracy: {0}%".F(accuracy)); Console.WriteLine(string.Empty); }
void Perform <TColor>() where TColor : IColor { var amax = double.MinValue; var bmax = double.MinValue; var cmax = double.MinValue; var amin = double.MaxValue; var bmin = double.MaxValue; var cmin = double.MaxValue; Console.WriteLine(typeof(TColor).FullName); Console.WriteLine(string.Empty); var stopwatch = new Stopwatch(); stopwatch.Start(); for (var r = 0.0; r < 256; r++) { ConsoleExtensions.ClearLine(); Console.Write("Step {0}/255 ({1})".F(r.ToString().PadLeft(3, '0'), stopwatch.Elapsed.GetRemaining(255, r.ToInt64()).ToShortTime())); for (var g = 0.0; g < 256; g++) { for (var b = 0.0; b < 256; b++) { var result = new RGB(r / 255.0, g / 255.0, b / 255.0).To <TColor>(_converter).As <IColor>().Vector; if (result[0] > amax) { amax = result[0]; } if (result[1] > bmax) { bmax = result[1]; } if (result[2] > cmax) { cmax = result[2]; } if (result[0] < amin) { amin = result[0]; } if (result[1] < bmin) { bmin = result[1]; } if (result[2] < cmin) { cmin = result[2]; } } } } stopwatch.Stop(); ConsoleExtensions.ClearLine(); Console.WriteLine("Maximum: [{0}]".F(new Vector(VectorType.Row, amax, bmax, cmax))); Console.WriteLine(string.Empty); Console.WriteLine("Minimum: [{0}]".F(new Vector(VectorType.Row, amin, bmin, cmin))); Console.WriteLine(string.Empty); Console.WriteLine(Separator); Console.WriteLine(string.Empty); }