Skip to content

Commit 2734a14

Browse files
Builds and tests pass
1 parent 689c9c4 commit 2734a14

32 files changed

+1095
-525
lines changed

tests/ImageSharp.Drawing.Tests/ConfigurationTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Six Labors Split License.
33

44
using Moq;
5+
using SixLabors.ImageSharp.Formats;
56
using SixLabors.ImageSharp.Formats.Bmp;
67
using SixLabors.ImageSharp.IO;
78

@@ -84,7 +85,7 @@ public void MaxDegreeOfParallelism_CompatibleWith_ParallelOptions(int maxDegreeO
8485
[Fact]
8586
public void ConstructorCallConfigureOnFormatProvider()
8687
{
87-
var provider = new Mock<IConfigurationModule>();
88+
var provider = new Mock<IImageFormatConfigurationModule>();
8889
var config = new Configuration(provider.Object);
8990

9091
provider.Verify(x => x.Configure(config));
@@ -93,7 +94,7 @@ public void ConstructorCallConfigureOnFormatProvider()
9394
[Fact]
9495
public void AddFormatCallsConfig()
9596
{
96-
var provider = new Mock<IConfigurationModule>();
97+
var provider = new Mock<IImageFormatConfigurationModule>();
9798
var config = new Configuration();
9899
config.Configure(provider.Object);
99100

tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawTextOnImageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ public void PathAndTextDrawingMatch<TPixel>(TestImageProvider<TPixel> provider)
761761
};
762762

763763
FontRectangle bounds = TextMeasurer.MeasureBounds(text, to);
764-
float x = (img.Size().Width - bounds.Width) / 2;
764+
float x = (img.Size.Width - bounds.Width) / 2;
765765
PointF[] pathLine = new[]
766766
{
767767
new PointF(x, 500),

tests/ImageSharp.Drawing.Tests/Processing/BaseImageOperationsExtensionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class BaseImageOperationsExtensionTest
1717
protected readonly ShapeOptions shapeOptions;
1818
private readonly Image<Rgba32> source;
1919

20-
public Rectangle SourceBounds() => this.source.Bounds();
20+
public Rectangle SourceBounds() => this.source.Bounds;
2121

2222
public BaseImageOperationsExtensionTest()
2323
{

tests/ImageSharp.Drawing.Tests/Processing/FakeImageOperationsProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public FakeImageOperations(Configuration configuration, Image<TPixel> source, bo
5151

5252
public Image<TPixel> GetResultImage() => this.Source;
5353

54-
public Size GetCurrentSize() => this.Source.Size();
54+
public Size GetCurrentSize() => this.Source.Size;
5555

5656
public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle)
5757
{

tests/ImageSharp.Drawing.Tests/Shapes/ArcLineSegmentTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public class ArcLineSegmentTest
88
[Fact]
99
public void ContainsStartAndEnd()
1010
{
11-
var segment = new ArcLineSegment(new(10, 10), new(10, 20), 0, 0, 90);
11+
ArcLineSegment segment = new(new(10, 10), new(10, 20), 0, 0, 90);
1212
ReadOnlySpan<PointF> points = segment.Flatten().Span;
13-
Assert.Equal(20, points[0].X, 5);
14-
Assert.Equal(10, points[0].Y, 5);
15-
Assert.Equal(10, segment.EndPoint.X, 5);
16-
Assert.Equal(30, segment.EndPoint.Y, 5);
13+
Assert.Equal(20, points[0].X, 5F);
14+
Assert.Equal(10, points[0].Y, 5F);
15+
Assert.Equal(10, segment.EndPoint.X, 5F);
16+
Assert.Equal(30, segment.EndPoint.Y, 5F);
1717
}
1818

1919
[Fact]

tests/ImageSharp.Drawing.Tests/Shapes/InternalPathTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public void PointOnPath(float distance, float expectedX, float expectedY, float
9595
{
9696
InternalPath shape = Create(new PointF(50, 50), new Size(200, 60));
9797
SegmentInfo point = shape.PointAlongPath(distance);
98-
Assert.Equal(expectedX, point.Point.X, 4);
99-
Assert.Equal(expectedY, point.Point.Y, 4);
100-
Assert.Equal(expectedAngle, point.Angle, 4);
98+
Assert.Equal(expectedX, point.Point.X, 4F);
99+
Assert.Equal(expectedY, point.Point.Y, 4F);
100+
Assert.Equal(expectedAngle, point.Angle, 4F);
101101
}
102102
}

tests/ImageSharp.Drawing.Tests/Shapes/RegularPolygonTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public void GeneratesCorrectPath()
7171
}
7272

7373
float actual = Vector2.Distance(points[i], points[j]);
74-
Assert.Equal(baseline, actual, 3);
75-
Assert.Equal(Radius, Vector2.Distance(Vector2.Zero, points[i]), 3);
74+
Assert.Equal(baseline, actual, 3F);
75+
Assert.Equal(Radius, Vector2.Distance(Vector2.Zero, points[i]), 3F);
7676
}
7777
}
7878

tests/ImageSharp.Drawing.Tests/Shapes/StarTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ public void GeneratesCorrectPath()
7575
}
7676

7777
float actual = Vector2.Distance(points[i], points[j]);
78-
Assert.Equal(baseline, actual, 3);
78+
Assert.Equal(baseline, actual, 3F);
7979
if (i % 2 == 1)
8080
{
81-
Assert.Equal(Radius, Vector2.Distance(Vector2.Zero, points[i]), 3);
81+
Assert.Equal(Radius, Vector2.Distance(Vector2.Zero, points[i]), 3F);
8282
}
8383
else
8484
{
85-
Assert.Equal(Radius2, Vector2.Distance(Vector2.Zero, points[i]), 3);
85+
Assert.Equal(Radius2, Vector2.Distance(Vector2.Zero, points[i]), 3F);
8686
}
8787
}
8888
}

tests/ImageSharp.Drawing.Tests/TestFile.cs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Six Labors Split License.
33

44
using System.Collections.Concurrent;
5-
using SixLabors.ImageSharp.Advanced;
65
using SixLabors.ImageSharp.Formats;
76
using SixLabors.ImageSharp.PixelFormats;
87
using IOPath = System.IO.Path;
@@ -12,23 +11,18 @@ namespace SixLabors.ImageSharp.Drawing.Tests;
1211
/// <summary>
1312
/// A test image file.
1413
/// </summary>
15-
public class TestFile
14+
public sealed class TestFile
1615
{
1716
/// <summary>
1817
/// The test file cache.
1918
/// </summary>
20-
private static readonly ConcurrentDictionary<string, TestFile> Cache = new ConcurrentDictionary<string, TestFile>();
19+
private static readonly ConcurrentDictionary<string, TestFile> Cache = new();
2120

2221
/// <summary>
2322
/// The "Formats" directory, as lazy value
2423
/// </summary>
2524
// ReSharper disable once InconsistentNaming
26-
private static readonly Lazy<string> LazyInputImagesDirectory = new Lazy<string>(() => TestEnvironment.InputImagesDirectoryFullPath);
27-
28-
/// <summary>
29-
/// The image (lazy initialized value)
30-
/// </summary>
31-
private Image<Rgba32> image;
25+
private static readonly Lazy<string> InputImagesDirectoryValue = new(() => TestEnvironment.InputImagesDirectoryFullPath);
3226

3327
/// <summary>
3428
/// The image bytes
@@ -39,8 +33,7 @@ public class TestFile
3933
/// Initializes a new instance of the <see cref="TestFile"/> class.
4034
/// </summary>
4135
/// <param name="file">The file.</param>
42-
private TestFile(string file)
43-
=> this.FullPath = file;
36+
private TestFile(string file) => this.FullPath = file;
4437

4538
/// <summary>
4639
/// Gets the image bytes.
@@ -62,20 +55,17 @@ private TestFile(string file)
6255
/// </summary>
6356
public string FileNameWithoutExtension => IOPath.GetFileNameWithoutExtension(this.FullPath);
6457

65-
/// <summary>
66-
/// Gets the image with lazy initialization.
67-
/// </summary>
68-
private Image<Rgba32> Image => this.image ??= ImageSharp.Image.Load<Rgba32>(this.Bytes);
69-
7058
/// <summary>
7159
/// Gets the input image directory.
7260
/// </summary>
73-
private static string InputImagesDirectory => LazyInputImagesDirectory.Value;
61+
private static string InputImagesDirectory => InputImagesDirectoryValue.Value;
7462

7563
/// <summary>
7664
/// Gets the full qualified path to the input test file.
7765
/// </summary>
78-
/// <param name="file">The file path.</param>
66+
/// <param name="file">
67+
/// The file path.
68+
/// </param>
7969
/// <returns>
8070
/// The <see cref="string"/>.
8171
/// </returns>
@@ -90,7 +80,7 @@ public static string GetInputFileFullPath(string file)
9080
/// The <see cref="TestFile"/>.
9181
/// </returns>
9282
public static TestFile Create(string file)
93-
=> Cache.GetOrAdd(file, (string fileName) => new TestFile(GetInputFileFullPath(file)));
83+
=> Cache.GetOrAdd(file, (string fileName) => new TestFile(GetInputFileFullPath(fileName)));
9484

9585
/// <summary>
9686
/// Gets the file name.
@@ -113,19 +103,34 @@ public string GetFileNameWithoutExtension(object value)
113103
=> this.FileNameWithoutExtension + "-" + value;
114104

115105
/// <summary>
116-
/// Creates a new image.
106+
/// Creates a new <see cref="Rgba32"/> image.
117107
/// </summary>
118108
/// <returns>
119-
/// The <see cref="ImageSharp.Image"/>.
109+
/// The <see cref="Image{Rgba32}"/>.
120110
/// </returns>
121-
public Image<Rgba32> CreateRgba32Image() => this.Image.Clone();
111+
public Image<Rgba32> CreateRgba32Image() => Image.Load<Rgba32>(this.Bytes);
122112

123113
/// <summary>
124-
/// Creates a new image.
114+
/// Creates a new <see cref="Rgba32"/> image.
125115
/// </summary>
116+
/// <param name="decoder">The image decoder.</param>
126117
/// <returns>
127-
/// The <see cref="ImageSharp.Image"/>.
118+
/// The <see cref="Image{Rgba32}"/>.
128119
/// </returns>
129120
public Image<Rgba32> CreateRgba32Image(IImageDecoder decoder)
130-
=> ImageSharp.Image.Load<Rgba32>(this.Image.GetConfiguration(), this.Bytes, decoder);
121+
=> this.CreateRgba32Image(decoder, new());
122+
123+
/// <summary>
124+
/// Creates a new <see cref="Rgba32"/> image.
125+
/// </summary>
126+
/// <param name="decoder">The image decoder.</param>
127+
/// <param name="options">The general decoder options.</param>
128+
/// <returns>
129+
/// The <see cref="Image{Rgba32}"/>.
130+
/// </returns>
131+
public Image<Rgba32> CreateRgba32Image(IImageDecoder decoder, DecoderOptions options)
132+
{
133+
using MemoryStream stream = new(this.Bytes);
134+
return decoder.Decode<Rgba32>(options, stream);
135+
}
131136
}

0 commit comments

Comments
 (0)