From f73cdb05201f0164e63f4b67f122b79cda2e7563 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 17 Aug 2023 20:20:50 +1000 Subject: [PATCH] Expose non-nullable configuration to remove null check --- .../Advanced/AdvancedImageExtensions.cs | 40 ++--------- .../Advanced/IConfigurationProvider.cs | 2 +- src/ImageSharp/Formats/Bmp/BmpEncoder.cs | 4 +- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 2 +- src/ImageSharp/Formats/Gif/GifEncoder.cs | 2 +- src/ImageSharp/Formats/ImageEncoder.cs | 4 +- .../Formats/ImageExtensions.Save.cs | 72 +++++++++---------- .../Formats/ImageExtensions.Save.tt | 8 +-- .../Jpeg/Components/Encoder/JpegFrame.cs | 2 +- .../Encoder/SpectralConverter{TPixel}.cs | 2 +- src/ImageSharp/Formats/Pbm/PbmEncoder.cs | 2 +- src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs | 2 +- src/ImageSharp/Formats/Png/PngEncoder.cs | 4 +- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 8 +-- src/ImageSharp/Formats/Qoi/QoiEncoder.cs | 4 +- src/ImageSharp/Formats/Qoi/QoiEncoderCore.cs | 5 +- src/ImageSharp/Formats/Tga/TgaEncoder.cs | 6 +- src/ImageSharp/Formats/Tga/TgaEncoderCore.cs | 2 +- src/ImageSharp/Formats/Tiff/TiffEncoder.cs | 3 +- .../Formats/Tiff/TiffEncoderCore.cs | 2 +- src/ImageSharp/Formats/Webp/WebpEncoder.cs | 2 +- src/ImageSharp/Image.cs | 13 ++-- src/ImageSharp/ImageExtensions.cs | 12 ++-- src/ImageSharp/ImageFrame.cs | 14 ++-- .../ImageFrameCollection{TPixel}.cs | 20 +++--- src/ImageSharp/ImageFrame{TPixel}.cs | 12 ++-- src/ImageSharp/Image{TPixel}.cs | 8 +-- .../ProcessingExtensions.IntegralImage.cs | 2 +- .../Extensions/ProcessingExtensions.cs | 12 ++-- .../EntropyCropProcessor{TPixel}.cs | 2 +- .../Formats/WebP/YuvConversionTests.cs | 4 +- .../ImageFrameCollectionTests.NonGeneric.cs | 6 +- .../Image/ImageTests.SaveAsync.cs | 2 +- .../Image/ImageTests.WrapMemory.cs | 6 +- tests/ImageSharp.Tests/Image/ImageTests.cs | 8 +-- .../BaseImageOperationsExtensionTest.cs | 2 +- .../Processors/Convolution/BokehBlurTest.cs | 2 +- .../ImageComparison/ExactImageComparer.cs | 2 +- .../ImageComparison/TolerantImageComparer.cs | 2 +- ...SharpPngEncoderWithDefaultConfiguration.cs | 6 +- .../ReferenceCodecs/SystemDrawingBridge.cs | 8 +-- .../Tests/TestImageProviderTests.cs | 4 +- 42 files changed, 136 insertions(+), 189 deletions(-) diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index c3a9c212ee..a451e111d2 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -27,11 +27,11 @@ public static IImageEncoder DetectEncoder(this Image source, string filePath) Guard.NotNull(filePath, nameof(filePath)); string ext = Path.GetExtension(filePath); - if (!source.GetConfiguration().ImageFormatsManager.TryFindFormatByFileExtension(ext, out IImageFormat? format)) + if (!source.Configuration.ImageFormatsManager.TryFindFormatByFileExtension(ext, out IImageFormat? format)) { StringBuilder sb = new(); sb = sb.AppendLine(CultureInfo.InvariantCulture, $"No encoder was found for extension '{ext}'. Registered encoders include:"); - foreach (IImageFormat fmt in source.GetConfiguration().ImageFormats) + foreach (IImageFormat fmt in source.Configuration.ImageFormats) { sb = sb.AppendFormat(CultureInfo.InvariantCulture, " - {0} : {1}{2}", fmt.Name, string.Join(", ", fmt.FileExtensions), Environment.NewLine); } @@ -39,13 +39,13 @@ public static IImageEncoder DetectEncoder(this Image source, string filePath) throw new UnknownImageFormatException(sb.ToString()); } - IImageEncoder? encoder = source.GetConfiguration().ImageFormatsManager.GetEncoder(format); + IImageEncoder? encoder = source.Configuration.ImageFormatsManager.GetEncoder(format); if (encoder is null) { StringBuilder sb = new(); sb = sb.AppendLine(CultureInfo.InvariantCulture, $"No encoder was found for extension '{ext}' using image format '{format.Name}'. Registered encoders include:"); - foreach (KeyValuePair enc in source.GetConfiguration().ImageFormatsManager.ImageEncoders) + foreach (KeyValuePair enc in source.Configuration.ImageFormatsManager.ImageEncoders) { sb = sb.AppendFormat(CultureInfo.InvariantCulture, " - {0} : {1}{2}", enc.Key, enc.Value.GetType().Name, Environment.NewLine); } @@ -76,30 +76,6 @@ public static void AcceptVisitor(this Image source, IImageVisitor visitor) public static Task AcceptVisitorAsync(this Image source, IImageVisitorAsync visitor, CancellationToken cancellationToken = default) => source.AcceptAsync(visitor, cancellationToken); - /// - /// Gets the configuration for the image. - /// - /// The source image. - /// Returns the configuration. - public static Configuration GetConfiguration(this Image source) - => GetConfiguration((IConfigurationProvider)source); - - /// - /// Gets the configuration for the image frame. - /// - /// The source image. - /// Returns the configuration. - public static Configuration GetConfiguration(this ImageFrame source) - => GetConfiguration((IConfigurationProvider)source); - - /// - /// Gets the configuration. - /// - /// The source image - /// Returns the bounds of the image - private static Configuration GetConfiguration(IConfigurationProvider source) - => source?.Configuration ?? Configuration.Default; - /// /// Gets the representation of the pixels as a containing the backing pixel data of the image /// stored in row major order, as a list of contiguous blocks in the source image's pixel format. @@ -167,12 +143,4 @@ public static Memory DangerousGetPixelRowMemory(this Image - /// Gets the assigned to 'source'. - /// - /// The source image. - /// Returns the configuration. - internal static MemoryAllocator GetMemoryAllocator(this IConfigurationProvider source) - => GetConfiguration(source).MemoryAllocator; } diff --git a/src/ImageSharp/Advanced/IConfigurationProvider.cs b/src/ImageSharp/Advanced/IConfigurationProvider.cs index 086461f448..bb6d124f68 100644 --- a/src/ImageSharp/Advanced/IConfigurationProvider.cs +++ b/src/ImageSharp/Advanced/IConfigurationProvider.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Advanced; /// /// Defines the contract for objects that can provide access to configuration. /// -internal interface IConfigurationProvider +public interface IConfigurationProvider { /// /// Gets the configuration which allows altering default behaviour or extending the library. diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs index 156e2f9610..21d65b7696 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using SixLabors.ImageSharp.Advanced; - namespace SixLabors.ImageSharp.Formats.Bmp; /// @@ -26,7 +24,7 @@ public sealed class BmpEncoder : QuantizingImageEncoder /// protected override void Encode(Image image, Stream stream, CancellationToken cancellationToken) { - BmpEncoderCore encoder = new(this, image.GetMemoryAllocator()); + BmpEncoderCore encoder = new(this, image.Configuration.MemoryAllocator); encoder.Encode(image, stream, cancellationToken); } } diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index ce1660a912..499ecec8d1 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -118,7 +118,7 @@ public void Encode(Image image, Stream stream, CancellationToken Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); - Configuration configuration = image.GetConfiguration(); + Configuration configuration = image.Configuration; ImageMetadata metadata = image.Metadata; BmpMetadata bmpMetadata = metadata.GetBmpMetadata(); this.bitsPerPixel ??= bmpMetadata.BitsPerPixel; diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs index 386b1bd1c3..150ee9ccf0 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoder.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs @@ -18,7 +18,7 @@ public sealed class GifEncoder : QuantizingImageEncoder /// protected override void Encode(Image image, Stream stream, CancellationToken cancellationToken) { - GifEncoderCore encoder = new(image.GetConfiguration(), this); + GifEncoderCore encoder = new(image.Configuration, this); encoder.Encode(image, stream, cancellationToken); } } diff --git a/src/ImageSharp/Formats/ImageEncoder.cs b/src/ImageSharp/Formats/ImageEncoder.cs index d6870f716b..4acd29e81c 100644 --- a/src/ImageSharp/Formats/ImageEncoder.cs +++ b/src/ImageSharp/Formats/ImageEncoder.cs @@ -42,7 +42,7 @@ protected abstract void Encode(Image image, Stream stream, Cance private void EncodeWithSeekableStream(Image image, Stream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { - Configuration configuration = image.GetConfiguration(); + Configuration configuration = image.Configuration; if (stream.CanSeek) { this.Encode(image, stream, cancellationToken); @@ -59,7 +59,7 @@ private void EncodeWithSeekableStream(Image image, Stream stream private async Task EncodeWithSeekableStreamAsync(Image image, Stream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { - Configuration configuration = image.GetConfiguration(); + Configuration configuration = image.Configuration; if (stream.CanSeek) { await DoEncodeAsync(stream).ConfigureAwait(false); diff --git a/src/ImageSharp/Formats/ImageExtensions.Save.cs b/src/ImageSharp/Formats/ImageExtensions.Save.cs index 30f576e5c4..7e5989d6fc 100644 --- a/src/ImageSharp/Formats/ImageExtensions.Save.cs +++ b/src/ImageSharp/Formats/ImageExtensions.Save.cs @@ -59,7 +59,7 @@ public static Task SaveAsBmpAsync(this Image source, string path, CancellationTo public static void SaveAsBmp(this Image source, string path, BmpEncoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(BmpFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(BmpFormat.Instance)); /// /// Saves the image to the given stream with the Bmp format. @@ -73,7 +73,7 @@ public static void SaveAsBmp(this Image source, string path, BmpEncoder encoder) public static Task SaveAsBmpAsync(this Image source, string path, BmpEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(BmpFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(BmpFormat.Instance), cancellationToken); /// @@ -106,7 +106,7 @@ public static Task SaveAsBmpAsync(this Image source, Stream stream, Cancellation public static void SaveAsBmp(this Image source, Stream stream, BmpEncoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(BmpFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(BmpFormat.Instance)); /// /// Saves the image to the given stream with the Bmp format. @@ -120,7 +120,7 @@ public static void SaveAsBmp(this Image source, Stream stream, BmpEncoder encode public static Task SaveAsBmpAsync(this Image source, Stream stream, BmpEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(BmpFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(BmpFormat.Instance), cancellationToken); /// @@ -161,7 +161,7 @@ public static Task SaveAsGifAsync(this Image source, string path, CancellationTo public static void SaveAsGif(this Image source, string path, GifEncoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(GifFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(GifFormat.Instance)); /// /// Saves the image to the given stream with the Gif format. @@ -175,7 +175,7 @@ public static void SaveAsGif(this Image source, string path, GifEncoder encoder) public static Task SaveAsGifAsync(this Image source, string path, GifEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(GifFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(GifFormat.Instance), cancellationToken); /// @@ -208,7 +208,7 @@ public static Task SaveAsGifAsync(this Image source, Stream stream, Cancellation public static void SaveAsGif(this Image source, Stream stream, GifEncoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(GifFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(GifFormat.Instance)); /// /// Saves the image to the given stream with the Gif format. @@ -222,7 +222,7 @@ public static void SaveAsGif(this Image source, Stream stream, GifEncoder encode public static Task SaveAsGifAsync(this Image source, Stream stream, GifEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(GifFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(GifFormat.Instance), cancellationToken); /// @@ -263,7 +263,7 @@ public static Task SaveAsJpegAsync(this Image source, string path, CancellationT public static void SaveAsJpeg(this Image source, string path, JpegEncoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(JpegFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(JpegFormat.Instance)); /// /// Saves the image to the given stream with the Jpeg format. @@ -277,7 +277,7 @@ public static void SaveAsJpeg(this Image source, string path, JpegEncoder encode public static Task SaveAsJpegAsync(this Image source, string path, JpegEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(JpegFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(JpegFormat.Instance), cancellationToken); /// @@ -310,7 +310,7 @@ public static Task SaveAsJpegAsync(this Image source, Stream stream, Cancellatio public static void SaveAsJpeg(this Image source, Stream stream, JpegEncoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(JpegFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(JpegFormat.Instance)); /// /// Saves the image to the given stream with the Jpeg format. @@ -324,7 +324,7 @@ public static void SaveAsJpeg(this Image source, Stream stream, JpegEncoder enco public static Task SaveAsJpegAsync(this Image source, Stream stream, JpegEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(JpegFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(JpegFormat.Instance), cancellationToken); /// @@ -365,7 +365,7 @@ public static Task SaveAsPbmAsync(this Image source, string path, CancellationTo public static void SaveAsPbm(this Image source, string path, PbmEncoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(PbmFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(PbmFormat.Instance)); /// /// Saves the image to the given stream with the Pbm format. @@ -379,7 +379,7 @@ public static void SaveAsPbm(this Image source, string path, PbmEncoder encoder) public static Task SaveAsPbmAsync(this Image source, string path, PbmEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(PbmFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(PbmFormat.Instance), cancellationToken); /// @@ -412,7 +412,7 @@ public static Task SaveAsPbmAsync(this Image source, Stream stream, Cancellation public static void SaveAsPbm(this Image source, Stream stream, PbmEncoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(PbmFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(PbmFormat.Instance)); /// /// Saves the image to the given stream with the Pbm format. @@ -426,7 +426,7 @@ public static void SaveAsPbm(this Image source, Stream stream, PbmEncoder encode public static Task SaveAsPbmAsync(this Image source, Stream stream, PbmEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(PbmFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(PbmFormat.Instance), cancellationToken); /// @@ -467,7 +467,7 @@ public static Task SaveAsPngAsync(this Image source, string path, CancellationTo public static void SaveAsPng(this Image source, string path, PngEncoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(PngFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(PngFormat.Instance)); /// /// Saves the image to the given stream with the Png format. @@ -481,7 +481,7 @@ public static void SaveAsPng(this Image source, string path, PngEncoder encoder) public static Task SaveAsPngAsync(this Image source, string path, PngEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(PngFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(PngFormat.Instance), cancellationToken); /// @@ -514,7 +514,7 @@ public static Task SaveAsPngAsync(this Image source, Stream stream, Cancellation public static void SaveAsPng(this Image source, Stream stream, PngEncoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(PngFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(PngFormat.Instance)); /// /// Saves the image to the given stream with the Png format. @@ -528,7 +528,7 @@ public static void SaveAsPng(this Image source, Stream stream, PngEncoder encode public static Task SaveAsPngAsync(this Image source, Stream stream, PngEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(PngFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(PngFormat.Instance), cancellationToken); /// @@ -569,7 +569,7 @@ public static Task SaveAsQoiAsync(this Image source, string path, CancellationTo public static void SaveAsQoi(this Image source, string path, QoiEncoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(QoiFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(QoiFormat.Instance)); /// /// Saves the image to the given stream with the Qoi format. @@ -583,7 +583,7 @@ public static void SaveAsQoi(this Image source, string path, QoiEncoder encoder) public static Task SaveAsQoiAsync(this Image source, string path, QoiEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(QoiFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(QoiFormat.Instance), cancellationToken); /// @@ -616,7 +616,7 @@ public static Task SaveAsQoiAsync(this Image source, Stream stream, Cancellation public static void SaveAsQoi(this Image source, Stream stream, QoiEncoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(QoiFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(QoiFormat.Instance)); /// /// Saves the image to the given stream with the Qoi format. @@ -630,7 +630,7 @@ public static void SaveAsQoi(this Image source, Stream stream, QoiEncoder encode public static Task SaveAsQoiAsync(this Image source, Stream stream, QoiEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(QoiFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(QoiFormat.Instance), cancellationToken); /// @@ -671,7 +671,7 @@ public static Task SaveAsTgaAsync(this Image source, string path, CancellationTo public static void SaveAsTga(this Image source, string path, TgaEncoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(TgaFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(TgaFormat.Instance)); /// /// Saves the image to the given stream with the Tga format. @@ -685,7 +685,7 @@ public static void SaveAsTga(this Image source, string path, TgaEncoder encoder) public static Task SaveAsTgaAsync(this Image source, string path, TgaEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(TgaFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(TgaFormat.Instance), cancellationToken); /// @@ -718,7 +718,7 @@ public static Task SaveAsTgaAsync(this Image source, Stream stream, Cancellation public static void SaveAsTga(this Image source, Stream stream, TgaEncoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(TgaFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(TgaFormat.Instance)); /// /// Saves the image to the given stream with the Tga format. @@ -732,7 +732,7 @@ public static void SaveAsTga(this Image source, Stream stream, TgaEncoder encode public static Task SaveAsTgaAsync(this Image source, Stream stream, TgaEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(TgaFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(TgaFormat.Instance), cancellationToken); /// @@ -773,7 +773,7 @@ public static Task SaveAsTiffAsync(this Image source, string path, CancellationT public static void SaveAsTiff(this Image source, string path, TiffEncoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(TiffFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(TiffFormat.Instance)); /// /// Saves the image to the given stream with the Tiff format. @@ -787,7 +787,7 @@ public static void SaveAsTiff(this Image source, string path, TiffEncoder encode public static Task SaveAsTiffAsync(this Image source, string path, TiffEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(TiffFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(TiffFormat.Instance), cancellationToken); /// @@ -820,7 +820,7 @@ public static Task SaveAsTiffAsync(this Image source, Stream stream, Cancellatio public static void SaveAsTiff(this Image source, Stream stream, TiffEncoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(TiffFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(TiffFormat.Instance)); /// /// Saves the image to the given stream with the Tiff format. @@ -834,7 +834,7 @@ public static void SaveAsTiff(this Image source, Stream stream, TiffEncoder enco public static Task SaveAsTiffAsync(this Image source, Stream stream, TiffEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(TiffFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(TiffFormat.Instance), cancellationToken); /// @@ -875,7 +875,7 @@ public static Task SaveAsWebpAsync(this Image source, string path, CancellationT public static void SaveAsWebp(this Image source, string path, WebpEncoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(WebpFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(WebpFormat.Instance)); /// /// Saves the image to the given stream with the Webp format. @@ -889,7 +889,7 @@ public static void SaveAsWebp(this Image source, string path, WebpEncoder encode public static Task SaveAsWebpAsync(this Image source, string path, WebpEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(WebpFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(WebpFormat.Instance), cancellationToken); /// @@ -922,7 +922,7 @@ public static Task SaveAsWebpAsync(this Image source, Stream stream, Cancellatio public static void SaveAsWebp(this Image source, Stream stream, WebpEncoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(WebpFormat.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(WebpFormat.Instance)); /// /// Saves the image to the given stream with the Webp format. @@ -936,7 +936,7 @@ public static void SaveAsWebp(this Image source, Stream stream, WebpEncoder enco public static Task SaveAsWebpAsync(this Image source, Stream stream, WebpEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(WebpFormat.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(WebpFormat.Instance), cancellationToken); } diff --git a/src/ImageSharp/Formats/ImageExtensions.Save.tt b/src/ImageSharp/Formats/ImageExtensions.Save.tt index 538f62d041..d4f1ed233b 100644 --- a/src/ImageSharp/Formats/ImageExtensions.Save.tt +++ b/src/ImageSharp/Formats/ImageExtensions.Save.tt @@ -78,7 +78,7 @@ public static partial class ImageExtensions public static void SaveAs<#= fmt #>(this Image source, string path, <#= fmt #>Encoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance)); /// /// Saves the image to the given stream with the <#= fmt #> format. @@ -92,7 +92,7 @@ public static partial class ImageExtensions public static Task SaveAs<#= fmt #>Async(this Image source, string path, <#= fmt #>Encoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance), cancellationToken); /// @@ -125,7 +125,7 @@ public static partial class ImageExtensions public static void SaveAs<#= fmt #>(this Image source, Stream stream, <#= fmt #>Encoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance)); + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance)); /// /// Saves the image to the given stream with the <#= fmt #> format. @@ -139,7 +139,7 @@ public static partial class ImageExtensions public static Task SaveAs<#= fmt #>Async(this Image source, Stream stream, <#= fmt #>Encoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance), + encoder ?? source.Configuration.ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance), cancellationToken); <# diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/JpegFrame.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/JpegFrame.cs index 97a4a2dc0e..6ba0b82723 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/JpegFrame.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/JpegFrame.cs @@ -20,7 +20,7 @@ public JpegFrame(Image image, JpegFrameConfig frameConfig, bool interleaved) this.PixelWidth = image.Width; this.PixelHeight = image.Height; - MemoryAllocator allocator = image.GetConfiguration().MemoryAllocator; + MemoryAllocator allocator = image.Configuration.MemoryAllocator; JpegComponentConfig[] componentConfigs = frameConfig.Components; this.Components = new Component[componentConfigs.Length]; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/SpectralConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/SpectralConverter{TPixel}.cs index 47a6029065..fc93db9bb0 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/SpectralConverter{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/SpectralConverter{TPixel}.cs @@ -32,7 +32,7 @@ internal class SpectralConverter : SpectralConverter, IDisposable public SpectralConverter(JpegFrame frame, Image image, Block8x8F[] dequantTables) { - MemoryAllocator allocator = image.GetConfiguration().MemoryAllocator; + MemoryAllocator allocator = image.Configuration.MemoryAllocator; // iteration data int majorBlockWidth = frame.Components.Max((component) => component.SizeInBlocks.Width); diff --git a/src/ImageSharp/Formats/Pbm/PbmEncoder.cs b/src/ImageSharp/Formats/Pbm/PbmEncoder.cs index 0f492fae72..8258c91655 100644 --- a/src/ImageSharp/Formats/Pbm/PbmEncoder.cs +++ b/src/ImageSharp/Formats/Pbm/PbmEncoder.cs @@ -49,7 +49,7 @@ public sealed class PbmEncoder : ImageEncoder /// protected override void Encode(Image image, Stream stream, CancellationToken cancellationToken) { - PbmEncoderCore encoder = new(image.GetConfiguration(), this); + PbmEncoderCore encoder = new(image.Configuration, this); encoder.Encode(image, stream, cancellationToken); } } diff --git a/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs b/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs index 4a07173a14..b6e31a3c28 100644 --- a/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs +++ b/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs @@ -78,7 +78,7 @@ public void Encode(Image image, Stream stream, CancellationToken private void SanitizeAndSetEncoderOptions(Image image) where TPixel : unmanaged, IPixel { - this.configuration = image.GetConfiguration(); + this.configuration = image.Configuration; PbmMetadata metadata = image.Metadata.GetPbmMetadata(); this.encoding = this.encoder.Encoding ?? metadata.Encoding; this.colorType = this.encoder.ColorType ?? metadata.ColorType; diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index 1d068303bc..c7f699e0e6 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -2,8 +2,6 @@ // Licensed under the Six Labors Split License. #nullable disable -using SixLabors.ImageSharp.Advanced; - namespace SixLabors.ImageSharp.Formats.Png; /// @@ -77,7 +75,7 @@ public PngEncoder() => /// protected override void Encode(Image image, Stream stream, CancellationToken cancellationToken) { - using PngEncoderCore encoder = new(image.GetMemoryAllocator(), image.GetConfiguration(), this); + using PngEncoderCore encoder = new(image.Configuration, this); encoder.Encode(image, stream, cancellationToken); } } diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 175a9f777d..60b8ce8ea8 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -6,7 +6,6 @@ using System.Buffers.Binary; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Compression.Zlib; using SixLabors.ImageSharp.Formats.Png.Chunks; @@ -116,13 +115,12 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable /// /// Initializes a new instance of the class. /// - /// The to use for buffer allocations. /// The configuration. /// The encoder with options. - public PngEncoderCore(MemoryAllocator memoryAllocator, Configuration configuration, PngEncoder encoder) + public PngEncoderCore(Configuration configuration, PngEncoder encoder) { - this.memoryAllocator = memoryAllocator; this.configuration = configuration; + this.memoryAllocator = configuration.MemoryAllocator; this.encoder = encoder; } @@ -1294,7 +1292,7 @@ private static IndexedImageFrame CreateQuantizedFrame( ?? new WuQuantizer(new QuantizerOptions { MaxColors = ColorNumerics.GetColorCountForBitDepth(bitDepth) }); // Create quantized frame returning the palette and set the bit depth. - using IQuantizer frameQuantizer = quantizer.CreatePixelSpecificQuantizer(image.GetConfiguration()); + using IQuantizer frameQuantizer = quantizer.CreatePixelSpecificQuantizer(image.Configuration); frameQuantizer.BuildPalette(encoder.PixelSamplingStrategy, image); return frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds); diff --git a/src/ImageSharp/Formats/Qoi/QoiEncoder.cs b/src/ImageSharp/Formats/Qoi/QoiEncoder.cs index b3769d45cb..b9c2078b3f 100644 --- a/src/ImageSharp/Formats/Qoi/QoiEncoder.cs +++ b/src/ImageSharp/Formats/Qoi/QoiEncoder.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using SixLabors.ImageSharp.Advanced; - namespace SixLabors.ImageSharp.Formats.Qoi; /// @@ -27,7 +25,7 @@ public class QoiEncoder : ImageEncoder /// protected override void Encode(Image image, Stream stream, CancellationToken cancellationToken) { - QoiEncoderCore encoder = new(this, image.GetMemoryAllocator(), image.GetConfiguration()); + QoiEncoderCore encoder = new(this, image.Configuration); encoder.Encode(image, stream, cancellationToken); } } diff --git a/src/ImageSharp/Formats/Qoi/QoiEncoderCore.cs b/src/ImageSharp/Formats/Qoi/QoiEncoderCore.cs index 40b246faf2..53f67e765d 100644 --- a/src/ImageSharp/Formats/Qoi/QoiEncoderCore.cs +++ b/src/ImageSharp/Formats/Qoi/QoiEncoderCore.cs @@ -33,13 +33,12 @@ internal class QoiEncoderCore : IImageEncoderInternals /// Initializes a new instance of the class. /// /// The encoder with options. - /// The to use for buffer allocations. /// The configuration of the Encoder. - public QoiEncoderCore(QoiEncoder encoder, MemoryAllocator memoryAllocator, Configuration configuration) + public QoiEncoderCore(QoiEncoder encoder, Configuration configuration) { this.encoder = encoder; - this.memoryAllocator = memoryAllocator; this.configuration = configuration; + this.memoryAllocator = configuration.MemoryAllocator; } /// diff --git a/src/ImageSharp/Formats/Tga/TgaEncoder.cs b/src/ImageSharp/Formats/Tga/TgaEncoder.cs index 71acf3ae83..09b12e6081 100644 --- a/src/ImageSharp/Formats/Tga/TgaEncoder.cs +++ b/src/ImageSharp/Formats/Tga/TgaEncoder.cs @@ -1,12 +1,10 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using SixLabors.ImageSharp.Advanced; - namespace SixLabors.ImageSharp.Formats.Tga; /// -/// Image encoder for writing an image to a stream as a targa truevision image. +/// Image encoder for writing an image to a stream as a Targa true-vision image. /// public sealed class TgaEncoder : ImageEncoder { @@ -23,7 +21,7 @@ public sealed class TgaEncoder : ImageEncoder /// protected override void Encode(Image image, Stream stream, CancellationToken cancellationToken) { - TgaEncoderCore encoder = new(this, image.GetMemoryAllocator()); + TgaEncoderCore encoder = new(this, image.Configuration.MemoryAllocator); encoder.Encode(image, stream, cancellationToken); } } diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs index ad63bd356d..bbb476c017 100644 --- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs @@ -112,7 +112,7 @@ public void Encode(Image image, Stream stream, CancellationToken } else { - this.WriteImage(image.GetConfiguration(), stream, image.Frames.RootFrame); + this.WriteImage(image.Configuration, stream, image.Frames.RootFrame); } stream.Flush(); diff --git a/src/ImageSharp/Formats/Tiff/TiffEncoder.cs b/src/ImageSharp/Formats/Tiff/TiffEncoder.cs index 24cca41dc2..0e97bad449 100644 --- a/src/ImageSharp/Formats/Tiff/TiffEncoder.cs +++ b/src/ImageSharp/Formats/Tiff/TiffEncoder.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Compression.Zlib; using SixLabors.ImageSharp.Formats.Tiff.Constants; @@ -42,7 +41,7 @@ public class TiffEncoder : QuantizingImageEncoder /// protected override void Encode(Image image, Stream stream, CancellationToken cancellationToken) { - TiffEncoderCore encode = new(this, image.GetMemoryAllocator()); + TiffEncoderCore encode = new(this, image.Configuration.MemoryAllocator); encode.Encode(image, stream, cancellationToken); } } diff --git a/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs index d7243c6964..24849555de 100644 --- a/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs +++ b/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs @@ -127,7 +127,7 @@ public void Encode(Image image, Stream stream, CancellationToken Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); - this.configuration = image.GetConfiguration(); + this.configuration = image.Configuration; ImageFrameMetadata rootFrameMetaData = image.Frames.RootFrame.Metadata; TiffFrameMetadata rootFrameTiffMetaData = rootFrameMetaData.GetTiffMetadata(); diff --git a/src/ImageSharp/Formats/Webp/WebpEncoder.cs b/src/ImageSharp/Formats/Webp/WebpEncoder.cs index bd8303f1c8..29d0c9e3b0 100644 --- a/src/ImageSharp/Formats/Webp/WebpEncoder.cs +++ b/src/ImageSharp/Formats/Webp/WebpEncoder.cs @@ -82,7 +82,7 @@ public sealed class WebpEncoder : ImageEncoder /// protected override void Encode(Image image, Stream stream, CancellationToken cancellationToken) { - WebpEncoderCore encoder = new(this, image.GetConfiguration()); + WebpEncoderCore encoder = new(this, image.Configuration); encoder.Encode(image, stream, cancellationToken); } } diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs index cba32cb782..03a19a4be8 100644 --- a/src/ImageSharp/Image.cs +++ b/src/ImageSharp/Image.cs @@ -17,7 +17,6 @@ namespace SixLabors.ImageSharp; public abstract partial class Image : IDisposable, IConfigurationProvider { private bool isDisposed; - private readonly Configuration configuration; /// /// Initializes a new instance of the class. @@ -26,12 +25,12 @@ public abstract partial class Image : IDisposable, IConfigurationProvider /// The pixel type information. /// The image metadata. /// The size in px units. - protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetadata? metadata, Size size) + protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetadata metadata, Size size) { - this.configuration = configuration; + this.Configuration = configuration; this.PixelType = pixelType; this.Size = size; - this.Metadata = metadata ?? new ImageMetadata(); + this.Metadata = metadata; } /// @@ -45,7 +44,7 @@ protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetad internal Image( Configuration configuration, PixelTypeInfo pixelType, - ImageMetadata? metadata, + ImageMetadata metadata, int width, int height) : this(configuration, pixelType, metadata, new Size(width, height)) @@ -53,7 +52,7 @@ internal Image( } /// - Configuration IConfigurationProvider.Configuration => this.configuration; + public Configuration Configuration { get; } /// /// Gets information about the image pixels. @@ -147,7 +146,7 @@ public Task SaveAsync(Stream stream, IImageEncoder encoder, CancellationToken ca /// The pixel format. /// The public Image CloneAs() - where TPixel2 : unmanaged, IPixel => this.CloneAs(this.GetConfiguration()); + where TPixel2 : unmanaged, IPixel => this.CloneAs(this.Configuration); /// /// Returns a copy of the image in the given pixel format. diff --git a/src/ImageSharp/ImageExtensions.cs b/src/ImageSharp/ImageExtensions.cs index 75e4f13257..6c769a9d17 100644 --- a/src/ImageSharp/ImageExtensions.cs +++ b/src/ImageSharp/ImageExtensions.cs @@ -47,7 +47,7 @@ public static void Save(this Image source, string path, IImageEncoder encoder) { Guard.NotNull(path, nameof(path)); Guard.NotNull(encoder, nameof(encoder)); - using Stream fs = source.GetConfiguration().FileSystem.Create(path); + using Stream fs = source.Configuration.FileSystem.Create(path); source.Save(fs, encoder); } @@ -70,7 +70,7 @@ public static async Task SaveAsync( Guard.NotNull(path, nameof(path)); Guard.NotNull(encoder, nameof(encoder)); - await using Stream fs = source.GetConfiguration().FileSystem.CreateAsynchronous(path); + await using Stream fs = source.Configuration.FileSystem.CreateAsynchronous(path); await source.SaveAsync(fs, encoder, cancellationToken).ConfigureAwait(false); } @@ -94,14 +94,14 @@ public static void Save(this Image source, Stream stream, IImageFormat format) throw new NotSupportedException("Cannot write to the stream."); } - IImageEncoder encoder = source.GetConfiguration().ImageFormatsManager.GetEncoder(format); + IImageEncoder encoder = source.Configuration.ImageFormatsManager.GetEncoder(format); if (encoder is null) { StringBuilder sb = new(); sb.AppendLine("No encoder was found for the provided mime type. Registered encoders include:"); - foreach (KeyValuePair val in source.GetConfiguration().ImageFormatsManager.ImageEncoders) + foreach (KeyValuePair val in source.Configuration.ImageFormatsManager.ImageEncoders) { sb.AppendFormat(CultureInfo.InvariantCulture, " - {0} : {1}{2}", val.Key.Name, val.Value.GetType().Name, Environment.NewLine); } @@ -138,14 +138,14 @@ public static Task SaveAsync( throw new NotSupportedException("Cannot write to the stream."); } - IImageEncoder encoder = source.GetConfiguration().ImageFormatsManager.GetEncoder(format); + IImageEncoder encoder = source.Configuration.ImageFormatsManager.GetEncoder(format); if (encoder is null) { StringBuilder sb = new(); sb.AppendLine("No encoder was found for the provided mime type. Registered encoders include:"); - foreach (KeyValuePair val in source.GetConfiguration().ImageFormatsManager.ImageEncoders) + foreach (KeyValuePair val in source.Configuration.ImageFormatsManager.ImageEncoders) { sb.AppendFormat(CultureInfo.InvariantCulture, " - {0} : {1}{2}", val.Key.Name, val.Value.GetType().Name, Environment.NewLine); } diff --git a/src/ImageSharp/ImageFrame.cs b/src/ImageSharp/ImageFrame.cs index 1e5d40385c..2558e1a13a 100644 --- a/src/ImageSharp/ImageFrame.cs +++ b/src/ImageSharp/ImageFrame.cs @@ -15,8 +15,6 @@ namespace SixLabors.ImageSharp; /// public abstract partial class ImageFrame : IConfigurationProvider, IDisposable { - private readonly Configuration configuration; - /// /// Initializes a new instance of the class. /// @@ -26,10 +24,7 @@ public abstract partial class ImageFrame : IConfigurationProvider, IDisposable /// The . protected ImageFrame(Configuration configuration, int width, int height, ImageFrameMetadata metadata) { - Guard.NotNull(configuration, nameof(configuration)); - Guard.NotNull(metadata, nameof(metadata)); - - this.configuration = configuration ?? Configuration.Default; + this.Configuration = configuration; this.Width = width; this.Height = height; this.Metadata = metadata; @@ -51,19 +46,19 @@ protected ImageFrame(Configuration configuration, int width, int height, ImageFr public ImageFrameMetadata Metadata { get; } /// - Configuration IConfigurationProvider.Configuration => this.configuration; + public Configuration Configuration { get; } /// /// Gets the size of the frame. /// /// The - public Size Size() => new Size(this.Width, this.Height); + public Size Size() => new(this.Width, this.Height); /// /// Gets the bounds of the frame. /// /// The - public Rectangle Bounds() => new Rectangle(0, 0, this.Width, this.Height); + public Rectangle Bounds() => new(0, 0, this.Width, this.Height); /// public void Dispose() @@ -84,6 +79,7 @@ internal abstract void CopyPixelsTo(MemoryGroup /// Updates the size of the image frame. /// + /// The size. internal void UpdateSize(Size size) { this.Width = size.Width; diff --git a/src/ImageSharp/ImageFrameCollection{TPixel}.cs b/src/ImageSharp/ImageFrameCollection{TPixel}.cs index faa83b59e2..b32711ebf2 100644 --- a/src/ImageSharp/ImageFrameCollection{TPixel}.cs +++ b/src/ImageSharp/ImageFrameCollection{TPixel}.cs @@ -24,7 +24,7 @@ internal ImageFrameCollection(Image parent, int width, int height, TPixe this.parent = parent ?? throw new ArgumentNullException(nameof(parent)); // Frames are already cloned within the caller - this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, backgroundColor)); + this.frames.Add(new ImageFrame(parent.Configuration, width, height, backgroundColor)); } internal ImageFrameCollection(Image parent, int width, int height, MemoryGroup memorySource) @@ -32,7 +32,7 @@ internal ImageFrameCollection(Image parent, int width, int height, Memor this.parent = parent ?? throw new ArgumentNullException(nameof(parent)); // Frames are already cloned within the caller - this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, memorySource)); + this.frames.Add(new ImageFrame(parent.Configuration, width, height, memorySource)); } internal ImageFrameCollection(Image parent, IEnumerable> frames) @@ -138,7 +138,7 @@ public ImageFrame InsertFrame(int index, ImageFrame source) this.EnsureNotDisposed(); this.ValidateFrame(source); - ImageFrame clonedFrame = source.Clone(this.parent.GetConfiguration()); + ImageFrame clonedFrame = source.Clone(this.parent.Configuration); this.frames.Insert(index, clonedFrame); return clonedFrame; } @@ -153,7 +153,7 @@ public ImageFrame AddFrame(ImageFrame source) this.EnsureNotDisposed(); this.ValidateFrame(source); - ImageFrame clonedFrame = source.Clone(this.parent.GetConfiguration()); + ImageFrame clonedFrame = source.Clone(this.parent.Configuration); this.frames.Add(clonedFrame); return clonedFrame; } @@ -169,7 +169,7 @@ public ImageFrame AddFrame(ReadOnlySpan source) this.EnsureNotDisposed(); ImageFrame frame = ImageFrame.LoadPixelData( - this.parent.GetConfiguration(), + this.parent.Configuration, source, this.RootFrame.Width, this.RootFrame.Height); @@ -270,7 +270,7 @@ public override void MoveFrame(int sourceIndex, int destinationIndex) this.frames.Remove(frame); - return new Image(this.parent.GetConfiguration(), this.parent.Metadata.DeepClone(), new[] { frame }); + return new Image(this.parent.Configuration, this.parent.Metadata.DeepClone(), new[] { frame }); } /// @@ -285,7 +285,7 @@ public override void MoveFrame(int sourceIndex, int destinationIndex) ImageFrame frame = this[index]; ImageFrame clonedFrame = frame.Clone(); - return new Image(this.parent.GetConfiguration(), this.parent.Metadata.DeepClone(), new[] { clonedFrame }); + return new Image(this.parent.Configuration, this.parent.Metadata.DeepClone(), new[] { clonedFrame }); } /// @@ -299,7 +299,7 @@ public override void MoveFrame(int sourceIndex, int destinationIndex) this.EnsureNotDisposed(); ImageFrame frame = new( - this.parent.GetConfiguration(), + this.parent.Configuration, this.RootFrame.Width, this.RootFrame.Height); this.frames.Add(frame); @@ -365,7 +365,7 @@ protected override ImageFrame NonGenericCreateFrame(Color backgroundColor) => public ImageFrame CreateFrame(TPixel backgroundColor) { ImageFrame frame = new( - this.parent.GetConfiguration(), + this.parent.Configuration, this.RootFrame.Width, this.RootFrame.Height, backgroundColor); @@ -414,7 +414,7 @@ protected override void Dispose(bool disposing) private ImageFrame CopyNonCompatibleFrame(ImageFrame source) { ImageFrame result = new( - this.parent.GetConfiguration(), + this.parent.Configuration, source.Size(), source.Metadata.DeepClone()); source.CopyPixelsTo(result.PixelBuffer.FastMemoryGroup); diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 3734402d30..7157b7e76f 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -56,7 +56,7 @@ internal ImageFrame(Configuration configuration, int width, int height, ImageFra Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); - this.PixelBuffer = this.GetConfiguration().MemoryAllocator.Allocate2D( + this.PixelBuffer = this.Configuration.MemoryAllocator.Allocate2D( width, height, configuration.PreferContiguousImageBuffers, @@ -89,7 +89,7 @@ internal ImageFrame(Configuration configuration, int width, int height, TPixel b Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); - this.PixelBuffer = this.GetConfiguration().MemoryAllocator.Allocate2D( + this.PixelBuffer = this.Configuration.MemoryAllocator.Allocate2D( width, height, configuration.PreferContiguousImageBuffers); @@ -136,7 +136,7 @@ internal ImageFrame(Configuration configuration, ImageFrame source) Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(source, nameof(source)); - this.PixelBuffer = this.GetConfiguration().MemoryAllocator.Allocate2D( + this.PixelBuffer = this.Configuration.MemoryAllocator.Allocate2D( source.PixelBuffer.Width, source.PixelBuffer.Height, configuration.PreferContiguousImageBuffers); @@ -361,7 +361,7 @@ internal override void CopyPixelsTo(MemoryGroup PixelOperations.Instance.To(this.GetConfiguration(), s, d)); + => PixelOperations.Instance.To(this.Configuration, s, d)); } /// @@ -371,7 +371,7 @@ internal override void CopyPixelsTo(MemoryGroup /// The - internal ImageFrame Clone() => this.Clone(this.GetConfiguration()); + internal ImageFrame Clone() => this.Clone(this.Configuration); /// /// Clones the current instance. @@ -386,7 +386,7 @@ internal override void CopyPixelsTo(MemoryGroupThe pixel format. /// The internal ImageFrame? CloneAs() - where TPixel2 : unmanaged, IPixel => this.CloneAs(this.GetConfiguration()); + where TPixel2 : unmanaged, IPixel => this.CloneAs(this.Configuration); /// /// Returns a copy of the image frame in the given pixel format. diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index 69654329c4..c24014e698 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -78,12 +78,12 @@ public Image(int width, int height) /// The height of the image in pixels. /// The images metadata. internal Image(Configuration configuration, int width, int height, ImageMetadata? metadata) - : base(configuration, PixelTypeInfo.Create(), metadata, width, height) + : base(configuration, PixelTypeInfo.Create(), metadata ?? new(), width, height) => this.frames = new ImageFrameCollection(this, width, height, default(TPixel)); /// /// Initializes a new instance of the class - /// wrapping an external pixel bufferx. + /// wrapping an external pixel buffer. /// /// The configuration providing initialization code which allows extending the library. /// Pixel buffer. @@ -129,7 +129,7 @@ internal Image( int height, TPixel backgroundColor, ImageMetadata? metadata) - : base(configuration, PixelTypeInfo.Create(), metadata, width, height) + : base(configuration, PixelTypeInfo.Create(), metadata ?? new(), width, height) => this.frames = new ImageFrameCollection(this, width, height, backgroundColor); /// @@ -328,7 +328,7 @@ public bool DangerousTryGetSinglePixelMemory(out Memory memory) /// Clones the current image /// /// Returns a new image with all the same metadata as the original. - public Image Clone() => this.Clone(this.GetConfiguration()); + public Image Clone() => this.Clone(this.Configuration); /// /// Clones the current image with the given configuration. diff --git a/src/ImageSharp/Processing/Extensions/ProcessingExtensions.IntegralImage.cs b/src/ImageSharp/Processing/Extensions/ProcessingExtensions.IntegralImage.cs index fdf0967c53..713d4d5b77 100644 --- a/src/ImageSharp/Processing/Extensions/ProcessingExtensions.IntegralImage.cs +++ b/src/ImageSharp/Processing/Extensions/ProcessingExtensions.IntegralImage.cs @@ -54,7 +54,7 @@ public static Buffer2D CalculateIntegralImage(this ImageFrame CalculateIntegralImage(this ImageFrame source, Rectangle bounds) where TPixel : unmanaged, IPixel { - Configuration configuration = source.GetConfiguration(); + Configuration configuration = source.Configuration; var interest = Rectangle.Intersect(bounds, source.Bounds()); int startY = interest.Y; diff --git a/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs b/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs index f830ddfd09..784258aa51 100644 --- a/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs @@ -22,7 +22,7 @@ public static partial class ProcessingExtensions /// The source has been disposed. /// The processing operation failed. public static void Mutate(this Image source, Action operation) - => Mutate(source, source.GetConfiguration(), operation); + => Mutate(source, source.Configuration, operation); /// /// Mutates the source image by applying the image operation to it. @@ -57,7 +57,7 @@ public static void Mutate(this Image source, Configuration configuration, Action /// The processing operation failed. public static void Mutate(this Image source, Action operation) where TPixel : unmanaged, IPixel - => Mutate(source, source.GetConfiguration(), operation); + => Mutate(source, source.Configuration, operation); /// /// Mutates the source image by applying the image operation to it. @@ -97,7 +97,7 @@ IInternalImageProcessingContext operationsRunner /// The processing operation failed. public static void Mutate(this Image source, params IImageProcessor[] operations) where TPixel : unmanaged, IPixel - => Mutate(source, source.GetConfiguration(), operations); + => Mutate(source, source.Configuration, operations); /// /// Mutates the source image by applying the operations to it. @@ -135,7 +135,7 @@ IInternalImageProcessingContext operationsRunner /// The source has been disposed. /// The processing operation failed. public static Image Clone(this Image source, Action operation) - => Clone(source, source.GetConfiguration(), operation); + => Clone(source, source.Configuration, operation); /// /// Creates a deep clone of the current image. The clone is then mutated by the given operation. @@ -174,7 +174,7 @@ public static Image Clone(this Image source, Configuration configuration, Action /// The new . public static Image Clone(this Image source, Action operation) where TPixel : unmanaged, IPixel - => Clone(source, source.GetConfiguration(), operation); + => Clone(source, source.Configuration, operation); /// /// Creates a deep clone of the current image. The clone is then mutated by the given operation. @@ -217,7 +217,7 @@ IInternalImageProcessingContext operationsRunner /// The new public static Image Clone(this Image source, params IImageProcessor[] operations) where TPixel : unmanaged, IPixel - => Clone(source, source.GetConfiguration(), operations); + => Clone(source, source.Configuration, operations); /// /// Creates a deep clone of the current image. The clone is then mutated by the given operations. diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs index 9afc852b58..2eda61e41d 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs @@ -38,7 +38,7 @@ protected override void BeforeImageApply() // All frames have be the same size so we only need to calculate the correct dimensions for the first frame using (Image temp = new(this.Configuration, this.Source.Metadata.DeepClone(), new[] { this.Source.Frames.RootFrame.Clone() })) { - Configuration configuration = this.Source.GetConfiguration(); + Configuration configuration = this.Source.Configuration; // Detect the edges. new EdgeDetector2DProcessor(KnownEdgeDetectorKernels.Sobel, false).Execute(this.Configuration, temp, this.SourceRectangle); diff --git a/tests/ImageSharp.Tests/Formats/WebP/YuvConversionTests.cs b/tests/ImageSharp.Tests/Formats/WebP/YuvConversionTests.cs index 258ee5b9f7..9b03a447a9 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/YuvConversionTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/YuvConversionTests.cs @@ -42,7 +42,7 @@ public void ConvertRgbToYuv_Works(TestImageProvider provider) { // arrange using Image image = provider.GetImage(); - Configuration config = image.GetConfiguration(); + Configuration config = image.Configuration; MemoryAllocator memoryAllocator = config.MemoryAllocator; int pixels = image.Width * image.Height; int uvWidth = (image.Width + 1) >> 1; @@ -158,7 +158,7 @@ public void ConvertRgbToYuv_WithAlpha_Works(TestImageProvider pr { // arrange using Image image = provider.GetImage(); - Configuration config = image.GetConfiguration(); + Configuration config = image.Configuration; MemoryAllocator memoryAllocator = config.MemoryAllocator; int pixels = image.Width * image.Height; int uvWidth = (image.Width + 1) >> 1; diff --git a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs index bc22806c3c..14132f846d 100644 --- a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs +++ b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs @@ -20,7 +20,7 @@ public class NonGeneric : ImageFrameCollectionTests public void AddFrame_OfDifferentPixelType() { using (Image sourceImage = new( - this.Image.GetConfiguration(), + this.Image.Configuration, this.Image.Width, this.Image.Height, Color.Blue)) @@ -41,7 +41,7 @@ public void AddFrame_OfDifferentPixelType() public void InsertFrame_OfDifferentPixelType() { using (Image sourceImage = new( - this.Image.GetConfiguration(), + this.Image.Configuration, this.Image.Width, this.Image.Height, Color.Blue)) @@ -278,7 +278,7 @@ public void ConstructGif_FromDifferentPixelTypes(TestImageProvider { using Image source = provider.GetImage(); - using Image dest = new(source.GetConfiguration(), source.Width, source.Height); + using Image dest = new(source.Configuration, source.Width, source.Height); // Giphy.gif has 5 frames ImportFrameAs(source.Frames, dest.Frames, 0); ImportFrameAs(source.Frames, dest.Frames, 1); diff --git a/tests/ImageSharp.Tests/Image/ImageTests.SaveAsync.cs b/tests/ImageSharp.Tests/Image/ImageTests.SaveAsync.cs index 87794f3357..5fc58a752b 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.SaveAsync.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.SaveAsync.cs @@ -70,7 +70,7 @@ public async Task SaveStreamWithMime(string filename, string mimeType) { using Image image = new(5, 5); string ext = Path.GetExtension(filename); - image.GetConfiguration().ImageFormatsManager.TryFindFormatByFileExtension(ext, out IImageFormat format); + image.Configuration.ImageFormatsManager.TryFindFormatByFileExtension(ext, out IImageFormat format); Assert.Equal(mimeType, format!.DefaultMimeType); using MemoryStream stream = new(); diff --git a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs index 3239c57b1a..9aaefa41ef 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs @@ -136,7 +136,7 @@ public void WrapMemory_CreatedImageIsCorrect() ref Rgba32 pixel0 = ref imageMem.Span[0]; Assert.True(Unsafe.AreSame(ref array[0], ref pixel0)); - Assert.Equal(cfg, image.GetConfiguration()); + Assert.Equal(cfg, image.Configuration); Assert.Equal(metaData, image.Metadata); } } @@ -239,7 +239,7 @@ public void WrapMemory_FromBytes_CreatedImageIsCorrect() ref Rgba32 pixel0 = ref imageMem.Span[0]; Assert.True(Unsafe.AreSame(ref Unsafe.As(ref array[0]), ref pixel0)); - Assert.Equal(cfg, image.GetConfiguration()); + Assert.Equal(cfg, image.Configuration); Assert.Equal(metaData, image.Metadata); } } @@ -336,7 +336,7 @@ public unsafe void WrapMemory_FromPointer_CreatedImageIsCorrect() ref Rgba32 pixel_1 = ref imageSpan[imageSpan.Length - 1]; Assert.True(Unsafe.AreSame(ref array[array.Length - 1], ref pixel_1)); - Assert.Equal(cfg, image.GetConfiguration()); + Assert.Equal(cfg, image.Configuration); Assert.Equal(metaData, image.Metadata); } } diff --git a/tests/ImageSharp.Tests/Image/ImageTests.cs b/tests/ImageSharp.Tests/Image/ImageTests.cs index eefa81835e..1dec14ee16 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.cs @@ -31,7 +31,7 @@ public void Width_Height() Assert.Equal(11 * 23, imageMem.Length); image.ComparePixelBufferTo(default(Rgba32)); - Assert.Equal(Configuration.Default, image.GetConfiguration()); + Assert.Equal(Configuration.Default, image.Configuration); } } @@ -48,7 +48,7 @@ public void Configuration_Width_Height() Assert.Equal(11 * 23, imageMem.Length); image.ComparePixelBufferTo(default(Rgba32)); - Assert.Equal(configuration, image.GetConfiguration()); + Assert.Equal(configuration, image.Configuration); } } @@ -66,7 +66,7 @@ public void Configuration_Width_Height_BackgroundColor() Assert.Equal(11 * 23, imageMem.Length); image.ComparePixelBufferTo(color); - Assert.Equal(configuration, image.GetConfiguration()); + Assert.Equal(configuration, image.Configuration); } } @@ -83,7 +83,7 @@ public void CreateUninitialized() { Assert.Equal(21, image.Width); Assert.Equal(22, image.Height); - Assert.Same(configuration, image.GetConfiguration()); + Assert.Same(configuration, image.Configuration); Assert.Same(metadata, image.Metadata); Assert.Equal(dirtyValue, image[5, 5].PackedValue); diff --git a/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs index 98b5c8e980..403865e662 100644 --- a/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs +++ b/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs @@ -22,7 +22,7 @@ public BaseImageOperationsExtensionTest() this.options = new GraphicsOptions { Antialias = false }; 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.SetGraphicsOptions(this.options); this.operations = this.internalOperations; } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs index 0e53856dac..c94983ecd5 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs @@ -65,7 +65,7 @@ public void VerifyComplexComponents() // Make sure the kernel components are the same using Image image = new(1, 1); - Configuration configuration = image.GetConfiguration(); + Configuration configuration = image.Configuration; BokehBlurProcessor definition = new(10, BokehBlurProcessor.DefaultComponents, BokehBlurProcessor.DefaultGamma); using BokehBlurProcessor processor = (BokehBlurProcessor)definition.CreatePixelSpecificProcessor(configuration, image, image.Bounds); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs index 52f160dedc..aa8ab397d2 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs +++ b/tests/ImageSharp.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.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs index c541133079..93ed4c6fff 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -72,7 +72,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.Tests/TestUtilities/ReferenceCodecs/ImageSharpPngEncoderWithDefaultConfiguration.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/ImageSharpPngEncoderWithDefaultConfiguration.cs index a4d305d97f..d32a6c93f1 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/ImageSharpPngEncoderWithDefaultConfiguration.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/ImageSharpPngEncoderWithDefaultConfiguration.cs @@ -2,7 +2,6 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Formats.Png; -using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; @@ -15,10 +14,7 @@ public sealed class ImageSharpPngEncoderWithDefaultConfiguration : PngEncoder /// protected override void Encode(Image image, Stream stream, CancellationToken cancellationToken) { - Configuration configuration = Configuration.Default; - MemoryAllocator allocator = configuration.MemoryAllocator; - - using PngEncoderCore encoder = new(allocator, configuration, this); + using PngEncoderCore encoder = new(Configuration.Default, this); encoder.Encode(image, stream, cancellationToken); } } diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index e57da55895..04f59979f7 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.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.Frames.RootFrame.PixelBuffer; using (IMemoryOwner workBuffer = Configuration.Default.MemoryAllocator.Allocate(w)) @@ -134,7 +134,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; @@ -148,7 +148,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.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index cbce961103..974e951f6f 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -342,8 +342,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); } }