diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
index 620e0499f4..f30369d19b 100644
--- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
@@ -159,7 +159,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
WriteBitmapFileHeader(stream, infoHeaderSize, colorPaletteSize, iccProfileSize, infoHeader, buffer);
this.WriteBitmapInfoHeader(stream, infoHeader, buffer, infoHeaderSize);
- this.WriteImage(stream, image, configuration);
+ this.WriteImage(configuration, stream, image);
WriteColorProfile(stream, iccProfileData, buffer);
stream.Flush();
@@ -307,43 +307,43 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
/// Writes the pixel data to the binary stream.
///
/// The pixel format.
+ /// The global configuration.
/// The to write to.
///
/// The containing pixel data.
///
- /// The global configuration.
- private void WriteImage(Stream stream, Image image, Configuration configuration)
+ private void WriteImage(Configuration configuration, Stream stream, Image image)
where TPixel : unmanaged, IPixel
{
Buffer2D pixels = image.Frames.RootFrame.PixelBuffer;
switch (this.bitsPerPixel)
{
case BmpBitsPerPixel.Pixel32:
- this.Write32BitPixelData(stream, pixels, configuration);
+ this.Write32BitPixelData(configuration, stream, pixels);
break;
case BmpBitsPerPixel.Pixel24:
- this.Write24BitPixelData(stream, pixels, configuration);
+ this.Write24BitPixelData(configuration, stream, pixels);
break;
case BmpBitsPerPixel.Pixel16:
- this.Write16BitPixelData(stream, pixels, configuration);
+ this.Write16BitPixelData(configuration, stream, pixels);
break;
case BmpBitsPerPixel.Pixel8:
- this.Write8BitPixelData(stream, image, configuration);
+ this.Write8BitPixelData(configuration, stream, image);
break;
case BmpBitsPerPixel.Pixel4:
- this.Write4BitPixelData(stream, image, configuration);
+ this.Write4BitPixelData(configuration, stream, image);
break;
case BmpBitsPerPixel.Pixel2:
- this.Write2BitPixelData(stream, image, configuration);
+ this.Write2BitPixelData(configuration, stream, image);
break;
case BmpBitsPerPixel.Pixel1:
- this.Write1BitPixelData(stream, image, configuration);
+ this.Write1BitPixelData(configuration, stream, image);
break;
}
}
@@ -355,10 +355,10 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
/// Writes 32-bit data with a color palette to the stream.
///
/// The pixel format.
+ /// The global configuration.
/// The to write to.
/// The containing pixel data.
- /// The global configuration.
- private void Write32BitPixelData(Stream stream, Buffer2D pixels, Configuration configuration)
+ private void Write32BitPixelData(Configuration configuration, Stream stream, Buffer2D pixels)
where TPixel : unmanaged, IPixel
{
using IMemoryOwner row = this.AllocateRow(pixels.Width, 4);
@@ -380,10 +380,10 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
/// Writes 24-bit pixel data with a color palette to the stream.
///
/// The pixel format.
+ /// The global configuration.
/// The to write to.
/// The containing pixel data.
- /// The global configuration.
- private void Write24BitPixelData(Stream stream, Buffer2D pixels, Configuration configuration)
+ private void Write24BitPixelData(Configuration configuration, Stream stream, Buffer2D pixels)
where TPixel : unmanaged, IPixel
{
int width = pixels.Width;
@@ -407,11 +407,11 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
/// Writes 16-bit pixel data with a color palette to the stream.
///
/// The type of the pixel.
+ /// The global configuration.
/// The to write to.
/// The containing pixel data.
- /// The global configuration.
- private void Write16BitPixelData(Stream stream, Buffer2D pixels, Configuration configuration)
- where TPixel : unmanaged, IPixel
+ private void Write16BitPixelData(Configuration configuration, Stream stream, Buffer2D pixels)
+ where TPixel : unmanaged, IPixel
{
int width = pixels.Width;
int rowBytesWithoutPadding = width * 2;
@@ -436,10 +436,10 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
/// Writes 8 bit pixel data with a color palette. The color palette has 256 entry's with 4 bytes for each entry.
///
/// The type of the pixel.
+ /// The global configuration.
/// The to write to.
/// The containing pixel data.
- /// The global configuration.
- private void Write8BitPixelData(Stream stream, Image image, Configuration configuration)
+ private void Write8BitPixelData(Configuration configuration, Stream stream, Image image)
where TPixel : unmanaged, IPixel
{
bool isL8 = typeof(TPixel) == typeof(L8);
@@ -452,7 +452,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
}
else
{
- this.Write8BitColor(stream, image, colorPalette, configuration);
+ this.Write8BitColor(configuration, stream, image, colorPalette);
}
}
@@ -460,11 +460,11 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
/// Writes an 8 bit color image with a color palette. The color palette has 256 entry's with 4 bytes for each entry.
///
/// The type of the pixel.
+ /// The global configuration.
/// The to write to.
/// The containing pixel data.
/// A byte span of size 1024 for the color palette.
- /// The global configuration
- private void Write8BitColor(Stream stream, Image image, Span colorPalette, Configuration configuration)
+ private void Write8BitColor(Configuration configuration, Stream stream, Image image, Span colorPalette)
where TPixel : unmanaged, IPixel
{
using IQuantizer frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer(configuration);
@@ -473,7 +473,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
using IndexedImageFrame quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
ReadOnlySpan quantizedColorPalette = quantized.Palette.Span;
- WriteColorPalette(stream, quantizedColorPalette, colorPalette, configuration);
+ WriteColorPalette(configuration, stream, quantizedColorPalette, colorPalette);
for (int y = image.Height - 1; y >= 0; y--)
{
@@ -529,10 +529,10 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
/// Writes 4 bit pixel data with a color palette. The color palette has 16 entry's with 4 bytes for each entry.
///
/// The type of the pixel.
+ /// The global configuration.
/// The to write to.
/// The containing pixel data.
- /// The global configuration.
- private void Write4BitPixelData(Stream stream, Image image, Configuration configuration)
+ private void Write4BitPixelData(Configuration configuration, Stream stream, Image image)
where TPixel : unmanaged, IPixel
{
using IQuantizer frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer(configuration, new QuantizerOptions()
@@ -547,7 +547,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
Span colorPalette = colorPaletteBuffer.GetSpan();
ReadOnlySpan quantizedColorPalette = quantized.Palette.Span;
- WriteColorPalette(stream, quantizedColorPalette, colorPalette, configuration);
+ WriteColorPalette(configuration, stream, quantizedColorPalette, colorPalette);
ReadOnlySpan pixelRowSpan = quantized.DangerousGetRowSpan(0);
int rowPadding = pixelRowSpan.Length % 2 != 0 ? this.padding - 1 : this.padding;
@@ -577,10 +577,10 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
/// Writes 2 bit pixel data with a color palette. The color palette has 4 entry's with 4 bytes for each entry.
///
/// The type of the pixel.
+ /// The global configuration.
/// The to write to.
/// The containing pixel data.
- /// The global configuration
- private void Write2BitPixelData(Stream stream, Image image, Configuration configuration)
+ private void Write2BitPixelData(Configuration configuration, Stream stream, Image image)
where TPixel : unmanaged, IPixel
{
using IQuantizer frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer(configuration, new QuantizerOptions()
@@ -595,7 +595,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
Span colorPalette = colorPaletteBuffer.GetSpan();
ReadOnlySpan quantizedColorPalette = quantized.Palette.Span;
- WriteColorPalette(stream, quantizedColorPalette, colorPalette, configuration);
+ WriteColorPalette(configuration, stream, quantizedColorPalette, colorPalette);
ReadOnlySpan pixelRowSpan = quantized.DangerousGetRowSpan(0);
int rowPadding = pixelRowSpan.Length % 4 != 0 ? this.padding - 1 : this.padding;
@@ -634,10 +634,10 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
/// Writes 1 bit pixel data with a color palette. The color palette has 2 entry's with 4 bytes for each entry.
///
/// The type of the pixel.
+ /// The global configuration.
/// The to write to.
/// The containing pixel data.
- /// The global configuration
- private void Write1BitPixelData(Stream stream, Image image, Configuration configuration)
+ private void Write1BitPixelData(Configuration configuration, Stream stream, Image image)
where TPixel : unmanaged, IPixel
{
using IQuantizer frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer(configuration, new QuantizerOptions()
@@ -652,7 +652,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
Span colorPalette = colorPaletteBuffer.GetSpan();
ReadOnlySpan quantizedColorPalette = quantized.Palette.Span;
- WriteColorPalette(stream, quantizedColorPalette, colorPalette, configuration);
+ WriteColorPalette(configuration, stream, quantizedColorPalette, colorPalette);
ReadOnlySpan quantizedPixelRow = quantized.DangerousGetRowSpan(0);
int rowPadding = quantizedPixelRow.Length % 8 != 0 ? this.padding - 1 : this.padding;
@@ -684,11 +684,11 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
/// Writes the color palette to the stream. The color palette has 4 bytes for each entry.
///
/// The type of the pixel.
+ /// The global configuration.
/// The to write to.
/// The color palette from the quantized image.
/// A temporary byte span to write the color palette to.
- /// The global configuration
- private static void WriteColorPalette(Stream stream, ReadOnlySpan quantizedColorPalette, Span colorPalette, Configuration configuration)
+ private static void WriteColorPalette(Configuration configuration, Stream stream, ReadOnlySpan quantizedColorPalette, Span colorPalette)
where TPixel : unmanaged, IPixel
{
int quantizedColorBytes = quantizedColorPalette.Length * 4;
diff --git a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs
index 37ebc39bac..1136fbc9da 100644
--- a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs
@@ -26,7 +26,7 @@ public struct OctreeQuantizer : IQuantizer
private readonly int maxColors;
private readonly int bitDepth;
private readonly Octree octree;
- private IMemoryOwner paletteOwner;
+ private readonly IMemoryOwner paletteOwner;
private ReadOnlyMemory palette;
private EuclideanPixelMap? pixelMap;
private readonly bool isDithering;
@@ -38,11 +38,8 @@ public struct OctreeQuantizer : IQuantizer
/// The configuration which allows altering default behaviour or extending the library.
/// The quantizer options defining quantization rules.
[MethodImpl(InliningOptions.ShortMethod)]
- public OctreeQuantizer(Configuration? configuration, QuantizerOptions options)
+ public OctreeQuantizer(Configuration configuration, QuantizerOptions options)
{
- Guard.NotNull(configuration, nameof(configuration));
- Guard.NotNull(options, nameof(options));
-
this.Configuration = configuration;
this.Options = options;
diff --git a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs
index 182bed2382..86db9f6f01 100644
--- a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs
@@ -17,10 +17,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization;
"Design",
"CA1001:Types that own disposable fields should be disposable",
Justification = "https://github.com/dotnet/roslyn-analyzers/issues/6151")]
-internal struct PaletteQuantizer : IQuantizer
+internal readonly struct PaletteQuantizer : IQuantizer
where TPixel : unmanaged, IPixel
{
- private EuclideanPixelMap pixelMap;
+ private readonly EuclideanPixelMap pixelMap;
///
/// Initializes a new instance of the struct.
@@ -29,7 +29,7 @@ internal struct PaletteQuantizer : IQuantizer
/// The quantizer options defining quantization rules.
/// The palette to use.
[MethodImpl(InliningOptions.ShortMethod)]
- public PaletteQuantizer(Configuration? configuration, QuantizerOptions options, ReadOnlyMemory palette)
+ public PaletteQuantizer(Configuration configuration, QuantizerOptions options, ReadOnlyMemory palette)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(options, nameof(options));
@@ -65,8 +65,5 @@ internal struct PaletteQuantizer : IQuantizer
=> (byte)this.pixelMap.GetClosestColor(color, out match);
///
- public void Dispose()
- {
- this.pixelMap.Dispose();
- }
+ public void Dispose() => this.pixelMap.Dispose();
}
diff --git a/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs
index c04dbe1918..edf293d39e 100644
--- a/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs
@@ -69,9 +69,9 @@ internal struct WuQuantizer : IQuantizer
///
private const int TableLength = IndexCount * IndexCount * IndexCount * IndexAlphaCount;
- private IMemoryOwner momentsOwner;
- private IMemoryOwner tagsOwner;
- private IMemoryOwner paletteOwner;
+ private readonly IMemoryOwner momentsOwner;
+ private readonly IMemoryOwner tagsOwner;
+ private readonly IMemoryOwner paletteOwner;
private ReadOnlyMemory palette;
private int maxColors;
private readonly Box[] colorCube;
@@ -85,7 +85,7 @@ internal struct WuQuantizer : IQuantizer
/// The configuration which allows altering default behaviour or extending the library.
/// The quantizer options defining quantization rules.
[MethodImpl(InliningOptions.ShortMethod)]
- public WuQuantizer(Configuration? configuration, QuantizerOptions options)
+ public WuQuantizer(Configuration configuration, QuantizerOptions options)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(options, nameof(options));