diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
index a410a862b5..4d2f52ccfa 100644
--- a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
@@ -2,16 +2,20 @@
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.Processing.Processors.Quantization;
+using SixLabors.ImageSharp.Processing;
namespace SixLabors.ImageSharp.Formats.Bmp;
///
/// Image encoder for writing an image to a stream as a Windows bitmap.
///
-public sealed class BmpEncoder : IImageEncoder, IBmpEncoderOptions
+public sealed class BmpEncoder : QuantizingImageEncoder
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public BmpEncoder() => this.Quantizer = KnownQuantizers.Wu;
+
///
/// Gets or sets the number of bits per pixel.
///
@@ -25,25 +29,17 @@ public sealed class BmpEncoder : IImageEncoder, IBmpEncoderOptions
///
public bool SupportTransparency { get; set; }
- ///
- /// Gets or sets the quantizer for reducing the color count for 8-Bit images.
- /// Defaults to Wu Quantizer.
- ///
- public IQuantizer Quantizer { get; set; }
-
///
- public void Encode(Image image, Stream stream)
- where TPixel : unmanaged, IPixel
+ public override void Encode(Image image, Stream stream)
{
- var encoder = new BmpEncoderCore(this, image.GetMemoryAllocator());
+ BmpEncoderCore encoder = new(this, image.GetMemoryAllocator());
encoder.Encode(image, stream);
}
///
- public Task EncodeAsync(Image image, Stream stream, CancellationToken cancellationToken)
- where TPixel : unmanaged, IPixel
+ public override Task EncodeAsync(Image image, Stream stream, CancellationToken cancellationToken)
{
- var encoder = new BmpEncoderCore(this, image.GetMemoryAllocator());
+ BmpEncoderCore encoder = new(this, image.GetMemoryAllocator());
return encoder.EncodeAsync(image, stream, cancellationToken);
}
}
diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
index 471e741826..f2821b288e 100644
--- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
@@ -95,14 +95,14 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
///
/// Initializes a new instance of the class.
///
- /// The encoder options.
+ /// The Bmp encoder.
/// The memory manager.
- public BmpEncoderCore(IBmpEncoderOptions options, MemoryAllocator memoryAllocator)
+ public BmpEncoderCore(BmpEncoder encoder, MemoryAllocator memoryAllocator)
{
this.memoryAllocator = memoryAllocator;
- this.bitsPerPixel = options.BitsPerPixel;
- this.quantizer = options.Quantizer ?? KnownQuantizers.Octree;
- this.infoHeaderType = options.SupportTransparency ? BmpInfoHeaderType.WinVersion4 : BmpInfoHeaderType.WinVersion3;
+ this.bitsPerPixel = encoder.BitsPerPixel;
+ this.quantizer = encoder.Quantizer ?? KnownQuantizers.Octree;
+ this.infoHeaderType = encoder.SupportTransparency ? BmpInfoHeaderType.WinVersion4 : BmpInfoHeaderType.WinVersion3;
}
///
diff --git a/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs b/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs
deleted file mode 100644
index c2ce99ec71..0000000000
--- a/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (c) Six Labors.
-// Licensed under the Six Labors Split License.
-
-using SixLabors.ImageSharp.Processing.Processors.Quantization;
-
-namespace SixLabors.ImageSharp.Formats.Bmp;
-
-///
-/// Configuration options for use during bmp encoding.
-///
-internal interface IBmpEncoderOptions
-{
- ///
- /// Gets the number of bits per pixel.
- ///
- BmpBitsPerPixel? BitsPerPixel { get; }
-
- ///
- /// Gets a value indicating whether the encoder should support transparency.
- /// Note: Transparency support only works together with 32 bits per pixel. This option will
- /// change the default behavior of the encoder of writing a bitmap version 3 info header with no compression.
- /// Instead a bitmap version 4 info header will be written with the BITFIELDS compression.
- ///
- bool SupportTransparency { get; }
-
- ///
- /// Gets the quantizer for reducing the color count for 8-Bit, 4-Bit, and 1-Bit images.
- ///
- IQuantizer Quantizer { get; }
-}