diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs index 216eb59cd0..9e20da170a 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs @@ -11,17 +11,17 @@ namespace SixLabors.ImageSharp.Formats.Bmp; public sealed class BmpEncoder : QuantizingImageEncoder { /// - /// Gets or sets the number of bits per pixel. + /// Gets the number of bits per pixel. /// - public BmpBitsPerPixel? BitsPerPixel { get; set; } + public BmpBitsPerPixel? BitsPerPixel { get; init; } /// - /// Gets or sets a value indicating whether the encoder should support transparency. + /// 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. /// - public bool SupportTransparency { get; set; } + public bool SupportTransparency { get; init; } /// public override void Encode(Image image, Stream stream) diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 378fed4a5f..98d8b6233f 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -99,7 +99,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals /// /// Initializes a new instance of the class. /// - /// The Bmp encoder. + /// The encoder with options. /// The memory manager. public BmpEncoderCore(BmpEncoder encoder, MemoryAllocator memoryAllocator) { diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs index 7490490a12..351554eb07 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoder.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs @@ -11,9 +11,9 @@ namespace SixLabors.ImageSharp.Formats.Gif; public sealed class GifEncoder : QuantizingImageEncoder { /// - /// Gets or sets the color table mode: Global or local. + /// Gets the color table mode: Global or local. /// - public GifColorTableMode? ColorTableMode { get; set; } + public GifColorTableMode? ColorTableMode { get; init; } /// public override void Encode(Image image, Stream stream) diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index f1dfd26b42..c0eb160eb3 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -62,7 +62,7 @@ internal sealed class GifEncoderCore : IImageEncoderInternals /// Initializes a new instance of the class. /// /// The configuration which allows altering default behaviour or extending the library. - /// The gif encoder. + /// The encoder with options. public GifEncoderCore(Configuration configuration, GifEncoder encoder) { this.configuration = configuration; diff --git a/src/ImageSharp/Formats/IEncoderOptions.cs b/src/ImageSharp/Formats/IEncoderOptions.cs index c05ba23bb5..5e627f02b3 100644 --- a/src/ImageSharp/Formats/IEncoderOptions.cs +++ b/src/ImageSharp/Formats/IEncoderOptions.cs @@ -11,9 +11,9 @@ namespace SixLabors.ImageSharp.Formats; public interface IEncoderOptions { /// - /// Gets or sets a value indicating whether to ignore decoded metadata when encoding. + /// Gets a value indicating whether to ignore decoded metadata when encoding. /// - bool SkipMetadata { get; set; } + bool SkipMetadata { get; init; } } /// @@ -22,12 +22,12 @@ public interface IEncoderOptions public interface IQuantizingEncoderOptions : IEncoderOptions { /// - /// Gets or sets the quantizer used to generate the color palette. + /// Gets the quantizer used to generate the color palette. /// - IQuantizer Quantizer { get; set; } + IQuantizer Quantizer { get; init; } /// - /// Gets or sets the used for quantization when building a global color palette. + /// Gets the used for quantization when building a global color palette. /// - IPixelSamplingStrategy GlobalPixelSamplingStrategy { get; set; } + IPixelSamplingStrategy GlobalPixelSamplingStrategy { get; init; } } diff --git a/src/ImageSharp/Formats/ImageEncoder.cs b/src/ImageSharp/Formats/ImageEncoder.cs index ef4365e380..ffd87a31bf 100644 --- a/src/ImageSharp/Formats/ImageEncoder.cs +++ b/src/ImageSharp/Formats/ImageEncoder.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Formats; public abstract class ImageEncoder : IImageEncoder, IEncoderOptions { /// - public bool SkipMetadata { get; set; } + public bool SkipMetadata { get; init; } /// public abstract void Encode(Image image, Stream stream) @@ -30,8 +30,8 @@ public abstract class ImageEncoder : IImageEncoder, IEncoderOptions public abstract class QuantizingImageEncoder : ImageEncoder, IQuantizingEncoderOptions { /// - public IQuantizer Quantizer { get; set; } = KnownQuantizers.Octree; + public IQuantizer Quantizer { get; init; } = KnownQuantizers.Octree; /// - public IPixelSamplingStrategy GlobalPixelSamplingStrategy { get; set; } = new DefaultPixelSamplingStrategy(); + public IPixelSamplingStrategy GlobalPixelSamplingStrategy { get; init; } = new DefaultPixelSamplingStrategy(); } diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs index fb48d2b443..cde893b481 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs @@ -14,7 +14,7 @@ public sealed class JpegEncoder : ImageEncoder private int? quality; /// - /// Gets or sets the quality, that will be used to encode the image. Quality + /// Gets the quality, that will be used to encode the image. Quality /// index must be between 0 and 100 (compression from max to min). /// Defaults to 75. /// @@ -22,7 +22,7 @@ public sealed class JpegEncoder : ImageEncoder public int? Quality { get => this.quality; - set + init { if (value is < 1 or > 100) { @@ -34,39 +34,27 @@ public sealed class JpegEncoder : ImageEncoder } /// - /// Gets or sets the component encoding mode. + /// Gets the component encoding mode. /// /// /// Interleaved encoding mode encodes all color components in a single scan. /// Non-interleaved encoding mode encodes each color component in a separate scan. /// - public bool? Interleaved { get; set; } + public bool? Interleaved { get; init; } /// - /// Gets or sets jpeg color for encoding. + /// Gets the jpeg color for encoding. /// - public JpegEncodingColor? ColorType { get; set; } + public JpegEncodingColor? ColorType { get; init; } - /// - /// Encodes the image to the specified stream from the . - /// - /// The pixel format. - /// The to encode from. - /// The to encode the image data to. + /// public override void Encode(Image image, Stream stream) { JpegEncoderCore encoder = new(this); encoder.Encode(image, stream); } - /// - /// Encodes the image to the specified stream from the . - /// - /// The pixel format. - /// The to encode from. - /// The to encode the image data to. - /// The token to monitor for cancellation requests. - /// A representing the asynchronous operation. + /// public override Task EncodeAsync(Image image, Stream stream, CancellationToken cancellationToken) { JpegEncoderCore encoder = new(this); diff --git a/src/ImageSharp/Formats/Pbm/PbmEncoder.cs b/src/ImageSharp/Formats/Pbm/PbmEncoder.cs index e0e93cc11e..6b25347c04 100644 --- a/src/ImageSharp/Formats/Pbm/PbmEncoder.cs +++ b/src/ImageSharp/Formats/Pbm/PbmEncoder.cs @@ -2,7 +2,6 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Pbm; @@ -30,36 +29,34 @@ namespace SixLabors.ImageSharp.Formats.Pbm; /// /// The specification of these images is found at . /// -public sealed class PbmEncoder : IImageEncoder, IPbmEncoderOptions +public sealed class PbmEncoder : ImageEncoder { /// - /// Gets or sets the Encoding of the pixels. + /// Gets the encoding of the pixels. /// - public PbmEncoding? Encoding { get; set; } + public PbmEncoding? Encoding { get; init; } /// - /// Gets or sets the Color type of the resulting image. + /// Gets the Color type of the resulting image. /// - public PbmColorType? ColorType { get; set; } + public PbmColorType? ColorType { get; init; } /// - /// Gets or sets the data type of the pixels components. + /// Gets the Data Type of the pixel components. /// - public PbmComponentType? ComponentType { get; set; } + public PbmComponentType? ComponentType { get; init; } /// - public void Encode(Image image, Stream stream) - where TPixel : unmanaged, IPixel + public override void Encode(Image image, Stream stream) { - var encoder = new PbmEncoderCore(image.GetConfiguration(), this); + PbmEncoderCore encoder = new(image.GetConfiguration(), this); 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 PbmEncoderCore(image.GetConfiguration(), this); + PbmEncoderCore encoder = new(image.GetConfiguration(), this); return encoder.EncodeAsync(image, stream, cancellationToken); } } diff --git a/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs b/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs index c7d8d183c2..8595498ce3 100644 --- a/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs +++ b/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs @@ -22,9 +22,9 @@ internal sealed class PbmEncoderCore : IImageEncoderInternals private Configuration configuration; /// - /// The encoder options. + /// The encoder with options. /// - private readonly IPbmEncoderOptions options; + private readonly PbmEncoder encoder; /// /// The encoding for the pixels. @@ -45,11 +45,11 @@ internal sealed class PbmEncoderCore : IImageEncoderInternals /// Initializes a new instance of the class. /// /// The configuration. - /// The encoder options. - public PbmEncoderCore(Configuration configuration, IPbmEncoderOptions options) + /// The encoder with options. + public PbmEncoderCore(Configuration configuration, PbmEncoder encoder) { this.configuration = configuration; - this.options = options; + this.encoder = encoder; } /// @@ -80,11 +80,11 @@ internal sealed class PbmEncoderCore : IImageEncoderInternals { this.configuration = image.GetConfiguration(); PbmMetadata metadata = image.Metadata.GetPbmMetadata(); - this.encoding = this.options.Encoding ?? metadata.Encoding; - this.colorType = this.options.ColorType ?? metadata.ColorType; + this.encoding = this.encoder.Encoding ?? metadata.Encoding; + this.colorType = this.encoder.ColorType ?? metadata.ColorType; if (this.colorType != PbmColorType.BlackAndWhite) { - this.componentType = this.options.ComponentType ?? metadata.ComponentType; + this.componentType = this.encoder.ComponentType ?? metadata.ComponentType; } else {