@@ -89,7 +89,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
8989 // If the color type was not specified by the user, preserve the color type of the input image.
9090 if ( ! this . colorType . HasValue )
9191 {
92- this . colorType = SetFallbackColorType ( image ) ;
92+ this . colorType = GetFallbackColorType ( image ) ;
9393 }
9494
9595 // Compute number of components based on color type in options.
@@ -162,31 +162,28 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
162162 /// returns <see langword="null"/> defering the field assignment
163163 /// to <see cref="InitQuantizationTables(int, JpegMetadata, out Block8x8F, out Block8x8F)"/>.
164164 /// </summary>
165- private static JpegColorType ? SetFallbackColorType < TPixel > ( Image < TPixel > image )
165+ private static JpegColorType ? GetFallbackColorType < TPixel > ( Image < TPixel > image )
166166 where TPixel : unmanaged, IPixel < TPixel >
167167 {
168168 // First inspect the image metadata.
169169 JpegColorType ? colorType = null ;
170170 JpegMetadata metadata = image . Metadata . GetJpegMetadata ( ) ;
171171 if ( IsSupportedColorType ( metadata . ColorType ) )
172172 {
173- colorType = metadata . ColorType ;
173+ return metadata . ColorType ;
174174 }
175175
176176 // Secondly, inspect the pixel type.
177177 // TODO: PixelTypeInfo should contain a component count!
178- if ( colorType is null )
179- {
180- bool isGrayscale =
181- typeof ( TPixel ) == typeof ( L8 ) || typeof ( TPixel ) == typeof ( L16 ) ||
182- typeof ( TPixel ) == typeof ( La16 ) || typeof ( TPixel ) == typeof ( La32 ) ;
178+ bool isGrayscale =
179+ typeof ( TPixel ) == typeof ( L8 ) || typeof ( TPixel ) == typeof ( L16 ) ||
180+ typeof ( TPixel ) == typeof ( La16 ) || typeof ( TPixel ) == typeof ( La32 ) ;
183181
184- // We don't set multi-component color types here since we can set it based upon
185- // the quality in InitQuantizationTables.
186- if ( isGrayscale )
187- {
188- colorType = JpegColorType . Luminance ;
189- }
182+ // We don't set multi-component color types here since we can set it based upon
183+ // the quality in InitQuantizationTables.
184+ if ( isGrayscale )
185+ {
186+ colorType = JpegColorType . Luminance ;
190187 }
191188
192189 return colorType ;
0 commit comments