// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. namespace SixLabors.ImageSharp.Formats.Jpeg; /// /// Encoder for writing the data image to a stream in jpeg format. /// public sealed class JpegEncoder : ImageEncoder { /// /// Backing field for . /// private int? quality; /// /// Gets the quality, that will be used to encode the image. Quality /// index must be between 1 and 100 (compression from max to min). /// Defaults to 75. /// /// Quality factor must be in [1..100] range. public int? Quality { get => this.quality; init { if (value is < 1 or > 100) { throw new ArgumentException("Quality factor must be in [1..100] range."); } this.quality = value; } } /// /// 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; init; } /// /// Gets the jpeg color for encoding. /// public JpegEncodingColor? ColorType { get; init; } /// public override void Encode(Image image, Stream stream) { JpegEncoderCore encoder = new(this); encoder.Encode(image, stream); } /// public override Task EncodeAsync(Image image, Stream stream, CancellationToken cancellationToken) { JpegEncoderCore encoder = new(this); return encoder.EncodeAsync(image, stream, cancellationToken); } }