File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
src/ImageSharp/Formats/Png
tests/ImageSharp.Tests/Formats/Png Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ public static PngMetadata FromFormatConnectingMetadata(FormatConnectingMetadata
111111 color = PngColorType . Rgb ;
112112 break ;
113113 default :
114- if ( colorType . HasFlag ( PixelColorType . Luminance ) )
114+ if ( colorType . HasFlag ( PixelColorType . Luminance | PixelColorType . Alpha ) )
115115 {
116116 color = PngColorType . GrayscaleWithAlpha ;
117117 break ;
Original file line number Diff line number Diff line change @@ -336,4 +336,29 @@ public void Identify_ReadsLegacyExifData(string imagePath)
336336
337337 Assert . Equal ( 42 , ( int ) exif . GetValue ( ExifTag . ImageNumber ) . Value ) ;
338338 }
339+
340+
341+ [ Theory ]
342+ [ InlineData ( PixelColorType . Binary , PngColorType . Palette ) ]
343+ [ InlineData ( PixelColorType . Indexed , PngColorType . Palette ) ]
344+ [ InlineData ( PixelColorType . Luminance , PngColorType . Grayscale ) ]
345+ [ InlineData ( PixelColorType . RGB , PngColorType . Rgb ) ]
346+ [ InlineData ( PixelColorType . BGR , PngColorType . Rgb ) ]
347+ [ InlineData ( PixelColorType . YCbCr , PngColorType . RgbWithAlpha ) ]
348+ [ InlineData ( PixelColorType . CMYK , PngColorType . RgbWithAlpha ) ]
349+ [ InlineData ( PixelColorType . YCCK , PngColorType . RgbWithAlpha ) ]
350+ public void FromFormatConnectingMetadata_ConvertColorTypeAsExpected ( PixelColorType pixelColorType , PngColorType expectedPngColorType )
351+ {
352+ FormatConnectingMetadata formatConnectingMetadata = new ( )
353+ {
354+ PixelTypeInfo = new PixelTypeInfo ( 24 )
355+ {
356+ ColorType = pixelColorType ,
357+ } ,
358+ } ;
359+
360+ PngMetadata actual = PngMetadata . FromFormatConnectingMetadata ( formatConnectingMetadata ) ;
361+
362+ Assert . Equal ( expectedPngColorType , actual . ColorType ) ;
363+ }
339364}
You can’t perform that action at this time.
0 commit comments