Browse Source

Rename base refs

af/merge-core
James Jackson-South 9 years ago
parent
commit
b5cf29c8d7
  1. 36
      src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
  2. 40
      src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
  3. 24
      src/ImageSharp/Formats/Png/Filters/SubFilter.cs
  4. 22
      src/ImageSharp/Formats/Png/Filters/UpFilter.cs
  5. 4
      src/ImageSharp/Formats/Png/PngEncoderCore.cs

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

@ -24,23 +24,23 @@ namespace ImageSharp.Formats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Decode(BufferSpan<byte> scanline, BufferSpan<byte> previousScanline, int bytesPerScanline, int bytesPerPixel)
{
ref byte scanPointer = ref scanline.DangerousGetPinnableReference();
ref byte prevPointer = ref previousScanline.DangerousGetPinnableReference();
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
// Average(x) + floor((Raw(x-bpp)+Prior(x))/2)
for (int x = 1; x < bytesPerScanline; x++)
{
if (x - bytesPerPixel < 1)
{
ref byte scan = ref Unsafe.Add(ref scanPointer, x);
byte above = Unsafe.Add(ref prevPointer, x);
ref byte scan = ref Unsafe.Add(ref scanBaseRef, x);
byte above = Unsafe.Add(ref prevBaseRef, x);
scan = (byte)((scan + (above >> 1)) % 256);
}
else
{
ref byte scan = ref Unsafe.Add(ref scanPointer, x);
byte left = Unsafe.Add(ref scanPointer, x - bytesPerPixel);
byte above = Unsafe.Add(ref prevPointer, 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);
scan = (byte)((scan + Average(left, above)) % 256);
}
}
@ -57,28 +57,28 @@ namespace ImageSharp.Formats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Encode(BufferSpan<byte> scanline, BufferSpan<byte> previousScanline, BufferSpan<byte> result, int bytesPerScanline, int bytesPerPixel)
{
ref byte scanPointer = ref scanline.DangerousGetPinnableReference();
ref byte prevPointer = ref previousScanline.DangerousGetPinnableReference();
ref byte resultPointer = ref result.DangerousGetPinnableReference();
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
// Average(x) = Raw(x) - floor((Raw(x-bpp)+Prior(x))/2)
resultPointer = 3;
resultBaseRef = 3;
for (int x = 0; x < bytesPerScanline; x++)
{
if (x - bytesPerPixel < 0)
{
byte scan = Unsafe.Add(ref scanPointer, x);
byte above = Unsafe.Add(ref prevPointer, x);
ref byte res = ref Unsafe.Add(ref resultPointer, x + 1);
byte scan = Unsafe.Add(ref scanBaseRef, x);
byte above = Unsafe.Add(ref prevBaseRef, x);
ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1);
res = (byte)((scan - (above >> 1)) % 256);
}
else
{
byte scan = Unsafe.Add(ref scanPointer, x);
byte left = Unsafe.Add(ref scanPointer, x - bytesPerPixel);
byte above = Unsafe.Add(ref prevPointer, x);
ref byte res = ref Unsafe.Add(ref resultPointer, x + 1);
byte scan = Unsafe.Add(ref scanBaseRef, x);
byte left = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel);
byte above = Unsafe.Add(ref prevBaseRef, x);
ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1);
res = (byte)((scan - Average(left, above)) % 256);
}
}

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

@ -25,24 +25,24 @@ namespace ImageSharp.Formats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Decode(BufferSpan<byte> scanline, BufferSpan<byte> previousScanline, int bytesPerScanline, int bytesPerPixel)
{
ref byte scanPointer = ref scanline.DangerousGetPinnableReference();
ref byte prevPointer = ref previousScanline.DangerousGetPinnableReference();
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
// Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp))
for (int x = 1; x < bytesPerScanline; x++)
{
if (x - bytesPerPixel < 1)
{
ref byte scan = ref Unsafe.Add(ref scanPointer, x);
byte above = Unsafe.Add(ref prevPointer, x);
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 scanPointer, x);
byte left = Unsafe.Add(ref scanPointer, x - bytesPerPixel);
byte above = Unsafe.Add(ref prevPointer, x);
byte upperLeft = Unsafe.Add(ref prevPointer, x - bytesPerPixel);
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);
}
}
@ -59,29 +59,29 @@ namespace ImageSharp.Formats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Encode(BufferSpan<byte> scanline, BufferSpan<byte> previousScanline, BufferSpan<byte> result, int bytesPerScanline, int bytesPerPixel)
{
ref byte scanPointer = ref scanline.DangerousGetPinnableReference();
ref byte prevPointer = ref previousScanline.DangerousGetPinnableReference();
ref byte resultPointer = ref result.DangerousGetPinnableReference();
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
// Paeth(x) = Raw(x) - PaethPredictor(Raw(x-bpp), Prior(x), Prior(x - bpp))
resultPointer = 4;
resultBaseRef = 4;
for (int x = 0; x < bytesPerScanline; x++)
{
if (x - bytesPerPixel < 0)
{
byte scan = Unsafe.Add(ref scanPointer, x);
byte above = Unsafe.Add(ref prevPointer, x);
ref byte res = ref Unsafe.Add(ref resultPointer, x + 1);
byte scan = Unsafe.Add(ref scanBaseRef, x);
byte above = Unsafe.Add(ref prevBaseRef, x);
ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1);
res = (byte)((scan - PaethPredicator(0, above, 0)) % 256);
}
else
{
byte scan = Unsafe.Add(ref scanPointer, x);
byte left = Unsafe.Add(ref scanPointer, x - bytesPerPixel);
byte above = Unsafe.Add(ref prevPointer, x);
byte upperLeft = Unsafe.Add(ref prevPointer, x - bytesPerPixel);
ref byte res = ref Unsafe.Add(ref resultPointer, x + 1);
byte scan = 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);
ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1);
res = (byte)((scan - PaethPredicator(left, above, upperLeft)) % 256);
}
}

24
src/ImageSharp/Formats/Png/Filters/SubFilter.cs

@ -23,20 +23,20 @@ namespace ImageSharp.Formats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Decode(BufferSpan<byte> scanline, int bytesPerScanline, int bytesPerPixel)
{
ref byte scanPointer = ref scanline.DangerousGetPinnableReference();
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
// Sub(x) + Raw(x-bpp)
for (int x = 1; x < bytesPerScanline; x++)
{
if (x - bytesPerPixel < 1)
{
ref byte scan = ref Unsafe.Add(ref scanPointer, x);
ref byte scan = ref Unsafe.Add(ref scanBaseRef, x);
scan = (byte)(scan % 256);
}
else
{
ref byte scan = ref Unsafe.Add(ref scanPointer, x);
byte prev = Unsafe.Add(ref scanPointer, x - bytesPerPixel);
ref byte scan = ref Unsafe.Add(ref scanBaseRef, x);
byte prev = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel);
scan = (byte)((scan + prev) % 256);
}
}
@ -52,25 +52,25 @@ namespace ImageSharp.Formats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Encode(BufferSpan<byte> scanline, BufferSpan<byte> result, int bytesPerScanline, int bytesPerPixel)
{
ref byte scanPointer = ref scanline.DangerousGetPinnableReference();
ref byte resultPointer = ref result.DangerousGetPinnableReference();
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
// Sub(x) = Raw(x) - Raw(x-bpp)
resultPointer = 1;
resultBaseRef = 1;
for (int x = 0; x < bytesPerScanline; x++)
{
if (x - bytesPerPixel < 0)
{
byte scan = Unsafe.Add(ref scanPointer, x);
ref byte res = ref Unsafe.Add(ref resultPointer, x + 1);
byte scan = Unsafe.Add(ref scanBaseRef, x);
ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1);
res = (byte)(scan % 256);
}
else
{
byte scan = Unsafe.Add(ref scanPointer, x);
byte prev = Unsafe.Add(ref scanPointer, x - bytesPerPixel);
ref byte res = ref Unsafe.Add(ref resultPointer, x + 1);
byte scan = Unsafe.Add(ref scanBaseRef, x);
byte prev = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel);
ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1);
res = (byte)((scan - prev) % 256);
}
}

22
src/ImageSharp/Formats/Png/Filters/UpFilter.cs

@ -23,14 +23,14 @@ namespace ImageSharp.Formats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Decode(BufferSpan<byte> scanline, BufferSpan<byte> previousScanline, int bytesPerScanline)
{
ref byte scanPointer = ref scanline.DangerousGetPinnableReference();
ref byte prevPointer = ref previousScanline.DangerousGetPinnableReference();
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
// Up(x) + Prior(x)
for (int x = 1; x < bytesPerScanline; x++)
{
ref byte scan = ref Unsafe.Add(ref scanPointer, x);
byte above = Unsafe.Add(ref prevPointer, x);
ref byte scan = ref Unsafe.Add(ref scanBaseRef, x);
byte above = Unsafe.Add(ref prevBaseRef, x);
scan = (byte)((scan + above) % 256);
}
}
@ -45,18 +45,18 @@ namespace ImageSharp.Formats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Encode(BufferSpan<byte> scanline, BufferSpan<byte> previousScanline, BufferSpan<byte> result, int bytesPerScanline)
{
ref byte scanPointer = ref scanline.DangerousGetPinnableReference();
ref byte prevPointer = ref previousScanline.DangerousGetPinnableReference();
ref byte resultPointer = ref result.DangerousGetPinnableReference();
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
// Up(x) = Raw(x) - Prior(x)
resultPointer = 2;
resultBaseRef = 2;
for (int x = 0; x < bytesPerScanline; x++)
{
byte scan = Unsafe.Add(ref scanPointer, x);
byte above = Unsafe.Add(ref prevPointer, x);
ref byte res = ref Unsafe.Add(ref resultPointer, x + 1);
byte scan = Unsafe.Add(ref scanBaseRef, x);
byte above = Unsafe.Add(ref prevBaseRef, x);
ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1);
res = (byte)((scan - above) % 256);
}
}

4
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -420,12 +420,12 @@ namespace ImageSharp.Formats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int CalculateTotalVariation(BufferSpan<byte> scanline, int lastSum)
{
ref byte scanPointer = ref scanline.DangerousGetPinnableReference();
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
int sum = 0;
for (int i = 1; i < this.bytesPerScanline; i++)
{
byte v = Unsafe.Add(ref scanPointer, i);
byte v = Unsafe.Add(ref scanBaseRef, i);
sum += v < 128 ? v : 256 - v;
// No point continuing if we are larger.

Loading…
Cancel
Save