@@ -33,20 +33,15 @@ internal sealed unsafe class JpegEncoderCore : IImageEncoderInternals
3333 /// </summary>
3434 private readonly byte [ ] buffer = new byte [ 20 ] ;
3535
36- /// <summary>
37- /// Gets or sets the subsampling method to use.
38- /// </summary>
39- private JpegSubsample ? subsample ;
40-
4136 /// <summary>
4237 /// The quality, that will be used to encode the image.
4338 /// </summary>
4439 private readonly int ? quality ;
4540
4641 /// <summary>
47- /// Gets or sets the subsampling method to use.
42+ /// Gets or sets the colorspace to use.
4843 /// </summary>
49- private readonly JpegColorType ? colorType ;
44+ private JpegColorType ? colorType ;
5045
5146 /// <summary>
5247 /// The output stream. All attempted writes after the first error become no-ops.
@@ -56,11 +51,10 @@ internal sealed unsafe class JpegEncoderCore : IImageEncoderInternals
5651 /// <summary>
5752 /// Initializes a new instance of the <see cref="JpegEncoderCore"/> class.
5853 /// </summary>
59- /// <param name="options">The options</param>
54+ /// <param name="options">The options. </param>
6055 public JpegEncoderCore ( IJpegEncoderOptions options )
6156 {
6257 this . quality = options . Quality ;
63- this . subsample = options . Subsample ;
6458 this . colorType = options . ColorType ;
6559 }
6660
@@ -118,21 +112,22 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
118112 var scanEncoder = new HuffmanScanEncoder ( stream ) ;
119113 if ( this . colorType == JpegColorType . Luminance )
120114 {
121- // luminance quantization table only
115+ // luminance quantization table only.
122116 scanEncoder . EncodeGrayscale ( image , ref luminanceQuantTable , cancellationToken ) ;
123117 }
124118 else
125119 {
126- // luminance and chrominance quantization tables
127- switch ( this . subsample )
120+ // luminance and chrominance quantization tables.
121+ switch ( this . colorType )
128122 {
129- case JpegSubsample . Ratio444 :
123+ case JpegColorType . YCbCrRatio444 :
124+ case JpegColorType . Luminance :
130125 scanEncoder . Encode444 ( image , ref luminanceQuantTable , ref chrominanceQuantTable , cancellationToken ) ;
131126 break ;
132- case JpegSubsample . Ratio420 :
127+ case JpegColorType . YCbCrRatio420 :
133128 scanEncoder . Encode420 ( image , ref luminanceQuantTable , ref chrominanceQuantTable , cancellationToken ) ;
134129 break ;
135- case JpegSubsample . Rgb :
130+ case JpegColorType . Rgb :
136131 scanEncoder . EncodeRgb ( image , ref luminanceQuantTable , ref chrominanceQuantTable , cancellationToken ) ;
137132 break ;
138133 }
@@ -151,7 +146,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
151146 /// <returns>The component Ids.</returns>
152147 private byte [ ] GetComponentIds ( )
153148 {
154- if ( this . subsample == JpegSubsample . Rgb )
149+ if ( this . colorType == JpegColorType . Rgb )
155150 {
156151 return new byte [ ] { 82 , 71 , 66 } ;
157152 }
@@ -268,7 +263,7 @@ private void WriteDefineHuffmanTables(int componentCount)
268263 /// </summary>
269264 private void WriteDefineQuantizationTables ( ref Block8x8F luminanceQuantTable , ref Block8x8F chrominanceQuantTable )
270265 {
271- // Marker + quantization table lengths
266+ // Marker + quantization table lengths.
272267 int markerlen = 2 + ( QuantizationTableCount * ( 1 + Block8x8F . Size ) ) ;
273268 this . WriteMarkerHeader ( JpegConstants . Markers . DQT , markerlen ) ;
274269
@@ -404,7 +399,7 @@ private void WriteAppHeader(int length, byte appMarker)
404399 /// </summary>
405400 /// <param name="iccProfile">The ICC profile to write.</param>
406401 /// <exception cref="ImageFormatException">
407- /// Thrown if any of the ICC profiles size exceeds the limit
402+ /// Thrown if any of the ICC profiles size exceeds the limit.
408403 /// </exception>
409404 private void WriteIccProfile ( IccProfile iccProfile )
410405 {
@@ -424,7 +419,7 @@ private void WriteIccProfile(IccProfile iccProfile)
424419 return ;
425420 }
426421
427- // Calculate the number of markers we'll need, rounding up of course
422+ // Calculate the number of markers we'll need, rounding up of course.
428423 int dataLength = data . Length ;
429424 int count = dataLength / MaxData ;
430425
@@ -531,18 +526,18 @@ private void WriteStartOfFrame(int width, int height, int componentCount, byte[]
531526 }
532527 else
533528 {
534- switch ( this . subsample )
529+ switch ( this . colorType )
535530 {
536- case JpegSubsample . Rgb :
537- case JpegSubsample . Ratio444 :
531+ case JpegColorType . YCbCrRatio444 :
532+ case JpegColorType . Rgb :
538533 subsamples = stackalloc byte [ ]
539534 {
540535 0x11 ,
541536 0x11 ,
542537 0x11
543538 } ;
544539 break ;
545- case JpegSubsample . Ratio420 :
540+ case JpegColorType . YCbCrRatio420 :
546541 subsamples = stackalloc byte [ ]
547542 {
548543 0x22 ,
@@ -685,9 +680,9 @@ private void InitQuantizationTables(int componentCount, JpegMetadata metadata, o
685680 chromaQuality = Numerics . Clamp ( chromaQuality , 1 , 100 ) ;
686681 chrominanceQuantTable = Quantization . ScaleChrominanceTable ( chromaQuality ) ;
687682
688- if ( ! this . subsample . HasValue )
683+ if ( ! this . colorType . HasValue )
689684 {
690- this . subsample = chromaQuality >= 91 ? JpegSubsample . Ratio444 : JpegSubsample . Ratio420 ;
685+ this . colorType = chromaQuality >= 91 ? JpegColorType . YCbCrRatio444 : JpegColorType . YCbCrRatio420 ;
691686 }
692687 }
693688 }
0 commit comments