Browse Source

Much better output. Nearly there. Touch #9

Image in issue works perfectly as does rgba test image. rgb 8x8 test
image shows 2 pixel error though and I don't know why.
pull/33/head
James Jackson-South 10 years ago
parent
commit
e6af16b081
  1. 2
      src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
  2. 50
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  3. 5
      tests/ImageSharp.Tests/FileTestBase.cs
  4. 5
      tests/ImageSharp.Tests/TestImages.cs
  5. BIN
      tests/ImageSharp.Tests/TestImages/Formats/Png/interlaced.png

2
src/ImageSharp/Formats/Png/Filters/AverageFilter.cs

@ -5,8 +5,6 @@
namespace ImageSharp.Formats
{
using System;
/// <summary>
/// The Average filter uses the average of the two neighboring pixels (left and above) to predict
/// the value of a pixel.

50
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -440,28 +440,28 @@ namespace ImageSharp.Formats
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
{
for (int pass = 0; pass < 7; pass++)
{
int y = Adam7FirstRow[pass];
int numColumns = this.ComputeColumnsAdam7(pass);
if (numColumns == 0)
{
// This pass contains no data; skip to next pass
continue;
}
byte[] previousScanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline);
byte[] scanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline);
int bytesPerInterlaceScanline = this.CalculateScanlineLength(numColumns) + 1;
// Zero out the previousScanline, because the bytes that are rented from the arraypool may not be zero.
Array.Clear(previousScanline, 0, this.bytesPerScanline);
while (y < this.header.Height)
try
{
for (int pass = 0; pass < 7; pass++)
{
byte[] previousScanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline);
byte[] scanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline);
int y = Adam7FirstRow[pass];
int numColumns = this.ComputeColumnsAdam7(pass);
// Zero out the previousScanline, because the bytes that are rented from the arraypool may not be zero.
Array.Clear(previousScanline, 0, this.bytesPerScanline);
if (numColumns == 0)
{
// This pass contains no data; skip to next pass
continue;
}
try
int bytesPerInterlaceScanline = this.CalculateScanlineLength(numColumns) + 1;
while (y < this.header.Height)
{
compressedStream.Read(scanline, 0, bytesPerInterlaceScanline);
@ -506,16 +506,17 @@ namespace ImageSharp.Formats
this.ProcessInterlacedDefilteredScanline(scanline, y, pixels, Adam7FirstColumn[pass], Adam7ColumnIncrement[pass]);
Swap(ref scanline, ref previousScanline);
}
finally
{
ArrayPool<byte>.Shared.Return(previousScanline);
ArrayPool<byte>.Shared.Return(scanline);
}
y += Adam7RowIncrement[pass];
y += Adam7RowIncrement[pass];
}
}
}
finally
{
ArrayPool<byte>.Shared.Return(previousScanline);
ArrayPool<byte>.Shared.Return(scanline);
}
}
/// <summary>
@ -765,7 +766,6 @@ namespace ImageSharp.Formats
}
}
/// <summary>
/// Reads a text chunk containing image properties from the data.
/// </summary>

5
tests/ImageSharp.Tests/FileTestBase.cs

@ -31,8 +31,9 @@ namespace ImageSharp.Tests
// new TestFile(TestImages.Bmp.Neg_height), // Perf: Enable for local testing only
// new TestFile(TestImages.Png.Blur), // Perf: Enable for local testing only
// new TestFile(TestImages.Png.Indexed), // Perf: Enable for local testing only
//new TestFile(TestImages.Png.Splash),
new TestFile(TestImages.Png.SplashInterlace),
new TestFile(TestImages.Png.Splash),
//new TestFile(TestImages.Png.SplashInterlaced),
new TestFile(TestImages.Png.Interlaced),
// new TestFile(TestImages.Png.Filter0), // Perf: Enable for local testing only
// new TestFile(TestImages.Png.Filter1), // Perf: Enable for local testing only
// new TestFile(TestImages.Png.Filter2), // Perf: Enable for local testing only

5
tests/ImageSharp.Tests/TestImages.cs

@ -20,7 +20,10 @@ namespace ImageSharp.Tests
public static string Indexed => folder + "indexed.png";
public static string Splash => folder + "splash.png";
public static string SplashInterlace => folder + "splash-interlaced.png";
public static string SplashInterlaced => folder + "splash-interlaced.png";
public static string Interlaced => folder + "interlaced.png";
// filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html
public static string Filter0 => folder + "filter0.png";
public static string Filter1 => folder + "filter1.png";

BIN
tests/ImageSharp.Tests/TestImages/Formats/Png/interlaced.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Loading…
Cancel
Save