Browse Source

Jpeg should not have nullable metadata

pull/2751/head
James Jackson-South 2 years ago
parent
commit
fbefb37a10
  1. 2
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
  2. 25
      src/ImageSharp/Formats/Jpeg/JpegMetadata.cs

2
src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

@ -72,7 +72,7 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals
JpegMetadata jpegMetadata = metadata.GetJpegMetadata(); JpegMetadata jpegMetadata = metadata.GetJpegMetadata();
JpegFrameConfig frameConfig = this.GetFrameConfig(jpegMetadata); JpegFrameConfig frameConfig = this.GetFrameConfig(jpegMetadata);
bool interleaved = this.encoder.Interleaved ?? jpegMetadata.Interleaved ?? true; bool interleaved = this.encoder.Interleaved ?? jpegMetadata.Interleaved;
using JpegFrame frame = new(image, frameConfig, interleaved); using JpegFrame frame = new(image, frameConfig, interleaved);
// Write the Start Of Image marker. // Write the Start Of Image marker.

25
src/ImageSharp/Formats/Jpeg/JpegMetadata.cs

@ -48,11 +48,12 @@ public class JpegMetadata : IFormatMetadata<JpegMetadata>
internal int? ChrominanceQuality { get; set; } internal int? ChrominanceQuality { get; set; }
/// <summary> /// <summary>
/// Gets the encoded quality. /// Gets or sets the encoded quality.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Note that jpeg image can have different quality for luminance and chrominance components. /// Note that jpeg image can have different quality for luminance and chrominance components.
/// This property returns maximum value of luma/chroma qualities if both are present. /// This property returns maximum value of luma/chroma qualities if both are present.
/// Setting the quality will update both values.
/// </remarks> /// </remarks>
public int Quality public int Quality
{ {
@ -70,34 +71,40 @@ public class JpegMetadata : IFormatMetadata<JpegMetadata>
return this.ChrominanceQuality ?? Quantization.DefaultQualityFactor; return this.ChrominanceQuality ?? Quantization.DefaultQualityFactor;
} }
set
{
this.LuminanceQuality = value;
this.ChrominanceQuality = value;
}
} }
/// <summary> /// <summary>
/// Gets the color type. /// Gets or sets the color type.
/// </summary> /// </summary>
public JpegEncodingColor? ColorType { get; internal set; } public JpegEncodingColor ColorType { get; set; } = JpegEncodingColor.YCbCrRatio420;
/// <summary> /// <summary>
/// Gets the component encoding mode. /// Gets or sets a value indicating whether the component encoding mode should be interleaved.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Interleaved encoding mode encodes all color components in a single scan. /// Interleaved encoding mode encodes all color components in a single scan.
/// Non-interleaved encoding mode encodes each color component in a separate scan. /// Non-interleaved encoding mode encodes each color component in a separate scan.
/// </remarks> /// </remarks>
public bool? Interleaved { get; internal set; } public bool Interleaved { get; set; } = true;
/// <summary> /// <summary>
/// Gets the scan encoding mode. /// Gets or sets a value indicating whether the scan encoding mode is progressive.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Progressive jpeg images encode component data across multiple scans. /// Progressive jpeg images encode component data across multiple scans.
/// </remarks> /// </remarks>
public bool? Progressive { get; internal set; } public bool Progressive { get; set; }
/// <summary> /// <summary>
/// Gets the comments. /// Gets or sets collection of comments.
/// </summary> /// </summary>
public IList<JpegComData> Comments { get; } public IList<JpegComData> Comments { get; set; } = [];
/// <inheritdoc/> /// <inheritdoc/>
public static JpegMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata) public static JpegMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata)

Loading…
Cancel
Save