Browse Source

Merge branch 'png-fixes'

pull/319/head
James Jackson-South 9 years ago
parent
commit
bfec18e30c
  1. 29
      src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
  2. 5
      src/ImageSharp/Formats/Png/PngDecoderCore.cs

29
src/ImageSharp/Formats/Png/Filters/PaethFilter.cs

@ -31,22 +31,21 @@ namespace ImageSharp.Formats
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
// Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp))
for (int x = 1; x < scanline.Length; x++)
int offset = bytesPerPixel + 1;
for (int x = 1; x < offset; x++)
{
if (x - bytesPerPixel < 1)
{
ref byte scan = ref Unsafe.Add(ref scanBaseRef, x);
byte above = Unsafe.Add(ref prevBaseRef, x);
scan = (byte)((scan + PaethPredicator(0, above, 0)) % 256);
}
else
{
ref byte scan = ref Unsafe.Add(ref scanBaseRef, x);
byte left = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel);
byte above = Unsafe.Add(ref prevBaseRef, x);
byte upperLeft = Unsafe.Add(ref prevBaseRef, x - bytesPerPixel);
scan = (byte)((scan + PaethPredicator(left, above, upperLeft)) % 256);
}
ref byte scan = ref Unsafe.Add(ref scanBaseRef, x);
byte above = Unsafe.Add(ref prevBaseRef, x);
scan = (byte)(scan + above);
}
for (int x = offset; x < scanline.Length; x++)
{
ref byte scan = ref Unsafe.Add(ref scanBaseRef, x);
byte left = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel);
byte above = Unsafe.Add(ref prevBaseRef, x);
byte upperLeft = Unsafe.Add(ref prevBaseRef, x - bytesPerPixel);
scan = (byte)(scan + PaethPredicator(left, above, upperLeft));
}
}

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

@ -515,7 +515,7 @@ namespace ImageSharp.Formats
this.currentRowBytesRead = 0;
Span<byte> scanSpan = this.scanline.Slice(0, bytesPerInterlaceScanline);
Span<byte> prevSpan = this.previousScanline.Span.Slice(0, bytesPerInterlaceScanline);
Span<byte> prevSpan = this.previousScanline.Slice(0, bytesPerInterlaceScanline);
var filterType = (FilterType)scanSpan[0];
switch (filterType)
@ -556,12 +556,15 @@ namespace ImageSharp.Formats
}
this.pass++;
this.previousScanline.Clear();
if (this.pass < 7)
{
this.currentRow = Adam7FirstRow[this.pass];
}
else
{
this.pass = 0;
break;
}
}

Loading…
Cancel
Save