diff --git a/src/ImageSharp/Formats/DecoderOptions.cs b/src/ImageSharp/Formats/DecoderOptions.cs index 989fc49fc..6243a071d 100644 --- a/src/ImageSharp/Formats/DecoderOptions.cs +++ b/src/ImageSharp/Formats/DecoderOptions.cs @@ -15,15 +15,25 @@ 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 IDE0032 // Use auto property + private Configuration configuration = Configuration.Default; +#pragma warning restore IDE0032 // Use auto property + /// /// Gets the shared default general decoder options instance. + /// Used internally to reduce allocations for default decoding operations. /// internal static DecoderOptions Default { get; } = LazyOptions.Value; /// /// Gets a custom configuration instance to be used by the image processing pipeline. /// - public Configuration Configuration { get; internal set; } = Configuration.Default; +#pragma warning disable IDE0032 // Use auto property +#pragma warning disable RCS1085 // Use auto-implemented property. + public Configuration Configuration { get => this.configuration; init => this.configuration = value; } +#pragma warning restore RCS1085 // Use auto-implemented property. +#pragma warning restore IDE0032 // Use auto property /// /// Gets the target size to decode the image into. Scaling should use an operation equivalent to . @@ -44,4 +54,6 @@ public sealed class DecoderOptions /// Gets the maximum number of image frames to decode, inclusive. /// public uint MaxFrames { get => this.maxFrames; init => this.maxFrames = Math.Clamp(value, 1, int.MaxValue); } + + internal void SetConfiguration(Configuration configuration) => this.configuration = configuration; } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs index 3285da31b..3652d77a1 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);