Browse Source
Merge pull request #3034 from Socolin/fix-3033
Fix PixelColorType.YCbCr wrongly interpreted as grayscale in PngEncoder
pull/3036/head
James Jackson-South
2 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
26 additions and
1 deletions
-
src/ImageSharp/Formats/Png/PngMetadata.cs
-
tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs
|
|
|
@ -111,7 +111,7 @@ public class PngMetadata : IFormatMetadata<PngMetadata> |
|
|
|
color = PngColorType.Rgb; |
|
|
|
break; |
|
|
|
default: |
|
|
|
if (colorType.HasFlag(PixelColorType.Luminance)) |
|
|
|
if (colorType.HasFlag(PixelColorType.Luminance | PixelColorType.Alpha)) |
|
|
|
{ |
|
|
|
color = PngColorType.GrayscaleWithAlpha; |
|
|
|
break; |
|
|
|
|
|
|
|
@ -336,4 +336,29 @@ public class PngMetadataTests |
|
|
|
|
|
|
|
Assert.Equal(42, (int)exif.GetValue(ExifTag.ImageNumber).Value); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(PixelColorType.Binary, PngColorType.Palette)] |
|
|
|
[InlineData(PixelColorType.Indexed, PngColorType.Palette)] |
|
|
|
[InlineData(PixelColorType.Luminance, PngColorType.Grayscale)] |
|
|
|
[InlineData(PixelColorType.RGB, PngColorType.Rgb)] |
|
|
|
[InlineData(PixelColorType.BGR, PngColorType.Rgb)] |
|
|
|
[InlineData(PixelColorType.YCbCr, PngColorType.RgbWithAlpha)] |
|
|
|
[InlineData(PixelColorType.CMYK, PngColorType.RgbWithAlpha)] |
|
|
|
[InlineData(PixelColorType.YCCK, PngColorType.RgbWithAlpha)] |
|
|
|
public void FromFormatConnectingMetadata_ConvertColorTypeAsExpected(PixelColorType pixelColorType, PngColorType expectedPngColorType) |
|
|
|
{ |
|
|
|
FormatConnectingMetadata formatConnectingMetadata = new() |
|
|
|
{ |
|
|
|
PixelTypeInfo = new PixelTypeInfo(24) |
|
|
|
{ |
|
|
|
ColorType = pixelColorType, |
|
|
|
}, |
|
|
|
}; |
|
|
|
|
|
|
|
PngMetadata actual = PngMetadata.FromFormatConnectingMetadata(formatConnectingMetadata); |
|
|
|
|
|
|
|
Assert.Equal(expectedPngColorType, actual.ColorType); |
|
|
|
} |
|
|
|
} |
|
|
|
|