diff --git a/src/ImageSharp.Drawing/Processing/EllipticGradientBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/EllipticGradientBrush{TPixel}.cs index 8af01564c4..64901c8e80 100644 --- a/src/ImageSharp.Drawing/Processing/EllipticGradientBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/EllipticGradientBrush{TPixel}.cs @@ -18,9 +18,9 @@ namespace SixLabors.ImageSharp.Processing public sealed class EllipticGradientBrush : GradientBrushBase where TPixel : struct, IPixel { - private readonly Point center; + private readonly PointF center; - private readonly Point referenceAxisEnd; + private readonly PointF referenceAxisEnd; private readonly float axisRatio; @@ -35,8 +35,8 @@ public sealed class EllipticGradientBrush : GradientBrushBase /// Defines how the colors of the gradients are repeated. /// the color stops as defined in base class. public EllipticGradientBrush( - Point center, - Point referenceAxisEnd, + PointF center, + PointF referenceAxisEnd, float axisRatio, GradientRepetitionMode repetitionMode, params ColorStop[] colorStops) @@ -64,9 +64,9 @@ public override BrushApplicator CreateApplicator( /// private sealed class RadialGradientBrushApplicator : GradientBrushApplicatorBase { - private readonly Point center; + private readonly PointF center; - private readonly Point referenceAxisEnd; + private readonly PointF referenceAxisEnd; private readonly float axisRatio; @@ -99,8 +99,8 @@ private sealed class RadialGradientBrushApplicator : GradientBrushApplicatorBase public RadialGradientBrushApplicator( ImageFrame target, GraphicsOptions options, - Point center, - Point referenceAxisEnd, + PointF center, + PointF referenceAxisEnd, float axisRatio, ColorStop[] colorStops, GradientRepetitionMode repetitionMode) @@ -129,7 +129,7 @@ public override void Dispose() } /// - protected override float PositionOnGradient(int xt, int yt) + protected override float PositionOnGradient(float xt, float yt) { float x0 = xt - this.center.X; float y0 = yt - this.center.Y; diff --git a/src/ImageSharp.Drawing/Processing/GradientBrushBase{TPixel}.cs b/src/ImageSharp.Drawing/Processing/GradientBrushBase{TPixel}.cs index ca565c46c9..2dfae9e8f1 100644 --- a/src/ImageSharp.Drawing/Processing/GradientBrushBase{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/GradientBrushBase{TPixel}.cs @@ -81,7 +81,7 @@ protected GradientBrushApplicatorBase( { get { - float positionOnCompleteGradient = this.PositionOnGradient(x, y); + float positionOnCompleteGradient = this.PositionOnGradient(x + 0.5f, y + 0.5f); switch (this.repetitionMode) { @@ -137,18 +137,18 @@ protected GradientBrushApplicatorBase( } /// - /// calculates the position on the gradient for a given pixel. + /// calculates the position on the gradient for a given point. /// This method is abstract as it's content depends on the shape of the gradient. /// - /// The x coordinate of the pixel - /// The y coordinate of the pixel + /// The x coordinate of the point + /// The y coordinate of the point /// - /// The position the given pixel has on the gradient. + /// The position the given point has on the gradient. /// The position is not bound to the [0..1] interval. /// Values outside of that interval may be treated differently, /// e.g. for the enum. /// - protected abstract float PositionOnGradient(int x, int y); + protected abstract float PositionOnGradient(float x, float y); private (ColorStop from, ColorStop to) GetGradientSegment( float positionOnCompleteGradient) diff --git a/src/ImageSharp.Drawing/Processing/LinearGradientBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/LinearGradientBrush{TPixel}.cs index 765bf5499d..efdc852f28 100644 --- a/src/ImageSharp.Drawing/Processing/LinearGradientBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/LinearGradientBrush{TPixel}.cs @@ -17,9 +17,9 @@ namespace SixLabors.ImageSharp.Processing public sealed class LinearGradientBrush : GradientBrushBase where TPixel : struct, IPixel { - private readonly Point p1; + private readonly PointF p1; - private readonly Point p2; + private readonly PointF p2; /// /// Initializes a new instance of the class. @@ -29,8 +29,8 @@ public sealed class LinearGradientBrush : GradientBrushBase /// defines how colors are repeated. /// public LinearGradientBrush( - Point p1, - Point p2, + PointF p1, + PointF p2, GradientRepetitionMode repetitionMode, params ColorStop[] colorStops) : base(repetitionMode, colorStops) @@ -48,9 +48,9 @@ public override BrushApplicator CreateApplicator(ImageFrame sour /// private sealed class LinearGradientBrushApplicator : GradientBrushApplicatorBase { - private readonly Point start; + private readonly PointF start; - private readonly Point end; + private readonly PointF end; /// /// the vector along the gradient, x component @@ -93,8 +93,8 @@ private sealed class LinearGradientBrushApplicator : GradientBrushApplicatorBase /// the graphics options public LinearGradientBrushApplicator( ImageFrame source, - Point start, - Point end, + PointF start, + PointF end, ColorStop[] colorStops, GradientRepetitionMode repetitionMode, GraphicsOptions options) @@ -116,15 +116,15 @@ public LinearGradientBrushApplicator( this.length = (float)Math.Sqrt(this.alongsSquared); } - protected override float PositionOnGradient(int x, int y) + protected override float PositionOnGradient(float x, float y) { if (this.acrossX == 0) { - return (x - this.start.X) / (float)(this.end.X - this.start.X); + return (x - this.start.X) / (this.end.X - this.start.X); } else if (this.acrossY == 0) { - return (y - this.start.Y) / (float)(this.end.Y - this.start.Y); + return (y - this.start.Y) / (this.end.Y - this.start.Y); } else { diff --git a/src/ImageSharp.Drawing/Processing/RadialGradientBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/RadialGradientBrush{TPixel}.cs index 16380fc34b..d33d099931 100644 --- a/src/ImageSharp.Drawing/Processing/RadialGradientBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/RadialGradientBrush{TPixel}.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Processing public sealed class RadialGradientBrush : GradientBrushBase where TPixel : struct, IPixel { - private readonly Point center; + private readonly PointF center; private readonly float radius; @@ -25,7 +25,7 @@ public sealed class RadialGradientBrush : GradientBrushBase /// Defines how the colors in the gradient are repeated. /// the color stops as defined in base class. public RadialGradientBrush( - Point center, + PointF center, float radius, GradientRepetitionMode repetitionMode, params ColorStop[] colorStops) @@ -51,7 +51,7 @@ public override BrushApplicator CreateApplicator( /// private sealed class RadialGradientBrushApplicator : GradientBrushApplicatorBase { - private readonly Point center; + private readonly PointF center; private readonly float radius; @@ -67,7 +67,7 @@ private sealed class RadialGradientBrushApplicator : GradientBrushApplicatorBase public RadialGradientBrushApplicator( ImageFrame target, GraphicsOptions options, - Point center, + PointF center, float radius, ColorStop[] colorStops, GradientRepetitionMode repetitionMode) @@ -89,7 +89,7 @@ public override void Dispose() /// The X coordinate of the target pixel. /// The Y coordinate of the target pixel. /// the position on the color gradient. - protected override float PositionOnGradient(int x, int y) + protected override float PositionOnGradient(float x, float y) { float distance = (float)Math.Sqrt(Math.Pow(this.center.X - x, 2) + Math.Pow(this.center.Y - y, 2)); return distance / this.radius; diff --git a/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs index 0bab2c079b..0f4a98a24a 100644 --- a/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs @@ -275,10 +275,6 @@ public void DiagonalReturnsCorrectImages( int verticalSign = startY == 0 ? 1 : -1; int horizontalSign = startX == 0 ? 1 : -1; - // check first and last pixel, these are known: - Assert.Equal(red, image[startX, startY]); - Assert.Equal(yellow, image[endX, endY]); - for (int i = 0; i < image.Height; i++) { // it's diagonal, so for any (a, a) on the gradient line, for all (a-x, b+x) - +/- depending on the diagonal direction - must be the same color) diff --git a/tests/Images/External b/tests/Images/External index bc2765fb94..94b5a8e11b 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit bc2765fb949d5d4ddba289b29174022bb94646de +Subproject commit 94b5a8e11b33ba62c15d1d03f1b8b721468764f1