Browse Source

Fix spelling

af/merge-core
James Jackson-South 10 years ago
parent
commit
ee68c7d743
  1. 6
      src/ImageSharp/Drawing/Brushes/RecolorBrush.cs
  2. 42
      src/ImageSharp/Drawing/Brushes/RecolorBrush{TColor}.cs

6
src/ImageSharp/Drawing/Brushes/RecolorBrush.cs

@ -15,9 +15,9 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="sourceColor">Color of the source.</param> /// <param name="sourceColor">Color of the source.</param>
/// <param name="targetColor">Color of the target.</param> /// <param name="targetColor">Color of the target.</param>
/// <param name="threashold">The threashold.</param> /// <param name="threshold">The threshold.</param>
public RecolorBrush(Color sourceColor, Color targetColor, float threashold) public RecolorBrush(Color sourceColor, Color targetColor, float threshold)
: base(sourceColor, targetColor, threashold) : base(sourceColor, targetColor, threshold)
{ {
} }
} }

42
src/ImageSharp/Drawing/Brushes/RecolorBrush{TColor}.cs

@ -22,21 +22,21 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="sourceColor">Color of the source.</param> /// <param name="sourceColor">Color of the source.</param>
/// <param name="targetColor">Color of the target.</param> /// <param name="targetColor">Color of the target.</param>
/// <param name="threashold">The threashold as a value between 0 and 1.</param> /// <param name="threshold">The threshold as a value between 0 and 1.</param>
public RecolorBrush(TColor sourceColor, TColor targetColor, float threashold) public RecolorBrush(TColor sourceColor, TColor targetColor, float threshold)
{ {
this.SourceColor = sourceColor; this.SourceColor = sourceColor;
this.Threashold = threashold; this.Threshold = threshold;
this.TargetColor = targetColor; this.TargetColor = targetColor;
} }
/// <summary> /// <summary>
/// Gets the threashold. /// Gets the threshold.
/// </summary> /// </summary>
/// <value> /// <value>
/// The threashold. /// The threshold.
/// </value> /// </value>
public float Threashold { get; } public float Threshold { get; }
/// <summary> /// <summary>
/// Gets the source color. /// Gets the source color.
@ -57,7 +57,7 @@ namespace ImageSharp.Drawing.Brushes
/// <inheritdoc /> /// <inheritdoc />
public IBrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region) public IBrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region)
{ {
return new RecolorBrushApplicator(sourcePixels, this.SourceColor, this.TargetColor, this.Threashold); return new RecolorBrushApplicator(sourcePixels, this.SourceColor, this.TargetColor, this.Threshold);
} }
/// <summary> /// <summary>
@ -69,10 +69,21 @@ namespace ImageSharp.Drawing.Brushes
/// The source pixel accessor. /// The source pixel accessor.
/// </summary> /// </summary>
private readonly PixelAccessor<TColor> source; private readonly PixelAccessor<TColor> source;
/// <summary>
/// The source color.
/// </summary>
private readonly Vector4 sourceColor; private readonly Vector4 sourceColor;
/// <summary>
/// The target color.
/// </summary>
private readonly Vector4 targetColor; private readonly Vector4 targetColor;
private readonly float threashold;
private readonly float totalDistance; /// <summary>
/// The threshold.
/// </summary>
private readonly float threshold;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RecolorBrushApplicator" /> class. /// Initializes a new instance of the <see cref="RecolorBrushApplicator" /> class.
@ -80,20 +91,19 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="sourcePixels">The source pixels.</param> /// <param name="sourcePixels">The source pixels.</param>
/// <param name="sourceColor">Color of the source.</param> /// <param name="sourceColor">Color of the source.</param>
/// <param name="targetColor">Color of the target.</param> /// <param name="targetColor">Color of the target.</param>
/// <param name="threashold">The threashold .</param> /// <param name="threshold">The threshold .</param>
public RecolorBrushApplicator(PixelAccessor<TColor> sourcePixels, TColor sourceColor, TColor targetColor, float threashold) public RecolorBrushApplicator(PixelAccessor<TColor> sourcePixels, TColor sourceColor, TColor targetColor, float threshold)
{ {
this.source = sourcePixels; this.source = sourcePixels;
this.sourceColor = sourceColor.ToVector4(); this.sourceColor = sourceColor.ToVector4();
this.targetColor = targetColor.ToVector4(); this.targetColor = targetColor.ToVector4();
// lets hack a min max extreams for a color space by letteing the IPackedPixle clamp our values to something in the correct spaces :) // Lets hack a min max extreams for a color space by letteing the IPackedPixel clamp our values to something in the correct spaces :)
TColor maxColor = default(TColor); TColor maxColor = default(TColor);
maxColor.PackFromVector4(new Vector4(float.MaxValue)); maxColor.PackFromVector4(new Vector4(float.MaxValue));
TColor minColor = default(TColor); TColor minColor = default(TColor);
minColor.PackFromVector4(new Vector4(float.MinValue)); minColor.PackFromVector4(new Vector4(float.MinValue));
this.totalDistance = Vector4.DistanceSquared(maxColor.ToVector4(), minColor.ToVector4()); this.threshold = Vector4.DistanceSquared(maxColor.ToVector4(), minColor.ToVector4()) * threshold;
this.threashold = this.totalDistance * threashold;
} }
/// <summary> /// <summary>
@ -109,9 +119,9 @@ namespace ImageSharp.Drawing.Brushes
TColor result = this.source[(int)point.X, (int)point.Y]; TColor result = this.source[(int)point.X, (int)point.Y];
Vector4 background = result.ToVector4(); Vector4 background = result.ToVector4();
float distance = Vector4.DistanceSquared(background, this.sourceColor); float distance = Vector4.DistanceSquared(background, this.sourceColor);
if (distance <= this.threashold) if (distance <= this.threshold)
{ {
var lerpAmount = (this.threashold - distance) / this.threashold; var lerpAmount = (this.threshold - distance) / this.threshold;
Vector4 blended = Vector4BlendTransforms.PremultipliedLerp(background, this.targetColor, lerpAmount); Vector4 blended = Vector4BlendTransforms.PremultipliedLerp(background, this.targetColor, lerpAmount);
result.PackFromVector4(blended); result.PackFromVector4(blended);
} }

Loading…
Cancel
Save