private void SetClosestIndex(Color color) { ColorMine.ColorSpaces.Rgb rgbColorStop = new ColorMine.ColorSpaces.Rgb() { R = color.R, G = color.G, B = color.B }; Tuple <Color, double, int>[] colorWeights = new Tuple <Color, double, int> [Width]; // Create a color weight for every cell compared to the color stop for (int x = 0; x < Width; x++) { ColorMine.ColorSpaces.Rgb rgbColor = new ColorMine.ColorSpaces.Rgb() { R = this[x, 0].Foreground.R, G = this[x, 0].Foreground.G, B = this[x, 0].Foreground.B }; ColorMine.ColorSpaces.Cmy cmyColor = rgbColor.To <ColorMine.ColorSpaces.Cmy>(); colorWeights[x] = new Tuple <Color, double, int>(this[x, 0].Foreground, rgbColorStop.Compare(cmyColor, new ColorMine.ColorSpaces.Comparisons.Cie1976Comparison()), x); } var foundColor = colorWeights.OrderBy(t => t.Item2).First(); _selectedPosition = foundColor.Item3; this.IsDirty = true; }
public byte[] GetDMXFromColors(IEnumerable <Color> LEDColors) { if (LEDColors == null || !LEDColors.Any()) { return(null); } if (LEDColors.Count() > maxChannel / 3) { LEDColors = LEDColors.Take(maxChannel / 3); } byte[] channels = LEDColors.SelectMany((color) => { var A = color.A / 255M; var RGB = new ColorMine.ColorSpaces.Rgb() { R = (int)(color.R * A), G = (int)(color.G * A), B = (int)(color.B * A) }; var CMY = RGB.To <ColorMine.ColorSpaces.Cmy>(); // LAB return(new byte[] { (byte)(15 * CMY.C), (byte)(15 * CMY.M), (byte)(15 * CMY.Y) }); }).ToArray(); return(channels); }
private void SetClosestIndex(Color color) { ColorMine.ColorSpaces.Rgb rgbColorStop = new ColorMine.ColorSpaces.Rgb() { R = color.R, G = color.G, B = color.B }; Tuple <Color, double, int>[] colorWeights = new Tuple <Color, double, int> [TextSurface.Cells.Length]; // Create a color weight for every cell compared to the color stop for (int x = 0; x < TextSurface.Cells.Length; x++) { ColorMine.ColorSpaces.Rgb rgbColor = new ColorMine.ColorSpaces.Rgb() { R = this[x].Background.R, G = this[x].Background.G, B = this[x].Background.B }; ColorMine.ColorSpaces.Cmy cmyColor = rgbColor.To <ColorMine.ColorSpaces.Cmy>(); colorWeights[x] = new Tuple <Color, double, int>(this[x].Background, rgbColorStop.Compare(cmyColor, new ColorMine.ColorSpaces.Comparisons.Cie1976Comparison()), x); } var foundColor = colorWeights.OrderBy(t => t.Item2).First(); this[_selectedColorPosition.X, _selectedColorPosition.Y].Glyph = 0; _selectedColorPosition = SadConsole.Surfaces.BasicSurface.GetPointFromIndex(foundColor.Item3, Width); this[_selectedColorPosition.X, _selectedColorPosition.Y].Glyph = 4; this.IsDirty = true; }
public override double Distance(Color3d circleColor, Color3d pixelColor, int distX, int distY) { if (circleColor.GetType() != pixelColor.GetType()) { throw new Exception("Can't compare colors in different color spaces"); } var circleColorRgb = circleColor.ConvertTo <ColorRgb>(); var pixelColorRgb = pixelColor.ConvertTo <ColorRgb>(); var mineCircleColor = new ColorMine.ColorSpaces.Rgb { R = circleColorRgb.R, G = circleColorRgb.G, B = circleColorRgb.B }; var minePixelColor = new ColorMine.ColorSpaces.Rgb { R = pixelColorRgb.R, G = pixelColorRgb.G, B = pixelColorRgb.B }; var ciede2000diff = mineCircleColor.Compare(minePixelColor, new ColorMine.ColorSpaces.Comparisons.CieDe2000Comparison()); int distFromPoint = (int)Math.Sqrt(distX * distX + distY * distY); return(ciede2000diff + distFromPoint); }
static private void ScTextGspsShapesTest(string studyDirectoryPath, string scFileName, string outputFileName, string seriesDescription) { string[] files = Directory.GetFiles(studyDirectoryPath); string sourceFilePath = files.Single(a => DicomFile.Open(a).Dataset.GetSingleValue <string>(DicomTag.Modality) != "PR"); var dataset = DicomFile.Open(sourceFilePath).Dataset; var image = dataset.ReadL16Image(); var newDataset = new DicomDataset(); dataset.CopyTo(newDataset); FontCollection fontCollection = new FontCollection(); ushort windowCenter = dataset.GetValue <ushort>(DicomTag.WindowCenter, 0); ushort windowWidth = dataset.GetValue <ushort>(DicomTag.WindowWidth, 0); ushort colorValue = (ushort)(windowCenter + windowWidth); Color color = new Color(new Rgba64(colorValue, colorValue, colorValue, colorValue)); FontFamily fontFamily = fontCollection.Install("/media/nikolaev_ov/CEFE3C54FE3C36D5/fonts/TimesNewRoman/TimesNewRomanRegular/TimesNewRomanRegular.ttf"); Font font = new Font(fontFamily, 36, FontStyle.Regular); var objectCoord = (1000F, 1000F); var objectSize = (400F, 200f); image.Mutate(a => { a.DrawText("1: (Информация о находке)", font, color, new PointF(100, 100)); a.DrawText(new DrawingOptions() { GraphicsOptions = new GraphicsOptions(), TextOptions = new TextOptions() { HorizontalAlignment = HorizontalAlignment.Center } }, "1", font, color, new PointF(objectCoord.Item1 + objectSize.Item1 * 0.5F, objectCoord.Item2 + objectSize.Item2 + 5)); }); var pixelData = image.ToPixelData(); var dicomPixelData = DicomPixelData.Create(newDataset, true); dicomPixelData.AddFrame(new MemoryByteBuffer(pixelData)); dataset = newDataset.Compress(DicomTransferSyntax.JPEGLSLossless, new DicomJpegLsLosslessCodec(), new DicomJpegParams()); string destFilePath = Path.Combine(studyDirectoryPath, Path.GetFileNameWithoutExtension(scFileName) + ".dcm"); EnsureDirectories(Path.GetDirectoryName(destFilePath)); new DicomFile(dataset).Save(destFilePath); var pre = CreatePresentationState(new[] { sourceFilePath }, true, seriesDescription, 1); const float thickness = 2F; ColorMine.ColorSpaces.Rgb rgb = new ColorMine.ColorSpaces.Rgb { G = 255 }; AddPolyline(pre, objectCoord.Item1 + thickness * 0.5F, objectCoord.Item2 + thickness * 0.5F, objectSize.Item1 - thickness, objectSize.Item2 - thickness, thickness, rgb); destFilePath = Path.Combine(studyDirectoryPath, Path.GetFileNameWithoutExtension(outputFileName) + ".dcm"); EnsureDirectories(Path.GetDirectoryName(destFilePath)); new DicomFile(pre.PresentationStateDataset).Save(destFilePath); }
public double compareColor(Color c, Color k) { ColorMine.ColorSpaces.Rgb cRgb = new ColorMine.ColorSpaces.Rgb(c.R, c.G, c.B); ColorMine.ColorSpaces.Rgb kRgb = new ColorMine.ColorSpaces.Rgb(k.R, k.G, k.B); double delta = cRgb.Compare(kRgb, new ColorMine.ColorSpaces.Comparisons.Cie1976Comparison()); log.Info("delta :" + delta + " color : " + c + " and " + k); return(delta); }
// compare two Emgu CV colors using ColorMine, an API for C# public static int colorDifference(Bgr c1, Bgr c2) { var myRGB1 = new ColorMine.ColorSpaces.Rgb { R = c1.Red, G = c1.Green, B = c1.Blue }; var myRGB2 = new ColorMine.ColorSpaces.Rgb { R = c2.Red, G = c2.Green, B = c2.Blue }; return((int)myRGB1.Compare(myRGB2, new Cie1976Comparison())); }
/// <summary> /// RGBカラーからMunsell文字列へ変換する /// </summary> /// <param name="rgb">RGBカラー</param> /// <returns>Munsell文字列</returns> public string getMunsellString(Rgb rgb) { var r = new ColorMine.ColorSpaces.Rgb { R = rgb.R, G = rgb.G, B = rgb.B }; var m = r.To <ColorMine.ColorSpaces.Munsell>(); //Munsell munsell = MunsellConverter.ToColor(rgb); //return munsell.ToString(); return(m.ToString()); }
public LCCColorDenorm RGBToLCC(ColorF c) { var rgb = new ColorMine.ColorSpaces.Rgb { R = c.R, G = c.G, B = c.B }; var lab = rgb.To <ColorMine.ColorSpaces.Hsl>(); // https://github.com/hvalidi/ColorMine/blob/master/ColorMine/ColorSpaces/ColorSpaces.xml LCCColorDenorm ret; ret.L = lab.L; ret.C1 = lab.H; ret.C2 = lab.S; return(ret); }
public static void DumpColors() { Func <Color, Color, bool> Equals = (c1, c2) => c1.R == c2.R && c1.G == c2.G && c1.B == c2.B; var fn = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName), "NamedColors.txt"); using (var sw = new System.IO.StreamWriter(fn)) { sw.WriteLine("Color\tName\tHex (RGB)" + "\tRed (RGB)\tGreen (RGB)\tBlue (RGB)" + "\tL (LAB)\tA (LAB)\tB (LAB)" + "\tHue (HSL)\tSat (HSL)\tLum (HSL)" + "\tHue (HSV)\tSat (HSV)\tValue (HSV)" + "\tRound Trip (HSL)\tRed (HSL)\tGreen (HSL)\tBlue (HSL)" + "\tRound Trip (HSV)\tRed (HSV)\tGreen (HSV)\tBlue (HSV)" ); foreach (var c in ColorEx.KnownColors) { double L, A, B; #if USE_COLORMINE var lab = new ColorMine.ColorSpaces.Rgb { R = c.R, G = c.G, B = c.B }.To <ColorMine.ColorSpaces.Lab>(); L = lab.L; A = lab.A; B = lab.B; #else var lab = RGBtoLab(c); L = lab[0]; A = lab[1]; B = lab[2]; #endif HSLColor hsl = c; HSVColor hsv = c; Color hsl2c = hsl; Color hsv2c = hsv; sw.WriteLine($"\t{c.Name}\t#{ColorEx.MakeArgb(0, c.R, c.G, c.B):X6}" + $"\t{c.R}\t{c.G}\t{c.B}" + $"\t{L}\t{A}\t{B}" + $"\t{hsl.Hue}\t{hsl.Saturation}\t{hsl.Luminosity}" + $"\t{hsv.Hue}\t{hsv.Saturation}\t{hsv.Value}" + $"\t{Equals(hsl2c, c)}\t{hsl2c.R}\t{hsl2c.G}\t{hsl2c.B}" + $"\t{Equals(hsv2c, c)}\t{hsv2c.R}\t{hsv2c.G}\t{hsv2c.B}" ); } } }
public ColorItem(string colorName) { Color = Color.FromName(colorName); #if USE_COLORMINE var lab = new ColorMine.ColorSpaces.Rgb { R = Color.R, G = Color.G, B = Color.B }.To <ColorMine.ColorSpaces.Lab>(); L = lab.L; A = lab.A; B = lab.B; #else var lab = RGBtoLab(this.Color); L = lab[0]; A = lab[1]; B = lab[2]; #endif }
public override void SetFromRgb(byte R, byte G, byte B) { var colorMineRgb = new ColorMine.ColorSpaces.Rgb { R = R, G = G, B = B }; var colorMineLab = colorMineRgb.To <ColorMine.ColorSpaces.Lab>(); //var colourfulRgb = new Colourful.RGBColor(System.Drawing.Color.FromArgb(R, G, B)); //var colourfulLab = colorfulConverter.ToLab(colourfulRgb); L = (int)colorMineLab.L; a = (int)colorMineLab.A; b = (int)colorMineLab.B; }
/// <summary> /// Given a specified color, get the nearest known web or system color. Transparency is ignored. /// </summary> /// <param name="color">Color to match</param> /// <returns>The known color that most closely resembles the specified color</returns> public static Color NearestKnownColor(this Color color) { //using (var g = Graphics.FromHwnd(IntPtr.Zero)) return g.GetNearestColor(color); // For finding nearest known perceptual color, using the LAB color space gives much better results than weighted HSL. double L, A, B; #if USE_COLORMINE var lab = new ColorMine.ColorSpaces.Rgb { R = color.R, G = color.G, B = color.B }.To <ColorMine.ColorSpaces.Lab>(); L = lab.L; A = lab.A; B = lab.B; #else var lab = RGBtoLab(color); L = lab[0]; A = lab[1]; B = lab[2]; #endif double distance = double.MaxValue; int index = 0; for (int i = 0; i < KnownColorItems.Count; i++) { var item = KnownColorItems[i]; var dL = Math.Abs(item.L - L); var dA = Math.Abs(item.A - A); var dB = Math.Abs(item.B - B); var r = dL * dL + dA * dA + dB * dB; //(L1-L2)^2 + (a1-a2)^2 + (b1-b2)^2 if (r < distance) { distance = r; index = i; } } return(KnownColorItems[index].Color); }
public Dictionary <short, byte> GetDMXChannelColors() { var rtn = new Dictionary <short, byte>(); foreach (LED led in LEDList) { var red = HonorAlpha ? led.Red : led.Red.ApplyDimmer(led.Alpha, Dimmer); var green = HonorAlpha ? led.Green : led.Green.ApplyDimmer(led.Alpha, Dimmer); var blue = HonorAlpha ? led.Blue : led.Blue.ApplyDimmer(led.Alpha, Dimmer); var A = led.Alpha / 255M; // var RGB = new ColorMine.ColorSpaces.Rgb() { R = (int)(color.R * A), G = (int)(color.G * A), B = (int)(color.B * A) }; var RGB = new ColorMine.ColorSpaces.Rgb() { R = (int)(red), G = (int)(green), B = (int)(blue) }; var CMY = RGB.To <ColorMine.ColorSpaces.Cmy>(); // LAB rtn.Add((short)(led.Index + 0), (byte)(15 * CMY.C)); rtn.Add((short)(led.Index + 1), (byte)(15 * CMY.M)); rtn.Add((short)(led.Index + 2), (byte)(15 * CMY.Y)); } return(rtn); }
/// <inheritdoc /> public override void UpdateAndDraw(ControlBase control, TimeSpan time) { if (!(control is HueBarControl bar)) { return; } if (!bar.IsDirty) { return; } control.Surface.Fill(Color.White, Color.Black, 0, null); bar._positions = control.Width; ColorGradient gradient = new ColorGradient(Color.Red, Color.Yellow, Color.Green, Color.Turquoise, Color.Blue, Color.Purple, Color.Red); for (int x = 0; x < control.Width; x++) { control.Surface[x, 0].Glyph = 219; control.Surface[x, 0].Foreground = gradient.Lerp((float)x / (float)(control.Width - 1)); } control.Surface[bar.SelectedPosition, 1].Glyph = 30; control.Surface[bar.SelectedPosition, 1].Foreground = Color.LightGray;//this[_selectedPosition, 0].Foreground; // Build an array of all the colors Color[] colors = new Color[control.Width]; for (int x = 0; x < control.Width; x++) { colors[x] = control.Surface[x, 0].Foreground; } List <int> colorIndexesFinished = new List <int>(control.Width); foreach (var stop in gradient.Stops) { ColorMine.ColorSpaces.Rgb rgbColorStop = new ColorMine.ColorSpaces.Rgb() { R = stop.Color.R, G = stop.Color.G, B = stop.Color.B }; Tuple <Color, double, int>[] colorWeights = new Tuple <Color, double, int> [control.Width]; // Create a color weight for every cell compared to the color stop for (int x = 0; x < control.Width; x++) { if (!colorIndexesFinished.Contains(x)) { ColorMine.ColorSpaces.Rgb rgbColor = new ColorMine.ColorSpaces.Rgb() { R = colors[x].R, G = colors[x].G, B = colors[x].B }; ColorMine.ColorSpaces.Cmy cmyColor = rgbColor.To <ColorMine.ColorSpaces.Cmy>(); colorWeights[x] = new Tuple <Color, double, int>(colors[x], rgbColorStop.Compare(cmyColor, new ColorMine.ColorSpaces.Comparisons.Cie1976Comparison()), x); } else { colorWeights[x] = new Tuple <Color, double, int>(colors[x], 10000, x); } } var foundColor = colorWeights.OrderBy(t => t.Item2).First(); control.Surface[foundColor.Item3, 0].Foreground = stop.Color; colorIndexesFinished.Add(foundColor.Item3); } control.IsDirty = false; }
private Color rainbowRGB(double value, double max, double min) { double range = max - min; double percent = (value - min) / range; double startCol = 0.2; double endCol = 1; int red; int grn; int blu; Color rgb = new Color(); //percent is the position in the spectrum 0 = red 1 = violet //first flip percent = 1 - percent; double threeSixty = Math.PI * 2; //but then we shift to squeeze into the desired range double scaledCol = percent * (endCol - startCol) + startCol; //startCol is a % into the roygbinv spectrum //endCol is a % before the end of the roygbinv spectrum red = Convert.ToInt16(Math.Sin(threeSixty * scaledCol + 2 * Math.PI / 3) * 128 + 127); grn = Convert.ToInt16(Math.Sin(threeSixty * scaledCol + 4 * Math.PI / 3) * 128 + 127); blu = Convert.ToInt16(Math.Sin(threeSixty * scaledCol + 0) * 128 + 127); if (red < 0) { red = 0; } if (red > 255) { red = 255; } if (grn < 0) { grn = 0; } if (grn > 255) { grn = 255; } if (blu < 0) { blu = 0; } if (blu > 255) { blu = 255; } ColorMine.ColorSpaces.Rgb colMRGB = new ColorMine.ColorSpaces.Rgb { R = red, B = blu, G = grn }; colMRGB.R = red; colMRGB.G = grn; colMRGB.B = blu; var colMHSV = colMRGB.To <ColorMine.ColorSpaces.Hsv>(); colMHSV.S = colMHSV.S * 0.7; colMRGB = colMHSV.To <ColorMine.ColorSpaces.Rgb>(); rgb = Color.FromArgb((int)colMRGB.R, (int)colMRGB.G, (int)colMRGB.B); return(rgb); }
/// <summary> /// Return best color match by computing the metric distance with the selected formula /// </summary> public static JToken GetNearestColor(string colorHex, JObject jColorList) { int colorR = int.Parse(colorHex.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier); int colorG = int.Parse(colorHex.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier); int colorB = int.Parse(colorHex.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier); var colorRgb = new ColorMine.ColorSpaces.Rgb { R = colorR, G = colorG, B = colorB }; double bestDistance = -1; JToken nearestColor = null; string nearestColorHex = null; JObject hueColorsList = null; if (jColorList["Info"]["hasHueValues"].ToObject <bool>() == true && jColorList.ContainsKey("HueColors")) { hueColorsList = jColorList["HueColors"].ToObject <JObject>(); } foreach (var item in jColorList["Colors"].ToObject <JObject>()) { string itemColorHex = item.Key; if (string.Compare(item.Key, colorHex, true) == 0) { bestDistance = 0; nearestColor = item.Value; nearestColorHex = item.Key; break; } int nearestColorR = int.Parse(itemColorHex.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier); int nearestColorG = int.Parse(itemColorHex.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier); int nearestColorB = int.Parse(itemColorHex.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier); var itemRgb = new ColorMine.ColorSpaces.Rgb { R = nearestColorR, G = nearestColorG, B = nearestColorB }; // Space comparison formulas: https://en.wikipedia.org/wiki/Color_difference // Note: Delta-e calculations are quasimetric, // the result of comparing color a to b isn't always equal to comparing color b to a // but it will probably be pretty close double deltaE = colorRgb.Compare(itemRgb, Common.spaceComparison); if (bestDistance < 0 || bestDistance > deltaE) { bestDistance = deltaE; nearestColor = item.Value; nearestColorHex = item.Key; } } // Add color info if (nearestColor != null) { nearestColor["hex"] = nearestColorHex; int nearestColorR = int.Parse(nearestColorHex.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier); int nearestColorG = int.Parse(nearestColorHex.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier); int nearestColorB = int.Parse(nearestColorHex.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier); nearestColor["rgb"] = string.Format("{0}, {1}, {2}", nearestColorR, nearestColorG, nearestColorB); nearestColor["distance"] = bestDistance; // Find Hue color info if (hueColorsList != null) { string hueName = nearestColor["hueName"].ToString(); if (hueColorsList.ContainsKey(hueName) == true) { nearestColor["hueHex"] = hueColorsList[hueName]["hex"]; } } } return(nearestColor); }
// compare two Emgu CV colors using ColorMine, an API for C# public static int colorDifference(Bgr c1, Bgr c2) { var myRGB1 = new ColorMine.ColorSpaces.Rgb { R = c1.Red, G = c1.Green, B = c1.Blue }; var myRGB2 = new ColorMine.ColorSpaces.Rgb { R = c2.Red, G = c2.Green, B = c2.Blue }; return (int)myRGB1.Compare(myRGB2, new Cie1976Comparison()); }
private void SetClosestIndex(Color color) { ColorMine.ColorSpaces.Rgb rgbColorStop = new ColorMine.ColorSpaces.Rgb() { R = color.R, G = color.G, B = color.B }; Tuple<Color, double, int>[] colorWeights = new Tuple<Color, double, int>[Width]; // Create a color weight for every cell compared to the color stop for (int x = 0; x < Width; x++) { ColorMine.ColorSpaces.Rgb rgbColor = new ColorMine.ColorSpaces.Rgb() { R = this[x, 0].Foreground.R, G = this[x, 0].Foreground.G, B = this[x, 0].Foreground.B }; ColorMine.ColorSpaces.Cmy cmyColor = rgbColor.To<ColorMine.ColorSpaces.Cmy>(); colorWeights[x] = new Tuple<Color, double, int>(this[x, 0].Foreground, rgbColorStop.Compare(cmyColor, new ColorMine.ColorSpaces.Comparisons.Cie1976Comparison()), x); } var foundColor = colorWeights.OrderBy(t => t.Item2).First(); _selectedPosition = foundColor.Item3; this.IsDirty = true; }
public override void Compose() { if (this.IsDirty) { this.Fill(Color.White, Color.Black, 0, null); _positions = Width; ColorGradient gradient = new ColorGradient(Color.Red, Color.Yellow, Color.Green, Color.Turquoise, Color.Blue, Color.Purple, Color.Red); for (int x = 0; x < Width; x++) { this[x, 0].GlyphIndex = 219; this[x, 0].Foreground = gradient.Lerp((float)x / (float)(Width - 1)); } this[_selectedPosition, 1].GlyphIndex = 30; this[_selectedPosition, 1].Foreground = Color.LightGray;//this[_selectedPosition, 0].Foreground; // Build an array of all the colors Color[] colors = new Color[Width]; for (int x = 0; x < Width; x++) colors[x] = this[x, 0].Foreground; List<int> colorIndexesFinished = new List<int>(Width); foreach (var stop in gradient.Stops) { ColorMine.ColorSpaces.Rgb rgbColorStop = new ColorMine.ColorSpaces.Rgb() { R = stop.Color.R, G = stop.Color.G, B = stop.Color.B }; Tuple<Color, double, int>[] colorWeights = new Tuple<Color, double, int>[Width]; // Create a color weight for every cell compared to the color stop for (int x = 0; x < Width; x++) { if (!colorIndexesFinished.Contains(x)) { ColorMine.ColorSpaces.Rgb rgbColor = new ColorMine.ColorSpaces.Rgb() { R = colors[x].R, G = colors[x].G, B = colors[x].B }; ColorMine.ColorSpaces.Cmy cmyColor = rgbColor.To<ColorMine.ColorSpaces.Cmy>(); colorWeights[x] = new Tuple<Color, double, int>(colors[x], rgbColorStop.Compare(cmyColor, new ColorMine.ColorSpaces.Comparisons.Cie1976Comparison()), x); } else colorWeights[x] = new Tuple<Color, double, int>(colors[x], 10000, x); } var foundColor = colorWeights.OrderBy(t => t.Item2).First(); this[foundColor.Item3, 0].Foreground = stop.Color; colorIndexesFinished.Add(foundColor.Item3); } this.IsDirty = false; } }
private void SetClosestIndex(Color color) { ColorMine.ColorSpaces.Rgb rgbColorStop = new ColorMine.ColorSpaces.Rgb() { R = color.R, G = color.G, B = color.B }; Tuple<Color, double, int>[] colorWeights = new Tuple<Color, double, int>[textSurface.Cells.Length]; // Create a color weight for every cell compared to the color stop for (int x = 0; x < textSurface.Cells.Length; x++) { ColorMine.ColorSpaces.Rgb rgbColor = new ColorMine.ColorSpaces.Rgb() { R = this[x].Background.R, G = this[x].Background.G, B = this[x].Background.B }; ColorMine.ColorSpaces.Cmy cmyColor = rgbColor.To<ColorMine.ColorSpaces.Cmy>(); colorWeights[x] = new Tuple<Color, double, int>(this[x].Background, rgbColorStop.Compare(cmyColor, new ColorMine.ColorSpaces.Comparisons.Cie1976Comparison()), x); } var foundColor = colorWeights.OrderBy(t => t.Item2).First(); this[_selectedColorPosition.X, _selectedColorPosition.Y].GlyphIndex = 0; _selectedColorPosition = SadConsole.Consoles.TextSurface.GetPointFromIndex(foundColor.Item3, Width); this[_selectedColorPosition.X, _selectedColorPosition.Y].GlyphIndex = 4; this.IsDirty = true; }