Skip to content

Commit a7a1a91

Browse files
committed
Revert color conversion and add test.
1 parent b619066 commit a7a1a91

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

src/ImageSharp.Drawing/Processing/PathGradientBrush.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,7 @@ public PathGradientBrushApplicator(
281281
Vector4 pointColor = ((1 - u - v) * this.edges[0].StartColor) + (u * this.edges[0].EndColor) +
282282
(v * this.edges[2].StartColor);
283283

284-
TPixel px = default;
285-
px.FromVector4(pointColor);
286-
return px;
284+
return new Color(pointColor).ToPixel<TPixel>();
287285
}
288286

289287
var direction = Vector2.Normalize(point - this.center);
@@ -304,9 +302,7 @@ public PathGradientBrushApplicator(
304302

305303
var color = Vector4.Lerp(edgeColor, this.centerColor, ratio);
306304

307-
TPixel pixel = default;
308-
pixel.FromVector4(color);
309-
return pixel;
305+
return new Color(color).ToPixel<TPixel>();
310306
}
311307
}
312308

tests/ImageSharp.Drawing.Tests/Drawing/FillPathGradientBrushTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,34 @@ public void FillTriangleWithDifferentColors<TPixel>(TestImageProvider<TPixel> pr
5353
});
5454
}
5555

56+
[Theory]
57+
[WithBlankImages(20, 20, PixelTypes.HalfSingle)]
58+
public void FillTriangleWithGreyscale<TPixel>(TestImageProvider<TPixel> provider)
59+
where TPixel : unmanaged, IPixel<TPixel>
60+
{
61+
provider.VerifyOperation(
62+
TolerantComparer,
63+
image =>
64+
{
65+
PointF[] points = { new PointF(10, 0), new PointF(20, 20), new PointF(0, 20) };
66+
67+
var c1 = new Rgba32();
68+
var c2 = new Rgba32();
69+
var c3 = new Rgba32();
70+
new HalfSingle(-1).ToRgba32(ref c1);
71+
new HalfSingle(0).ToRgba32(ref c2);
72+
new HalfSingle(1).ToRgba32(ref c3);
73+
74+
Color[] colors = { new Color(c1), new Color(c2), new Color(c3) };
75+
76+
var brush = new PathGradientBrush(points, colors);
77+
78+
image.Mutate(x => x.Fill(brush));
79+
image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
80+
});
81+
}
82+
83+
5684
[Theory]
5785
[WithBlankImages(20, 20, PixelTypes.Rgba32)]
5886
public void FillTriangleWithDifferentColorsCenter<TPixel>(TestImageProvider<TPixel> provider)
424 Bytes
Loading
424 Bytes
Loading

0 commit comments

Comments
 (0)