From 706a8a33bc0a1fa8085eac73b9d7c9fcadd3b062 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 6 Dec 2023 19:57:22 +1000 Subject: [PATCH] Update refs to latest --- src/Directory.Build.props | 4 ++ .../ImageSharp.Drawing.csproj | 4 +- .../Processing/GradientBrush.cs | 1 + tests/Directory.Build.props | 4 ++ .../ConfigurationTests.cs | 2 +- .../BaseImageOperationsExtensionTest.cs | 2 +- .../Processing/FillPathProcessorTests.cs | 2 +- .../TestFileSystem.cs | 42 ++++++++++--------- .../ImageComparison/ExactImageComparer.cs | 2 +- .../ImageComparison/TolerantImageComparer.cs | 2 +- .../ReferenceCodecs/SystemDrawingBridge.cs | 8 ++-- .../Tests/TestImageProviderTests.cs | 4 +- 12 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 5fb767ff..5ac8f2bf 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -20,6 +20,10 @@ true + + + true + diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj index f760c476..0862593f 100644 --- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj +++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj @@ -45,8 +45,8 @@ - - + + \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Processing/GradientBrush.cs b/src/ImageSharp.Drawing/Processing/GradientBrush.cs index 32e9cadd..4b2364d9 100644 --- a/src/ImageSharp.Drawing/Processing/GradientBrush.cs +++ b/src/ImageSharp.Drawing/Processing/GradientBrush.cs @@ -4,6 +4,7 @@ using System.Numerics; using SixLabors.ImageSharp.Drawing.Utilities; using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Drawing.Processing; diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 17882502..4ffed447 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -16,4 +16,8 @@ + + true + + diff --git a/tests/ImageSharp.Drawing.Tests/ConfigurationTests.cs b/tests/ImageSharp.Drawing.Tests/ConfigurationTests.cs index 0f907bdd..d3fd08ca 100644 --- a/tests/ImageSharp.Drawing.Tests/ConfigurationTests.cs +++ b/tests/ImageSharp.Drawing.Tests/ConfigurationTests.cs @@ -18,7 +18,7 @@ public class ConfigurationTests public Configuration DefaultConfiguration { get; } - private readonly int expectedDefaultConfigurationCount = 8; + private readonly int expectedDefaultConfigurationCount = 9; public ConfigurationTests() { diff --git a/tests/ImageSharp.Drawing.Tests/Processing/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Drawing.Tests/Processing/BaseImageOperationsExtensionTest.cs index ce1514ee..ee1a0ecf 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/BaseImageOperationsExtensionTest.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/BaseImageOperationsExtensionTest.cs @@ -33,7 +33,7 @@ public BaseImageOperationsExtensionTest() this.shapeOptions = new ShapeOptions { IntersectionRule = IntersectionRule.NonZero }; this.source = new Image(91 + 324, 123 + 56); this.rect = new Rectangle(91, 123, 324, 56); // make this random? - this.internalOperations = new FakeImageOperationsProvider.FakeImageOperations(this.source.GetConfiguration(), this.source, false); + this.internalOperations = new FakeImageOperationsProvider.FakeImageOperations(this.source.Configuration, this.source, false); this.internalOperations.SetShapeOptions(this.shapeOptions); this.internalOperations.SetGraphicsOptions(this.graphicsOptions); this.operations = this.internalOperations; diff --git a/tests/ImageSharp.Drawing.Tests/Processing/FillPathProcessorTests.cs b/tests/ImageSharp.Drawing.Tests/Processing/FillPathProcessorTests.cs index 2f038778..832d4adc 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/FillPathProcessorTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/FillPathProcessorTests.cs @@ -33,7 +33,7 @@ public void FillOffCanvas() var options = new GraphicsOptions { Antialias = true }; var processor = new FillPathProcessor(new DrawingOptions() { GraphicsOptions = options }, brush.Object, path); var img = new Image(10, 10); - processor.Execute(img.GetConfiguration(), img, bounds); + processor.Execute(img.Configuration, img, bounds); } [Fact] diff --git a/tests/ImageSharp.Drawing.Tests/TestFileSystem.cs b/tests/ImageSharp.Drawing.Tests/TestFileSystem.cs index 6b1cf888..06138d45 100644 --- a/tests/ImageSharp.Drawing.Tests/TestFileSystem.cs +++ b/tests/ImageSharp.Drawing.Tests/TestFileSystem.cs @@ -8,9 +8,9 @@ namespace SixLabors.ImageSharp.Drawing.Tests; /// public class TestFileSystem : IO.IFileSystem { - private readonly Dictionary fileSystem = new(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary> fileSystem = new(StringComparer.OrdinalIgnoreCase); - public void AddFile(string path, Stream data) + public void AddFile(string path, Func data) { lock (this.fileSystem) { @@ -18,35 +18,39 @@ public void AddFile(string path, Stream data) } } - public Stream Create(string path) + public Stream Create(string path) => this.GetStream(path) ?? File.Create(path); + + public Stream CreateAsynchronous(string path) => this.GetStream(path) ?? File.Open(path, new FileStreamOptions { - // if we have injected a fake file use it instead - lock (this.fileSystem) - { - if (this.fileSystem.ContainsKey(path)) - { - Stream stream = this.fileSystem[path]; - stream.Position = 0; - return stream; - } - } + Mode = FileMode.Create, + Access = FileAccess.ReadWrite, + Share = FileShare.None, + Options = FileOptions.Asynchronous, + }); - return File.Create(path); - } + public Stream OpenRead(string path) => this.GetStream(path) ?? File.OpenRead(path); + + public Stream OpenReadAsynchronous(string path) => this.GetStream(path) ?? File.Open(path, new FileStreamOptions + { + Mode = FileMode.Open, + Access = FileAccess.Read, + Share = FileShare.Read, + Options = FileOptions.Asynchronous, + }); - public Stream OpenRead(string path) + private Stream? GetStream(string path) { // if we have injected a fake file use it instead lock (this.fileSystem) { - if (this.fileSystem.ContainsKey(path)) + if (this.fileSystem.TryGetValue(path, out Func? streamFactory)) { - Stream stream = this.fileSystem[path]; + Stream stream = streamFactory(); stream.Position = 0; return stream; } } - return File.OpenRead(path); + return null; } } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs index 32163233..4b4293f5 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs @@ -28,7 +28,7 @@ public override ImageSimilarityReport CompareImagesOrFrames(); - Configuration configuration = expected.GetConfiguration(); + Configuration configuration = expected.Configuration; Buffer2D expectedBuffer = expected.PixelBuffer; Buffer2D actualBuffer = actual.PixelBuffer; diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs index 70fbcf5a..55690bde 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -70,7 +70,7 @@ public override ImageSimilarityReport CompareImagesOrFrames(); - Configuration configuration = expected.GetConfiguration(); + Configuration configuration = expected.Configuration; Buffer2D expectedBuffer = expected.PixelBuffer; Buffer2D actualBuffer = actual.PixelBuffer; diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index 9b137ff2..8e087f75 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -45,7 +45,7 @@ internal static unsafe Image From32bppArgbSystemDrawingBitmap(Bi long sourceRowByteCount = data.Stride; long destRowByteCount = w * sizeof(Bgra32); - Configuration configuration = image.GetConfiguration(); + Configuration configuration = image.Configuration; image.ProcessPixelRows(accessor => { using IMemoryOwner workBuffer = Configuration.Default.MemoryAllocator.Allocate(w); @@ -104,7 +104,7 @@ internal static unsafe Image From24bppRgbSystemDrawingBitmap(Bit long sourceRowByteCount = data.Stride; long destRowByteCount = w * sizeof(Bgr24); - Configuration configuration = image.GetConfiguration(); + Configuration configuration = image.Configuration; Buffer2D imageBuffer = image.GetRootFramePixelBuffer(); using IMemoryOwner workBuffer = Configuration.Default.MemoryAllocator.Allocate(w); @@ -132,7 +132,7 @@ internal static unsafe Image From24bppRgbSystemDrawingBitmap(Bit internal static unsafe Bitmap To32bppArgbSystemDrawingBitmap(Image image) where TPixel : unmanaged, IPixel { - Configuration configuration = image.GetConfiguration(); + Configuration configuration = image.Configuration; int w = image.Width; int h = image.Height; @@ -147,7 +147,7 @@ internal static unsafe Bitmap To32bppArgbSystemDrawingBitmap(Image { - using IMemoryOwner workBuffer = image.GetConfiguration().MemoryAllocator.Allocate(w); + using IMemoryOwner workBuffer = image.Configuration.MemoryAllocator.Allocate(w); fixed (Bgra32* sourcePtr = &workBuffer.GetReference()) { for (int y = 0; y < h; y++) diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestImageProviderTests.cs index c4b7b544..404cb5f7 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -346,8 +346,8 @@ private static void EnsureCustomConfigurationIsApplied(TestImageProvider using (Image image2 = provider.GetImage()) using (Image image3 = provider.GetImage()) { - Assert.Same(customConfiguration, image2.GetConfiguration()); - Assert.Same(customConfiguration, image3.GetConfiguration()); + Assert.Same(customConfiguration, image2.Configuration); + Assert.Same(customConfiguration, image3.Configuration); } } }