Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 public override void Read(BinaryReader input)
 {
     Name             = input.ReadString();
     IsIndexedPalette = input.ReadBoolean();
     input.ReadTactileContent(Palette, PaletteEntry.GetEmptyInstance());
     input.ReadTactileContent(Ramps, PaletteRamp.GetEmptyInstance());
     _DarkestColor = _DarkestColor.read(input);
 }
        private float SaturationMultiplier(GeneratedColorPalette rawPalette, PaletteRamp ramp, int index)
        {
            Color target = rawPalette.GetColor(ColorValues[index]);
            Color source = ramp.Colors[index];

            XnaHSL targetHsl = new XnaHSL(target);
            XnaHSL sourceHsl = new XnaHSL(source);

            return(SaturationMultiplier(targetHsl, sourceHsl));
        }
Exemplo n.º 4
0
        public void AddRamp()
        {
            string name = "New Ramp";

            for (int index = 1; Ramps.Any(x => x.Name == name); index++)
            {
                name = string.Format("New Ramp{0}", index);
            }

            var ramp = new PaletteRamp(name, _DarkestColor);

            Ramps.Add(ramp);
        }
Exemplo n.º 5
0
 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);
         }
     }
 }
Exemplo n.º 6
0
        internal List <PaletteEntry> RampEntries(PaletteRamp ramp)
        {
            var result = ramp.Colors
                         .Select(color =>
            {
                int index = ColorIndex(color);
                if (index >= 0)
                {
                    return(GetEntry(index));
                }
                else
                {
                    return(new PaletteEntry(color, 0));
                }
            })
                         .ToList();

            return(result);
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
 internal void ReplaceRamp(int index, PaletteRamp ramp)
 {
     Ramps[index] = ramp;
 }
Exemplo n.º 9
0
 private SpriteRamp(SpriteRamp source)
 {
     Palette = source.Palette;
     Ramp    = (PaletteRamp)source.Ramp.Clone();
 }
Exemplo n.º 10
0
 internal SpriteRamp(SpritePalette palette, PaletteRamp ramp)
 {
     Palette = palette;
     Ramp    = ramp;
 }
Exemplo n.º 11
0
 private PaletteRamp(PaletteRamp source)
 {
     CopyFrom(source);
 }