internal void OrderColors() { if (!Ramp.Colors.Any()) { return; } int oldBaseIndex = (int)Math.Floor(Ramp.BaseColorIndex); float adjustment = Ramp.BaseColorIndex - oldBaseIndex; var entries = Palette.RampEntries(Ramp); var order = PaletteRamp.ColorLumaOrder(entries.Select(x => x.Color)).ToList(); var colors = order .Select(x => Ramp.Colors[x]) .ToList(); var adjustments = order .Select(x => Ramp.Adjustments[x]) .ToList(); Ramp.SetColors(colors, adjustments); float newBaseIndex = oldBaseIndex; if (oldBaseIndex >= 0 && oldBaseIndex < this.Count) { newBaseIndex = order.IndexOf(oldBaseIndex); } newBaseIndex += adjustment; Ramp.BaseColorIndex = newBaseIndex; }
public void RefreshDarkestColor() { if (Palette.Any()) { var order = PaletteRamp.ColorLumaOrder(GetRemappedPalette()); order = order .Where(x => Palette[x].Color.A > 0) .ToList(); if (order.Any()) { int index = order.ElementAt(0); SetDarkestColor(index); } } }
public void AddRamp(List <Color> sourceColors, List <int> sourceWeights) { // Order the colors by lightness var order = PaletteRamp.ColorLumaOrder(sourceColors); var orderedColors = order .Select(x => sourceColors[x]) .ToList(); var orderedWeights = order .Select(x => sourceWeights[x]) .ToList(); AddRamp(); int rampIndex = Ramps.Count - 1; foreach (int index in order) { int colorIndex = AddColor(orderedColors[index], orderedWeights[index]); AddColorToRamp(colorIndex, rampIndex); } }