Browse Source
Merge pull request #740 from SixLabors/js/fix-1bit-grayscale-trns-png-decode
Use scaled luminance trns comparison.
af/merge-core
James Jackson-South
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
10 additions and
3 deletions
-
src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
-
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
-
tests/ImageSharp.Tests/TestImages.cs
-
tests/Images/Input/Png/gray-1-trns.png
|
|
|
@ -80,6 +80,7 @@ namespace SixLabors.ImageSharp.Formats.Png |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
byte scaledLuminanceTrans = (byte)(luminanceTrans * scaleFactor); |
|
|
|
Rgba32 rgba32 = default; |
|
|
|
for (int x = 0; x < header.Width; x++) |
|
|
|
{ |
|
|
|
@ -87,7 +88,7 @@ namespace SixLabors.ImageSharp.Formats.Png |
|
|
|
rgba32.R = luminance; |
|
|
|
rgba32.G = luminance; |
|
|
|
rgba32.B = luminance; |
|
|
|
rgba32.A = luminance.Equals(luminanceTrans) ? byte.MinValue : byte.MaxValue; |
|
|
|
rgba32.A = luminance.Equals(scaledLuminanceTrans) ? byte.MinValue : byte.MaxValue; |
|
|
|
|
|
|
|
pixel.PackFromRgba32(rgba32); |
|
|
|
Unsafe.Add(ref rowSpanRef, x) = pixel; |
|
|
|
@ -163,6 +164,7 @@ namespace SixLabors.ImageSharp.Formats.Png |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
byte scaledLuminanceTrans = (byte)(luminanceTrans * scaleFactor); |
|
|
|
Rgba32 rgba32 = default; |
|
|
|
for (int x = pixelOffset; x < header.Width; x += increment) |
|
|
|
{ |
|
|
|
@ -170,7 +172,7 @@ namespace SixLabors.ImageSharp.Formats.Png |
|
|
|
rgba32.R = luminance; |
|
|
|
rgba32.G = luminance; |
|
|
|
rgba32.B = luminance; |
|
|
|
rgba32.A = luminance.Equals(luminanceTrans) ? byte.MinValue : byte.MaxValue; |
|
|
|
rgba32.A = luminance.Equals(scaledLuminanceTrans) ? byte.MinValue : byte.MaxValue; |
|
|
|
|
|
|
|
pixel.PackFromRgba32(rgba32); |
|
|
|
Unsafe.Add(ref rowSpanRef, x) = pixel; |
|
|
|
|
|
|
|
@ -40,7 +40,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png |
|
|
|
TestImages.Png.VimImage2, |
|
|
|
|
|
|
|
TestImages.Png.Rgb24BppTrans, |
|
|
|
TestImages.Png.GrayAlpha8Bit |
|
|
|
TestImages.Png.GrayAlpha8Bit, |
|
|
|
TestImages.Png.Gray1BitTrans |
|
|
|
}; |
|
|
|
|
|
|
|
public static readonly string[] TestImages48Bpp = |
|
|
|
|
|
|
|
@ -45,6 +45,7 @@ namespace SixLabors.ImageSharp.Tests |
|
|
|
public const string Kaboom = "Png/kaboom.png"; |
|
|
|
public const string PDSrc = "Png/pd-source.png"; |
|
|
|
public const string PDDest = "Png/pd-dest.png"; |
|
|
|
public const string Gray1BitTrans = "Png/gray-1-trns.png"; |
|
|
|
|
|
|
|
// Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html
|
|
|
|
public const string Filter0 = "Png/filter0.png"; |
|
|
|
|
|
|
|
@ -0,0 +1,3 @@ |
|
|
|
version https://git-lfs.github.com/spec/v1 |
|
|
|
oid sha256:cca88b334de7037abfacd9d87c2cb8eec7391f355c1d6b4a694fc4240f358ee1 |
|
|
|
size 366 |