private static void GetShadow( XnaHSL baseHSL, PaletteGenerator generator, PaletteParameters parameters, out XnaHSL shadow, out XnaHSL darkest) { XnaHSL blackHSL = new XnaHSL( baseHSL.Hue, baseHSL.Saturation * generator.ShadowAmount, generator.BlackLevel, baseHSL.Alpha); // If the base color is sufficiently bright, lighten the darker shades float lightnessRatio = (baseHSL.Lightness - 0.5f) * 2f; if (lightnessRatio > 0) { blackHSL = blackHSL.SetSaturation(blackHSL.Saturation * (1f - lightnessRatio * 0.95f)); float blackLuma = Color_Util.GetLuma(blackHSL.GetColor()); // Increase the lightness by more if it's a color with a low // luma to lightness ratio float lumaRatio = 1f; if (blackLuma > 0) { lumaRatio = blackHSL.Lightness / blackLuma; } blackHSL = blackHSL.SetLightness( MathHelper.Lerp(blackHSL.Lightness, MathHelper.Lerp(blackHSL.Lightness, 1f, 0.25f), lightnessRatio * lumaRatio)); } // Tint black and shadow blue blackHSL = blackHSL.LerpHue(240, parameters.BlueShadow); blackHSL = blackHSL.SetSaturation(MathHelper.Lerp(blackHSL.Saturation, 1f, parameters.BlueShadow / 4f)); XnaHSL shadowHSL = XnaHSL.Lerp(blackHSL, baseHSL, generator.ShadowAmount); shadowHSL = shadowHSL.SetSaturation(MathHelper.Lerp(blackHSL.Saturation, baseHSL.Saturation, 0.5f)); shadowHSL = shadowHSL.SetHue(blackHSL.Hue); shadowHSL = shadowHSL.LerpHue(baseHSL.Hue, 0.25f); shadow = shadowHSL; darkest = blackHSL; }
public void LuminanceSort() { var ordered_colors = Palette .Select(x => new Tuple <PaletteEntry, float>( x, Color_Util.GetLuma(x.Color))) // Put transparent colors last .OrderBy(x => x.Item1.Value.A == 0 ? 1 : -1) // Sort by luma .ThenByDescending(x => x.Item2) .Select(x => x.Item1) .ToList(); // Reverse if it was already sorted if (Enumerable.Range(0, Palette.Count) .All(x => Palette.ElementAt(x) == ordered_colors.ElementAt(x))) { ordered_colors = ordered_colors .Reverse <PaletteEntry>() .OrderBy(x => x.Value.A == 0 ? 1 : -1) .ToList(); } Palette = ordered_colors.ToList(); }
public static float ValueFormula(Color color) { return(Color_Util.GetLuma(color)); }