Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace SixLabors.ImageSharp.Processing
public sealed class EllipticGradientBrush<TPixel> : GradientBrushBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private readonly Point center;
private readonly PointF center;

private readonly Point referenceAxisEnd;
private readonly PointF referenceAxisEnd;

private readonly float axisRatio;

Expand All @@ -35,8 +35,8 @@ public sealed class EllipticGradientBrush<TPixel> : GradientBrushBase<TPixel>
/// <param name="repetitionMode">Defines how the colors of the gradients are repeated.</param>
/// <param name="colorStops">the color stops as defined in base class.</param>
public EllipticGradientBrush(
Point center,
Point referenceAxisEnd,
PointF center,
PointF referenceAxisEnd,
float axisRatio,
GradientRepetitionMode repetitionMode,
params ColorStop<TPixel>[] colorStops)
Expand Down Expand Up @@ -64,9 +64,9 @@ public override BrushApplicator<TPixel> CreateApplicator(
/// <inheritdoc />
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;

Expand Down Expand Up @@ -99,8 +99,8 @@ private sealed class RadialGradientBrushApplicator : GradientBrushApplicatorBase
public RadialGradientBrushApplicator(
ImageFrame<TPixel> target,
GraphicsOptions options,
Point center,
Point referenceAxisEnd,
PointF center,
PointF referenceAxisEnd,
float axisRatio,
ColorStop<TPixel>[] colorStops,
GradientRepetitionMode repetitionMode)
Expand Down Expand Up @@ -129,7 +129,7 @@ public override void Dispose()
}

/// <inheritdoc />
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;
Expand Down
12 changes: 6 additions & 6 deletions src/ImageSharp.Drawing/Processing/GradientBrushBase{TPixel}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -137,18 +137,18 @@ protected GradientBrushApplicatorBase(
}

/// <summary>
/// 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.
/// </summary>
/// <param name="x">The x coordinate of the pixel</param>
/// <param name="y">The y coordinate of the pixel</param>
/// <param name="x">The x coordinate of the point</param>
/// <param name="y">The y coordinate of the point</param>
/// <returns>
/// 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 <see cref="GradientRepetitionMode" /> enum.
/// </returns>
protected abstract float PositionOnGradient(int x, int y);
protected abstract float PositionOnGradient(float x, float y);

private (ColorStop<TPixel> from, ColorStop<TPixel> to) GetGradientSegment(
float positionOnCompleteGradient)
Expand Down
22 changes: 11 additions & 11 deletions src/ImageSharp.Drawing/Processing/LinearGradientBrush{TPixel}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace SixLabors.ImageSharp.Processing
public sealed class LinearGradientBrush<TPixel> : GradientBrushBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private readonly Point p1;
private readonly PointF p1;

private readonly Point p2;
private readonly PointF p2;

/// <summary>
/// Initializes a new instance of the <see cref="LinearGradientBrush{TPixel}"/> class.
Expand All @@ -29,8 +29,8 @@ public sealed class LinearGradientBrush<TPixel> : GradientBrushBase<TPixel>
/// <param name="repetitionMode">defines how colors are repeated.</param>
/// <param name="colorStops"><inheritdoc /></param>
public LinearGradientBrush(
Point p1,
Point p2,
PointF p1,
PointF p2,
GradientRepetitionMode repetitionMode,
params ColorStop<TPixel>[] colorStops)
: base(repetitionMode, colorStops)
Expand All @@ -48,9 +48,9 @@ public override BrushApplicator<TPixel> CreateApplicator(ImageFrame<TPixel> sour
/// </summary>
private sealed class LinearGradientBrushApplicator : GradientBrushApplicatorBase
{
private readonly Point start;
private readonly PointF start;

private readonly Point end;
private readonly PointF end;

/// <summary>
/// the vector along the gradient, x component
Expand Down Expand Up @@ -93,8 +93,8 @@ private sealed class LinearGradientBrushApplicator : GradientBrushApplicatorBase
/// <param name="options">the graphics options</param>
public LinearGradientBrushApplicator(
ImageFrame<TPixel> source,
Point start,
Point end,
PointF start,
PointF end,
ColorStop<TPixel>[] colorStops,
GradientRepetitionMode repetitionMode,
GraphicsOptions options)
Expand All @@ -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
{
Expand Down
10 changes: 5 additions & 5 deletions src/ImageSharp.Drawing/Processing/RadialGradientBrush{TPixel}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Processing
public sealed class RadialGradientBrush<TPixel> : GradientBrushBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private readonly Point center;
private readonly PointF center;

private readonly float radius;

Expand All @@ -25,7 +25,7 @@ public sealed class RadialGradientBrush<TPixel> : GradientBrushBase<TPixel>
/// <param name="repetitionMode">Defines how the colors in the gradient are repeated.</param>
/// <param name="colorStops">the color stops as defined in base class.</param>
public RadialGradientBrush(
Point center,
PointF center,
float radius,
GradientRepetitionMode repetitionMode,
params ColorStop<TPixel>[] colorStops)
Expand All @@ -51,7 +51,7 @@ public override BrushApplicator<TPixel> CreateApplicator(
/// <inheritdoc />
private sealed class RadialGradientBrushApplicator : GradientBrushApplicatorBase
{
private readonly Point center;
private readonly PointF center;

private readonly float radius;

Expand All @@ -67,7 +67,7 @@ private sealed class RadialGradientBrushApplicator : GradientBrushApplicatorBase
public RadialGradientBrushApplicator(
ImageFrame<TPixel> target,
GraphicsOptions options,
Point center,
PointF center,
float radius,
ColorStop<TPixel>[] colorStops,
GradientRepetitionMode repetitionMode)
Expand All @@ -89,7 +89,7 @@ public override void Dispose()
/// <param name="x">The X coordinate of the target pixel.</param>
/// <param name="y">The Y coordinate of the target pixel.</param>
/// <returns>the position on the color gradient.</returns>
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,6 @@ public void DiagonalReturnsCorrectImages<TPixel>(
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)
Expand Down
2 changes: 1 addition & 1 deletion tests/Images/External
Submodule External updated 49 files
+ ...tput/Drawing/GradientBrushes/FillEllipticGradientBrushTests/AxisParallelEllipsesWithDifferentRatio_0.10.png
+ ...tput/Drawing/GradientBrushes/FillEllipticGradientBrushTests/AxisParallelEllipsesWithDifferentRatio_0.40.png
+ ...tput/Drawing/GradientBrushes/FillEllipticGradientBrushTests/AxisParallelEllipsesWithDifferentRatio_0.80.png
+ ...tput/Drawing/GradientBrushes/FillEllipticGradientBrushTests/AxisParallelEllipsesWithDifferentRatio_1.00.png
+ ...tput/Drawing/GradientBrushes/FillEllipticGradientBrushTests/AxisParallelEllipsesWithDifferentRatio_1.20.png
+ ...tput/Drawing/GradientBrushes/FillEllipticGradientBrushTests/AxisParallelEllipsesWithDifferentRatio_1.60.png
+ ...tput/Drawing/GradientBrushes/FillEllipticGradientBrushTests/AxisParallelEllipsesWithDifferentRatio_2.00.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.10_AT_00deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.10_AT_30deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.10_AT_45deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.10_AT_90deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.40_AT_00deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.40_AT_30deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.40_AT_45deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.40_AT_90deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.80_AT_00deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.80_AT_30deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.80_AT_45deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_0.80_AT_90deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_1.00_AT_00deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_1.00_AT_30deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_1.00_AT_45deg.png
+ .../Drawing/GradientBrushes/FillEllipticGradientBrushTests/RotatedEllipsesWithDifferentRatio_1.00_AT_90deg.png
+ ...tBrushTests/ArbitraryGradients_(0,0)_TO_(499,499)__[000080FF@0;[email protected];[email protected];[email protected];].png
+ ...llLinearGradientBrushTests/ArbitraryGradients_(0,0)_TO_(499,499)__[000080FF@0;[email protected];FF0000FF@1;].png
+ ...tBrushTests/ArbitraryGradients_(0,499)_TO_(499,0)__[000080FF@0;[email protected];[email protected];[email protected];].png
+ ...tBrushTests/ArbitraryGradients_(499,499)_TO_(0,0)__[000080FF@0;[email protected];[email protected];[email protected];].png
+ ...enceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/DiagonalReturnsCorrectImages_BottomLeft.png
+ ...nceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/DiagonalReturnsCorrectImages_BottomRight.png
+ ReferenceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/DiagonalReturnsCorrectImages_TopLeft.png
+ ReferenceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/DiagonalReturnsCorrectImages_TopRight.png
+ ReferenceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/DoesNotDependOnSinglePixelType_Argb32.png
+ ReferenceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/DoesNotDependOnSinglePixelType_Rgb24.png
+ ReferenceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/DoesNotDependOnSinglePixelType_Rgba32.png
+ ...renceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/HorizontalGradientWithRepMode_DontFill.png
+ ReferenceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/HorizontalGradientWithRepMode_None.png
+ ReferenceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/HorizontalGradientWithRepMode_Reflect.png
+ ReferenceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/HorizontalGradientWithRepMode_Repeat.png
+ ReferenceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/HorizontalReturnsUnicolorColumns.png
+ ...plePointGradients_(0,0)_TO_(199,199)__[000000FF@0;[email protected];[email protected];[email protected];00FF00FF@1;].png
+ ReferenceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/VerticalBrushReturnsUnicolorRows.png
+ .../Drawing/GradientBrushes/FillLinearGradientBrushTests/WithDoubledStopsProduceDashedPatterns_0.1_0.3_0.6.png
+ ...wing/GradientBrushes/FillLinearGradientBrushTests/WithDoubledStopsProduceDashedPatterns_0.2_0.4_0.6_0.8.png
+ ...ceOutput/Drawing/GradientBrushes/FillLinearGradientBrushTests/WithDoubledStopsProduceDashedPatterns_0.5.png
+ ...t/Drawing/GradientBrushes/FillRadialGradientBrushTests/WithDifferentCentersReturnsImage_center(-40,100).png
+ ...utput/Drawing/GradientBrushes/FillRadialGradientBrushTests/WithDifferentCentersReturnsImage_center(0,0).png
+ ...put/Drawing/GradientBrushes/FillRadialGradientBrushTests/WithDifferentCentersReturnsImage_center(0,100).png
+ ...put/Drawing/GradientBrushes/FillRadialGradientBrushTests/WithDifferentCentersReturnsImage_center(100,0).png
+ ...t/Drawing/GradientBrushes/FillRadialGradientBrushTests/WithDifferentCentersReturnsImage_center(100,100).png