diff --git a/src/ImageSharp/Formats/IEncoderOptions.cs b/src/ImageSharp/Formats/IEncoderOptions.cs
new file mode 100644
index 0000000000..c05ba23bb5
--- /dev/null
+++ b/src/ImageSharp/Formats/IEncoderOptions.cs
@@ -0,0 +1,33 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+using SixLabors.ImageSharp.Processing.Processors.Quantization;
+
+namespace SixLabors.ImageSharp.Formats;
+
+///
+/// Defines the contract for basic encoder options.
+///
+public interface IEncoderOptions
+{
+ ///
+ /// Gets or sets a value indicating whether to ignore decoded metadata when encoding.
+ ///
+ bool SkipMetadata { get; set; }
+}
+
+///
+/// Defines the contract for encoder options that allow color palette generation via quantization.
+///
+public interface IQuantizingEncoderOptions : IEncoderOptions
+{
+ ///
+ /// Gets or sets the quantizer used to generate the color palette.
+ ///
+ IQuantizer Quantizer { get; set; }
+
+ ///
+ /// Gets or sets the used for quantization when building a global color palette.
+ ///
+ IPixelSamplingStrategy GlobalPixelSamplingStrategy { get; set; }
+}
diff --git a/src/ImageSharp/Formats/ImageDecoderUtilities.cs b/src/ImageSharp/Formats/ImageDecoderUtilities.cs
index 42f15cf976..c05e0d83cb 100644
--- a/src/ImageSharp/Formats/ImageDecoderUtilities.cs
+++ b/src/ImageSharp/Formats/ImageDecoderUtilities.cs
@@ -58,7 +58,7 @@ internal static class ImageDecoderUtilities
Stream stream,
CancellationToken cancellationToken)
{
- using var bufferedReadStream = new BufferedReadStream(configuration, stream);
+ using BufferedReadStream bufferedReadStream = new(configuration, stream);
try
{
@@ -86,7 +86,7 @@ internal static class ImageDecoderUtilities
CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel
{
- using var bufferedReadStream = new BufferedReadStream(configuration, stream);
+ using BufferedReadStream bufferedReadStream = new(configuration, stream);
try
{
diff --git a/src/ImageSharp/Formats/ImageEncoder.cs b/src/ImageSharp/Formats/ImageEncoder.cs
new file mode 100644
index 0000000000..ef4365e380
--- /dev/null
+++ b/src/ImageSharp/Formats/ImageEncoder.cs
@@ -0,0 +1,37 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Processing;
+using SixLabors.ImageSharp.Processing.Processors.Quantization;
+
+namespace SixLabors.ImageSharp.Formats;
+
+///
+/// The base class for all image encoders.
+///
+public abstract class ImageEncoder : IImageEncoder, IEncoderOptions
+{
+ ///
+ public bool SkipMetadata { get; set; }
+
+ ///
+ public abstract void Encode(Image image, Stream stream)
+ where TPixel : unmanaged, IPixel;
+
+ ///
+ public abstract Task EncodeAsync(Image image, Stream stream, CancellationToken cancellationToken)
+ where TPixel : unmanaged, IPixel;
+}
+
+///
+/// The base class for all image encoders that allow color palette generation via quantization.
+///
+public abstract class QuantizingImageEncoder : ImageEncoder, IQuantizingEncoderOptions
+{
+ ///
+ public IQuantizer Quantizer { get; set; } = KnownQuantizers.Octree;
+
+ ///
+ public IPixelSamplingStrategy GlobalPixelSamplingStrategy { get; set; } = new DefaultPixelSamplingStrategy();
+}
diff --git a/src/ImageSharp/Formats/ImageEncoderUtilities.cs b/src/ImageSharp/Formats/ImageEncoderUtilities.cs
index 94f74ea253..665431c952 100644
--- a/src/ImageSharp/Formats/ImageEncoderUtilities.cs
+++ b/src/ImageSharp/Formats/ImageEncoderUtilities.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Six Labors.
+// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Advanced;
@@ -22,11 +22,11 @@ internal static class ImageEncoderUtilities
}
else
{
- using var ms = new MemoryStream();
+ using MemoryStream ms = new();
await DoEncodeAsync(ms);
ms.Position = 0;
await ms.CopyToAsync(stream, configuration.StreamProcessingBufferSize, cancellationToken)
- .ConfigureAwait(false);
+ .ConfigureAwait(false);
}
Task DoEncodeAsync(Stream innerStream)