@@ -30,8 +30,10 @@ public static void AdjustOptions<TPixel>(
3030 // Always take the encoder options over the metadata values.
3131 options . Gamma ??= pngMetadata . Gamma ;
3232
33- options . ColorType ??= SuggestColorType < TPixel > ( ) ?? pngMetadata . ColorType ;
34- options . BitDepth ??= SuggestBitDepth < TPixel > ( ) ?? pngMetadata . BitDepth ;
33+ // Use options, then check metadata, if nothing set there then we suggest
34+ // a sensible default based upon the pixel format.
35+ options . ColorType ??= pngMetadata . ColorType ?? SuggestColorType < TPixel > ( ) ;
36+ options . BitDepth ??= pngMetadata . BitDepth ?? SuggestBitDepth < TPixel > ( ) ;
3537
3638 options . InterlaceMethod ??= pngMetadata . InterlaceMethod ;
3739
@@ -148,7 +150,7 @@ private static int CalculateBytesPerPixel(PngColorType? pngColorType, bool use16
148150 /// Returns a suggested <see cref="PngColorType"/> for the given <typeparamref name="TPixel"/>
149151 /// This is not exhaustive but covers many common pixel formats.
150152 /// </summary>
151- private static PngColorType ? SuggestColorType < TPixel > ( )
153+ private static PngColorType SuggestColorType < TPixel > ( )
152154 where TPixel : struct , IPixel < TPixel >
153155 {
154156 return typeof ( TPixel ) switch
@@ -166,15 +168,15 @@ private static int CalculateBytesPerPixel(PngColorType? pngColorType, bool use16
166168 Type t when t == typeof ( Rgb48 ) => PngColorType . Rgb ,
167169 Type t when t == typeof ( Rgba64 ) => PngColorType . RgbWithAlpha ,
168170 Type t when t == typeof ( RgbaVector ) => PngColorType . RgbWithAlpha ,
169- _ => default ( PngColorType ? )
171+ _ => PngColorType . RgbWithAlpha
170172 } ;
171173 }
172174
173175 /// <summary>
174176 /// Returns a suggested <see cref="PngBitDepth"/> for the given <typeparamref name="TPixel"/>
175177 /// This is not exhaustive but covers many common pixel formats.
176178 /// </summary>
177- private static PngBitDepth ? SuggestBitDepth < TPixel > ( )
179+ private static PngBitDepth SuggestBitDepth < TPixel > ( )
178180 where TPixel : struct , IPixel < TPixel >
179181 {
180182 return typeof ( TPixel ) switch
@@ -192,7 +194,7 @@ private static int CalculateBytesPerPixel(PngColorType? pngColorType, bool use16
192194 Type t when t == typeof ( Rgb48 ) => PngBitDepth . Bit16 ,
193195 Type t when t == typeof ( Rgba64 ) => PngBitDepth . Bit16 ,
194196 Type t when t == typeof ( RgbaVector ) => PngBitDepth . Bit16 ,
195- _ => default ( PngBitDepth ? )
197+ _ => PngBitDepth . Bit8
196198 } ;
197199 }
198200 }
0 commit comments