diff --git a/src/ImageSharp/Formats/DecoderOptions.cs b/src/ImageSharp/Formats/DecoderOptions.cs index a4f46368bb..f786a9df19 100644 --- a/src/ImageSharp/Formats/DecoderOptions.cs +++ b/src/ImageSharp/Formats/DecoderOptions.cs @@ -15,6 +15,11 @@ public sealed class DecoderOptions private uint maxFrames = int.MaxValue; + // Used by the FileProvider in the unit tests to set the configuration on the fly. +#pragma warning disable SA1401 // Fields should be private + internal Configuration BackingConfiguration = Configuration.Default; +#pragma warning restore SA1401 // Fields should be private + /// /// Gets the shared default general decoder options instance. /// Used internally to reduce allocations for default decoding operations. @@ -24,7 +29,7 @@ public sealed class DecoderOptions /// /// Gets a custom configuration instance to be used by the image processing pipeline. /// - public Configuration Configuration { get; init; } = Configuration.Default; + public Configuration Configuration { get => this.BackingConfiguration; init => this.BackingConfiguration = value; } /// /// Gets the target size to decode the image into. Scaling should use an operation equivalent to . @@ -46,3 +51,9 @@ public sealed class DecoderOptions /// public uint MaxFrames { get => this.maxFrames; init => this.maxFrames = Math.Clamp(value, 1, int.MaxValue); } } + +internal static class DecoderOptionsExtensions +{ + public static void SetConfiguration(this DecoderOptions options, Configuration configuration) + => options.BackingConfiguration = configuration; +} diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs index 3285da31b4..3652d77a1e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs @@ -207,7 +207,7 @@ public abstract partial class TestImageProvider : IXunitSerializable Guard.NotNull(decoder, nameof(decoder)); Guard.NotNull(options, nameof(options)); - options.Configuration = this.Configuration; + options.SetConfiguration(this.Configuration); // Used in small subset of decoder tests, no caching. // TODO: Check Path here. Why combined? @@ -244,7 +244,7 @@ public abstract partial class TestImageProvider : IXunitSerializable Guard.NotNull(decoder, nameof(decoder)); Guard.NotNull(options, nameof(options)); - options.GeneralOptions.Configuration = this.Configuration; + options.GeneralOptions.SetConfiguration(this.Configuration); // Used in small subset of decoder tests, no caching. // TODO: Check Path here. Why combined? @@ -268,7 +268,7 @@ public abstract partial class TestImageProvider : IXunitSerializable private Image DecodeImage(IImageDecoder decoder, DecoderOptions options) { - options.Configuration = this.Configuration; + options.SetConfiguration(this.Configuration); var testFile = TestFile.Create(this.FilePath); using Stream stream = new MemoryStream(testFile.Bytes); @@ -278,7 +278,7 @@ public abstract partial class TestImageProvider : IXunitSerializable private Image DecodeImage(ISpecializedImageDecoder decoder, T options) where T : class, ISpecializedDecoderOptions, new() { - options.GeneralOptions.Configuration = this.Configuration; + options.GeneralOptions.SetConfiguration(this.Configuration); var testFile = TestFile.Create(this.FilePath); using Stream stream = new MemoryStream(testFile.Bytes);