Skip to content

Commit fbefb37

Browse files
Jpeg should not have nullable metadata
1 parent cbd1b93 commit fbefb37

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
7272
JpegMetadata jpegMetadata = metadata.GetJpegMetadata();
7373
JpegFrameConfig frameConfig = this.GetFrameConfig(jpegMetadata);
7474

75-
bool interleaved = this.encoder.Interleaved ?? jpegMetadata.Interleaved ?? true;
75+
bool interleaved = this.encoder.Interleaved ?? jpegMetadata.Interleaved;
7676
using JpegFrame frame = new(image, frameConfig, interleaved);
7777

7878
// Write the Start Of Image marker.

src/ImageSharp/Formats/Jpeg/JpegMetadata.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ private JpegMetadata(JpegMetadata other)
4848
internal int? ChrominanceQuality { get; set; }
4949

5050
/// <summary>
51-
/// Gets the encoded quality.
51+
/// Gets or sets the encoded quality.
5252
/// </summary>
5353
/// <remarks>
5454
/// Note that jpeg image can have different quality for luminance and chrominance components.
5555
/// This property returns maximum value of luma/chroma qualities if both are present.
56+
/// Setting the quality will update both values.
5657
/// </remarks>
5758
public int Quality
5859
{
@@ -70,34 +71,40 @@ public int Quality
7071

7172
return this.ChrominanceQuality ?? Quantization.DefaultQualityFactor;
7273
}
74+
75+
set
76+
{
77+
this.LuminanceQuality = value;
78+
this.ChrominanceQuality = value;
79+
}
7380
}
7481

7582
/// <summary>
76-
/// Gets the color type.
83+
/// Gets or sets the color type.
7784
/// </summary>
78-
public JpegEncodingColor? ColorType { get; internal set; }
85+
public JpegEncodingColor ColorType { get; set; } = JpegEncodingColor.YCbCrRatio420;
7986

8087
/// <summary>
81-
/// Gets the component encoding mode.
88+
/// Gets or sets a value indicating whether the component encoding mode should be interleaved.
8289
/// </summary>
8390
/// <remarks>
8491
/// Interleaved encoding mode encodes all color components in a single scan.
8592
/// Non-interleaved encoding mode encodes each color component in a separate scan.
8693
/// </remarks>
87-
public bool? Interleaved { get; internal set; }
94+
public bool Interleaved { get; set; } = true;
8895

8996
/// <summary>
90-
/// Gets the scan encoding mode.
97+
/// Gets or sets a value indicating whether the scan encoding mode is progressive.
9198
/// </summary>
9299
/// <remarks>
93100
/// Progressive jpeg images encode component data across multiple scans.
94101
/// </remarks>
95-
public bool? Progressive { get; internal set; }
102+
public bool Progressive { get; set; }
96103

97104
/// <summary>
98-
/// Gets the comments.
105+
/// Gets or sets collection of comments.
99106
/// </summary>
100-
public IList<JpegComData> Comments { get; }
107+
public IList<JpegComData> Comments { get; set; } = [];
101108

102109
/// <inheritdoc/>
103110
public static JpegMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata)

0 commit comments

Comments
 (0)