diff --git a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs index aabf24b2f..fcfe698ba 100644 --- a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs @@ -24,23 +24,23 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Decode(BufferSpan scanline, BufferSpan 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 scanline, BufferSpan previousScanline, BufferSpan 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); } } diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs index a8e397a30..b7b3e8123 100644 --- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs @@ -25,24 +25,24 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Decode(BufferSpan scanline, BufferSpan 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 scanline, BufferSpan previousScanline, BufferSpan 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); } } diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs index d5ec2e7dc..6c88f385e 100644 --- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs @@ -23,20 +23,20 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Decode(BufferSpan 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 scanline, BufferSpan 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); } } diff --git a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs index 30cdf65a3..c1969e8cb 100644 --- a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs @@ -23,14 +23,14 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Decode(BufferSpan scanline, BufferSpan 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 scanline, BufferSpan previousScanline, BufferSpan 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); } } diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 2d63539c2..bd3cd5fe7 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -420,12 +420,12 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] private int CalculateTotalVariation(BufferSpan 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.