public static ColorPatch GeneratePatch(MWColor _old, Color _new) { if (_old == null && _new != null) { return(new ColorPatch(_new)); } else if (_new == null) { return(null); } var patch = new ColorPatch() { R = _old.R != _new.r ? (float?)_new.r : null, G = _old.G != _new.g ? (float?)_new.g : null, B = _old.B != _new.b ? (float?)_new.b : null, A = _old.A != _new.a ? (float?)_new.a : null }; if (patch.IsPatched()) { return(patch); } else { return(null); } }
public static MWColor ApplyPatch(this MWColor _this, ColorPatch color) { if (color == null) { return(_this); } if (color.A != null) { _this.A = color.A.Value; } if (color.R != null) { _this.R = color.R.Value; } if (color.G != null) { _this.G = color.G.Value; } if (color.B != null) { _this.B = color.B.Value; } return(_this); }
private void CreateOrChangeColor(Color color, ColorPatch colorPatch, Point location) { if (colorPatch != null) { colorPatch.Color = color; SaveAndRefreshPalette(); } else { CreatePatch(location, color); } }
private void Window_Loaded(object sender, RoutedEventArgs eventArgs) { #if DISP_ASTAR_LSTAR // a*L*平面。L軸は0~100なので float originOffsetX = 400; float originOffsetY = 800; labelAxisA.Content = "a*→"; labelAxisA.Margin = new Thickness(700, 200, 0, 0); labelAxisB.Content = "↑L*"; labelAxisB.Margin = new Thickness(400, 100, 0, 0); labelOrigin.Margin = new Thickness(400, 766, 0, 0); #else // a*b*平面 float originOffsetX = 400; float originOffsetY = 400; labelAxisA.Content = "a*"; labelAxisA.Margin = new Thickness(763, 400, 0, 0); labelAxisB.Content = "b*"; labelAxisB.Margin = new Thickness(400, 6, 0, 0); labelOrigin.Margin = new Thickness(400, 400, 0, 0); #endif rectangleV.Height = canvas1.Height; rectangleV.Margin = new Thickness(originOffsetX, 0, 0, 0); rectangleH.Width = canvas1.Width; rectangleH.Margin = new Thickness(0, originOffsetY, 0, 0); var rgbHash = new HashSet <int>(); var colors = new List <ColorPatch> [SEGMENT_NUM]; for (int i = 0; i < SEGMENT_NUM; ++i) { colors[i] = new List <ColorPatch>(); } for (int i = 0; i < colorTable.Length / 3; ++i) { byte r = colorTable[i * 3]; byte g = colorTable[i * 3 + 1]; byte b = colorTable[i * 3 + 2]; var c = Color.FromRgb(r, g, b); RGB rgb = new RGB(); rgb.Set(r, g, b); LabStar lab = XYZtoLabStar(RGBtoXYZ(rgb)); var cp = new ColorPatch(); cp.id = i; cp.rgb = rgb; cp.lab = lab; colors[i / COLOR_NUM_PER_SEGMENT].Add(cp); Ellipse e = new Ellipse(); e.Fill = new SolidColorBrush(c); e.Height = 16; e.Width = 16; #if DISP_ASTAR_LSTAR // a*L*平面 var pos = new Thickness((lab.a) * 10 + originOffsetX, (-lab.L) * 10 + originOffsetY, 0, 0); #else // a*b*平面 var pos = new Thickness((lab.a) * 10 + originOffsetX, (-lab.b) * 10 + originOffsetY, 0, 0); #endif e.Margin = pos; canvas1.Children.Add(e); Canvas.SetZIndex(e, -1); bool collision = false; int hashValue = r * 65536 + g * 256 + b; if (rgbHash.Contains(hashValue)) { collision = true; } rgbHash.Add(hashValue); Label l = new Label(); l.Content = string.Format("{0}", i + 1); l.FontSize = 8; l.Foreground = new SolidColorBrush(Colors.White); l.Margin = pos; if (collision) { l.Margin = new Thickness(pos.Left, pos.Top + l.FontSize, pos.Right, pos.Bottom); } canvas1.Children.Add(l); } for (int segment = 0; segment < SEGMENT_NUM; ++segment) { for (int i = 0; i < COLOR_NUM_PER_SEGMENT; ++i) { var cpFrom = colors[segment].ElementAt(i); var cpSort = new Dictionary <float, ColorPatch>(); for (int j = 0; j < COLOR_NUM_PER_SEGMENT; ++j) { if (i == j) { continue; } var cpTo = colors[segment].ElementAt(j); cpSort.Add(cpFrom.lab.DistanceSquared(cpTo.lab), cpTo); } var sorted = (from entry in cpSort orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); var e = sorted.GetEnumerator(); e.MoveNext(); cpFrom.neighbor = e.Current.Value; e.MoveNext(); cpFrom.neighbor2 = e.Current.Value; e.MoveNext(); cpFrom.neighbor3 = e.Current.Value; } } Console.WriteLine("graph g {"); Console.WriteLine(" graph [bgcolor=\"#484848\"]"); Console.WriteLine(" node [style=filled, fontsize=32, fontcolor=white]"); Console.WriteLine(" edge [fontsize=32, fontcolor=white]"); Console.WriteLine(" rankdir=LR;"); for (int segment = 0; segment < SEGMENT_NUM; ++segment) { Console.WriteLine(" subgraph cluster{0} {{", segment); Console.WriteLine(" style=invis;"); for (int i = 0; i < COLOR_NUM_PER_SEGMENT; ++i) { var cp = colors[segment].ElementAt(i); string shape = "color=\"#484848\", shape=ellipse"; if (i == 0 || i == COLOR_NUM_PER_SEGMENT - 1) { shape = ", color=white, shape=doublecircle"; } Console.WriteLine(" {4} [fillcolor=\"#{0:x2}{1:x2}{2:x2}\"{3}];", (int)(cp.rgb.r), (int)(cp.rgb.g), (int)(cp.rgb.b), shape, cp.id + 1); //< ★★★★★ 要注意 1足して表示 ★★★★★ } for (int i = 0; i < COLOR_NUM_PER_SEGMENT; ++i) { var cp = colors[segment].ElementAt(i); WriteLink(segment * COLOR_NUM_PER_SEGMENT, colors[segment], cp.id, cp.neighbor.id, "style=bold, "); WriteLink(segment * COLOR_NUM_PER_SEGMENT, colors[segment], cp.id, cp.neighbor2.id, " "); WriteLink(segment * COLOR_NUM_PER_SEGMENT, colors[segment], cp.id, cp.neighbor3.id, "style=dotted,"); } Console.WriteLine(" }"); } Console.WriteLine("}"); }
private void ColorGrid_OnMouseRightButtonDown(object sender, MouseButtonEventArgs e) { _contextMenuMouseLocation = e.GetPosition(ColorGrid); _contextMenuColorPatch = ColorGrid.GetColorPatchAt(e.GetPosition(ColorGrid)); OpenColorPatchContextMenu(); }
private void ColorGrid_OnColorPatchRightClick(object sender, ColorPatchRoutedEventArgs e) { _contextMenuColorPatch = e.ColorPatch; OpenColorPatchContextMenu(); }
private void Window_Loaded(object sender, RoutedEventArgs eventArgs) { #if DISP_ASTAR_LSTAR // a*L*平面。L軸は0~100なので float originOffsetX = 400; float originOffsetY = 800; labelAxisA.Content = "a*→"; labelAxisA.Margin = new Thickness(700, 200, 0, 0); labelAxisB.Content = "↑L*"; labelAxisB.Margin = new Thickness(400, 100, 0, 0); labelOrigin.Margin = new Thickness(400, 766, 0, 0); #else // a*b*平面 float originOffsetX = 400; float originOffsetY = 400; labelAxisA.Content = "a*"; labelAxisA.Margin = new Thickness(763, 400, 0, 0); labelAxisB.Content = "b*"; labelAxisB.Margin = new Thickness(400, 6, 0, 0); labelOrigin.Margin = new Thickness(400, 400, 0, 0); #endif rectangleV.Height = canvas1.Height; rectangleV.Margin = new Thickness(originOffsetX, 0, 0, 0); rectangleH.Width = canvas1.Width; rectangleH.Margin = new Thickness(0, originOffsetY, 0, 0); var rgbHash = new HashSet<int>(); var colors = new List<ColorPatch>[SEGMENT_NUM]; for (int i = 0; i < SEGMENT_NUM; ++i) { colors[i] = new List<ColorPatch>(); } for (int i = 0; i < colorTable.Length / 3; ++i) { byte r = colorTable[i * 3]; byte g = colorTable[i * 3 + 1]; byte b = colorTable[i * 3 + 2]; var c = Color.FromRgb(r, g, b); RGB rgb = new RGB(); rgb.Set(r, g, b); LabStar lab = XYZtoLabStar(RGBtoXYZ(rgb)); var cp = new ColorPatch(); cp.id = i; cp.rgb = rgb; cp.lab = lab; colors[i / COLOR_NUM_PER_SEGMENT].Add(cp); Ellipse e = new Ellipse(); e.Fill = new SolidColorBrush(c); e.Height = 16; e.Width = 16; #if DISP_ASTAR_LSTAR // a*L*平面 var pos = new Thickness((lab.a) * 10 + originOffsetX, (-lab.L) * 10 + originOffsetY, 0, 0); #else // a*b*平面 var pos = new Thickness((lab.a) * 10 + originOffsetX, (-lab.b) * 10 + originOffsetY, 0, 0); #endif e.Margin = pos; canvas1.Children.Add(e); Canvas.SetZIndex(e, -1); bool collision = false; int hashValue = r * 65536 + g * 256 + b; if (rgbHash.Contains(hashValue)) { collision = true; } rgbHash.Add(hashValue); Label l = new Label(); l.Content = string.Format("{0}", i + 1); l.FontSize = 8; l.Foreground = new SolidColorBrush(Colors.White); l.Margin = pos; if (collision) { l.Margin = new Thickness(pos.Left, pos.Top + l.FontSize, pos.Right, pos.Bottom); } canvas1.Children.Add(l); } for (int segment = 0; segment < SEGMENT_NUM; ++segment) { for (int i = 0; i < COLOR_NUM_PER_SEGMENT; ++i) { var cpFrom = colors[segment].ElementAt(i); var cpSort = new Dictionary<float, ColorPatch>(); for (int j = 0; j < COLOR_NUM_PER_SEGMENT; ++j) { if (i == j) { continue; } var cpTo = colors[segment].ElementAt(j); cpSort.Add(cpFrom.lab.DistanceSquared(cpTo.lab), cpTo); } var sorted = (from entry in cpSort orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); var e = sorted.GetEnumerator(); e.MoveNext(); cpFrom.neighbor = e.Current.Value; e.MoveNext(); cpFrom.neighbor2 = e.Current.Value; e.MoveNext(); cpFrom.neighbor3 = e.Current.Value; } } Console.WriteLine("graph g {"); Console.WriteLine(" graph [bgcolor=\"#484848\"]"); Console.WriteLine(" node [style=filled, fontsize=32, fontcolor=white]"); Console.WriteLine(" edge [fontsize=32, fontcolor=white]"); Console.WriteLine(" rankdir=LR;"); for (int segment = 0; segment < SEGMENT_NUM; ++segment) { Console.WriteLine(" subgraph cluster{0} {{", segment); Console.WriteLine(" style=invis;"); for (int i = 0; i < COLOR_NUM_PER_SEGMENT; ++i) { var cp = colors[segment].ElementAt(i); string shape = "color=\"#484848\", shape=ellipse"; if (i == 0 || i == COLOR_NUM_PER_SEGMENT - 1) { shape = ", color=white, shape=doublecircle"; } Console.WriteLine(" {4} [fillcolor=\"#{0:x2}{1:x2}{2:x2}\"{3}];", (int)(cp.rgb.r), (int)(cp.rgb.g), (int)(cp.rgb.b), shape, cp.id + 1); //< ★★★★★ 要注意 1足して表示 ★★★★★ } for (int i = 0; i < COLOR_NUM_PER_SEGMENT; ++i) { var cp = colors[segment].ElementAt(i); WriteLink(segment * COLOR_NUM_PER_SEGMENT, colors[segment], cp.id, cp.neighbor.id, "style=bold, "); WriteLink(segment * COLOR_NUM_PER_SEGMENT, colors[segment], cp.id, cp.neighbor2.id, " "); WriteLink(segment * COLOR_NUM_PER_SEGMENT, colors[segment], cp.id, cp.neighbor3.id, "style=dotted,"); } Console.WriteLine(" }"); } Console.WriteLine("}"); }