Browse Source
Merge branch 'main' into js/format-conversion
pull/2751/head
James Jackson-South
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with
13 additions and
8 deletions
-
src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
-
src/ImageSharp/Formats/Png/Filters/SubFilter.cs
-
src/ImageSharp/Formats/Png/Filters/UpFilter.cs
-
src/ImageSharp/Formats/Png/PngEncoderCore.cs
|
|
|
@ -169,7 +169,7 @@ internal static class AverageFilter |
|
|
|
Vector256<int> sumAccumulator = Vector256<int>.Zero; |
|
|
|
Vector256<byte> allBitsSet = Avx2.CompareEqual(sumAccumulator, sumAccumulator).AsByte(); |
|
|
|
|
|
|
|
for (nuint xLeft = x - bytesPerPixel; x <= (uint)(scanline.Length - Vector256<byte>.Count); xLeft += (uint)Vector256<byte>.Count) |
|
|
|
for (nuint xLeft = x - bytesPerPixel; (int)x <= scanline.Length - Vector256<byte>.Count; xLeft += (uint)Vector256<byte>.Count) |
|
|
|
{ |
|
|
|
Vector256<byte> scan = Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref scanBaseRef, x)); |
|
|
|
Vector256<byte> left = Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref scanBaseRef, xLeft)); |
|
|
|
@ -192,7 +192,7 @@ internal static class AverageFilter |
|
|
|
Vector128<int> sumAccumulator = Vector128<int>.Zero; |
|
|
|
Vector128<byte> allBitsSet = Sse2.CompareEqual(sumAccumulator, sumAccumulator).AsByte(); |
|
|
|
|
|
|
|
for (nuint xLeft = x - bytesPerPixel; x <= (uint)(scanline.Length - Vector128<byte>.Count); xLeft += (uint)Vector128<byte>.Count) |
|
|
|
for (nuint xLeft = x - bytesPerPixel; (int)x <= scanline.Length - Vector128<byte>.Count; xLeft += (uint)Vector128<byte>.Count) |
|
|
|
{ |
|
|
|
Vector128<byte> scan = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref scanBaseRef, x)); |
|
|
|
Vector128<byte> left = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref scanBaseRef, xLeft)); |
|
|
|
|
|
|
|
@ -136,7 +136,7 @@ internal static class SubFilter |
|
|
|
Vector256<byte> zero = Vector256<byte>.Zero; |
|
|
|
Vector256<int> sumAccumulator = Vector256<int>.Zero; |
|
|
|
|
|
|
|
for (nuint xLeft = x - (uint)bytesPerPixel; x <= (uint)(scanline.Length - Vector256<byte>.Count); xLeft += (uint)Vector256<byte>.Count) |
|
|
|
for (nuint xLeft = x - (uint)bytesPerPixel; (int)x <= (scanline.Length - Vector256<byte>.Count); xLeft += (uint)Vector256<byte>.Count) |
|
|
|
{ |
|
|
|
Vector256<byte> scan = Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref scanBaseRef, x)); |
|
|
|
Vector256<byte> prev = Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref scanBaseRef, xLeft)); |
|
|
|
@ -150,11 +150,12 @@ internal static class SubFilter |
|
|
|
|
|
|
|
sum += Numerics.EvenReduceSum(sumAccumulator); |
|
|
|
} |
|
|
|
else if (Vector.IsHardwareAccelerated) |
|
|
|
else |
|
|
|
if (Vector.IsHardwareAccelerated) |
|
|
|
{ |
|
|
|
Vector<uint> sumAccumulator = Vector<uint>.Zero; |
|
|
|
|
|
|
|
for (nuint xLeft = x - (uint)bytesPerPixel; x <= (uint)(scanline.Length - Vector<byte>.Count); xLeft += (uint)Vector<byte>.Count) |
|
|
|
for (nuint xLeft = x - (uint)bytesPerPixel; (int)x <= (scanline.Length - Vector<byte>.Count); xLeft += (uint)Vector<byte>.Count) |
|
|
|
{ |
|
|
|
Vector<byte> scan = Unsafe.As<byte, Vector<byte>>(ref Unsafe.Add(ref scanBaseRef, x)); |
|
|
|
Vector<byte> prev = Unsafe.As<byte, Vector<byte>>(ref Unsafe.Add(ref scanBaseRef, xLeft)); |
|
|
|
|
|
|
|
@ -179,7 +179,7 @@ internal static class UpFilter |
|
|
|
Vector256<byte> zero = Vector256<byte>.Zero; |
|
|
|
Vector256<int> sumAccumulator = Vector256<int>.Zero; |
|
|
|
|
|
|
|
for (; x <= (uint)(scanline.Length - Vector256<byte>.Count);) |
|
|
|
for (; (int)x <= scanline.Length - Vector256<byte>.Count;) |
|
|
|
{ |
|
|
|
Vector256<byte> scan = Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref scanBaseRef, x)); |
|
|
|
Vector256<byte> above = Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref prevBaseRef, x)); |
|
|
|
@ -197,7 +197,7 @@ internal static class UpFilter |
|
|
|
{ |
|
|
|
Vector<uint> sumAccumulator = Vector<uint>.Zero; |
|
|
|
|
|
|
|
for (; x <= (uint)(scanline.Length - Vector<byte>.Count);) |
|
|
|
for (; (int)x <= scanline.Length - Vector<byte>.Count;) |
|
|
|
{ |
|
|
|
Vector<byte> scan = Unsafe.As<byte, Vector<byte>>(ref Unsafe.Add(ref scanBaseRef, x)); |
|
|
|
Vector<byte> above = Unsafe.As<byte, Vector<byte>>(ref Unsafe.Add(ref prevBaseRef, x)); |
|
|
|
|
|
|
|
@ -1447,7 +1447,11 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable |
|
|
|
this.colorType = color; |
|
|
|
this.bitDepth = bits; |
|
|
|
|
|
|
|
if (!encoder.FilterMethod.HasValue) |
|
|
|
if (encoder.FilterMethod.HasValue) |
|
|
|
{ |
|
|
|
this.filterMethod = encoder.FilterMethod.Value; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// Specification recommends default filter method None for paletted images and Paeth for others.
|
|
|
|
this.filterMethod = this.colorType is PngColorType.Palette ? PngFilterMethod.None : PngFilterMethod.Paeth; |
|
|
|
|