public Color GetColor() { Color color = Color_Util.HSLToColor(Hue, Saturation, Lightness); color.A = Alpha; return(color); }
internal static Color BaseSpecularColor(Color baseColor) { float h, s, v; Color_Util.ColorToHSV(baseColor, out h, out s, out v); Color fullValue = Color_Util.HSVToColor(h, s, 1f); fullValue.A = baseColor.A; return(Color.Lerp(baseColor, fullValue, 0.5f)); }
public XnaHSL(Color color) { float hue, sat, lit; Color_Util.ColorToHSL(color, out hue, out sat, out lit); Hue = hue; Saturation = sat; Lightness = lit; Alpha = color.A; }
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; }
/// <summary> /// Adjusts base color lightness up if it's too close to the BlackLevel /// </summary> private static XnaHSL AdjustBaseColor(Color color, float blackLevel) { // Use HSV instead of HSL to have finer control over the saturation float h, s, v; Color_Util.ColorToHSV(color, out h, out s, out v); float adjustedV = BlackLevelAdjustment(v, blackLevel); // Adjust the saturation down if the color is brightened, so // extremely dark colors don't have strangely high saturation float adjustedS = adjustedV == 0 ? 0 : s * (v / adjustedV); Color adjusted = Color_Util.HSVToColor(h, adjustedS, adjustedV); adjusted.A = color.A; return(new XnaHSL(adjusted)); }
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)); }