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> [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; }
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; }
/// <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 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; }
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); }
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; }