Skip to content

Commit 92ac2d7

Browse files
Merge branch 'main' into js/decoder-options
2 parents 52a26d1 + 1b6728b commit 92ac2d7

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

src/ImageSharp/Formats/Png/PngDecoderCore.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancella
383383
/// <summary>
384384
/// Reads the least significant bits from the byte pair with the others set to 0.
385385
/// </summary>
386-
/// <param name="buffer">The source buffer</param>
387-
/// <param name="offset">THe offset</param>
386+
/// <param name="buffer">The source buffer.</param>
387+
/// <param name="offset">THe offset.</param>
388388
/// <returns>The <see cref="int"/></returns>
389389
[MethodImpl(MethodImplOptions.AggressiveInlining)]
390390
private static byte ReadByteLittleEndian(ReadOnlySpan<byte> buffer, int offset)
@@ -395,7 +395,7 @@ private static byte ReadByteLittleEndian(ReadOnlySpan<byte> buffer, int offset)
395395
/// specified number of bits.
396396
/// </summary>
397397
/// <param name="source">The bytes to convert from. Cannot be empty.</param>
398-
/// <param name="bytesPerScanline">The number of bytes per scanline</param>
398+
/// <param name="bytesPerScanline">The number of bytes per scanline.</param>
399399
/// <param name="bits">The number of bits per value.</param>
400400
/// <param name="buffer">The new array.</param>
401401
/// <returns>The resulting <see cref="ReadOnlySpan{Byte}"/> array.</returns>
@@ -976,6 +976,10 @@ private void AssignTransparentMarkers(ReadOnlySpan<byte> alpha, PngMetadata pngM
976976
pngMetadata.HasTransparency = true;
977977
}
978978
}
979+
else if (this.pngColorType == PngColorType.Palette && alpha.Length > 0)
980+
{
981+
pngMetadata.HasTransparency = true;
982+
}
979983
}
980984

981985
/// <summary>

tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,30 @@ public void Issue1765<TPixel>(TestImageProvider<TPixel> provider)
492492
Assert.Null(ex);
493493
}
494494

495+
// https://github.com/SixLabors/ImageSharp/issues/2209
496+
[Theory]
497+
[WithFile(TestImages.Png.Issue2209IndexedWithTransparency, PixelTypes.Rgba32)]
498+
public void Issue2209_Decode_HasTransparencyIsTrue<TPixel>(TestImageProvider<TPixel> provider)
499+
where TPixel : unmanaged, IPixel<TPixel>
500+
{
501+
using Image<TPixel> image = provider.GetImage(PngDecoder);
502+
image.DebugSave(provider);
503+
PngMetadata metadata = image.Metadata.GetPngMetadata();
504+
Assert.True(metadata.HasTransparency);
505+
}
506+
507+
// https://github.com/SixLabors/ImageSharp/issues/2209
508+
[Theory]
509+
[InlineData(TestImages.Png.Issue2209IndexedWithTransparency)]
510+
public void Issue2209_Identify_HasTransparencyIsTrue(string imagePath)
511+
{
512+
var testFile = TestFile.Create(imagePath);
513+
using var stream = new MemoryStream(testFile.Bytes, false);
514+
IImageInfo imageInfo = Image.Identify(stream);
515+
PngMetadata metadata = imageInfo.Metadata.GetPngMetadata();
516+
Assert.True(metadata.HasTransparency);
517+
}
518+
495519
// https://github.com/SixLabors/ImageSharp/issues/410
496520
[Theory]
497521
[WithFile(TestImages.Png.Bad.Issue410_MalformedApplePng, PixelTypes.Rgba32)]

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ public static class Png
125125
// Discussion 1875: https://github.com/SixLabors/ImageSharp/discussions/1875
126126
public const string Issue1875 = "Png/raw-profile-type-exif.png";
127127

128+
// Issue 2209: https://github.com/SixLabors/ImageSharp/issues/2209
129+
public const string Issue2209IndexedWithTransparency = "Png/issues/Issue_2209.png";
130+
128131
public static class Bad
129132
{
130133
public const string MissingDataChunk = "Png/xdtn0g01.png";
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)