|
|
|
@ -5,12 +5,9 @@ |
|
|
|
|
|
|
|
namespace ImageSharp.Tests.Drawing |
|
|
|
{ |
|
|
|
using System; |
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
|
using System.IO; |
|
|
|
using Xunit; |
|
|
|
using Drawing; |
|
|
|
using ImageSharp.Drawing; |
|
|
|
|
|
|
|
using System.Numerics; |
|
|
|
using ImageSharp.Drawing.Shapes; |
|
|
|
using ImageSharp.Drawing.Pens; |
|
|
|
@ -20,98 +17,100 @@ namespace ImageSharp.Tests.Drawing |
|
|
|
[Fact] |
|
|
|
public void ImageShouldBeOverlayedByPolygonOutline() |
|
|
|
{ |
|
|
|
string path = CreateOutputDirectory("Drawing", "LineComplexPolygon"); |
|
|
|
var simplePath = new LinearPolygon( |
|
|
|
string path = this.CreateOutputDirectory("Drawing", "LineComplexPolygon"); |
|
|
|
LinearPolygon simplePath = new LinearPolygon( |
|
|
|
new Vector2(10, 10), |
|
|
|
new Vector2(200, 150), |
|
|
|
new Vector2(50, 300)); |
|
|
|
|
|
|
|
var hole1 = new LinearPolygon( |
|
|
|
LinearPolygon hole1 = new LinearPolygon( |
|
|
|
new Vector2(37, 85), |
|
|
|
new Vector2(93, 85), |
|
|
|
new Vector2(65, 137)); |
|
|
|
|
|
|
|
var image = new Image(500, 500); |
|
|
|
|
|
|
|
using (FileStream output = File.OpenWrite($"{path}/Simple.png")) |
|
|
|
using (Image image = new Image(500, 500)) |
|
|
|
{ |
|
|
|
image |
|
|
|
.BackgroundColor(Color.Blue) |
|
|
|
.DrawPolygon(Color.HotPink, 5, new ComplexPolygon(simplePath, hole1)) |
|
|
|
.Save(output); |
|
|
|
} |
|
|
|
using (FileStream output = File.OpenWrite($"{path}/Simple.png")) |
|
|
|
{ |
|
|
|
image |
|
|
|
.BackgroundColor(Color.Blue) |
|
|
|
.DrawPolygon(Color.HotPink, 5, new ComplexPolygon(simplePath, hole1)) |
|
|
|
.Save(output); |
|
|
|
} |
|
|
|
|
|
|
|
using (var sourcePixels = image.Lock()) |
|
|
|
{ |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[10, 10]); |
|
|
|
using (PixelAccessor<Color> sourcePixels = image.Lock()) |
|
|
|
{ |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[10, 10]); |
|
|
|
|
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[200, 150]); |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[200, 150]); |
|
|
|
|
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[50, 300]); |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[50, 300]); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[37, 85]); |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[37, 85]); |
|
|
|
|
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[93, 85]); |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[93, 85]); |
|
|
|
|
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[65, 137]); |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[65, 137]); |
|
|
|
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[2, 2]); |
|
|
|
Assert.Equal(Color.Blue, sourcePixels[2, 2]); |
|
|
|
|
|
|
|
//inside hole
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[57, 99]); |
|
|
|
//inside hole
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[57, 99]); |
|
|
|
|
|
|
|
//inside shape
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[100, 192]); |
|
|
|
//inside shape
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[100, 192]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void ImageShouldBeOverlayedByPolygonOutlineNoOverlapping() |
|
|
|
{ |
|
|
|
string path = CreateOutputDirectory("Drawing", "LineComplexPolygon"); |
|
|
|
var simplePath = new LinearPolygon( |
|
|
|
string path = this.CreateOutputDirectory("Drawing", "LineComplexPolygon"); |
|
|
|
LinearPolygon simplePath = new LinearPolygon( |
|
|
|
new Vector2(10, 10), |
|
|
|
new Vector2(200, 150), |
|
|
|
new Vector2(50, 300)); |
|
|
|
|
|
|
|
var hole1 = new LinearPolygon( |
|
|
|
LinearPolygon hole1 = new LinearPolygon( |
|
|
|
new Vector2(207, 25), |
|
|
|
new Vector2(263, 25), |
|
|
|
new Vector2(235, 57)); |
|
|
|
|
|
|
|
var image = new Image(500, 500); |
|
|
|
|
|
|
|
using (FileStream output = File.OpenWrite($"{path}/SimpleVanishHole.png")) |
|
|
|
using (Image image = new Image(500, 500)) |
|
|
|
{ |
|
|
|
image |
|
|
|
.BackgroundColor(Color.Blue) |
|
|
|
.DrawPolygon(Color.HotPink, 5, new ComplexPolygon(simplePath, hole1)) |
|
|
|
.Save(output); |
|
|
|
} |
|
|
|
using (FileStream output = File.OpenWrite($"{path}/SimpleVanishHole.png")) |
|
|
|
{ |
|
|
|
image |
|
|
|
.BackgroundColor(Color.Blue) |
|
|
|
.DrawPolygon(Color.HotPink, 5, new ComplexPolygon(simplePath, hole1)) |
|
|
|
.Save(output); |
|
|
|
} |
|
|
|
|
|
|
|
using (var sourcePixels = image.Lock()) |
|
|
|
{ |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[10, 10]); |
|
|
|
using (PixelAccessor<Color> sourcePixels = image.Lock()) |
|
|
|
{ |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[10, 10]); |
|
|
|
|
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[200, 150]); |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[200, 150]); |
|
|
|
|
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[50, 300]); |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[50, 300]); |
|
|
|
|
|
|
|
|
|
|
|
//Assert.Equal(Color.HotPink, sourcePixels[37, 85]);
|
|
|
|
//Assert.Equal(Color.HotPink, sourcePixels[37, 85]);
|
|
|
|
|
|
|
|
//Assert.Equal(Color.HotPink, sourcePixels[93, 85]);
|
|
|
|
//Assert.Equal(Color.HotPink, sourcePixels[93, 85]);
|
|
|
|
|
|
|
|
//Assert.Equal(Color.HotPink, sourcePixels[65, 137]);
|
|
|
|
//Assert.Equal(Color.HotPink, sourcePixels[65, 137]);
|
|
|
|
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[2, 2]); |
|
|
|
Assert.Equal(Color.Blue, sourcePixels[2, 2]); |
|
|
|
|
|
|
|
//inside hole
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[57, 99]); |
|
|
|
//inside hole
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[57, 99]); |
|
|
|
|
|
|
|
//inside shape
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[100, 192]); |
|
|
|
//inside shape
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[100, 192]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -119,44 +118,45 @@ namespace ImageSharp.Tests.Drawing |
|
|
|
[Fact] |
|
|
|
public void ImageShouldBeOverlayedByPolygonOutlineOverlapping() |
|
|
|
{ |
|
|
|
string path = CreateOutputDirectory("Drawing", "LineComplexPolygon"); |
|
|
|
var simplePath = new LinearPolygon( |
|
|
|
string path = this.CreateOutputDirectory("Drawing", "LineComplexPolygon"); |
|
|
|
LinearPolygon simplePath = new LinearPolygon( |
|
|
|
new Vector2(10, 10), |
|
|
|
new Vector2(200, 150), |
|
|
|
new Vector2(50, 300)); |
|
|
|
|
|
|
|
var hole1 = new LinearPolygon( |
|
|
|
LinearPolygon hole1 = new LinearPolygon( |
|
|
|
new Vector2(37, 85), |
|
|
|
new Vector2(130, 40), |
|
|
|
new Vector2(65, 137)); |
|
|
|
|
|
|
|
var image = new Image(500, 500); |
|
|
|
|
|
|
|
using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png")) |
|
|
|
using (Image image = new Image(500, 500)) |
|
|
|
{ |
|
|
|
image |
|
|
|
.BackgroundColor(Color.Blue) |
|
|
|
.DrawPolygon(Color.HotPink, 5, new ComplexPolygon(simplePath, hole1)) |
|
|
|
.Save(output); |
|
|
|
} |
|
|
|
using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png")) |
|
|
|
{ |
|
|
|
image |
|
|
|
.BackgroundColor(Color.Blue) |
|
|
|
.DrawPolygon(Color.HotPink, 5, new ComplexPolygon(simplePath, hole1)) |
|
|
|
.Save(output); |
|
|
|
} |
|
|
|
|
|
|
|
using (var sourcePixels = image.Lock()) |
|
|
|
{ |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[10, 10]); |
|
|
|
using (PixelAccessor<Color> sourcePixels = image.Lock()) |
|
|
|
{ |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[10, 10]); |
|
|
|
|
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[200, 150]); |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[200, 150]); |
|
|
|
|
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[50, 300]); |
|
|
|
Assert.Equal(Color.HotPink, sourcePixels[50, 300]); |
|
|
|
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[130, 41]); |
|
|
|
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[2, 2]); |
|
|
|
Assert.Equal(Color.Blue, sourcePixels[130, 41]); |
|
|
|
|
|
|
|
//inside hole
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[57, 99]); |
|
|
|
Assert.Equal(Color.Blue, sourcePixels[2, 2]); |
|
|
|
|
|
|
|
//inside shape
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[100, 192]); |
|
|
|
//inside hole
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[57, 99]); |
|
|
|
|
|
|
|
//inside shape
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[100, 192]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -164,25 +164,26 @@ namespace ImageSharp.Tests.Drawing |
|
|
|
[Fact] |
|
|
|
public void ImageShouldBeOverlayedByPolygonOutlineDashed() |
|
|
|
{ |
|
|
|
string path = CreateOutputDirectory("Drawing", "LineComplexPolygon"); |
|
|
|
var simplePath = new LinearPolygon( |
|
|
|
string path = this.CreateOutputDirectory("Drawing", "LineComplexPolygon"); |
|
|
|
LinearPolygon simplePath = new LinearPolygon( |
|
|
|
new Vector2(10, 10), |
|
|
|
new Vector2(200, 150), |
|
|
|
new Vector2(50, 300)); |
|
|
|
|
|
|
|
var hole1 = new LinearPolygon( |
|
|
|
LinearPolygon hole1 = new LinearPolygon( |
|
|
|
new Vector2(37, 85), |
|
|
|
new Vector2(93, 85), |
|
|
|
new Vector2(65, 137)); |
|
|
|
|
|
|
|
var image = new Image(500, 500); |
|
|
|
|
|
|
|
using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) |
|
|
|
using (Image image = new Image(500, 500)) |
|
|
|
{ |
|
|
|
image |
|
|
|
.BackgroundColor(Color.Blue) |
|
|
|
.DrawPolygon(Pens.Dash(Color.HotPink, 5), new ComplexPolygon(simplePath, hole1)) |
|
|
|
.Save(output); |
|
|
|
using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) |
|
|
|
{ |
|
|
|
image |
|
|
|
.BackgroundColor(Color.Blue) |
|
|
|
.DrawPolygon(Pens.Dash(Color.HotPink, 5), new ComplexPolygon(simplePath, hole1)) |
|
|
|
.Save(output); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -190,54 +191,55 @@ namespace ImageSharp.Tests.Drawing |
|
|
|
[Fact] |
|
|
|
public void ImageShouldBeOverlayedPolygonOutlineWithOpacity() |
|
|
|
{ |
|
|
|
string path = CreateOutputDirectory("Drawing", "LineComplexPolygon"); |
|
|
|
var simplePath = new LinearPolygon( |
|
|
|
string path = this.CreateOutputDirectory("Drawing", "LineComplexPolygon"); |
|
|
|
LinearPolygon simplePath = new LinearPolygon( |
|
|
|
new Vector2(10, 10), |
|
|
|
new Vector2(200, 150), |
|
|
|
new Vector2(50, 300)); |
|
|
|
|
|
|
|
var hole1 = new LinearPolygon( |
|
|
|
LinearPolygon hole1 = new LinearPolygon( |
|
|
|
new Vector2(37, 85), |
|
|
|
new Vector2(93, 85), |
|
|
|
new Vector2(65, 137)); |
|
|
|
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); |
|
|
|
|
|
|
|
using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) |
|
|
|
using (Image image = new Image(500, 500)) |
|
|
|
{ |
|
|
|
image |
|
|
|
.BackgroundColor(Color.Blue) |
|
|
|
.DrawPolygon(color, 5, new ComplexPolygon(simplePath, hole1)) |
|
|
|
.Save(output); |
|
|
|
} |
|
|
|
using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) |
|
|
|
{ |
|
|
|
image |
|
|
|
.BackgroundColor(Color.Blue) |
|
|
|
.DrawPolygon(color, 5, new ComplexPolygon(simplePath, hole1)) |
|
|
|
.Save(output); |
|
|
|
} |
|
|
|
|
|
|
|
//shift background color towards forground color by the opacity amount
|
|
|
|
var mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); |
|
|
|
//shift background color towards forground color by the opacity amount
|
|
|
|
Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); |
|
|
|
|
|
|
|
using (var sourcePixels = image.Lock()) |
|
|
|
{ |
|
|
|
Assert.Equal(mergedColor, sourcePixels[10, 10]); |
|
|
|
using (PixelAccessor<Color> sourcePixels = image.Lock()) |
|
|
|
{ |
|
|
|
Assert.Equal(mergedColor, sourcePixels[10, 10]); |
|
|
|
|
|
|
|
Assert.Equal(mergedColor, sourcePixels[200, 150]); |
|
|
|
Assert.Equal(mergedColor, sourcePixels[200, 150]); |
|
|
|
|
|
|
|
Assert.Equal(mergedColor, sourcePixels[50, 300]); |
|
|
|
Assert.Equal(mergedColor, sourcePixels[50, 300]); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(mergedColor, sourcePixels[37, 85]); |
|
|
|
Assert.Equal(mergedColor, sourcePixels[37, 85]); |
|
|
|
|
|
|
|
Assert.Equal(mergedColor, sourcePixels[93, 85]); |
|
|
|
Assert.Equal(mergedColor, sourcePixels[93, 85]); |
|
|
|
|
|
|
|
Assert.Equal(mergedColor, sourcePixels[65, 137]); |
|
|
|
Assert.Equal(mergedColor, sourcePixels[65, 137]); |
|
|
|
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[2, 2]); |
|
|
|
Assert.Equal(Color.Blue, sourcePixels[2, 2]); |
|
|
|
|
|
|
|
//inside hole
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[57, 99]); |
|
|
|
//inside hole
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[57, 99]); |
|
|
|
|
|
|
|
|
|
|
|
//inside shape
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[100, 192]); |
|
|
|
//inside shape
|
|
|
|
Assert.Equal(Color.Blue, sourcePixels[100, 192]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|