|
|
@ -5,11 +5,9 @@ |
|
|
|
|
|
|
|
|
namespace ImageSharp.Tests.Drawing |
|
|
namespace ImageSharp.Tests.Drawing |
|
|
{ |
|
|
{ |
|
|
using Drawing; |
|
|
|
|
|
using ImageSharp.Drawing; |
|
|
using ImageSharp.Drawing; |
|
|
using ImageSharp.Drawing.Pens; |
|
|
using ImageSharp.Drawing.Pens; |
|
|
using System; |
|
|
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
|
|
|
using System.IO; |
|
|
using System.IO; |
|
|
using System.Numerics; |
|
|
using System.Numerics; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
@ -19,14 +17,15 @@ namespace ImageSharp.Tests.Drawing |
|
|
[Fact] |
|
|
[Fact] |
|
|
public void ImageShouldBeOverlayedByPath() |
|
|
public void ImageShouldBeOverlayedByPath() |
|
|
{ |
|
|
{ |
|
|
string path = CreateOutputDirectory("Drawing", "Lines"); |
|
|
string path = this.CreateOutputDirectory("Drawing", "Lines"); |
|
|
var image = new Image(500, 500); |
|
|
using (Image image = new Image(500, 500)) |
|
|
|
|
|
{ |
|
|
using (FileStream output = File.OpenWrite($"{path}/Simple.png")) |
|
|
using (FileStream output = File.OpenWrite($"{path}/Simple.png")) |
|
|
{ |
|
|
{ |
|
|
image |
|
|
image |
|
|
.BackgroundColor(Color.Blue) |
|
|
.BackgroundColor(Color.Blue) |
|
|
.DrawLines(Color.HotPink, 5, new[] { |
|
|
.DrawLines(Color.HotPink, 5, |
|
|
|
|
|
new[] { |
|
|
new Vector2(10, 10), |
|
|
new Vector2(10, 10), |
|
|
new Vector2(200, 150), |
|
|
new Vector2(200, 150), |
|
|
new Vector2(50, 300) |
|
|
new Vector2(50, 300) |
|
|
@ -34,7 +33,7 @@ namespace ImageSharp.Tests.Drawing |
|
|
.Save(output); |
|
|
.Save(output); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
using (var sourcePixels = image.Lock()) |
|
|
using (PixelAccessor<Color> sourcePixels = image.Lock()) |
|
|
{ |
|
|
{ |
|
|
Assert.Equal(Color.HotPink, sourcePixels[9, 9]); |
|
|
Assert.Equal(Color.HotPink, sourcePixels[9, 9]); |
|
|
|
|
|
|
|
|
@ -43,26 +42,29 @@ namespace ImageSharp.Tests.Drawing |
|
|
Assert.Equal(Color.Blue, sourcePixels[50, 50]); |
|
|
Assert.Equal(Color.Blue, sourcePixels[50, 50]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void ImageShouldBeOverlayedByPath_NoAntialias() |
|
|
public void ImageShouldBeOverlayedByPath_NoAntialias() |
|
|
{ |
|
|
{ |
|
|
string path = CreateOutputDirectory("Drawing", "Lines"); |
|
|
string path = this.CreateOutputDirectory("Drawing", "Lines"); |
|
|
var image = new Image(500, 500); |
|
|
using (Image image = new Image(500, 500)) |
|
|
|
|
|
{ |
|
|
using (FileStream output = File.OpenWrite($"{path}/Simple_noantialias.png")) |
|
|
using (FileStream output = File.OpenWrite($"{path}/Simple_noantialias.png")) |
|
|
{ |
|
|
{ |
|
|
image |
|
|
image |
|
|
.BackgroundColor(Color.Blue) |
|
|
.BackgroundColor(Color.Blue) |
|
|
.DrawLines(Color.HotPink, 5, new[] { |
|
|
.DrawLines(Color.HotPink, 5, |
|
|
|
|
|
new[] { |
|
|
new Vector2(10, 10), |
|
|
new Vector2(10, 10), |
|
|
new Vector2(200, 150), |
|
|
new Vector2(200, 150), |
|
|
new Vector2(50, 300) |
|
|
new Vector2(50, 300) |
|
|
}, new GraphicsOptions(false)) |
|
|
}, |
|
|
|
|
|
new GraphicsOptions(false)) |
|
|
.Save(output); |
|
|
.Save(output); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
using (var sourcePixels = image.Lock()) |
|
|
using (PixelAccessor<Color> sourcePixels = image.Lock()) |
|
|
{ |
|
|
{ |
|
|
Assert.Equal(Color.HotPink, sourcePixels[9, 9]); |
|
|
Assert.Equal(Color.HotPink, sourcePixels[9, 9]); |
|
|
|
|
|
|
|
|
@ -71,38 +73,41 @@ namespace ImageSharp.Tests.Drawing |
|
|
Assert.Equal(Color.Blue, sourcePixels[50, 50]); |
|
|
Assert.Equal(Color.Blue, sourcePixels[50, 50]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void ImageShouldBeOverlayedByPathDashed() |
|
|
public void ImageShouldBeOverlayedByPathDashed() |
|
|
{ |
|
|
{ |
|
|
string path = CreateOutputDirectory("Drawing", "Lines"); |
|
|
string path = this.CreateOutputDirectory("Drawing", "Lines"); |
|
|
var image = new Image(500, 500); |
|
|
using (Image image = new Image(500, 500)) |
|
|
|
|
|
{ |
|
|
using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) |
|
|
using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) |
|
|
{ |
|
|
{ |
|
|
image |
|
|
image |
|
|
.BackgroundColor(Color.Blue) |
|
|
.BackgroundColor(Color.Blue) |
|
|
.DrawLines(Pens.Dash(Color.HotPink, 5), new[] { |
|
|
.DrawLines(Pens.Dash(Color.HotPink, 5), |
|
|
|
|
|
new[] { |
|
|
new Vector2(10, 10), |
|
|
new Vector2(10, 10), |
|
|
new Vector2(200, 150), |
|
|
new Vector2(200, 150), |
|
|
new Vector2(50, 300) |
|
|
new Vector2(50, 300) |
|
|
}) |
|
|
}) |
|
|
.Save(output); |
|
|
.Save(output); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void ImageShouldBeOverlayedByPathDotted() |
|
|
public void ImageShouldBeOverlayedByPathDotted() |
|
|
{ |
|
|
{ |
|
|
string path = CreateOutputDirectory("Drawing", "Lines"); |
|
|
string path = this.CreateOutputDirectory("Drawing", "Lines"); |
|
|
var image = new Image(500, 500); |
|
|
using (Image image = new Image(500, 500)) |
|
|
|
|
|
{ |
|
|
using (FileStream output = File.OpenWrite($"{path}/Dot.png")) |
|
|
using (FileStream output = File.OpenWrite($"{path}/Dot.png")) |
|
|
{ |
|
|
{ |
|
|
image |
|
|
image |
|
|
.BackgroundColor(Color.Blue) |
|
|
.BackgroundColor(Color.Blue) |
|
|
.DrawLines(Pens.Dot(Color.HotPink, 5), new[] { |
|
|
.DrawLines(Pens.Dot(Color.HotPink, 5), |
|
|
|
|
|
new[] { |
|
|
new Vector2(10, 10), |
|
|
new Vector2(10, 10), |
|
|
new Vector2(200, 150), |
|
|
new Vector2(200, 150), |
|
|
new Vector2(50, 300) |
|
|
new Vector2(50, 300) |
|
|
@ -110,32 +115,34 @@ namespace ImageSharp.Tests.Drawing |
|
|
.Save(output); |
|
|
.Save(output); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void ImageShouldBeOverlayedByPathDashDot() |
|
|
public void ImageShouldBeOverlayedByPathDashDot() |
|
|
{ |
|
|
{ |
|
|
string path = CreateOutputDirectory("Drawing", "Lines"); |
|
|
string path = this.CreateOutputDirectory("Drawing", "Lines"); |
|
|
var image = new Image(500, 500); |
|
|
using (Image image = new Image(500, 500)) |
|
|
|
|
|
{ |
|
|
using (FileStream output = File.OpenWrite($"{path}/DashDot.png")) |
|
|
using (FileStream output = File.OpenWrite($"{path}/DashDot.png")) |
|
|
{ |
|
|
{ |
|
|
image |
|
|
image |
|
|
.BackgroundColor(Color.Blue) |
|
|
.BackgroundColor(Color.Blue) |
|
|
.DrawLines(Pens.DashDot(Color.HotPink, 5), new[] { |
|
|
.DrawLines(Pens.DashDot(Color.HotPink, 5), |
|
|
|
|
|
new[] { |
|
|
new Vector2(10, 10), |
|
|
new Vector2(10, 10), |
|
|
new Vector2(200, 150), |
|
|
new Vector2(200, 150), |
|
|
new Vector2(50, 300) |
|
|
new Vector2(50, 300) |
|
|
}) |
|
|
}) |
|
|
.Save(output); |
|
|
.Save(output); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void ImageShouldBeOverlayedByPathDashDotDot() |
|
|
public void ImageShouldBeOverlayedByPathDashDotDot() |
|
|
{ |
|
|
{ |
|
|
string path = CreateOutputDirectory("Drawing", "Lines"); |
|
|
string path = this.CreateOutputDirectory("Drawing", "Lines"); |
|
|
var image = new Image(500, 500); |
|
|
Image image = new Image(500, 500); |
|
|
|
|
|
|
|
|
using (FileStream output = File.OpenWrite($"{path}/DashDotDot.png")) |
|
|
using (FileStream output = File.OpenWrite($"{path}/DashDotDot.png")) |
|
|
{ |
|
|
{ |
|
|
@ -153,11 +160,11 @@ namespace ImageSharp.Tests.Drawing |
|
|
[Fact] |
|
|
[Fact] |
|
|
public void ImageShouldBeOverlayedPathWithOpacity() |
|
|
public void ImageShouldBeOverlayedPathWithOpacity() |
|
|
{ |
|
|
{ |
|
|
string path = CreateOutputDirectory("Drawing", "Lines"); |
|
|
string path = this.CreateOutputDirectory("Drawing", "Lines"); |
|
|
|
|
|
|
|
|
var color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); |
|
|
Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); |
|
|
|
|
|
|
|
|
var image = new Image(500, 500); |
|
|
Image image = new Image(500, 500); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) |
|
|
using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) |
|
|
@ -173,9 +180,9 @@ namespace ImageSharp.Tests.Drawing |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//shift background color towards forground color by the opacity amount
|
|
|
//shift background color towards forground color by the opacity amount
|
|
|
var mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f/255f)); |
|
|
Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f/255f)); |
|
|
|
|
|
|
|
|
using (var sourcePixels = image.Lock()) |
|
|
using (PixelAccessor<Color> sourcePixels = image.Lock()) |
|
|
{ |
|
|
{ |
|
|
Assert.Equal(mergedColor, sourcePixels[9, 9]); |
|
|
Assert.Equal(mergedColor, sourcePixels[9, 9]); |
|
|
|
|
|
|
|
|
@ -188,9 +195,9 @@ namespace ImageSharp.Tests.Drawing |
|
|
[Fact] |
|
|
[Fact] |
|
|
public void ImageShouldBeOverlayedByPathOutline() |
|
|
public void ImageShouldBeOverlayedByPathOutline() |
|
|
{ |
|
|
{ |
|
|
string path = CreateOutputDirectory("Drawing", "Lines"); |
|
|
string path = this.CreateOutputDirectory("Drawing", "Lines"); |
|
|
|
|
|
|
|
|
var image = new Image(500, 500); |
|
|
Image image = new Image(500, 500); |
|
|
|
|
|
|
|
|
using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) |
|
|
using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) |
|
|
{ |
|
|
{ |
|
|
@ -205,7 +212,7 @@ namespace ImageSharp.Tests.Drawing |
|
|
.Save(output); |
|
|
.Save(output); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
using (var sourcePixels = image.Lock()) |
|
|
using (PixelAccessor<Color> sourcePixels = image.Lock()) |
|
|
{ |
|
|
{ |
|
|
Assert.Equal(Color.HotPink, sourcePixels[8, 8]); |
|
|
Assert.Equal(Color.HotPink, sourcePixels[8, 8]); |
|
|
|
|
|
|
|
|
|