/// <summary> /// Multiplies the Color's Saturation, and Luminance or Brightness by the arguments; /// and optionally specifies the output Alpha. /// </summary> /// <param name="color">The color to transform.</param> /// <param name="colorTransformMode">Transform mode.</param> /// <param name="saturationTransform">The transformation multiplier.</param> /// <param name="brightnessTransform">The transformation multiplier.</param> /// <param name="outputAlpha">Can optionally specify the Alpha to directly /// set on the output. If null, then the input <paramref name="color"/> /// Alpha is used.</param> /// <returns>RGB Color.</returns> public static Color TransformSaturationAndValue( Color color, ColorTransformMode colorTransformMode, double saturationTransform, double brightnessTransform, byte?outputAlpha = null) { double[] hsl = colorTransformMode == ColorTransformMode.Hsl ? SimpleColorTransforms.RgbToHsl(color) : SimpleColorTransforms.RgbToHsb(color); if ((SystemMath.Abs(hsl[1]) < SimpleColorTransforms.tolerance) && (saturationTransform > 1D)) { hsl[1] = saturationTransform - 1D; } else { hsl[1] *= saturationTransform; } if ((SystemMath.Abs(hsl[2]) < SimpleColorTransforms.tolerance) && (brightnessTransform > 1D)) { hsl[2] = brightnessTransform - 1D; } else { hsl[2] *= brightnessTransform; } return(colorTransformMode == ColorTransformMode.Hsl ? SimpleColorTransforms.HslToRgb(hsl[0], hsl[1], hsl[2], outputAlpha ?? color.A) : SimpleColorTransforms.HsbToRgb(hsl[0], hsl[1], hsl[2], outputAlpha ?? color.A)); }
/// <summary> /// Transforms the input <paramref name="color"/> Hue by adding the specified /// <paramref name="hueTransform"/>; which is in [-360, 360]. The given /// transformation value is added to the current hue (in [0, 360]); and /// the output will be rotated to within [0, 360] (does not raise exceptions). /// </summary> /// <param name="color">The color to transform.</param> /// <param name="hueTransform">The transformation to apply to this /// <paramref name="color"/> hue: [-360, 360].</param> /// <param name="outputAlpha">Can optionally specify the Alpha to directly /// set on the output. If null, then the input <paramref name="color"/> /// Alpha is used.</param> /// <returns>RGB Color.</returns> public static Color TransformHue(Color color, double hueTransform, byte?outputAlpha = null) { double[] hsl = SimpleColorTransforms.RgbToHsl(color); hueTransform = SystemMath.Max(-360D, SystemMath.Min(360D, hueTransform)); hsl[0] += hueTransform; if (hsl[0] > 360D) { hsl[0] -= 360D; } else if (hsl[0] < 0D) { hsl[0] += 360D; } return(SimpleColorTransforms.HslToRgb(hsl[0], hsl[1], hsl[2], outputAlpha ?? color.A)); }