From 6ae2eb9eb208681a20bbcfbc8932fea5feae60f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 13 Mar 2023 13:17:26 +0100 Subject: [PATCH 01/86] Used unsigned division for vector sizes to get better codegen Cf. https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABAJgEYBYAKGIAYACY8gOgCUBXAOwwEt8YLAJI8ovLrl5hcAbho1iAZiakGAYQYBvGg11NlXcRgYBZcgAojDADYwuAcwwALAJQMAvAD4bdx04YA9AwAajBgGNDkpAAcADwAZtYQ2BieLGoQ3Bhy1Hr6DIY8pqSWRbYOzm5eDOaFGC7mHEYu5X6BIWERUFFxicmp6Zk8OQC+QA= --- src/ImageSharp/Common/Helpers/Numerics.cs | 12 ++- .../Helpers/SimdUtils.ExtendedIntrinsics.cs | 8 +- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 84 +++++++++---------- .../Formats/Jpeg/Components/Block8x8F.cs | 4 +- .../JpegColorConverter.CmykAvx.cs | 4 +- .../JpegColorConverter.CmykVector.cs | 4 +- .../JpegColorConverter.GrayScaleAvx.cs | 4 +- .../JpegColorConverter.GrayScaleVector.cs | 4 +- .../JpegColorConverter.RgbAvx.cs | 2 +- .../JpegColorConverter.RgbVector.cs | 2 +- .../JpegColorConverter.YCbCrAvx.cs | 4 +- .../JpegColorConverter.YCbCrVector.cs | 4 +- .../JpegColorConverter.YccKAvx.cs | 4 +- .../JpegColorConverter.YccKVector.cs | 4 +- .../Components/Encoder/ComponentProcessor.cs | 8 +- .../ImageSharp.Benchmarks/Bulk/FromVector4.cs | 4 +- .../Bulk/ToVector4_Rgba32.cs | 12 +-- .../PixelConversion_PackFromRgbPlanes.cs | 4 +- .../General/Vectorization/UInt32ToSingle.cs | 16 ++-- .../General/Vectorization/VectorFetching.cs | 18 ++-- .../Vectorization/WidenBytesToUInt32.cs | 4 +- 21 files changed, 108 insertions(+), 102 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index 7ba60cfe57..6fbd48f8cd 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -55,6 +55,12 @@ internal static class Numerics [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Modulo4(int x) => x & 3; + /// + /// Calculates % 4 + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Modulo4(nint x) => x & 3; + /// /// Calculates % 8 /// @@ -430,9 +436,9 @@ internal static class Numerics var vmin = new Vector(min); var vmax = new Vector(max); - int n = span.Length / Vector.Count; - int m = Modulo4(n); - int u = n - m; + nint n = (nint)(uint)span.Length / Vector.Count; + nint m = Modulo4(n); + nint u = n - m; ref Vector vs0 = ref Unsafe.As>(ref MemoryMarshal.GetReference(span)); ref Vector vs1 = ref Unsafe.Add(ref vs0, 1); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs index 2014a2a35b..9d2da7dc83 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs @@ -97,12 +97,12 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector.Count); - int n = dest.Length / Vector.Count; + nint n = (nint)(uint)dest.Length / Vector.Count; ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { Vector b = Unsafe.Add(ref sourceBase, i); @@ -132,13 +132,13 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector.Count); - int n = dest.Length / Vector.Count; + nint n = (nint)(uint)dest.Length / Vector.Count; ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { ref Vector s = ref Unsafe.Add(ref sourceBase, i * 4); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 3841b64b4d..a82b5559c7 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -221,11 +221,11 @@ internal static partial class SimdUtils ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - int n = dest.Length / Vector256.Count; - int m = Numerics.Modulo4(n); - int u = n - m; + nint n = (nint)(uint)dest.Length / Vector256.Count; + nint m = Numerics.Modulo4(n); + nint u = n - m; - for (int i = 0; i < u; i += 4) + for (nint i = 0; i < u; i += 4) { ref Vector256 vd0 = ref Unsafe.Add(ref destBase, i); ref Vector256 vs0 = ref Unsafe.Add(ref sourceBase, i); @@ -238,7 +238,7 @@ internal static partial class SimdUtils if (m > 0) { - for (int i = u; i < n; i++) + for (nint i = u; i < n; i++) { Unsafe.Add(ref destBase, i) = Avx.Permute(Unsafe.Add(ref sourceBase, i), control); } @@ -253,11 +253,11 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - int n = dest.Length / Vector128.Count; - int m = Numerics.Modulo4(n); - int u = n - m; + nint n = (nint)(uint)dest.Length / Vector128.Count; + nint m = Numerics.Modulo4(n); + nint u = n - m; - for (int i = 0; i < u; i += 4) + for (nint i = 0; i < u; i += 4) { ref Vector128 vd0 = ref Unsafe.Add(ref destBase, i); ref Vector128 vs0 = ref Unsafe.Add(ref sourceBase, i); @@ -276,7 +276,7 @@ internal static partial class SimdUtils if (m > 0) { - for (int i = u; i < n; i++) + for (nint i = u; i < n; i++) { Vector128 vs = Unsafe.Add(ref sourceBase, i); Unsafe.Add(ref destBase, i) = Sse.Shuffle(vs, vs, control); @@ -306,11 +306,11 @@ internal static partial class SimdUtils ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - int n = dest.Length / Vector256.Count; - int m = Numerics.Modulo4(n); - int u = n - m; + nint n = (nint)(uint)dest.Length / Vector256.Count; + nint m = Numerics.Modulo4(n); + nint u = n - m; - for (int i = 0; i < u; i += 4) + for (nint i = 0; i < u; i += 4) { ref Vector256 vs0 = ref Unsafe.Add(ref sourceBase, i); ref Vector256 vd0 = ref Unsafe.Add(ref destBase, i); @@ -323,7 +323,7 @@ internal static partial class SimdUtils if (m > 0) { - for (int i = u; i < n; i++) + for (nint i = u; i < n; i++) { Unsafe.Add(ref destBase, i) = Avx2.Shuffle(Unsafe.Add(ref sourceBase, i), vshuffle); } @@ -342,11 +342,11 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - int n = dest.Length / Vector128.Count; - int m = Numerics.Modulo4(n); - int u = n - m; + nint n = (nint)(uint)dest.Length / Vector128.Count; + nint m = Numerics.Modulo4(n); + nint u = n - m; - for (int i = 0; i < u; i += 4) + for (nint i = 0; i < u; i += 4) { ref Vector128 vs0 = ref Unsafe.Add(ref sourceBase, i); ref Vector128 vd0 = ref Unsafe.Add(ref destBase, i); @@ -359,7 +359,7 @@ internal static partial class SimdUtils if (m > 0) { - for (int i = u; i < n; i++) + for (nint i = u; i < n; i++) { Unsafe.Add(ref destBase, i) = Ssse3.Shuffle(Unsafe.Add(ref sourceBase, i), vshuffle); } @@ -391,9 +391,9 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / Vector128.Count; + nint n = (nint)(uint)source.Length / Vector128.Count; - for (int i = 0; i < n; i += 3) + for (nint i = 0; i < n; i += 3) { ref Vector128 vs = ref Unsafe.Add(ref sourceBase, i); @@ -454,9 +454,9 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / Vector128.Count; + nint n = (nint)(uint)source.Length / Vector128.Count; - for (int i = 0, j = 0; i < n; i += 3, j += 4) + for (nint i = 0, j = 0; i < n; i += 3, j += 4) { ref Vector128 v0 = ref Unsafe.Add(ref sourceBase, i); Vector128 v1 = Unsafe.Add(ref v0, 1); @@ -498,9 +498,9 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / Vector128.Count; + nint n = (nint)(uint)source.Length / Vector128.Count; - for (int i = 0, j = 0; i < n; i += 4, j += 3) + for (nint i = 0, j = 0; i < n; i += 4, j += 3) { ref Vector128 vs = ref Unsafe.Add(ref sourceBase, i); @@ -650,16 +650,16 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector256.Count); - int n = dest.Length / Vector256.Count; + nint n = (nint)(uint)dest.Length / Vector256.Count; ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); var scale = Vector256.Create(1 / (float)byte.MaxValue); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { - int si = Vector256.Count * i; + nint si = Vector256.Count * i; Vector256 i0 = Avx2.ConvertToVector256Int32(sourceBase + si); Vector256 i1 = Avx2.ConvertToVector256Int32(sourceBase + si + Vector256.Count); Vector256 i2 = Avx2.ConvertToVector256Int32(sourceBase + si + (Vector256.Count * 2)); @@ -683,7 +683,7 @@ internal static partial class SimdUtils // Sse VerifySpanInput(source, dest, Vector128.Count); - int n = dest.Length / Vector128.Count; + nint n = (nint)(uint)dest.Length / Vector128.Count; ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); @@ -691,9 +691,9 @@ internal static partial class SimdUtils var scale = Vector128.Create(1 / (float)byte.MaxValue); Vector128 zero = Vector128.Zero; - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { - int si = Vector128.Count * i; + nint si = Vector128.Count * i; Vector128 i0, i1, i2, i3; if (Sse41.IsSupported) @@ -782,7 +782,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector256.Count); - int n = dest.Length / Vector256.Count; + nint n = (nint)(uint)dest.Length / Vector256.Count; ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -794,7 +794,7 @@ internal static partial class SimdUtils ref byte maskBase = ref MemoryMarshal.GetReference(PermuteMaskDeinterleave8x32); Vector256 mask = Unsafe.As>(ref maskBase); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { ref Vector256 s = ref Unsafe.Add(ref sourceBase, i * 4); @@ -821,7 +821,7 @@ internal static partial class SimdUtils // Sse VerifySpanInput(source, dest, Vector128.Count); - int n = dest.Length / Vector128.Count; + nint n = (nint)(uint)dest.Length / Vector128.Count; ref Vector128 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -831,7 +831,7 @@ internal static partial class SimdUtils var scale = Vector128.Create((float)byte.MaxValue); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { ref Vector128 s = ref Unsafe.Add(ref sourceBase, i * 4); @@ -864,7 +864,7 @@ internal static partial class SimdUtils ref Vector256 bBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(blueChannel)); ref byte dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(destination)); - int count = redChannel.Length / Vector256.Count; + nint count = (nint)(uint)redChannel.Length / Vector256.Count; ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32); Vector256 control1 = Unsafe.As>(ref control1Bytes); @@ -875,7 +875,7 @@ internal static partial class SimdUtils Vector256 shuffleAlpha = Unsafe.As>(ref MemoryMarshal.GetReference(ShuffleMaskShiftAlpha)); - for (int i = 0; i < count; i++) + for (nint i = 0; i < count; i++) { Vector256 r0 = Unsafe.Add(ref rBase, i); Vector256 g0 = Unsafe.Add(ref gBase, i); @@ -918,7 +918,7 @@ internal static partial class SimdUtils Unsafe.As>(ref d4) = rgb4; } - int slice = count * Vector256.Count; + int slice = (int)count * Vector256.Count; redChannel = redChannel[slice..]; greenChannel = greenChannel[slice..]; blueChannel = blueChannel[slice..]; @@ -936,12 +936,12 @@ internal static partial class SimdUtils ref Vector256 bBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(blueChannel)); ref Vector256 dBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - int count = redChannel.Length / Vector256.Count; + nint count = (nint)(uint)redChannel.Length / Vector256.Count; ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32); Vector256 control1 = Unsafe.As>(ref control1Bytes); var a = Vector256.Create((byte)255); - for (int i = 0; i < count; i++) + for (nint i = 0; i < count; i++) { Vector256 r0 = Unsafe.Add(ref rBase, i); Vector256 g0 = Unsafe.Add(ref gBase, i); @@ -970,7 +970,7 @@ internal static partial class SimdUtils Unsafe.Add(ref d0, 3) = rgb4; } - int slice = count * Vector256.Count; + int slice = (int)count * Vector256.Count; redChannel = redChannel[slice..]; greenChannel = greenChannel[slice..]; blueChannel = blueChannel[slice..]; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs index 3bd5d28e74..a0a8cd28e2 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs @@ -425,7 +425,7 @@ internal partial struct Block8x8F : IEquatable Vector256 targetVector = Vector256.Create(value); ref Vector256 blockStride = ref this.V0; - for (int i = 0; i < RowCount; i++) + for (nint i = 0; i < RowCount; i++) { Vector256 areEqual = Avx2.CompareEqual(Avx.ConvertToVector256Int32WithTruncation(Unsafe.Add(ref this.V0, i)), targetVector); if (Avx2.MoveMask(areEqual.AsByte()) != equalityMask) @@ -439,7 +439,7 @@ internal partial struct Block8x8F : IEquatable ref float scalars = ref Unsafe.As(ref this); - for (int i = 0; i < Size; i++) + for (nint i = 0; i < Size; i++) { if ((int)Unsafe.Add(ref scalars, i) != value) { diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs index 7d7b7e1859..3144afa76b 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs @@ -32,7 +32,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / (this.MaximumValue * this.MaximumValue)); - nint n = values.Component0.Length / Vector256.Count; + nint n = (nint)(uint)values.Component0.Length / Vector256.Count; for (nint i = 0; i < n; i++) { ref Vector256 c = ref Unsafe.Add(ref c0Base, i); @@ -71,7 +71,7 @@ internal abstract partial class JpegColorConverterBase var scale = Vector256.Create(maxValue); - nint n = values.Component0.Length / Vector256.Count; + nint n = (nint)(uint)values.Component0.Length / Vector256.Count; for (nint i = 0; i < n; i++) { Vector256 ctmp = Avx.Subtract(scale, Unsafe.Add(ref srcR, i)); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs index 93dcd378c8..03d9a1532a 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs @@ -30,7 +30,7 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / (this.MaximumValue * this.MaximumValue)); - nint n = values.Component0.Length / Vector.Count; + nint n = (nint)(uint)values.Component0.Length / Vector.Count; for (nint i = 0; i < n; i++) { ref Vector c = ref Unsafe.Add(ref cBase, i); @@ -78,7 +78,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = new Vector(maxValue); - nint n = values.Component0.Length / Vector.Count; + nint n = (nint)(uint)values.Component0.Length / Vector.Count; for (nint i = 0; i < n; i++) { Vector ctmp = scale - Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs index 9cdbe71e84..4bb9869728 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs @@ -27,7 +27,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / this.MaximumValue); - nint n = values.Component0.Length / Vector256.Count; + nint n = (nint)(uint)values.Component0.Length / Vector256.Count; for (nint i = 0; i < n; i++) { ref Vector256 c0 = ref Unsafe.Add(ref c0Base, i); @@ -53,7 +53,7 @@ internal abstract partial class JpegColorConverterBase var f0587 = Vector256.Create(0.587f); var f0114 = Vector256.Create(0.114f); - nint n = values.Component0.Length / Vector256.Count; + nint n = (nint)(uint)values.Component0.Length / Vector256.Count; for (nint i = 0; i < n; i++) { ref Vector256 r = ref Unsafe.Add(ref srcRed, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs index 4d2355b95d..d8ba115d24 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs @@ -24,7 +24,7 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / this.MaximumValue); - nint n = values.Component0.Length / Vector.Count; + nint n = (nint)(uint)values.Component0.Length / Vector.Count; for (nint i = 0; i < n; i++) { ref Vector c0 = ref Unsafe.Add(ref cBase, i); @@ -53,7 +53,7 @@ internal abstract partial class JpegColorConverterBase var gMult = new Vector(0.587f); var bMult = new Vector(0.114f); - nint n = values.Component0.Length / Vector.Count; + nint n = (nint)(uint)values.Component0.Length / Vector.Count; for (nint i = 0; i < n; i++) { Vector r = Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs index b6c5117d44..76b2e9936c 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs @@ -29,7 +29,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / this.MaximumValue); - nint n = values.Component0.Length / Vector256.Count; + nint n = (nint)(uint)values.Component0.Length / Vector256.Count; for (nint i = 0; i < n; i++) { ref Vector256 r = ref Unsafe.Add(ref rBase, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs index e51b0df4d2..5d85bb0482 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs @@ -28,7 +28,7 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / this.MaximumValue); - nint n = values.Component0.Length / Vector.Count; + nint n = (nint)(uint)values.Component0.Length / Vector.Count; for (nint i = 0; i < n; i++) { ref Vector r = ref Unsafe.Add(ref rBase, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs index 081b985dbb..59f24493a1 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs @@ -38,7 +38,7 @@ internal abstract partial class JpegColorConverterBase var bCbMult = Vector256.Create(YCbCrScalar.BCbMult); // Walking 8 elements at one step: - nint n = values.Component0.Length / Vector256.Count; + nint n = (nint)(uint)values.Component0.Length / Vector256.Count; for (nint i = 0; i < n; i++) { // y = yVals[i]; @@ -98,7 +98,7 @@ internal abstract partial class JpegColorConverterBase var fn0081312F = Vector256.Create(-0.081312F); var f05 = Vector256.Create(0.5f); - nint n = values.Component0.Length / Vector256.Count; + nint n = (nint)(uint)values.Component0.Length / Vector256.Count; for (nint i = 0; i < n; i++) { Vector256 r = Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs index 85211d4abf..0f7a364868 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs @@ -35,7 +35,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(-YCbCrScalar.GCrMult); var bCbMult = new Vector(YCbCrScalar.BCbMult); - nint n = values.Component0.Length / Vector.Count; + nint n = (nint)(uint)values.Component0.Length / Vector.Count; for (nint i = 0; i < n; i++) { // y = yVals[i]; @@ -103,7 +103,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(0.418688f); var bCrMult = new Vector(0.081312f); - nint n = values.Component0.Length / Vector.Count; + nint n = (nint)(uint)values.Component0.Length / Vector.Count; for (nint i = 0; i < n; i++) { Vector r = Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs index 1f79cbffb6..0cfb3201b4 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs @@ -40,7 +40,7 @@ internal abstract partial class JpegColorConverterBase var bCbMult = Vector256.Create(YCbCrScalar.BCbMult); // Walking 8 elements at one step: - nint n = values.Component0.Length / Vector256.Count; + nint n = (nint)(uint)values.Component0.Length / Vector256.Count; for (nint i = 0; i < n; i++) { // y = yVals[i]; @@ -109,7 +109,7 @@ internal abstract partial class JpegColorConverterBase var fn0081312F = Vector256.Create(-0.081312F); var f05 = Vector256.Create(0.5f); - nint n = values.Component0.Length / Vector256.Count; + nint n = (nint)(uint)values.Component0.Length / Vector256.Count; for (nint i = 0; i < n; i++) { Vector256 r = Avx.Subtract(maxSampleValue, Unsafe.Add(ref srcR, i)); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs index 91a6cedc06..feefe3021d 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs @@ -36,7 +36,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(-YCbCrScalar.GCrMult); var bCbMult = new Vector(YCbCrScalar.BCbMult); - nint n = values.Component0.Length / Vector.Count; + nint n = (nint)(uint)values.Component0.Length / Vector.Count; for (nint i = 0; i < n; i++) { // y = yVals[i]; @@ -107,7 +107,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(0.418688f); var bCrMult = new Vector(0.081312f); - nint n = values.Component0.Length / Vector.Count; + nint n = (nint)(uint)values.Component0.Length / Vector.Count; for (nint i = 0; i < n; i++) { Vector r = maxSampleValue - Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs index 2bc1405509..23ddd0e495 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs @@ -122,7 +122,7 @@ internal class ComponentProcessor : IDisposable ref Vector256 sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed - nint count = source.Length / Vector256.Count; + nint count = (nint)(uint)source.Length / Vector256.Count; for (nint i = 0; i < count; i++) { Unsafe.Add(ref targetVectorRef, i) = Avx.Add(Unsafe.Add(ref targetVectorRef, i), Unsafe.Add(ref sourceVectorRef, i)); @@ -133,7 +133,7 @@ internal class ComponentProcessor : IDisposable ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); ref Vector sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); - nint count = source.Length / Vector.Count; + nint count = (nint)(uint)source.Length / Vector.Count; for (nint i = 0; i < count; i++) { Unsafe.Add(ref targetVectorRef, i) += Unsafe.Add(ref sourceVectorRef, i); @@ -200,7 +200,7 @@ internal class ComponentProcessor : IDisposable ref Vector256 targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed - nint count = target.Length / Vector256.Count; + nint count = (nint)(uint)target.Length / Vector256.Count; var multiplierVector = Vector256.Create(multiplier); for (nint i = 0; i < count; i++) { @@ -211,7 +211,7 @@ internal class ComponentProcessor : IDisposable { ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); - nint count = target.Length / Vector.Count; + nint count = (nint)(uint)target.Length / Vector.Count; var multiplierVector = new Vector(multiplier); for (nint i = 0; i < count; i++) { diff --git a/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs b/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs index dd3fb8ac82..0637b33347 100644 --- a/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs +++ b/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs @@ -103,7 +103,7 @@ public class FromVector4Rgba32 : FromVector4 Span src = MemoryMarshal.Cast(this.source.GetSpan()); Span dest = MemoryMarshal.Cast(this.destination.GetSpan()); - int n = dest.Length / Vector.Count; + nint n = (nint)(uint)dest.Length / Vector.Count; ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(src)); @@ -114,7 +114,7 @@ public class FromVector4Rgba32 : FromVector4 var maxBytes = Vector256.Create(255f); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { ref Vector256 s = ref Unsafe.Add(ref sourceBase, i * 4); diff --git a/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs b/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs index b0eb6b46dc..913ab24dc1 100644 --- a/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs +++ b/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs @@ -54,13 +54,13 @@ public class ToVector4_Rgba32 : ToVector4 Span sBytes = MemoryMarshal.Cast(this.source.GetSpan()); Span dFloats = MemoryMarshal.Cast(this.destination.GetSpan()); - int n = dFloats.Length / Vector.Count; + nint n = (nint)(uint)dFloats.Length / Vector.Count; ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference((ReadOnlySpan)sBytes)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dFloats)); ref Vector destBaseU = ref Unsafe.As, Vector>(ref destBase); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { Vector b = Unsafe.Add(ref sourceBase, i); @@ -75,10 +75,10 @@ public class ToVector4_Rgba32 : ToVector4 Unsafe.Add(ref d, 3) = w3; } - n = dFloats.Length / Vector.Count; + n = (nint)(uint)dFloats.Length / Vector.Count; var scale = new Vector(1f / 255f); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { ref Vector dRef = ref Unsafe.Add(ref destBase, i); @@ -96,13 +96,13 @@ public class ToVector4_Rgba32 : ToVector4 Span sBytes = MemoryMarshal.Cast(this.source.GetSpan()); Span dFloats = MemoryMarshal.Cast(this.destination.GetSpan()); - int n = dFloats.Length / Vector.Count; + nint n = (nint)(uint)dFloats.Length / Vector.Count; ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference((ReadOnlySpan)sBytes)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dFloats)); var scale = new Vector(1f / 255f); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { Vector b = Unsafe.Add(ref sourceBase, i); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs index 86ac928af9..061b1e1269 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs @@ -205,14 +205,14 @@ public unsafe class PixelConversion_PackFromRgbPlanes ref Vector256 bBase = ref Unsafe.As>(ref this.bFloat[0]); ref Vector256 resultBase = ref Unsafe.As>(ref this.rgbaFloat[0]); - int count = this.Count / Vector256.Count; + nint count = (nint)(uint)this.Count / Vector256.Count; ref byte control = ref MemoryMarshal.GetReference(SimdUtils.HwIntrinsics.PermuteMaskEvenOdd8x32); Vector256 vcontrol = Unsafe.As>(ref control); var va = Vector256.Create(1F); - for (int i = 0; i < count; i++) + for (nint i = 0; i < count; i++) { Vector256 r = Unsafe.Add(ref rBase, i); Vector256 g = Unsafe.Add(ref gBase, i); diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs index 63d363c688..57c7b6faf7 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs @@ -25,14 +25,14 @@ public class UInt32ToSingle { ref Vector b = ref Unsafe.As>(ref this.data[0]); - int n = Count / Vector.Count; + nint n = Count / Vector.Count; var bVec = new Vector(256.0f / 255.0f); var magicFloat = new Vector(32768.0f); var magicInt = new Vector(1191182336); // reinterpreted value of 32768.0f var mask = new Vector(255); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { ref Vector df = ref Unsafe.Add(ref b, i); @@ -50,14 +50,14 @@ public class UInt32ToSingle [Benchmark] public void StandardSimd() { - int n = Count / Vector.Count; + nint n = Count / Vector.Count; ref Vector bf = ref Unsafe.As>(ref this.data[0]); ref Vector bu = ref Unsafe.As, Vector>(ref bf); var scale = new Vector(1f / 255f); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { Vector u = Unsafe.Add(ref bu, i); Vector v = Vector.ConvertToSingle(u); @@ -69,14 +69,14 @@ public class UInt32ToSingle [Benchmark] public void StandardSimdFromInt() { - int n = Count / Vector.Count; + nint n = Count / Vector.Count; ref Vector bf = ref Unsafe.As>(ref this.data[0]); ref Vector bu = ref Unsafe.As, Vector>(ref bf); var scale = new Vector(1f / 255f); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { Vector u = Unsafe.Add(ref bu, i); Vector v = Vector.ConvertToSingle(u); @@ -88,12 +88,12 @@ public class UInt32ToSingle [Benchmark] public void StandardSimdFromInt_RefCast() { - int n = Count / Vector.Count; + nint n = Count / Vector.Count; ref Vector bf = ref Unsafe.As>(ref this.data[0]); var scale = new Vector(1f / 255f); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { ref Vector fRef = ref Unsafe.Add(ref bf, i); diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs index 07ace06686..7da2626dcc 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs @@ -63,14 +63,14 @@ public class VectorFetching var v = new Vector(this.testValue); ref Vector start = ref Unsafe.As>(ref this.data[0]); - int n = this.InputSize / Vector.Count; + nint n = (nint)(uint)this.InputSize / Vector.Count; - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { ref Vector p = ref Unsafe.Add(ref start, i); Vector a = p; - a = a * v; + a *= v; p = a; } @@ -82,12 +82,12 @@ public class VectorFetching var v = new Vector(this.testValue); ref Vector start = ref Unsafe.As>(ref this.data[0]); - int n = this.InputSize / Vector.Count; + nint n = (nint)(uint)this.InputSize / Vector.Count; - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { ref Vector a = ref Unsafe.Add(ref start, i); - a = a * v; + a *= v; } } @@ -100,12 +100,12 @@ public class VectorFetching ref Vector start = ref Unsafe.As>(ref MemoryMarshal.GetReference(span)); - int n = this.InputSize / Vector.Count; + nint n = (nint)(uint)this.InputSize / Vector.Count; - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { ref Vector a = ref Unsafe.Add(ref start, i); - a = a * v; + a *= v; } } } diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs index 429475ffd3..4615376a5f 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs @@ -42,12 +42,12 @@ public class WidenBytesToUInt32 [Benchmark] public void Simd() { - int n = Count / Vector.Count; + nint n = Count / Vector.Count; ref Vector sBase = ref Unsafe.As>(ref this.source[0]); ref Vector dBase = ref Unsafe.As>(ref this.dest[0]); - for (int i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { Vector b = Unsafe.Add(ref sBase, i); From 1920e28ed0313e998a2fae6735969ebfc1242c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 13 Mar 2023 16:47:32 +0100 Subject: [PATCH 02/86] Revised Unsafe.Add to avoid the sign-extending move --- .../ColorSpaces/Companding/SRgbCompanding.cs | 4 +- .../Conversion/ColorSpaceConverter.CieLab.cs | 26 +- .../Conversion/ColorSpaceConverter.CieLch.cs | 26 +- .../ColorSpaceConverter.CieLchuv.cs | 26 +- .../Conversion/ColorSpaceConverter.CieLuv.cs | 26 +- .../Conversion/ColorSpaceConverter.CieXyy.cs | 26 +- .../Conversion/ColorSpaceConverter.CieXyz.cs | 26 +- .../Conversion/ColorSpaceConverter.Cmyk.cs | 26 +- .../Conversion/ColorSpaceConverter.Hsl.cs | 26 +- .../Conversion/ColorSpaceConverter.Hsv.cs | 26 +- .../ColorSpaceConverter.HunterLab.cs | 26 +- .../ColorSpaceConverter.LinearRgb.cs | 26 +- .../Conversion/ColorSpaceConverter.Lms.cs | 28 +- .../Conversion/ColorSpaceConverter.Rgb.cs | 26 +- .../Conversion/ColorSpaceConverter.YCbCr.cs | 24 +- .../VonKriesChromaticAdaptation.cs | 2 +- src/ImageSharp/Common/Helpers/Numerics.cs | 24 +- .../Helpers/Shuffle/IComponentShuffle.cs | 20 +- .../Common/Helpers/Shuffle/IPad3Shuffle4.cs | 12 +- .../Common/Helpers/Shuffle/IShuffle3.cs | 8 +- .../Common/Helpers/Shuffle/IShuffle4Slice3.cs | 14 +- .../SimdUtils.FallbackIntrinsics128.cs | 4 +- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 4 +- .../Common/Helpers/SimdUtils.Pack.cs | 18 +- .../Common/Helpers/SimdUtils.Shuffle.cs | 18 +- src/ImageSharp/Compression/Zlib/Crc32.cs | 2 +- .../Compression/Zlib/DeflaterHuffman.cs | 94 ++-- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 8 +- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 2 +- src/ImageSharp/Formats/Gif/LzwDecoder.cs | 38 +- src/ImageSharp/Formats/Gif/LzwEncoder.cs | 22 +- .../Formats/Jpeg/Components/Block8x8.cs | 10 +- .../Jpeg/Components/Block8x8F.Generated.cs | 18 +- .../Jpeg/Components/Block8x8F.Intrinsic.cs | 6 +- .../Jpeg/Components/Block8x8F.ScaledCopy.cs | 12 +- .../JpegColorConverter.GrayScaleScalar.cs | 2 +- .../Decoder/ArithmeticScanDecoder.cs | 4 +- .../Components/Decoder/HuffmanScanDecoder.cs | 12 +- .../Components/Encoder/ComponentProcessor.cs | 12 +- .../Components/Encoder/HuffmanScanEncoder.cs | 4 +- .../Formats/Png/Filters/AverageFilter.cs | 16 +- .../Formats/Png/Filters/PaethFilter.cs | 12 +- .../Formats/Png/Filters/SubFilter.cs | 14 +- .../Formats/Png/Filters/UpFilter.cs | 14 +- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 4 +- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 14 +- .../Formats/Png/PngEncoderHelpers.cs | 6 +- .../Formats/Png/PngScanlineProcessor.cs | 110 ++--- .../Decompressors/T6TiffCompression.cs | 2 +- .../BlackIsZero1TiffColor{TPixel}.cs | 6 +- .../WhiteIsZero1TiffColor{TPixel}.cs | 6 +- src/ImageSharp/Formats/Webp/AlphaDecoder.cs | 11 +- .../Formats/Webp/Lossless/LosslessUtils.cs | 22 +- .../Formats/Webp/Lossless/Vp8LHistogram.cs | 29 +- .../Formats/Webp/Lossy/LossyUtils.cs | 114 ++--- src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs | 2 +- .../Formats/Webp/Lossy/YuvConversion.cs | 8 +- .../Allocators/Internals/ManagedBufferBase.cs | 2 +- .../DiscontiguousBuffers/MemoryGroup{T}.cs | 2 +- .../DefaultPixelBlenders.Generated.cs | 432 +++++++++--------- .../DefaultPixelBlenders.Generated.tt | 4 +- .../PixelImplementations/Abgr32.cs | 2 +- .../PixelImplementations/Bgr24.cs | 2 +- .../Abgr32.PixelOperations.Generated.cs | 14 +- .../Argb32.PixelOperations.Generated.cs | 14 +- .../Bgr24.PixelOperations.Generated.cs | 14 +- .../Bgra32.PixelOperations.Generated.cs | 14 +- .../Bgra5551.PixelOperations.Generated.cs | 24 +- .../L16.PixelOperations.Generated.cs | 24 +- .../Generated/L8.PixelOperations.Generated.cs | 24 +- .../La16.PixelOperations.Generated.cs | 6 +- .../Rgb24.PixelOperations.Generated.cs | 14 +- .../Rgb48.PixelOperations.Generated.cs | 24 +- .../Generated/_Common.ttinclude | 2 +- .../RgbaVector.PixelOperations.cs | 4 +- .../PixelOperations{TPixel}.Generated.cs | 52 +-- .../PixelOperations{TPixel}.Generated.tt | 4 +- .../PixelFormats/PixelOperations{TPixel}.cs | 4 +- .../Utils/Vector4Converters.Default.cs | 10 +- .../Convolution/BokehBlurProcessor.cs | 6 +- .../Convolution/BokehBlurProcessor{TPixel}.cs | 16 +- .../Convolution2DRowOperation{TPixel}.cs | 30 +- .../Convolution/Convolution2DState.cs | 4 +- .../Convolution2PassProcessor{TPixel}.cs | 30 +- .../ConvolutionProcessor{TPixel}.cs | 20 +- .../Convolution/ConvolutionState.cs | 4 +- .../EdgeDetectorCompassProcessor{TPixel}.cs | 4 +- .../Processors/Convolution/Kernel.cs | 6 +- .../Convolution/KernelSamplingMap.cs | 2 +- .../Convolution/MedianConvolutionState.cs | 4 +- .../Convolution/MedianRowOperation{TPixel}.cs | 14 +- .../Parameters/BokehBlurKernelDataProvider.cs | 16 +- .../Processors/Convolution/ReadOnlyKernel.cs | 2 +- .../Processors/Dithering/ErrorDither.cs | 6 +- .../Effects/OilPaintingProcessor{TPixel}.cs | 24 +- .../Filters/OpaqueProcessor{TPixel}.cs | 2 +- ...alizationSlidingWindowProcessor{TPixel}.cs | 10 +- .../AutoLevelProcessor{TPixel}.cs | 10 +- ...lHistogramEqualizationProcessor{TPixel}.cs | 6 +- .../GrayscaleLevelsRowOperation{TPixel}.cs | 4 +- .../HistogramEqualizationProcessor{TPixel}.cs | 8 +- .../Quantization/EuclideanPixelMap{TPixel}.cs | 4 +- .../Transforms/Resize/ResizeWorker.cs | 6 +- .../ImageSharp.Benchmarks/Bulk/FromVector4.cs | 2 +- .../Bulk/PremultiplyVector4.cs | 4 +- .../Bulk/UnPremultiplyVector4.cs | 4 +- .../BlockOperations/Block8x8F_CopyTo1x1.cs | 78 ++-- .../BlockOperations/Block8x8F_CopyTo2x2.cs | 68 +-- .../Jpeg/BlockOperations/Block8x8F_Round.cs | 8 +- .../PixelConversion_ConvertFromRgba32.cs | 10 +- .../PixelConversion_ConvertFromVector4.cs | 4 +- .../PixelConversion_ConvertToRgba32.cs | 4 +- ...vertToRgba32_AsPartOfCompositeOperation.cs | 4 +- .../PixelConversion_ConvertToVector4.cs | 4 +- ...ertToVector4_AsPartOfCompositeOperation.cs | 4 +- .../PixelConversion_PackFromRgbPlanes.cs | 6 +- .../PixelConversion_Rgba32_To_Argb32.cs | 12 +- .../PixelConversion_Rgba32_To_Bgra32.cs | 26 +- .../Vectorization/WidenBytesToUInt32.cs | 2 +- .../PorterDuffBulkVsSingleVector.cs | 2 +- .../Formats/Png/ReferenceImplementations.cs | 22 +- ...ConverterTests.ReferenceImplementations.cs | 6 +- .../PixelOperations/PixelOperationsTests.cs | 2 +- 123 files changed, 1166 insertions(+), 1164 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs b/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs index e776a0dc20..2a6fcb0832 100644 --- a/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs +++ b/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs @@ -175,7 +175,7 @@ public static class SRgbCompanding // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 vectorsBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors)); - ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u)); + ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (uint)vectors.Length / 2u); while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast)) { @@ -204,7 +204,7 @@ public static class SRgbCompanding Vector4 zero = Vector4.Zero; var scale = new Vector4(Scale); ref Vector4 vectorsBase = ref MemoryMarshal.GetReference(vectors); - ref Vector4 vectorsLast = ref Unsafe.Add(ref vectorsBase, vectors.Length); + ref Vector4 vectorsLast = ref Unsafe.Add(ref vectorsBase, (uint)vectors.Length); while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast)) { diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs index 721df36678..88343cbab4 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs @@ -37,7 +37,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -70,7 +70,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -103,7 +103,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -136,7 +136,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -169,7 +169,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -266,7 +266,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -299,7 +299,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -332,7 +332,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -365,7 +365,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -398,7 +398,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -431,7 +431,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs index da8e68b480..dcd6be185c 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -168,7 +168,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -200,7 +200,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -233,7 +233,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -266,7 +266,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -299,7 +299,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -332,7 +332,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -365,7 +365,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -398,7 +398,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -431,7 +431,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs index 75e955e41f..eb21394a09 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -168,7 +168,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -267,7 +267,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -300,7 +300,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -333,7 +333,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -366,7 +366,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -399,7 +399,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -431,7 +431,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs index b04acc9907..1b6735e623 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs @@ -35,7 +35,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -67,7 +67,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -169,7 +169,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -233,7 +233,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -265,7 +265,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -297,7 +297,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -329,7 +329,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -361,7 +361,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -393,7 +393,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -425,7 +425,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs index a3851de9f0..2b34e66f2e 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -163,7 +163,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -196,7 +196,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -229,7 +229,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -262,7 +262,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -295,7 +295,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -328,7 +328,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -361,7 +361,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -394,7 +394,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -427,7 +427,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs index 1244655227..1495a28b64 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs @@ -41,7 +41,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -76,7 +76,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -111,7 +111,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -146,7 +146,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -177,7 +177,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -210,7 +210,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -243,7 +243,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -277,7 +277,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -310,7 +310,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -345,7 +345,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -374,7 +374,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -407,7 +407,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -440,7 +440,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs index cadcc9e03f..068583e82f 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -168,7 +168,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -267,7 +267,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -300,7 +300,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -333,7 +333,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -366,7 +366,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -394,7 +394,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -427,7 +427,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs index b763a3ebe7..f40544b7a9 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -168,7 +168,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -267,7 +267,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -300,7 +300,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -333,7 +333,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -366,7 +366,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -394,7 +394,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -427,7 +427,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs index 4b4b9d0077..8bd014ed96 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -168,7 +168,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -267,7 +267,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -300,7 +300,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -333,7 +333,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -366,7 +366,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -394,7 +394,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -427,7 +427,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs index 01c040231a..2890594651 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs @@ -24,7 +24,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -45,7 +45,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -66,7 +66,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -87,7 +87,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -108,7 +108,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -129,7 +129,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -150,7 +150,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -171,7 +171,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -192,7 +192,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -213,7 +213,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -255,7 +255,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -276,7 +276,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs index 416274e003..897ec02a0f 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs @@ -24,7 +24,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -45,7 +45,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -66,7 +66,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -87,7 +87,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -108,7 +108,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -129,7 +129,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -150,7 +150,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -171,7 +171,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -192,7 +192,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -213,7 +213,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -255,7 +255,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -276,7 +276,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs index e2870a6eb4..291f3a5fac 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System.Runtime.CompilerServices; @@ -24,7 +24,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -45,7 +45,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -66,7 +66,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -87,7 +87,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -108,7 +108,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -129,7 +129,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -150,7 +150,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -171,7 +171,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -192,7 +192,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -213,7 +213,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -255,7 +255,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -276,7 +276,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs index 7346a28f33..557c294992 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs @@ -24,7 +24,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -45,7 +45,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -66,7 +66,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -87,7 +87,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -108,7 +108,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -129,7 +129,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -150,7 +150,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -171,7 +171,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -192,7 +192,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -213,7 +213,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -255,7 +255,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -276,7 +276,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs index f267a0d89d..8ea875a3d7 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs @@ -24,7 +24,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -45,7 +45,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -66,7 +66,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -87,7 +87,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -108,7 +108,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -129,7 +129,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -150,7 +150,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -171,7 +171,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -192,7 +192,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -213,7 +213,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -255,7 +255,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs index 7b9915c23f..55ed41220d 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs @@ -81,7 +81,7 @@ public sealed class VonKriesChromaticAdaptation : IChromaticAdaptation ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index 6fbd48f8cd..876f6e1fe6 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -297,7 +297,7 @@ internal static class Numerics if (remainder.Length > 0) { ref byte remainderStart = ref MemoryMarshal.GetReference(remainder); - ref byte remainderEnd = ref Unsafe.Add(ref remainderStart, remainder.Length); + ref byte remainderEnd = ref Unsafe.Add(ref remainderStart, (uint)remainder.Length); while (Unsafe.IsAddressLessThan(ref remainderStart, ref remainderEnd)) { @@ -322,7 +322,7 @@ internal static class Numerics if (remainder.Length > 0) { ref uint remainderStart = ref MemoryMarshal.GetReference(remainder); - ref uint remainderEnd = ref Unsafe.Add(ref remainderStart, remainder.Length); + ref uint remainderEnd = ref Unsafe.Add(ref remainderStart, (uint)remainder.Length); while (Unsafe.IsAddressLessThan(ref remainderStart, ref remainderEnd)) { @@ -347,7 +347,7 @@ internal static class Numerics if (remainder.Length > 0) { ref int remainderStart = ref MemoryMarshal.GetReference(remainder); - ref int remainderEnd = ref Unsafe.Add(ref remainderStart, remainder.Length); + ref int remainderEnd = ref Unsafe.Add(ref remainderStart, (uint)remainder.Length); while (Unsafe.IsAddressLessThan(ref remainderStart, ref remainderEnd)) { @@ -372,7 +372,7 @@ internal static class Numerics if (remainder.Length > 0) { ref float remainderStart = ref MemoryMarshal.GetReference(remainder); - ref float remainderEnd = ref Unsafe.Add(ref remainderStart, remainder.Length); + ref float remainderEnd = ref Unsafe.Add(ref remainderStart, (uint)remainder.Length); while (Unsafe.IsAddressLessThan(ref remainderStart, ref remainderEnd)) { @@ -397,7 +397,7 @@ internal static class Numerics if (remainder.Length > 0) { ref double remainderStart = ref MemoryMarshal.GetReference(remainder); - ref double remainderEnd = ref Unsafe.Add(ref remainderStart, remainder.Length); + ref double remainderEnd = ref Unsafe.Add(ref remainderStart, (uint)remainder.Length); while (Unsafe.IsAddressLessThan(ref remainderStart, ref remainderEnd)) { @@ -497,7 +497,7 @@ internal static class Numerics { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 vectorsBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors)); - ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u)); + ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (uint)vectors.Length / 2u); while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast)) { @@ -516,7 +516,7 @@ internal static class Numerics else { ref Vector4 vectorsStart = ref MemoryMarshal.GetReference(vectors); - ref Vector4 vectorsEnd = ref Unsafe.Add(ref vectorsStart, vectors.Length); + ref Vector4 vectorsEnd = ref Unsafe.Add(ref vectorsStart, (uint)vectors.Length); while (Unsafe.IsAddressLessThan(ref vectorsStart, ref vectorsEnd)) { @@ -562,7 +562,7 @@ internal static class Numerics { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 vectorsBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors)); - ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u)); + ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (uint)vectors.Length / 2u); Vector256 epsilon = Vector256.Create(Constants.Epsilon); while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast)) @@ -582,7 +582,7 @@ internal static class Numerics else { ref Vector4 vectorsStart = ref MemoryMarshal.GetReference(vectors); - ref Vector4 vectorsEnd = ref Unsafe.Add(ref vectorsStart, vectors.Length); + ref Vector4 vectorsEnd = ref Unsafe.Add(ref vectorsStart, (uint)vectors.Length); while (Unsafe.IsAddressLessThan(ref vectorsStart, ref vectorsEnd)) { @@ -656,7 +656,7 @@ internal static class Numerics public static unsafe void CubePowOnXYZ(Span vectors) { ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors); - ref Vector4 endRef = ref Unsafe.Add(ref baseRef, vectors.Length); + ref Vector4 endRef = ref Unsafe.Add(ref baseRef, (uint)vectors.Length); while (Unsafe.IsAddressLessThan(ref baseRef, ref endRef)) { @@ -687,7 +687,7 @@ internal static class Numerics if (Sse41.IsSupported) { ref Vector128 vectors128Ref = ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors)); - ref Vector128 vectors128End = ref Unsafe.Add(ref vectors128Ref, vectors.Length); + ref Vector128 vectors128End = ref Unsafe.Add(ref vectors128Ref, (uint)vectors.Length); var v128_341 = Vector128.Create(341); Vector128 v128_negativeZero = Vector128.Create(-0.0f).AsInt32(); @@ -736,7 +736,7 @@ internal static class Numerics else { ref Vector4 vectorsRef = ref MemoryMarshal.GetReference(vectors); - ref Vector4 vectorsEnd = ref Unsafe.Add(ref vectorsRef, vectors.Length); + ref Vector4 vectorsEnd = ref Unsafe.Add(ref vectorsRef, (uint)vectors.Length); // Fallback with scalar preprocessing and vectorized approximation steps while (Unsafe.IsAddressLessThan(ref vectorsRef, ref vectorsEnd)) diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index 9b73eb6ccf..18daaed481 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -63,12 +63,12 @@ internal readonly struct DefaultShuffle4 : IShuffle4 Shuffle.InverseMMShuffle(this.Control, out int p3, out int p2, out int p1, out int p0); - for (int i = 0; i < source.Length; i += 4) + for (nint i = 0; i < (uint)source.Length; i += 4) { - Unsafe.Add(ref dBase, i) = Unsafe.Add(ref sBase, p0 + i); - Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, p1 + i); - Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, p2 + i); - Unsafe.Add(ref dBase, i + 3) = Unsafe.Add(ref sBase, p3 + i); + Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, (nint)(uint)p0 + i); + Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, (nint)(uint)p1 + i); + Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, (nint)(uint)p2 + i); + Unsafe.Add(ref dBase, i + 3) = Unsafe.Add(ref sBase, (nint)(uint)p3 + i); } } } @@ -86,7 +86,7 @@ internal readonly struct WXYZShuffle4 : IShuffle4 ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = source.Length / 4; - for (int i = 0; i < n; i++) + for (nint i = 0; i < (uint)n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -110,7 +110,7 @@ internal readonly struct WZYXShuffle4 : IShuffle4 ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = source.Length / 4; - for (int i = 0; i < n; i++) + for (nint i = 0; i < (uint)n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -134,7 +134,7 @@ internal readonly struct YZWXShuffle4 : IShuffle4 ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = source.Length / 4; - for (int i = 0; i < n; i++) + for (nint i = 0; i < (uint)n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -158,7 +158,7 @@ internal readonly struct ZYXWShuffle4 : IShuffle4 ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = source.Length / 4; - for (int i = 0; i < n; i++) + for (nint i = 0; i < (uint)n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -189,7 +189,7 @@ internal readonly struct XWZYShuffle4 : IShuffle4 ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = source.Length / 4; - for (int i = 0; i < n; i++) + for (nint i = 0; i < (uint)n; i++) { uint packed = Unsafe.Add(ref sBase, i); diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs b/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs index 5dfdd91718..3e1084d313 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs @@ -35,15 +35,15 @@ internal readonly struct DefaultPad3Shuffle4 : IPad3Shuffle4 ref byte t = ref MemoryMarshal.GetReference(temp); ref uint tu = ref Unsafe.As(ref t); - for (int i = 0, j = 0; i < source.Length; i += 3, j += 4) + for (nint i = 0, j = 0; i < (uint)source.Length; i += 3, j += 4) { ref byte s = ref Unsafe.Add(ref sBase, i); tu = Unsafe.As(ref s) | 0xFF000000; - Unsafe.Add(ref dBase, j) = Unsafe.Add(ref t, p0); - Unsafe.Add(ref dBase, j + 1) = Unsafe.Add(ref t, p1); - Unsafe.Add(ref dBase, j + 2) = Unsafe.Add(ref t, p2); - Unsafe.Add(ref dBase, j + 3) = Unsafe.Add(ref t, p3); + Unsafe.Add(ref dBase, j + 0) = Unsafe.Add(ref t, (uint)p0); + Unsafe.Add(ref dBase, j + 1) = Unsafe.Add(ref t, (uint)p1); + Unsafe.Add(ref dBase, j + 2) = Unsafe.Add(ref t, (uint)p2); + Unsafe.Add(ref dBase, j + 3) = Unsafe.Add(ref t, (uint)p3); } } } @@ -60,7 +60,7 @@ internal readonly struct XYZWPad3Shuffle4 : IPad3Shuffle4 ref byte sBase = ref MemoryMarshal.GetReference(source); ref byte dBase = ref MemoryMarshal.GetReference(dest); - ref byte sEnd = ref Unsafe.Add(ref sBase, source.Length); + ref byte sEnd = ref Unsafe.Add(ref sBase, (uint)source.Length); ref byte sLoopEnd = ref Unsafe.Subtract(ref sEnd, 4); while (Unsafe.IsAddressLessThan(ref sBase, ref sLoopEnd)) diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs index 6bf8c5f03d..b149bde09d 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs @@ -31,11 +31,11 @@ internal readonly struct DefaultShuffle3 : IShuffle3 Shuffle.InverseMMShuffle(this.Control, out _, out int p2, out int p1, out int p0); - for (int i = 0; i < source.Length; i += 3) + for (nint i = 0; i < (uint)source.Length; i += 3) { - Unsafe.Add(ref dBase, i) = Unsafe.Add(ref sBase, p0 + i); - Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, p1 + i); - Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, p2 + i); + Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, (nint)(uint)p0 + i); + Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, (nint)(uint)p1 + i); + Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, (nint)(uint)p2 + i); } } } diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs index ef46661f5f..1f12cea257 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs @@ -31,11 +31,11 @@ internal readonly struct DefaultShuffle4Slice3 : IShuffle4Slice3 Shuffle.InverseMMShuffle(this.Control, out _, out int p2, out int p1, out int p0); - for (int i = 0, j = 0; i < dest.Length; i += 3, j += 4) + for (nint i = 0, j = 0; i < (uint)dest.Length; i += 3, j += 4) { - Unsafe.Add(ref dBase, i) = Unsafe.Add(ref sBase, p0 + j); - Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, p1 + j); - Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, p2 + j); + Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, (nint)(uint)p0 + j); + Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, (nint)(uint)p1 + j); + Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, (nint)(uint)p2 + j); } } } @@ -52,9 +52,9 @@ internal readonly struct XYZWShuffle4Slice3 : IShuffle4Slice3 ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref Byte3 dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; - int m = Numerics.Modulo4(n); - int u = n - m; + nint n = (nint)(uint)source.Length / 4; + nint m = Numerics.Modulo4(n); + nint u = n - m; ref uint sLoopEnd = ref Unsafe.Add(ref sBase, u); ref uint sEnd = ref Unsafe.Add(ref sBase, n); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs index 84760f2815..8c79b181ce 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs @@ -83,7 +83,7 @@ internal static partial class SimdUtils const float scale = 1f / 255f; Vector4 d = default; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref ByteVector4 s = ref Unsafe.Add(ref sBase, i); d.X = s.X; @@ -117,7 +117,7 @@ internal static partial class SimdUtils var half = new Vector4(0.5f); var maxBytes = new Vector4(255f); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Vector4 s = Unsafe.Add(ref sBase, i); s *= maxBytes; diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index a82b5559c7..654ae38103 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -995,9 +995,9 @@ internal static partial class SimdUtils const int bytesPerRgbStride = 24; int count = (int)((uint)source.Length / 8); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { - rgb = Avx2.PermuteVar8x32(Unsafe.AddByteOffset(ref rgbByteSpan, (IntPtr)(bytesPerRgbStride * i)).AsUInt32(), extractToLanesMask).AsByte(); + rgb = Avx2.PermuteVar8x32(Unsafe.AddByteOffset(ref rgbByteSpan, (uint)(bytesPerRgbStride * i)).AsUInt32(), extractToLanesMask).AsByte(); rgb = Avx2.Shuffle(rgb, extractRgbMask); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs b/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs index a01a32f5e1..ff8323df03 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs @@ -86,8 +86,8 @@ internal static partial class SimdUtils ref ByteTuple4 b = ref Unsafe.As(ref MemoryMarshal.GetReference(blueChannel)); ref Rgb24 rgb = ref MemoryMarshal.GetReference(destination); - int count = redChannel.Length / 4; - for (int i = 0; i < count; i++) + uint count = (uint)redChannel.Length / 4; + for (nint i = 0; i < count; i++) { ref Rgb24 d0 = ref Unsafe.Add(ref rgb, i * 4); ref Rgb24 d1 = ref Unsafe.Add(ref d0, 1); @@ -115,7 +115,7 @@ internal static partial class SimdUtils d3.B = bb.V3; } - int finished = count * 4; + int finished = (int)(count * 4); redChannel = redChannel[finished..]; greenChannel = greenChannel[finished..]; blueChannel = blueChannel[finished..]; @@ -133,9 +133,9 @@ internal static partial class SimdUtils ref ByteTuple4 b = ref Unsafe.As(ref MemoryMarshal.GetReference(blueChannel)); ref Rgba32 rgb = ref MemoryMarshal.GetReference(destination); - int count = redChannel.Length / 4; + uint count = (uint)redChannel.Length / 4; destination.Fill(new Rgba32(0, 0, 0, 255)); - for (int i = 0; i < count; i++) + for (nint i = 0; i < count; i++) { ref Rgba32 d0 = ref Unsafe.Add(ref rgb, i * 4); ref Rgba32 d1 = ref Unsafe.Add(ref d0, 1); @@ -163,7 +163,7 @@ internal static partial class SimdUtils d3.B = bb.V3; } - int finished = count * 4; + int finished = (int)(count * 4); redChannel = redChannel[finished..]; greenChannel = greenChannel[finished..]; blueChannel = blueChannel[finished..]; @@ -181,7 +181,7 @@ internal static partial class SimdUtils ref byte b = ref MemoryMarshal.GetReference(blueChannel); ref Rgb24 rgb = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < destination.Length; i++) + for (nint i = 0; i < (uint)destination.Length; i++) { ref Rgb24 d = ref Unsafe.Add(ref rgb, i); d.R = Unsafe.Add(ref r, i); @@ -201,7 +201,7 @@ internal static partial class SimdUtils ref byte b = ref MemoryMarshal.GetReference(blueChannel); ref Rgba32 rgba = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < destination.Length; i++) + for (nint i = 0; i < (uint)destination.Length; i++) { ref Rgba32 d = ref Unsafe.Add(ref rgba, i); d.R = Unsafe.Add(ref r, i); @@ -226,7 +226,7 @@ internal static partial class SimdUtils ref float b = ref MemoryMarshal.GetReference(blueChannel); ref Rgb24 rgb = ref MemoryMarshal.GetReference(source); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref Rgb24 src = ref Unsafe.Add(ref rgb, i); Unsafe.Add(ref r, i) = src.R; diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs b/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs index aecdaa6390..532f9d4fab 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs @@ -147,12 +147,12 @@ internal static partial class SimdUtils ref float dBase = ref MemoryMarshal.GetReference(dest); Shuffle.InverseMMShuffle(control, out int p3, out int p2, out int p1, out int p0); - for (int i = 0; i < source.Length; i += 4) + for (nint i = 0; i < (uint)source.Length; i += 4) { - Unsafe.Add(ref dBase, i) = Unsafe.Add(ref sBase, p0 + i); - Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, p1 + i); - Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, p2 + i); - Unsafe.Add(ref dBase, i + 3) = Unsafe.Add(ref sBase, p3 + i); + Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, (nint)(uint)p0 + i); + Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, (nint)(uint)p1 + i); + Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, (nint)(uint)p2 + i); + Unsafe.Add(ref dBase, i + 3) = Unsafe.Add(ref sBase, (nint)(uint)p3 + i); } } @@ -501,10 +501,10 @@ internal static partial class SimdUtils for (int i = 0; i < span.Length; i += 4) { - Unsafe.Add(ref spanBase, i) = (byte)(p0 + i); - Unsafe.Add(ref spanBase, i + 1) = (byte)(p1 + i); - Unsafe.Add(ref spanBase, i + 2) = (byte)(p2 + i); - Unsafe.Add(ref spanBase, i + 3) = (byte)(p3 + i); + Unsafe.Add(ref spanBase, (uint)(i + 0)) = (byte)(p0 + i); + Unsafe.Add(ref spanBase, (uint)(i + 1)) = (byte)(p1 + i); + Unsafe.Add(ref spanBase, (uint)(i + 2)) = (byte)(p2 + i); + Unsafe.Add(ref spanBase, (uint)(i + 3)) = (byte)(p3 + i); } } diff --git a/src/ImageSharp/Compression/Zlib/Crc32.cs b/src/ImageSharp/Compression/Zlib/Crc32.cs index 39c535c773..2d0a09bd4c 100644 --- a/src/ImageSharp/Compression/Zlib/Crc32.cs +++ b/src/ImageSharp/Compression/Zlib/Crc32.cs @@ -300,7 +300,7 @@ internal static partial class Crc32 for (int i = 0; i < buffer.Length; i++) { - crc = Unsafe.Add(ref crcTableRef, (int)((crc ^ Unsafe.Add(ref bufferRef, i)) & 0xFF)) ^ (crc >> 8); + crc = Unsafe.Add(ref crcTableRef, (crc ^ Unsafe.Add(ref bufferRef, i)) & 0xFF) ^ (crc >> 8); } return crc; diff --git a/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs b/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs index dc11de4259..d507d88c51 100644 --- a/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs +++ b/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs @@ -286,13 +286,13 @@ internal sealed unsafe class DeflaterHuffman : IDisposable int static_len = this.extraBits; ref byte staticLLengthRef = ref MemoryMarshal.GetReference(StaticLLength); - for (int i = 0; i < LiteralNumber; i++) + for (nint i = 0; i < LiteralNumber; i++) { static_len += this.literalTree.Frequencies[i] * Unsafe.Add(ref staticLLengthRef, i); } ref byte staticDLengthRef = ref MemoryMarshal.GetReference(StaticDLength); - for (int i = 0; i < DistanceNumber; i++) + for (nint i = 0; i < DistanceNumber; i++) { static_len += this.distTree.Frequencies[i] * Unsafe.Add(ref staticDLengthRef, i); } @@ -405,10 +405,10 @@ internal sealed unsafe class DeflaterHuffman : IDisposable ref byte bit4ReverseRef = ref MemoryMarshal.GetReference(Bit4Reverse); - return (short)(Unsafe.Add(ref bit4ReverseRef, toReverse & 0xF) << 12 - | Unsafe.Add(ref bit4ReverseRef, (toReverse >> 4) & 0xF) << 8 - | Unsafe.Add(ref bit4ReverseRef, (toReverse >> 8) & 0xF) << 4 - | Unsafe.Add(ref bit4ReverseRef, toReverseRightShiftBy12)); + return (short)((Unsafe.Add(ref bit4ReverseRef, (uint)toReverse & 0xF) << 12) + | (Unsafe.Add(ref bit4ReverseRef, (uint)(toReverse >> 4) & 0xF) << 8) + | (Unsafe.Add(ref bit4ReverseRef, (uint)(toReverse >> 8) & 0xF) << 4) + | Unsafe.Add(ref bit4ReverseRef, (uint)toReverseRightShiftBy12)); } /// @@ -551,8 +551,8 @@ internal sealed unsafe class DeflaterHuffman : IDisposable int code = 0; for (int bits = 0; bits < this.maxLength; bits++) { - Unsafe.Add(ref nextCodeRef, bits) = code; - code += Unsafe.Add(ref bitLengthCountsRef, bits) << (15 - bits); + Unsafe.Add(ref nextCodeRef, (uint)bits) = code; + code += Unsafe.Add(ref bitLengthCountsRef, (uint)bits) << (15 - bits); } for (int i = 0; i < this.NumCodes; i++) @@ -560,8 +560,8 @@ internal sealed unsafe class DeflaterHuffman : IDisposable int bits = this.Length[i]; if (bits > 0) { - this.codes[i] = BitReverse(Unsafe.Add(ref nextCodeRef, bits - 1)); - Unsafe.Add(ref nextCodeRef, bits - 1) += 1 << (16 - bits); + this.codes[i] = BitReverse(Unsafe.Add(ref nextCodeRef, (uint)(bits - 1))); + Unsafe.Add(ref nextCodeRef, (uint)(bits - 1)) += 1 << (16 - bits); } } } @@ -593,13 +593,13 @@ internal sealed unsafe class DeflaterHuffman : IDisposable // Insert n into heap int pos = heapLen++; int ppos; - while (pos > 0 && this.Frequencies[Unsafe.Add(ref heapRef, ppos = (pos - 1) >> 1)] > freq) + while (pos > 0 && this.Frequencies[Unsafe.Add(ref heapRef, (uint)(ppos = (pos - 1) >> 1))] > freq) { - Unsafe.Add(ref heapRef, pos) = Unsafe.Add(ref heapRef, ppos); + Unsafe.Add(ref heapRef, pos) = Unsafe.Add(ref heapRef, (uint)ppos); pos = ppos; } - Unsafe.Add(ref heapRef, pos) = n; + Unsafe.Add(ref heapRef, (uint)pos) = n; maxCode = n; } @@ -611,7 +611,7 @@ internal sealed unsafe class DeflaterHuffman : IDisposable // this case, both literals get a 1 bit code. while (heapLen < 2) { - Unsafe.Add(ref heapRef, heapLen++) = maxCode < 2 ? ++maxCode : 0; + Unsafe.Add(ref heapRef, (uint)heapLen++) = maxCode < 2 ? ++maxCode : 0; } this.NumCodes = Math.Max(maxCode + 1, this.minNumCodes); @@ -625,14 +625,14 @@ internal sealed unsafe class DeflaterHuffman : IDisposable ref int valuesRef = ref MemoryMarshal.GetReference(valuesMemoryOwner.Memory.Span); int numNodes = numLeafs; - for (int i = 0; i < heapLen; i++) + for (nint i = 0; i < (uint)heapLen; i++) { int node = Unsafe.Add(ref heapRef, i); - int i2 = 2 * i; + nint i2 = 2 * i; Unsafe.Add(ref childrenRef, i2) = node; Unsafe.Add(ref childrenRef, i2 + 1) = -1; Unsafe.Add(ref valuesRef, i) = this.Frequencies[node] << 8; - Unsafe.Add(ref heapRef, i) = i; + Unsafe.Add(ref heapRef, i) = (int)i; } // Construct the Huffman tree by repeatedly combining the least two @@ -640,7 +640,7 @@ internal sealed unsafe class DeflaterHuffman : IDisposable do { int first = Unsafe.Add(ref heapRef, 0); - int last = Unsafe.Add(ref heapRef, --heapLen); + int last = Unsafe.Add(ref heapRef, (uint)--heapLen); // Propagate the hole to the leafs of the heap int ppos = 0; @@ -648,35 +648,35 @@ internal sealed unsafe class DeflaterHuffman : IDisposable while (path < heapLen) { - if (path + 1 < heapLen && Unsafe.Add(ref valuesRef, Unsafe.Add(ref heapRef, path)) > Unsafe.Add(ref valuesRef, Unsafe.Add(ref heapRef, path + 1))) + if (path + 1 < heapLen && Unsafe.Add(ref valuesRef, (uint)Unsafe.Add(ref heapRef, (uint)path)) > Unsafe.Add(ref valuesRef, (uint)Unsafe.Add(ref heapRef, (uint)(path + 1)))) { path++; } - Unsafe.Add(ref heapRef, ppos) = Unsafe.Add(ref heapRef, path); + Unsafe.Add(ref heapRef, (uint)ppos) = Unsafe.Add(ref heapRef, (uint)path); ppos = path; path = (path * 2) + 1; } // Now propagate the last element down along path. Normally // it shouldn't go too deep. - int lastVal = Unsafe.Add(ref valuesRef, last); + int lastVal = Unsafe.Add(ref valuesRef, (uint)last); while ((path = ppos) > 0 - && Unsafe.Add(ref valuesRef, Unsafe.Add(ref heapRef, ppos = (path - 1) >> 1)) > lastVal) + && Unsafe.Add(ref valuesRef, (uint)Unsafe.Add(ref heapRef, (uint)(ppos = (path - 1) >> 1))) > lastVal) { - Unsafe.Add(ref heapRef, path) = Unsafe.Add(ref heapRef, ppos); + Unsafe.Add(ref heapRef, (uint)path) = Unsafe.Add(ref heapRef, (uint)ppos); } - Unsafe.Add(ref heapRef, path) = last; + Unsafe.Add(ref heapRef, (uint)path) = last; int second = Unsafe.Add(ref heapRef, 0); // Create a new node father of first and second last = numNodes++; - Unsafe.Add(ref childrenRef, 2 * last) = first; - Unsafe.Add(ref childrenRef, (2 * last) + 1) = second; - int mindepth = Math.Min(Unsafe.Add(ref valuesRef, first) & 0xFF, Unsafe.Add(ref valuesRef, second) & 0xFF); - Unsafe.Add(ref valuesRef, last) = lastVal = Unsafe.Add(ref valuesRef, first) + Unsafe.Add(ref valuesRef, second) - mindepth + 1; + Unsafe.Add(ref childrenRef, (uint)(2 * last)) = first; + Unsafe.Add(ref childrenRef, (uint)((2 * last) + 1)) = second; + int mindepth = Math.Min(Unsafe.Add(ref valuesRef, (uint)first) & 0xFF, Unsafe.Add(ref valuesRef, (uint)second) & 0xFF); + Unsafe.Add(ref valuesRef, (uint)last) = lastVal = Unsafe.Add(ref valuesRef, (uint)first) + Unsafe.Add(ref valuesRef, (uint)second) - mindepth + 1; // Again, propagate the hole to the leafs ppos = 0; @@ -685,23 +685,23 @@ internal sealed unsafe class DeflaterHuffman : IDisposable while (path < heapLen) { if (path + 1 < heapLen - && Unsafe.Add(ref valuesRef, Unsafe.Add(ref heapRef, path)) > Unsafe.Add(ref valuesRef, Unsafe.Add(ref heapRef, path + 1))) + && Unsafe.Add(ref valuesRef, (uint)Unsafe.Add(ref heapRef, (uint)path)) > Unsafe.Add(ref valuesRef, (uint)Unsafe.Add(ref heapRef, (uint)(path + 1)))) { path++; } - Unsafe.Add(ref heapRef, ppos) = Unsafe.Add(ref heapRef, path); + Unsafe.Add(ref heapRef, (uint)ppos) = Unsafe.Add(ref heapRef, (uint)path); ppos = path; path = (ppos * 2) + 1; } // Now propagate the new element down along path - while ((path = ppos) > 0 && Unsafe.Add(ref valuesRef, Unsafe.Add(ref heapRef, ppos = (path - 1) >> 1)) > lastVal) + while ((path = ppos) > 0 && Unsafe.Add(ref valuesRef, (uint)Unsafe.Add(ref heapRef, (uint)(ppos = (path - 1) >> 1))) > lastVal) { - Unsafe.Add(ref heapRef, path) = Unsafe.Add(ref heapRef, ppos); + Unsafe.Add(ref heapRef, (uint)path) = Unsafe.Add(ref heapRef, (uint)ppos); } - Unsafe.Add(ref heapRef, path) = last; + Unsafe.Add(ref heapRef, (uint)path) = last; } while (heapLen > 1); @@ -886,21 +886,21 @@ internal sealed unsafe class DeflaterHuffman : IDisposable { if (children[(2 * i) + 1] != -1) { - int bitLength = Unsafe.Add(ref lengthsRef, i) + 1; + int bitLength = Unsafe.Add(ref lengthsRef, (uint)i) + 1; if (bitLength > maxLen) { bitLength = maxLen; overflow++; } - Unsafe.Add(ref lengthsRef, Unsafe.Add(ref childrenRef, 2 * i)) = Unsafe.Add(ref lengthsRef, Unsafe.Add(ref childrenRef, (2 * i) + 1)) = bitLength; + Unsafe.Add(ref lengthsRef, (uint)Unsafe.Add(ref childrenRef, (uint)(2 * i))) = Unsafe.Add(ref lengthsRef, (uint)Unsafe.Add(ref childrenRef, (uint)((2 * i) + 1))) = bitLength; } else { // A leaf node - int bitLength = Unsafe.Add(ref lengthsRef, i); - Unsafe.Add(ref bitLengthCountsRef, bitLength - 1)++; - lengthPtr[Unsafe.Add(ref childrenRef, 2 * i)] = (byte)Unsafe.Add(ref lengthsRef, i); + int bitLength = Unsafe.Add(ref lengthsRef, (uint)i); + Unsafe.Add(ref bitLengthCountsRef, (uint)(bitLength - 1))++; + lengthPtr[Unsafe.Add(ref childrenRef, (uint)(2 * i))] = (byte)Unsafe.Add(ref lengthsRef, (uint)i); } } } @@ -914,7 +914,7 @@ internal sealed unsafe class DeflaterHuffman : IDisposable do { // Find the first bit length which could increase: - while (Unsafe.Add(ref bitLengthCountsRef, --incrBitLen) == 0) + while (Unsafe.Add(ref bitLengthCountsRef, (uint)--incrBitLen) == 0) { } @@ -922,8 +922,8 @@ internal sealed unsafe class DeflaterHuffman : IDisposable // number of overflow nodes. do { - Unsafe.Add(ref bitLengthCountsRef, incrBitLen)--; - Unsafe.Add(ref bitLengthCountsRef, ++incrBitLen)++; + Unsafe.Add(ref bitLengthCountsRef, (uint)incrBitLen)--; + Unsafe.Add(ref bitLengthCountsRef, (uint)++incrBitLen)++; overflow -= 1 << (maxLen - 1 - incrBitLen); } while (overflow > 0 && incrBitLen < maxLen - 1); @@ -932,8 +932,8 @@ internal sealed unsafe class DeflaterHuffman : IDisposable // We may have overshot above. Move some nodes from maxLength to // maxLength-1 in that case. - Unsafe.Add(ref bitLengthCountsRef, maxLen - 1) += overflow; - Unsafe.Add(ref bitLengthCountsRef, maxLen - 2) -= overflow; + Unsafe.Add(ref bitLengthCountsRef, (uint)(maxLen - 1)) += overflow; + Unsafe.Add(ref bitLengthCountsRef, (uint)(maxLen - 2)) -= overflow; // Now recompute all bit lengths, scanning in increasing // frequency. It is simpler to reconstruct all lengths instead of @@ -945,14 +945,14 @@ internal sealed unsafe class DeflaterHuffman : IDisposable int nodeIndex = 2 * numLeafs; for (int bits = maxLen; bits != 0; bits--) { - int n = Unsafe.Add(ref bitLengthCountsRef, bits - 1); + int n = Unsafe.Add(ref bitLengthCountsRef, (uint)(bits - 1)); while (n > 0) { - int childIndex = 2 * Unsafe.Add(ref childrenRef, nodeIndex++); - if (Unsafe.Add(ref childrenRef, childIndex + 1) == -1) + int childIndex = 2 * Unsafe.Add(ref childrenRef, (uint)nodeIndex++); + if (Unsafe.Add(ref childrenRef, (uint)(childIndex + 1)) == -1) { // We found another leaf - lengthPtr[Unsafe.Add(ref childrenRef, childIndex)] = (byte)bits; + lengthPtr[Unsafe.Add(ref childrenRef, (uint)childIndex)] = (byte)bits; n--; } } diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 17b5d8ec9b..6ff2723ddd 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -578,8 +578,8 @@ internal sealed class GifDecoderCore : IImageDecoderInternals // #403 The left + width value can be larger than the image width for (int x = descriptorLeft; x < descriptorRight && x < imageWidth; x++) { - int index = Numerics.Clamp(Unsafe.Add(ref indicesRowRef, x - descriptorLeft), 0, colorTableMaxIdx); - ref TPixel pixel = ref Unsafe.Add(ref rowRef, x); + int index = Numerics.Clamp(Unsafe.Add(ref indicesRowRef, (uint)(x - descriptorLeft)), 0, colorTableMaxIdx); + ref TPixel pixel = ref Unsafe.Add(ref rowRef, (uint)x); Rgb24 rgb = colorTable[index]; pixel.FromRgb24(rgb); } @@ -588,7 +588,7 @@ internal sealed class GifDecoderCore : IImageDecoderInternals { for (int x = descriptorLeft; x < descriptorRight && x < imageWidth; x++) { - int rawIndex = Unsafe.Add(ref indicesRowRef, x - descriptorLeft); + int rawIndex = Unsafe.Add(ref indicesRowRef, (uint)(x - descriptorLeft)); // Treat any out of bounds values as transparent. if (rawIndex > colorTableMaxIdx || rawIndex == transIndex) @@ -597,7 +597,7 @@ internal sealed class GifDecoderCore : IImageDecoderInternals } int index = Numerics.Clamp(rawIndex, 0, colorTableMaxIdx); - ref TPixel pixel = ref Unsafe.Add(ref rowRef, x); + ref TPixel pixel = ref Unsafe.Add(ref rowRef, (uint)x); Rgb24 rgb = colorTable[index]; pixel.FromRgb24(rgb); } diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 75c9b11860..f736da78dd 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -254,7 +254,7 @@ internal sealed class GifEncoderCore : IImageEncoderInternals for (int i = rgbaSpan.Length - 1; i >= 0; i--) { - if (Unsafe.Add(ref rgbaSpanRef, i).Equals(default)) + if (Unsafe.Add(ref rgbaSpanRef, (uint)i).Equals(default)) { index = i; } diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs index 64b9cf386c..4d282f26c6 100644 --- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs @@ -115,7 +115,7 @@ internal sealed class LzwDecoder : IDisposable for (code = 0; code < clearCode; code++) { - Unsafe.Add(ref suffixRef, code) = (byte)code; + Unsafe.Add(ref suffixRef, (uint)code) = (byte)code; } Span buffer = stackalloc byte[byte.MaxValue]; @@ -182,7 +182,7 @@ internal sealed class LzwDecoder : IDisposable if (oldCode == NullCode) { - Unsafe.Add(ref pixelStackRef, top++) = Unsafe.Add(ref suffixRef, code); + Unsafe.Add(ref pixelStackRef, (uint)top++) = Unsafe.Add(ref suffixRef, (uint)code); oldCode = code; first = code; continue; @@ -191,27 +191,27 @@ internal sealed class LzwDecoder : IDisposable int inCode = code; if (code == availableCode) { - Unsafe.Add(ref pixelStackRef, top++) = (byte)first; + Unsafe.Add(ref pixelStackRef, (uint)top++) = (byte)first; code = oldCode; } while (code > clearCode) { - Unsafe.Add(ref pixelStackRef, top++) = Unsafe.Add(ref suffixRef, code); - code = Unsafe.Add(ref prefixRef, code); + Unsafe.Add(ref pixelStackRef, (uint)top++) = Unsafe.Add(ref suffixRef, (uint)code); + code = Unsafe.Add(ref prefixRef, (uint)code); } - int suffixCode = Unsafe.Add(ref suffixRef, code); + int suffixCode = Unsafe.Add(ref suffixRef, (uint)code); first = suffixCode; - Unsafe.Add(ref pixelStackRef, top++) = suffixCode; + Unsafe.Add(ref pixelStackRef, (uint)top++) = suffixCode; // Fix for Gifs that have "deferred clear code" as per here : // https://bugzilla.mozilla.org/show_bug.cgi?id=55918 if (availableCode < MaxStackSize) { - Unsafe.Add(ref prefixRef, availableCode) = oldCode; - Unsafe.Add(ref suffixRef, availableCode) = first; + Unsafe.Add(ref prefixRef, (uint)availableCode) = oldCode; + Unsafe.Add(ref suffixRef, (uint)availableCode) = first; availableCode++; if (availableCode == codeMask + 1 && availableCode < MaxStackSize) { @@ -228,7 +228,7 @@ internal sealed class LzwDecoder : IDisposable // Clear missing pixels xyz++; - Unsafe.Add(ref pixelsRowRef, x++) = (byte)Unsafe.Add(ref pixelStackRef, top); + Unsafe.Add(ref pixelsRowRef, (uint)x++) = (byte)Unsafe.Add(ref pixelStackRef, (uint)top); } } @@ -282,7 +282,7 @@ internal sealed class LzwDecoder : IDisposable for (code = 0; code < clearCode; code++) { - Unsafe.Add(ref suffixRef, code) = (byte)code; + Unsafe.Add(ref suffixRef, (uint)code) = (byte)code; } Span buffer = stackalloc byte[byte.MaxValue]; @@ -336,7 +336,7 @@ internal sealed class LzwDecoder : IDisposable if (oldCode == NullCode) { - Unsafe.Add(ref pixelStackRef, top++) = Unsafe.Add(ref suffixRef, code); + Unsafe.Add(ref pixelStackRef, (uint)top++) = Unsafe.Add(ref suffixRef, (uint)code); oldCode = code; first = code; continue; @@ -345,27 +345,27 @@ internal sealed class LzwDecoder : IDisposable int inCode = code; if (code == availableCode) { - Unsafe.Add(ref pixelStackRef, top++) = (byte)first; + Unsafe.Add(ref pixelStackRef, (uint)top++) = (byte)first; code = oldCode; } while (code > clearCode) { - Unsafe.Add(ref pixelStackRef, top++) = Unsafe.Add(ref suffixRef, code); - code = Unsafe.Add(ref prefixRef, code); + Unsafe.Add(ref pixelStackRef, (uint)top++) = Unsafe.Add(ref suffixRef, (uint)code); + code = Unsafe.Add(ref prefixRef, (uint)code); } - int suffixCode = Unsafe.Add(ref suffixRef, code); + int suffixCode = Unsafe.Add(ref suffixRef, (uint)code); first = suffixCode; - Unsafe.Add(ref pixelStackRef, top++) = suffixCode; + Unsafe.Add(ref pixelStackRef, (uint)top++) = suffixCode; // Fix for Gifs that have "deferred clear code" as per here : // https://bugzilla.mozilla.org/show_bug.cgi?id=55918 if (availableCode < MaxStackSize) { - Unsafe.Add(ref prefixRef, availableCode) = oldCode; - Unsafe.Add(ref suffixRef, availableCode) = first; + Unsafe.Add(ref prefixRef, (uint)availableCode) = oldCode; + Unsafe.Add(ref suffixRef, (uint)availableCode) = first; availableCode++; if (availableCode == codeMask + 1 && availableCode < MaxStackSize) { diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs index fe27e7bf93..5253c0978a 100644 --- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs @@ -216,7 +216,7 @@ internal sealed class LzwEncoder : IDisposable [MethodImpl(MethodImplOptions.AggressiveInlining)] private void AddCharacter(byte c, ref byte accumulatorsRef, Stream stream) { - Unsafe.Add(ref accumulatorsRef, this.accumulatorCount++) = c; + Unsafe.Add(ref accumulatorsRef, (uint)this.accumulatorCount++) = c; if (this.accumulatorCount >= 254) { this.FlushPacket(stream); @@ -278,18 +278,18 @@ internal sealed class LzwEncoder : IDisposable for (int x = offsetX; x < indexedPixels.Width; x++) { - int code = Unsafe.Add(ref rowSpanRef, x); + int code = Unsafe.Add(ref rowSpanRef, (uint)x); int freeCode = (code << MaxBits) + entry; int hashIndex = (code << HashShift) ^ entry; - if (Unsafe.Add(ref hashTableRef, hashIndex) == freeCode) + if (Unsafe.Add(ref hashTableRef, (uint)hashIndex) == freeCode) { - entry = Unsafe.Add(ref codeTableRef, hashIndex); + entry = Unsafe.Add(ref codeTableRef, (uint)hashIndex); continue; } // Non-empty slot - if (Unsafe.Add(ref hashTableRef, hashIndex) >= 0) + if (Unsafe.Add(ref hashTableRef, (uint)hashIndex) >= 0) { int disp = 1; if (hashIndex != 0) @@ -304,15 +304,15 @@ internal sealed class LzwEncoder : IDisposable hashIndex += HashSize; } - if (Unsafe.Add(ref hashTableRef, hashIndex) == freeCode) + if (Unsafe.Add(ref hashTableRef, (uint)hashIndex) == freeCode) { - entry = Unsafe.Add(ref codeTableRef, hashIndex); + entry = Unsafe.Add(ref codeTableRef, (uint)hashIndex); break; } } - while (Unsafe.Add(ref hashTableRef, hashIndex) >= 0); + while (Unsafe.Add(ref hashTableRef, (uint)hashIndex) >= 0); - if (Unsafe.Add(ref hashTableRef, hashIndex) == freeCode) + if (Unsafe.Add(ref hashTableRef, (uint)hashIndex) == freeCode) { continue; } @@ -322,8 +322,8 @@ internal sealed class LzwEncoder : IDisposable entry = code; if (this.freeEntry < MaxMaxCode) { - Unsafe.Add(ref codeTableRef, hashIndex) = this.freeEntry++; // code -> hashtable - Unsafe.Add(ref hashTableRef, hashIndex) = freeCode; + Unsafe.Add(ref codeTableRef, (uint)hashIndex) = this.freeEntry++; // code -> hashtable + Unsafe.Add(ref hashTableRef, (uint)hashIndex) = freeCode; } else { diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs index 325d6c26f5..d119a18c8b 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs @@ -47,7 +47,7 @@ internal unsafe partial struct Block8x8 DebugGuard.MustBeBetweenOrEqualTo(idx, 0, Size - 1, nameof(idx)); ref short selfRef = ref Unsafe.As(ref this); - return Unsafe.Add(ref selfRef, idx); + return Unsafe.Add(ref selfRef, (uint)idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -56,7 +56,7 @@ internal unsafe partial struct Block8x8 DebugGuard.MustBeBetweenOrEqualTo(idx, 0, Size - 1, nameof(idx)); ref short selfRef = ref Unsafe.As(ref this); - Unsafe.Add(ref selfRef, idx) = value; + Unsafe.Add(ref selfRef, (uint)idx) = value; } } @@ -207,12 +207,12 @@ internal unsafe partial struct Block8x8 // Given mask is not actually suitable for lzcnt as 1's represent zero elements and 0's represent non-zero elements // So we need to invert it - int lzcnt = BitOperations.LeadingZeroCount(~(uint)areEqual); + uint lzcnt = (uint)BitOperations.LeadingZeroCount(~(uint)areEqual); // As input number is represented by 2 bits in the mask, we need to divide lzcnt result by 2 // to get the exact number of zero elements in the stride - int strideRelativeIndex = 15 - (lzcnt / 2); - return (i * 16) + strideRelativeIndex; + uint strideRelativeIndex = 15 - (lzcnt / 2); + return (i * 16) + (nint)strideRelativeIndex; } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs index 2610befcfe..d1cb3559b2 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs @@ -44,31 +44,31 @@ internal partial struct Block8x8F { var off = new Vector(MathF.Ceiling(maximum / 2)); var max = new Vector(maximum); - + ref Vector row0 = ref Unsafe.As>(ref this.V0L); row0 = NormalizeAndRound(row0, off, max); - + ref Vector row1 = ref Unsafe.As>(ref this.V1L); row1 = NormalizeAndRound(row1, off, max); - + ref Vector row2 = ref Unsafe.As>(ref this.V2L); row2 = NormalizeAndRound(row2, off, max); - + ref Vector row3 = ref Unsafe.As>(ref this.V3L); row3 = NormalizeAndRound(row3, off, max); - + ref Vector row4 = ref Unsafe.As>(ref this.V4L); row4 = NormalizeAndRound(row4, off, max); - + ref Vector row5 = ref Unsafe.As>(ref this.V5L); row5 = NormalizeAndRound(row5, off, max); - + ref Vector row6 = ref Unsafe.As>(ref this.V6L); row6 = NormalizeAndRound(row6, off, max); - + ref Vector row7 = ref Unsafe.As>(ref this.V7L); row7 = NormalizeAndRound(row7, off, max); - + } /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs index 78c82f11a0..7611d403ac 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs @@ -51,7 +51,7 @@ internal partial struct Block8x8F Vector256 row = Avx2.PackSignedSaturate(row0, row1); row = Avx2.PermuteVar8x32(row.AsInt32(), multiplyIntoInt16ShuffleMask).AsInt16(); - Unsafe.Add(ref destRef, (IntPtr)((uint)i / 2)) = row; + Unsafe.Add(ref destRef, i / 2) = row; } } @@ -64,13 +64,13 @@ internal partial struct Block8x8F ref Vector128 destBase = ref Unsafe.As>(ref dest); - for (int i = 0; i < 16; i += 2) + for (nint i = 0; i < 16; i += 2) { Vector128 left = Sse2.ConvertToVector128Int32(Sse.Multiply(Unsafe.Add(ref aBase, i + 0), Unsafe.Add(ref bBase, i + 0))); Vector128 right = Sse2.ConvertToVector128Int32(Sse.Multiply(Unsafe.Add(ref aBase, i + 1), Unsafe.Add(ref bBase, i + 1))); Vector128 row = Sse2.PackSignedSaturate(left, right); - Unsafe.Add(ref destBase, (IntPtr)((uint)i / 2)) = row; + Unsafe.Add(ref destBase, i / 2) = row; } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs index 813d9c37b7..e68ede9fbb 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs @@ -98,11 +98,11 @@ internal partial struct Block8x8F int xx = x * horizontalScale; float value = this[y8 + x]; - nint baseIdx = (yy * areaStride) + xx; + nint baseIdx = (nint)(uint)((yy * areaStride) + xx); for (nint i = 0; i < verticalScale; i++, baseIdx += areaStride) { - for (nint j = 0; j < horizontalScale; j++) + for (nint j = 0; j < (uint)horizontalScale; j++) { // area[xx + j, yy + i] = value; Unsafe.Add(ref areaOrigin, baseIdx + j) = value; @@ -128,8 +128,8 @@ internal partial struct Block8x8F [MethodImpl(MethodImplOptions.AggressiveInlining)] static void CopyRowImpl(ref byte origin, ref byte dest, int destStride, int row) { - origin = ref Unsafe.Add(ref origin, row * 8 * sizeof(float)); - dest = ref Unsafe.Add(ref dest, row * destStride); + origin = ref Unsafe.Add(ref origin, (uint)row * 8 * sizeof(float)); + dest = ref Unsafe.Add(ref dest, (uint)(row * destStride)); Unsafe.CopyBlock(ref dest, ref origin, 8 * sizeof(float)); } } @@ -150,8 +150,8 @@ internal partial struct Block8x8F [MethodImpl(MethodImplOptions.AggressiveInlining)] static void CopyRowImpl(ref byte origin, ref byte dest, int sourceStride, int row) { - origin = ref Unsafe.Add(ref origin, row * sourceStride); - dest = ref Unsafe.Add(ref dest, row * 8 * sizeof(float)); + origin = ref Unsafe.Add(ref origin, (uint)(row * sourceStride)); + dest = ref Unsafe.Add(ref dest, (uint)row * 8 * sizeof(float)); Unsafe.CopyBlock(ref dest, ref origin, 8 * sizeof(float)); } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleScalar.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleScalar.cs index 16dd7c768a..df511594af 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleScalar.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleScalar.cs @@ -28,7 +28,7 @@ internal abstract partial class JpegColorConverterBase ref float valuesRef = ref MemoryMarshal.GetReference(values); float scale = 1 / maxValue; - for (nint i = 0; i < values.Length; i++) + for (nint i = 0; i < (uint)values.Length; i++) { Unsafe.Add(ref valuesRef, i) *= scale; } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs index 922d7093b6..59789dcd25 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs @@ -705,7 +705,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder // Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients. // Table F.4: Point to statistics bin S0 for DC coefficient coding. - ref byte st = ref Unsafe.Add(ref component.DcStatistics.GetReference(), component.DcContext); + ref byte st = ref Unsafe.Add(ref component.DcStatistics.GetReference(), (uint)component.DcContext); // Figure F.19: Decode_DC_DIFF if (this.DecodeBinaryDecision(ref reader, ref st) == 0) @@ -955,7 +955,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder // Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients. // Table F.4: Point to statistics bin S0 for DC coefficient coding. - ref byte st = ref Unsafe.Add(ref component.DcStatistics.GetReference(), component.DcContext); + ref byte st = ref Unsafe.Add(ref component.DcStatistics.GetReference(), (uint)component.DcContext); /* Figure F.19: Decode_DC_DIFF */ if (this.DecodeBinaryDecision(ref reader, ref st) == 0) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs index e5c5098d05..bbd2bff53b 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs @@ -211,7 +211,7 @@ internal class HuffmanScanDecoder : IJpegScanDecoder this.DecodeBlockBaseline( component, - ref Unsafe.Add(ref blockRef, blockCol), + ref Unsafe.Add(ref blockRef, (uint)blockCol), ref dcHuffmanTable, ref acHuffmanTable); } @@ -255,7 +255,7 @@ internal class HuffmanScanDecoder : IJpegScanDecoder this.DecodeBlockBaseline( component, - ref Unsafe.Add(ref blockRef, i), + ref Unsafe.Add(ref blockRef, (uint)i), ref dcHuffmanTable, ref acHuffmanTable); @@ -297,7 +297,7 @@ internal class HuffmanScanDecoder : IJpegScanDecoder this.DecodeBlockBaseline( component, - ref Unsafe.Add(ref blockRef, k), + ref Unsafe.Add(ref blockRef, (uint)k), ref dcHuffmanTable, ref acHuffmanTable); @@ -417,7 +417,7 @@ internal class HuffmanScanDecoder : IJpegScanDecoder this.DecodeBlockProgressiveDC( component, - ref Unsafe.Add(ref blockRef, blockCol), + ref Unsafe.Add(ref blockRef, (uint)blockCol), ref dcHuffmanTable); } } @@ -459,7 +459,7 @@ internal class HuffmanScanDecoder : IJpegScanDecoder this.DecodeBlockProgressiveDC( component, - ref Unsafe.Add(ref blockRef, i), + ref Unsafe.Add(ref blockRef, (uint)i), ref dcHuffmanTable); this.HandleRestart(); @@ -485,7 +485,7 @@ internal class HuffmanScanDecoder : IJpegScanDecoder } this.DecodeBlockProgressiveAC( - ref Unsafe.Add(ref blockRef, i), + ref Unsafe.Add(ref blockRef, (uint)i), ref acHuffmanTable); this.HandleRestart(); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs index 23ddd0e495..3c89ab1fb6 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs @@ -141,7 +141,7 @@ internal class ComponentProcessor : IDisposable ref float targetRef = ref MemoryMarshal.GetReference(target); ref float sourceRef = ref MemoryMarshal.GetReference(source); - for (nint i = count * Vector.Count; i < source.Length; i++) + for (nint i = count * Vector.Count; i < (uint)source.Length; i++) { Unsafe.Add(ref targetRef, i) += Unsafe.Add(ref sourceRef, i); } @@ -166,16 +166,16 @@ internal class ComponentProcessor : IDisposable source = source.Slice(touchedCount); target = target.Slice(touchedCount / factor); - uint length = (uint)touchedCount / (uint)Vector256.Count; + nint length = (nint)(uint)touchedCount / Vector256.Count; for (int i = 0; i < haddIterationsCount; i++) { length /= 2; - for (nuint j = 0; j < length; j++) + for (nint j = 0; j < length; j++) { - nuint indexLeft = j * 2; - nuint indexRight = indexLeft + 1; + nint indexLeft = j * 2; + nint indexRight = indexLeft + 1; Vector256 sum = Avx.HorizontalAdd(Unsafe.Add(ref targetRef, indexLeft), Unsafe.Add(ref targetRef, indexRight)); Unsafe.Add(ref targetRef, j) = Avx2.Permute4x64(sum.AsDouble(), 0b11_01_10_00).AsSingle(); } @@ -219,7 +219,7 @@ internal class ComponentProcessor : IDisposable } ref float targetRef = ref MemoryMarshal.GetReference(target); - for (nint i = count * Vector.Count; i < target.Length; i++) + for (nint i = count * Vector.Count; i < (uint)target.Length; i++) { Unsafe.Add(ref targetRef, i) *= multiplier; } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs index 8edbc3c407..f479df7e2d 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs @@ -180,7 +180,7 @@ internal class HuffmanScanEncoder Span blockSpan = component.SpectralBlocks.DangerousGetRowSpan(y: 0); ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan); - for (nint k = 0; k < w; k++) + for (nint k = 0; k < (uint)w; k++) { this.WriteBlock( component, @@ -219,7 +219,7 @@ internal class HuffmanScanEncoder Span blockSpan = component.SpectralBlocks.DangerousGetRowSpan(y: i); ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan); - for (nint k = 0; k < w; k++) + for (nint k = 0; k < (uint)w; k++) { this.WriteBlock( component, diff --git a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs index 34e05d7796..0e601f5262 100644 --- a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs @@ -42,7 +42,7 @@ internal static class AverageFilter } else { - DecodeScalar(scanline, previousScanline, bytesPerPixel); + DecodeScalar(scanline, previousScanline, (nint)(uint)bytesPerPixel); } } @@ -88,7 +88,7 @@ internal static class AverageFilter Vector64 d = Vector64.Zero; int rb = scanline.Length; - int offset = 1; + nint offset = 1; const int bytesPerBatch = 4; while (rb >= bytesPerBatch) { @@ -108,7 +108,7 @@ internal static class AverageFilter } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void DecodeScalar(Span scanline, Span previousScanline, int bytesPerPixel) + private static void DecodeScalar(Span scanline, Span previousScanline, nint bytesPerPixel) { ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline); ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline); @@ -121,7 +121,7 @@ internal static class AverageFilter scan = (byte)(scan + (above >> 1)); } - for (; x < scanline.Length; ++x) + for (; x < (uint)scanline.Length; ++x) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); byte left = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel); @@ -153,7 +153,7 @@ internal static class AverageFilter resultBaseRef = (byte)FilterType.Average; nint x = 0; - for (; x < bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) + for (; x < (uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -169,7 +169,7 @@ internal static class AverageFilter Vector256 sumAccumulator = Vector256.Zero; Vector256 allBitsSet = Avx2.CompareEqual(sumAccumulator, sumAccumulator).AsByte(); - for (nint xLeft = x - bytesPerPixel; x <= scanline.Length - Vector256.Count; xLeft += Vector256.Count) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (uint)scanline.Length - Vector256.Count; xLeft += Vector256.Count) { Vector256 scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector256 left = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); @@ -192,7 +192,7 @@ internal static class AverageFilter Vector128 sumAccumulator = Vector128.Zero; Vector128 allBitsSet = Sse2.CompareEqual(sumAccumulator, sumAccumulator).AsByte(); - for (nint xLeft = x - bytesPerPixel; x <= scanline.Length - Vector128.Count; xLeft += Vector128.Count) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (uint)scanline.Length - Vector128.Count; xLeft += Vector128.Count) { Vector128 scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector128 left = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); @@ -221,7 +221,7 @@ internal static class AverageFilter sum += Numerics.EvenReduceSum(sumAccumulator); } - for (nint xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte left = Unsafe.Add(ref scanBaseRef, xLeft); diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs index 8998d6bc0f..540ec63231 100644 --- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs @@ -187,14 +187,14 @@ internal static class PaethFilter // Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp)) int offset = bytesPerPixel + 1; // Add one because x starts at one. nint x = 1; - for (; x < offset; x++) + for (; x < (uint)offset; x++) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); scan = (byte)(scan + above); } - for (; x < scanline.Length; x++) + for (; x < (uint)scanline.Length; x++) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); byte left = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel); @@ -227,7 +227,7 @@ internal static class PaethFilter resultBaseRef = (byte)FilterType.Paeth; nint x = 0; - for (; x < bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) + for (; x < (uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -242,7 +242,7 @@ internal static class PaethFilter Vector256 zero = Vector256.Zero; Vector256 sumAccumulator = Vector256.Zero; - for (nint xLeft = x - bytesPerPixel; x <= scanline.Length - Vector256.Count; xLeft += Vector256.Count) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (nint)(uint)scanline.Length - Vector256.Count; xLeft += Vector256.Count) { Vector256 scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector256 left = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); @@ -262,7 +262,7 @@ internal static class PaethFilter { Vector sumAccumulator = Vector.Zero; - for (nint xLeft = x - bytesPerPixel; x <= scanline.Length - Vector.Count; xLeft += Vector.Count) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (nint)(uint)scanline.Length - Vector.Count; xLeft += Vector.Count) { Vector scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector left = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); @@ -282,7 +282,7 @@ internal static class PaethFilter } } - for (nint xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (nint)(uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte left = Unsafe.Add(ref scanBaseRef, xLeft); diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs index 0f4aa3fcff..5dc7b15d74 100644 --- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs @@ -36,7 +36,7 @@ internal static class SubFilter } else { - DecodeScalar(scanline, bytesPerPixel); + DecodeScalar(scanline, (nint)(uint)bytesPerPixel); } } @@ -70,7 +70,7 @@ internal static class SubFilter Vector64 d = Vector64.Zero; int rb = scanline.Length; - int offset = 1; + nint offset = 1; const int bytesPerBatch = 4; while (rb >= bytesPerBatch) { @@ -87,7 +87,7 @@ internal static class SubFilter } } - private static void DecodeScalar(Span scanline, int bytesPerPixel) + private static void DecodeScalar(Span scanline, nint bytesPerPixel) { ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline); @@ -122,7 +122,7 @@ internal static class SubFilter resultBaseRef = (byte)FilterType.Sub; nint x = 0; - for (; x < bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) + for (; x < (nint)(uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); ++x; @@ -136,7 +136,7 @@ internal static class SubFilter Vector256 zero = Vector256.Zero; Vector256 sumAccumulator = Vector256.Zero; - for (nint xLeft = x - bytesPerPixel; x <= scanline.Length - Vector256.Count; xLeft += Vector256.Count) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (nint)(uint)scanline.Length - Vector256.Count; xLeft += Vector256.Count) { Vector256 scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector256 prev = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); @@ -154,7 +154,7 @@ internal static class SubFilter { Vector sumAccumulator = Vector.Zero; - for (nint xLeft = x - bytesPerPixel; x <= scanline.Length - Vector.Count; xLeft += Vector.Count) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (nint)(uint)scanline.Length - Vector.Count; xLeft += Vector.Count) { Vector scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector prev = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); @@ -172,7 +172,7 @@ internal static class SubFilter } } - for (nint xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (nint)(uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte prev = Unsafe.Add(ref scanBaseRef, xLeft); diff --git a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs index f90b129b62..55cc9ad6eb 100644 --- a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs @@ -66,7 +66,7 @@ internal static class UpFilter } // Handle left over. - for (nint i = offset; i < scanline.Length; i++) + for (nint i = offset; i < (uint)scanline.Length; i++) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, offset); byte above = Unsafe.Add(ref prevBaseRef, offset); @@ -96,7 +96,7 @@ internal static class UpFilter } // Handle left over. - for (nint i = offset; i < scanline.Length; i++) + for (nint i = offset; i < (uint)scanline.Length; i++) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, offset); byte above = Unsafe.Add(ref prevBaseRef, offset); @@ -127,7 +127,7 @@ internal static class UpFilter } // Handle left over. - for (nint i = offset; i < scanline.Length; i++) + for (nint i = offset; i < (uint)scanline.Length; i++) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, offset); byte above = Unsafe.Add(ref prevBaseRef, offset); @@ -143,7 +143,7 @@ internal static class UpFilter ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline); // Up(x) + Prior(x) - for (nint x = 1; x < scanline.Length; x++) + for (nint x = 1; x < (uint)scanline.Length; x++) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -179,7 +179,7 @@ internal static class UpFilter Vector256 zero = Vector256.Zero; Vector256 sumAccumulator = Vector256.Zero; - for (; x <= scanline.Length - Vector256.Count;) + for (; x <= (nint)(uint)(scanline.Length - Vector256.Count);) { Vector256 scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector256 above = Unsafe.As>(ref Unsafe.Add(ref prevBaseRef, x)); @@ -197,7 +197,7 @@ internal static class UpFilter { Vector sumAccumulator = Vector.Zero; - for (; x <= scanline.Length - Vector.Count;) + for (; x <= (nint)(uint)(scanline.Length - Vector.Count);) { Vector scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector above = Unsafe.As>(ref Unsafe.Add(ref prevBaseRef, x)); @@ -215,7 +215,7 @@ internal static class UpFilter } } - for (; x < scanline.Length; /* Note: ++x happens in the body to avoid one add operation */) + for (; x < (nint)(uint)scanline.Length; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 5c74232119..ea8120a5c1 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -414,11 +414,11 @@ internal sealed class PngDecoderCore : IImageDecoderInternals for (int i = 0; i < bytesPerScanline; i++) { - byte b = Unsafe.Add(ref sourceRef, i); + byte b = Unsafe.Add(ref sourceRef, (uint)i); for (int shift = 0; shift < 8; shift += bits) { int colorIndex = (b >> (8 - bits - shift)) & mask; - Unsafe.Add(ref resultRef, resultOffset) = (byte)colorIndex; + Unsafe.Add(ref resultRef, (uint)resultOffset) = (byte)colorIndex; resultOffset++; } } diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 5a66fc7d4b..4657ab17bb 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -266,7 +266,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable // Can't map directly to byte array as it's big-endian. for (int x = 0, o = 0; x < luminanceSpan.Length; x++, o += 2) { - L16 luminance = Unsafe.Add(ref luminanceRef, x); + L16 luminance = Unsafe.Add(ref luminanceRef, (uint)x); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), luminance.PackedValue); } } @@ -306,7 +306,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable // Can't map directly to byte array as it's big endian. for (int x = 0, o = 0; x < laSpan.Length; x++, o += 4) { - La32 la = Unsafe.Add(ref laRef, x); + La32 la = Unsafe.Add(ref laRef, (uint)x); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), la.L); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), la.A); } @@ -366,7 +366,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable // Can't map directly to byte array as it's big endian. for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 8) { - Rgba64 rgba = Unsafe.Add(ref rgbaRef, x); + Rgba64 rgba = Unsafe.Add(ref rgbaRef, (uint)x); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), rgba.R); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgba.G); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 4, 2), rgba.B); @@ -388,7 +388,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable // Can't map directly to byte array as it's big endian. for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 6) { - Rgb48 rgb = Unsafe.Add(ref rgbRef, x); + Rgb48 rgb = Unsafe.Add(ref rgbRef, (uint)x); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), rgb.R); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgb.G); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 4, 2), rgb.B); @@ -617,17 +617,17 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable // Loop, assign, and extract alpha values from the palette. for (int i = 0; i < paletteLength; i++) { - Rgba32 rgba = Unsafe.Add(ref rgbaPaletteRef, i); + Rgba32 rgba = Unsafe.Add(ref rgbaPaletteRef, (uint)i); byte alpha = rgba.A; - Unsafe.Add(ref colorTableRef, i) = rgba.Rgb; + Unsafe.Add(ref colorTableRef, (uint)i) = rgba.Rgb; if (alpha > this.encoder.Threshold) { alpha = byte.MaxValue; } hasAlpha = hasAlpha || alpha < byte.MaxValue; - Unsafe.Add(ref alphaTableRef, i) = alpha; + Unsafe.Add(ref alphaTableRef, (uint)i) = alpha; } this.WriteChunk(stream, PngChunkType.Palette, colorTable.GetSpan(), 0, colorTableLength); diff --git a/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs b/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs index 5bee1ebd53..712bd0e06a 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs @@ -31,13 +31,13 @@ internal static class PngEncoderHelpers for (int i = 0; i < source.Length; i++) { - int value = ((int)MathF.Round(Unsafe.Add(ref sourceRef, i) / scale)) & mask; + int value = ((int)MathF.Round(Unsafe.Add(ref sourceRef, (uint)i) / scale)) & mask; v |= value << shift; if (shift == 0) { shift = shift0; - Unsafe.Add(ref resultRef, resultOffset) = (byte)v; + Unsafe.Add(ref resultRef, (uint)resultOffset) = (byte)v; resultOffset++; v = 0; } @@ -49,7 +49,7 @@ internal static class PngEncoderHelpers if (shift != shift0) { - Unsafe.Add(ref resultRef, resultOffset) = (byte)v; + Unsafe.Add(ref resultRef, (uint)resultOffset) = (byte)v; } } } diff --git a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs index cf77788bc0..25c4a0d700 100644 --- a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs +++ b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs @@ -36,16 +36,16 @@ internal static class PngScanlineProcessor { ushort luminance = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, 2)); pixel.FromL16(Unsafe.As(ref luminance)); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else { for (int x = 0; x < header.Width; x++) { - byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, x) * scaleFactor); + byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, (uint)x) * scaleFactor); pixel.FromL8(Unsafe.As(ref luminance)); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } @@ -62,7 +62,7 @@ internal static class PngScanlineProcessor source.A = luminance.Equals(luminance16Trans.PackedValue) ? ushort.MinValue : ushort.MaxValue; pixel.FromLa32(source); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else @@ -71,12 +71,12 @@ internal static class PngScanlineProcessor byte scaledLuminanceTrans = (byte)(luminanceTrans.PackedValue * scaleFactor); for (int x = 0; x < header.Width; x++) { - byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, x) * scaleFactor); + byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, (uint)x) * scaleFactor); source.L = luminance; source.A = luminance.Equals(scaledLuminanceTrans) ? byte.MinValue : byte.MaxValue; pixel.FromLa16(source); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } } @@ -105,16 +105,16 @@ internal static class PngScanlineProcessor { ushort luminance = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, 2)); pixel.FromL16(Unsafe.As(ref luminance)); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else { for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o++) { - byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, o) * scaleFactor); + byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, (uint)o) * scaleFactor); pixel.FromL8(Unsafe.As(ref luminance)); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } @@ -131,7 +131,7 @@ internal static class PngScanlineProcessor source.A = luminance.Equals(luminance16Trans.PackedValue) ? ushort.MinValue : ushort.MaxValue; pixel.FromLa32(source); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else @@ -140,12 +140,12 @@ internal static class PngScanlineProcessor byte scaledLuminanceTrans = (byte)(luminanceTrans.PackedValue * scaleFactor); for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o++) { - byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, o) * scaleFactor); + byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, (uint)o) * scaleFactor); source.L = luminance; source.A = luminance.Equals(scaledLuminanceTrans) ? byte.MinValue : byte.MaxValue; pixel.FromLa16(source); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } } @@ -171,7 +171,7 @@ internal static class PngScanlineProcessor source.A = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + 2, 2)); pixel.FromLa32(source); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else @@ -180,11 +180,11 @@ internal static class PngScanlineProcessor for (int x = 0; x < header.Width; x++) { int offset = x * bytesPerPixel; - source.L = Unsafe.Add(ref scanlineSpanRef, offset); - source.A = Unsafe.Add(ref scanlineSpanRef, offset + bytesPerSample); + source.L = Unsafe.Add(ref scanlineSpanRef, (uint)offset); + source.A = Unsafe.Add(ref scanlineSpanRef, (uint)(offset + bytesPerSample)); pixel.FromLa16(source); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } } @@ -212,7 +212,7 @@ internal static class PngScanlineProcessor source.A = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + 2, 2)); pixel.FromLa32(source); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else @@ -221,11 +221,11 @@ internal static class PngScanlineProcessor La16 source = default; for (int x = pixelOffset; x < header.Width; x += increment) { - source.L = Unsafe.Add(ref scanlineSpanRef, offset); - source.A = Unsafe.Add(ref scanlineSpanRef, offset + bytesPerSample); + source.L = Unsafe.Add(ref scanlineSpanRef, (uint)offset); + source.A = Unsafe.Add(ref scanlineSpanRef, (uint)(offset + bytesPerSample)); pixel.FromLa16(source); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; offset += bytesPerPixel; } } @@ -259,23 +259,23 @@ internal static class PngScanlineProcessor for (int x = 0; x < header.Width; x++) { - int index = Unsafe.Add(ref scanlineSpanRef, x); - rgba.Rgb = Unsafe.Add(ref palettePixelsRef, index); - rgba.A = paletteAlpha.Length > index ? Unsafe.Add(ref paletteAlphaRef, index) : byte.MaxValue; + int index = Unsafe.Add(ref scanlineSpanRef, (uint)x); + rgba.Rgb = Unsafe.Add(ref palettePixelsRef, (uint)index); + rgba.A = paletteAlpha.Length > index ? Unsafe.Add(ref paletteAlphaRef, (uint)index) : byte.MaxValue; pixel.FromRgba32(rgba); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else { for (int x = 0; x < header.Width; x++) { - int index = Unsafe.Add(ref scanlineSpanRef, x); - Rgb24 rgb = Unsafe.Add(ref palettePixelsRef, index); + int index = Unsafe.Add(ref scanlineSpanRef, (uint)x); + Rgb24 rgb = Unsafe.Add(ref palettePixelsRef, (uint)index); pixel.FromRgb24(rgb); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } } @@ -304,23 +304,23 @@ internal static class PngScanlineProcessor ref byte paletteAlphaRef = ref paletteAlpha[0]; for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o++) { - int index = Unsafe.Add(ref scanlineSpanRef, o); - rgba.A = paletteAlpha.Length > index ? Unsafe.Add(ref paletteAlphaRef, index) : byte.MaxValue; - rgba.Rgb = Unsafe.Add(ref palettePixelsRef, index); + int index = Unsafe.Add(ref scanlineSpanRef, (uint)o); + rgba.A = paletteAlpha.Length > index ? Unsafe.Add(ref paletteAlphaRef, (uint)index) : byte.MaxValue; + rgba.Rgb = Unsafe.Add(ref palettePixelsRef, (uint)index); pixel.FromRgba32(rgba); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else { for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o++) { - int index = Unsafe.Add(ref scanlineSpanRef, o); - Rgb24 rgb = Unsafe.Add(ref palettePixelsRef, index); + int index = Unsafe.Add(ref scanlineSpanRef, (uint)o); + Rgb24 rgb = Unsafe.Add(ref palettePixelsRef, (uint)index); pixel.FromRgb24(rgb); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } } @@ -352,7 +352,7 @@ internal static class PngScanlineProcessor rgb48.B = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + (2 * bytesPerSample), bytesPerSample)); pixel.FromRgb48(rgb48); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else @@ -377,7 +377,7 @@ internal static class PngScanlineProcessor rgba64.A = rgb48.Equals(rgb48Trans) ? ushort.MinValue : ushort.MaxValue; pixel.FromRgba64(rgba64); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else @@ -387,12 +387,12 @@ internal static class PngScanlineProcessor ref Rgb24 rgb24SpanRef = ref MemoryMarshal.GetReference(rgb24Span); for (int x = 0; x < header.Width; x++) { - ref readonly Rgb24 rgb24 = ref Unsafe.Add(ref rgb24SpanRef, x); + ref readonly Rgb24 rgb24 = ref Unsafe.Add(ref rgb24SpanRef, (uint)x); rgba32.Rgb = rgb24; rgba32.A = rgb24.Equals(rgb24Trans) ? byte.MinValue : byte.MaxValue; pixel.FromRgba32(rgba32); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } } @@ -430,7 +430,7 @@ internal static class PngScanlineProcessor rgba64.A = rgb48.Equals(rgb48Trans) ? ushort.MinValue : ushort.MaxValue; pixel.FromRgba64(rgba64); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else @@ -443,7 +443,7 @@ internal static class PngScanlineProcessor rgb48.B = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + (2 * bytesPerSample), bytesPerSample)); pixel.FromRgb48(rgb48); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } @@ -455,13 +455,13 @@ internal static class PngScanlineProcessor Rgba32 rgba = default; for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += bytesPerPixel) { - rgba.R = Unsafe.Add(ref scanlineSpanRef, o); - rgba.G = Unsafe.Add(ref scanlineSpanRef, o + bytesPerSample); - rgba.B = Unsafe.Add(ref scanlineSpanRef, o + (2 * bytesPerSample)); + rgba.R = Unsafe.Add(ref scanlineSpanRef, (uint)o); + rgba.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample)); + rgba.B = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (2 * bytesPerSample))); rgba.A = rgb24Trans.Equals(rgba.Rgb) ? byte.MinValue : byte.MaxValue; pixel.FromRgba32(rgba); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else @@ -469,12 +469,12 @@ internal static class PngScanlineProcessor Rgb24 rgb = default; for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += bytesPerPixel) { - rgb.R = Unsafe.Add(ref scanlineSpanRef, o); - rgb.G = Unsafe.Add(ref scanlineSpanRef, o + bytesPerSample); - rgb.B = Unsafe.Add(ref scanlineSpanRef, o + (2 * bytesPerSample)); + rgb.R = Unsafe.Add(ref scanlineSpanRef, (uint)o); + rgb.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample)); + rgb.B = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (2 * bytesPerSample))); pixel.FromRgb24(rgb); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } } @@ -502,7 +502,7 @@ internal static class PngScanlineProcessor rgba64.A = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + (3 * bytesPerSample), bytesPerSample)); pixel.FromRgba64(rgba64); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else @@ -536,7 +536,7 @@ internal static class PngScanlineProcessor rgba64.A = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + (3 * bytesPerSample), bytesPerSample)); pixel.FromRgba64(rgba64); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } else @@ -544,13 +544,13 @@ internal static class PngScanlineProcessor Rgba32 rgba = default; for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += bytesPerPixel) { - rgba.R = Unsafe.Add(ref scanlineSpanRef, o); - rgba.G = Unsafe.Add(ref scanlineSpanRef, o + bytesPerSample); - rgba.B = Unsafe.Add(ref scanlineSpanRef, o + (2 * bytesPerSample)); - rgba.A = Unsafe.Add(ref scanlineSpanRef, o + (3 * bytesPerSample)); + rgba.R = Unsafe.Add(ref scanlineSpanRef, (uint)o); + rgba.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample)); + rgba.B = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (2 * bytesPerSample))); + rgba.A = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (3 * bytesPerSample))); pixel.FromRgba32(rgba); - Unsafe.Add(ref rowSpanRef, x) = pixel; + Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; } } } diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6TiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6TiffCompression.cs index eb97272cb8..1cd8e0dc80 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6TiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6TiffCompression.cs @@ -78,7 +78,7 @@ internal sealed class T6TiffCompression : TiffBaseDecompressor nint bitPos = Numerics.Modulo8(bitsWritten); nint bufferPos = bitsWritten / 8; ref byte scanLineRef = ref MemoryMarshal.GetReference(scanLine); - for (nint i = 0; i < scanLine.Length; i++) + for (nint i = 0; i < (uint)scanLine.Length; i++) { if (Unsafe.Add(ref scanLineRef, i) != this.white) { diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs index 6187ab8faa..a5a04d19d5 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs @@ -29,7 +29,7 @@ internal class BlackIsZero1TiffColor : TiffBaseColorDecoder { Span pixelRowSpan = pixels.DangerousGetRowSpan((int)y); ref TPixel pixelRowRef = ref MemoryMarshal.GetReference(pixelRowSpan); - for (nint x = left; x < left + width; x += 8) + for (nint x = (nint)(uint)left; x < (nint)(uint)(left + width); x += 8) { byte b = Unsafe.Add(ref dataRef, offset++); nint maxShift = Math.Min(left + width - x, 8); @@ -70,9 +70,9 @@ internal class BlackIsZero1TiffColor : TiffBaseColorDecoder } else { - for (int shift = 0; shift < maxShift; shift++) + for (nint shift = 0; shift < maxShift; shift++) { - int bit = (b >> (7 - shift)) & 1; + int bit = (b >> (7 - (int)shift)) & 1; ref TPixel pixel = ref Unsafe.Add(ref pixelRowRef, x + shift); pixel = bit == 0 ? colorBlack : colorWhite; diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs index a7519bc144..737f957676 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs @@ -24,11 +24,11 @@ internal class WhiteIsZero1TiffColor : TiffBaseColorDecoder colorBlack.FromRgba32(Color.Black); colorWhite.FromRgba32(Color.White); ref byte dataRef = ref MemoryMarshal.GetReference(data); - for (nint y = top; y < top + height; y++) + for (nint y = top; y < (nint)(uint)(top + height); y++) { Span pixelRowSpan = pixels.DangerousGetRowSpan((int)y); ref TPixel pixelRowRef = ref MemoryMarshal.GetReference(pixelRowSpan); - for (nint x = left; x < left + width; x += 8) + for (nint x = left; x < (nint)(uint)(left + width); x += 8) { byte b = Unsafe.Add(ref dataRef, offset++); nint maxShift = Math.Min(left + width - x, 8); @@ -73,7 +73,7 @@ internal class WhiteIsZero1TiffColor : TiffBaseColorDecoder { int bit = (b >> (7 - shift)) & 1; - ref TPixel pixel = ref Unsafe.Add(ref pixelRowRef, x + shift); + ref TPixel pixel = ref Unsafe.Add(ref pixelRowRef, x + (nint)(uint)shift); pixel = bit == 0 ? colorWhite : colorBlack; } } diff --git a/src/ImageSharp/Formats/Webp/AlphaDecoder.cs b/src/ImageSharp/Formats/Webp/AlphaDecoder.cs index 8875ae1150..637a38d1e4 100644 --- a/src/ImageSharp/Formats/Webp/AlphaDecoder.cs +++ b/src/ImageSharp/Formats/Webp/AlphaDecoder.cs @@ -322,7 +322,8 @@ internal class AlphaDecoder : IDisposable nint i; Vector128 last = Vector128.Zero.WithElement(0, dst[0]); ref byte srcRef = ref MemoryMarshal.GetReference(input); - for (i = 1; i + 8 <= width; i += 8) + ref byte dstRef = ref MemoryMarshal.GetReference(dst); + for (i = 1; i <= (uint)width - 8; i += 8) { Vector128 a0 = Vector128.Create(Unsafe.As(ref Unsafe.Add(ref srcRef, i)), 0); Vector128 a1 = Sse2.Add(a0.AsByte(), last.AsByte()); @@ -333,12 +334,12 @@ internal class AlphaDecoder : IDisposable Vector128 a6 = Sse2.ShiftLeftLogical128BitLane(a5, 4); Vector128 a7 = Sse2.Add(a5, a6); - ref byte outputRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(dst), i); + ref byte outputRef = ref Unsafe.Add(ref dstRef, i); Unsafe.As>(ref outputRef) = a7.GetLower(); last = Sse2.ShiftRightLogical(a7.AsInt64(), 56).AsInt32(); } - for (; i < width; ++i) + for (; i < (uint)width; ++i) { dst[(int)i] = (byte)(input[(int)i] + dst[(int)i - 1]); } @@ -366,7 +367,7 @@ internal class AlphaDecoder : IDisposable { nint i; int maxPos = width & ~31; - for (i = 0; i < maxPos; i += 32) + for (i = 0; i < (uint)maxPos; i += 32) { Vector256 a0 = Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(input), i)); Vector256 b0 = Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(prev), i)); @@ -375,7 +376,7 @@ internal class AlphaDecoder : IDisposable Unsafe.As>(ref outputRef) = c0; } - for (; i < width; i++) + for (; i < (uint) width; i++) { dst[(int)i] = (byte)(prev[(int)i] + input[(int)i]); } diff --git a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs index ac92ce6a6a..d4db3db53b 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs @@ -51,7 +51,7 @@ internal static unsafe class LosslessUtils ref uint array1Ref = ref MemoryMarshal.GetReference(array1); ref uint array2Ref = ref MemoryMarshal.GetReference(array2); - while (matchLen < length && Unsafe.Add(ref array1Ref, matchLen) == Unsafe.Add(ref array2Ref, matchLen)) + while (matchLen < length && Unsafe.Add(ref array1Ref, (uint)matchLen) == Unsafe.Add(ref array2Ref, (uint)matchLen)) { matchLen++; } @@ -99,7 +99,7 @@ internal static unsafe class LosslessUtils Vector256 addGreenToBlueAndRedMaskAvx2 = Vector256.Create(1, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 13, 255, 17, 255, 17, 255, 21, 255, 21, 255, 25, 255, 25, 255, 29, 255, 29, 255); int numPixels = pixelData.Length; nint i; - for (i = 0; i <= numPixels - 8; i += 8) + for (i = 0; i <= (nint)(uint)numPixels - 8; i += 8) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector256 input = Unsafe.As>(ref pos).AsByte(); @@ -118,7 +118,7 @@ internal static unsafe class LosslessUtils Vector128 addGreenToBlueAndRedMaskSsse3 = Vector128.Create(1, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 13, 255); int numPixels = pixelData.Length; nint i; - for (i = 0; i <= numPixels - 4; i += 4) + for (i = 0; i <= (nint)(uint)numPixels - 4; i += 4) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector128 input = Unsafe.As>(ref pos).AsByte(); @@ -136,7 +136,7 @@ internal static unsafe class LosslessUtils { int numPixels = pixelData.Length; nint i; - for (i = 0; i <= numPixels - 4; i += 4) + for (i = 0; i <= (nint)(uint)numPixels - 4; i += 4) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector128 input = Unsafe.As>(ref pos).AsByte(); @@ -179,7 +179,7 @@ internal static unsafe class LosslessUtils Vector256 subtractGreenFromBlueAndRedMaskAvx2 = Vector256.Create(1, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 13, 255, 17, 255, 17, 255, 21, 255, 21, 255, 25, 255, 25, 255, 29, 255, 29, 255); int numPixels = pixelData.Length; nint i; - for (i = 0; i <= numPixels - 8; i += 8) + for (i = 0; i <= (nint)(uint)numPixels - 8; i += 8) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector256 input = Unsafe.As>(ref pos).AsByte(); @@ -198,7 +198,7 @@ internal static unsafe class LosslessUtils Vector128 subtractGreenFromBlueAndRedMaskSsse3 = Vector128.Create(1, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 13, 255); int numPixels = pixelData.Length; nint i; - for (i = 0; i <= numPixels - 4; i += 4) + for (i = 0; i <= (nint)(uint)numPixels - 4; i += 4) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector128 input = Unsafe.As>(ref pos).AsByte(); @@ -216,7 +216,7 @@ internal static unsafe class LosslessUtils { int numPixels = pixelData.Length; nint i; - for (i = 0; i <= numPixels - 4; i += 4) + for (i = 0; i <= (nint)(uint)numPixels - 4; i += 4) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector128 input = Unsafe.As>(ref pos).AsByte(); @@ -373,7 +373,7 @@ internal static unsafe class LosslessUtils Vector256 multsb2 = MkCst32(Cst5b(m.RedToBlue), 0); nint idx; - for (idx = 0; idx <= numPixels - 8; idx += 8) + for (idx = 0; idx <= (nint)(uint)numPixels - 8; idx += 8) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), idx); Vector256 input = Unsafe.As>(ref pos); @@ -402,7 +402,7 @@ internal static unsafe class LosslessUtils Vector128 multsrb = MkCst16(Cst5b(m.GreenToRed), Cst5b(m.GreenToBlue)); Vector128 multsb2 = MkCst16(Cst5b(m.RedToBlue), 0); nint idx; - for (idx = 0; idx <= numPixels - 4; idx += 4) + for (idx = 0; idx <= (nint)(uint)numPixels - 4; idx += 4) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), idx); Vector128 input = Unsafe.As>(ref pos); @@ -461,7 +461,7 @@ internal static unsafe class LosslessUtils Vector256 multsrb = MkCst32(Cst5b(m.GreenToRed), Cst5b(m.GreenToBlue)); Vector256 multsb2 = MkCst32(Cst5b(m.RedToBlue), 0); nint idx; - for (idx = 0; idx <= pixelData.Length - 8; idx += 8) + for (idx = 0; idx <= (nint)(uint)pixelData.Length - 8; idx += 8) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), idx); Vector256 input = Unsafe.As>(ref pos); @@ -491,7 +491,7 @@ internal static unsafe class LosslessUtils Vector128 multsb2 = MkCst16(Cst5b(m.RedToBlue), 0); nint idx; - for (idx = 0; idx <= pixelData.Length - 4; idx += 4) + for (idx = 0; idx <= (nint)(uint)pixelData.Length - 4; idx += 4) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), idx); Vector128 input = Unsafe.As>(ref pos); diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs index a4bb2168d2..3f44a1bc05 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs @@ -518,28 +518,29 @@ internal sealed class Vp8LHistogram : IDeepCloneable ref uint aRef = ref MemoryMarshal.GetReference(a); ref uint bRef = ref MemoryMarshal.GetReference(b); ref uint outputRef = ref MemoryMarshal.GetReference(output); - int i; + nint idx; - for (i = 0; i + 32 <= count; i += 32) + for (idx = 0; idx <= (nint)(uint)count - 32; idx += 32) { // Load values. - Vector256 a0 = Unsafe.As>(ref Unsafe.Add(ref aRef, i)); - Vector256 a1 = Unsafe.As>(ref Unsafe.Add(ref aRef, i + 8)); - Vector256 a2 = Unsafe.As>(ref Unsafe.Add(ref aRef, i + 16)); - Vector256 a3 = Unsafe.As>(ref Unsafe.Add(ref aRef, i + 24)); - Vector256 b0 = Unsafe.As>(ref Unsafe.Add(ref bRef, i)); - Vector256 b1 = Unsafe.As>(ref Unsafe.Add(ref bRef, i + 8)); - Vector256 b2 = Unsafe.As>(ref Unsafe.Add(ref bRef, i + 16)); - Vector256 b3 = Unsafe.As>(ref Unsafe.Add(ref bRef, i + 24)); + Vector256 a0 = Unsafe.As>(ref Unsafe.Add(ref aRef, idx)); + Vector256 a1 = Unsafe.As>(ref Unsafe.Add(ref aRef, idx + 8)); + Vector256 a2 = Unsafe.As>(ref Unsafe.Add(ref aRef, idx + 16)); + Vector256 a3 = Unsafe.As>(ref Unsafe.Add(ref aRef, idx + 24)); + Vector256 b0 = Unsafe.As>(ref Unsafe.Add(ref bRef, idx)); + Vector256 b1 = Unsafe.As>(ref Unsafe.Add(ref bRef, idx + 8)); + Vector256 b2 = Unsafe.As>(ref Unsafe.Add(ref bRef, idx + 16)); + Vector256 b3 = Unsafe.As>(ref Unsafe.Add(ref bRef, idx + 24)); // Note we are adding uint32_t's as *signed* int32's (using _mm_add_epi32). But // that's ok since the histogram values are less than 1<<28 (max picture count). - Unsafe.As>(ref Unsafe.Add(ref outputRef, i)) = Avx2.Add(a0, b0); - Unsafe.As>(ref Unsafe.Add(ref outputRef, i + 8)) = Avx2.Add(a1, b1); - Unsafe.As>(ref Unsafe.Add(ref outputRef, i + 16)) = Avx2.Add(a2, b2); - Unsafe.As>(ref Unsafe.Add(ref outputRef, i + 24)) = Avx2.Add(a3, b3); + Unsafe.As>(ref Unsafe.Add(ref outputRef, idx)) = Avx2.Add(a0, b0); + Unsafe.As>(ref Unsafe.Add(ref outputRef, idx + 8)) = Avx2.Add(a1, b1); + Unsafe.As>(ref Unsafe.Add(ref outputRef, idx + 16)) = Avx2.Add(a2, b2); + Unsafe.As>(ref Unsafe.Add(ref outputRef, idx + 24)) = Avx2.Add(a3, b3); } + int i = (int)idx; for (; i < count; i++) { output[i] = a[i] + b[i]; diff --git a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs index 316c705e39..565e4c0293 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs @@ -1427,17 +1427,17 @@ internal static class LossyUtils if (Sse2.IsSupported) { // Load. - ref byte pRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(p), offset); + ref byte pRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(p), (uint)offset); Vector128 p1 = Unsafe.As>(ref Unsafe.Subtract(ref pRef, 2 * stride)); Vector128 p0 = Unsafe.As>(ref Unsafe.Subtract(ref pRef, stride)); Vector128 q0 = Unsafe.As>(ref pRef); - Vector128 q1 = Unsafe.As>(ref Unsafe.Add(ref pRef, stride)); + Vector128 q1 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)stride)); DoFilter2Sse2(ref p1, ref p0, ref q0, ref q1, thresh); // Store. - ref byte outputRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(p), offset); + ref byte outputRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(p), (uint)offset); Unsafe.As>(ref Unsafe.Subtract(ref outputRef, stride)) = p0.AsSByte(); Unsafe.As>(ref outputRef) = q0.AsSByte(); } @@ -1460,11 +1460,11 @@ internal static class LossyUtils if (Sse2.IsSupported) { // Beginning of p1 - ref byte pRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(p), offset - 2); + ref byte pRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(p), (uint)(offset - 2)); - Load16x4(ref pRef, ref Unsafe.Add(ref pRef, 8 * stride), stride, out Vector128 p1, out Vector128 p0, out Vector128 q0, out Vector128 q1); + Load16x4(ref pRef, ref Unsafe.Add(ref pRef, 8 * (uint)stride), stride, out Vector128 p1, out Vector128 p0, out Vector128 q0, out Vector128 q1); DoFilter2Sse2(ref p1, ref p0, ref q0, ref q1, thresh); - Store16x4(p1, p0, q0, q1, ref pRef, ref Unsafe.Add(ref pRef, 8 * stride), stride); + Store16x4(p1, p0, q0, q1, ref pRef, ref Unsafe.Add(ref pRef, 8 * (uint)stride), stride); } else { @@ -1527,19 +1527,19 @@ internal static class LossyUtils if (Sse2.IsSupported) { ref byte pRef = ref MemoryMarshal.GetReference(p); - Vector128 t1 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset - (4 * stride))); - Vector128 p2 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset - (3 * stride))); - Vector128 p1 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset - (2 * stride))); - Vector128 p0 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset - stride)); + Vector128 t1 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset - (4 * stride)))); + Vector128 p2 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset - (3 * stride)))); + Vector128 p1 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset - (2 * stride)))); + Vector128 p0 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset - stride))); Vector128 mask = Abs(p1, p0); mask = Sse2.Max(mask, Abs(t1, p2)); mask = Sse2.Max(mask, Abs(p2, p1)); - Vector128 q0 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset)); - Vector128 q1 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset + stride)); - Vector128 q2 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset + (2 * stride))); - t1 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset + (3 * stride))); + Vector128 q0 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)offset)); + Vector128 q1 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + stride))); + Vector128 q2 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + (2 * stride)))); + t1 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + (3 * stride)))); mask = Sse2.Max(mask, Abs(q1, q0)); mask = Sse2.Max(mask, Abs(t1, q2)); @@ -1550,12 +1550,12 @@ internal static class LossyUtils // Store. ref byte outputRef = ref MemoryMarshal.GetReference(p); - Unsafe.As>(ref Unsafe.Add(ref outputRef, offset - (3 * stride))) = p2.AsInt32(); - Unsafe.As>(ref Unsafe.Add(ref outputRef, offset - (2 * stride))) = p1.AsInt32(); - Unsafe.As>(ref Unsafe.Add(ref outputRef, offset - stride)) = p0.AsInt32(); - Unsafe.As>(ref Unsafe.Add(ref outputRef, offset)) = q0.AsInt32(); - Unsafe.As>(ref Unsafe.Add(ref outputRef, offset + stride)) = q1.AsInt32(); - Unsafe.As>(ref Unsafe.Add(ref outputRef, offset + (2 * stride))) = q2.AsInt32(); + Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset - (3 * stride)))) = p2.AsInt32(); + Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset - (2 * stride)))) = p1.AsInt32(); + Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset - stride))) = p0.AsInt32(); + Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset))) = q0.AsInt32(); + Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset + stride))) = q1.AsInt32(); + Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset + (2 * stride)))) = q2.AsInt32(); } else { @@ -1569,14 +1569,14 @@ internal static class LossyUtils if (Sse2.IsSupported) { ref byte pRef = ref MemoryMarshal.GetReference(p); - ref byte bRef = ref Unsafe.Add(ref pRef, offset - 4); - Load16x4(ref bRef, ref Unsafe.Add(ref bRef, 8 * stride), stride, out Vector128 p3, out Vector128 p2, out Vector128 p1, out Vector128 p0); + ref byte bRef = ref Unsafe.Add(ref pRef, (uint)offset - 4); + Load16x4(ref bRef, ref Unsafe.Add(ref bRef, 8 * (uint)stride), stride, out Vector128 p3, out Vector128 p2, out Vector128 p1, out Vector128 p0); Vector128 mask = Abs(p1, p0); mask = Sse2.Max(mask, Abs(p3, p2)); mask = Sse2.Max(mask, Abs(p2, p1)); - Load16x4(ref Unsafe.Add(ref pRef, offset), ref Unsafe.Add(ref pRef, offset + (8 * stride)), stride, out Vector128 q0, out Vector128 q1, out Vector128 q2, out Vector128 q3); + Load16x4(ref Unsafe.Add(ref pRef, (uint)offset), ref Unsafe.Add(ref pRef, (uint)(offset + (8 * stride))), stride, out Vector128 q0, out Vector128 q1, out Vector128 q2, out Vector128 q3); mask = Sse2.Max(mask, Abs(q1, q0)); mask = Sse2.Max(mask, Abs(q3, q2)); @@ -1585,8 +1585,8 @@ internal static class LossyUtils ComplexMask(p1, p0, q0, q1, thresh, ithresh, ref mask); DoFilter6Sse2(ref p2, ref p1, ref p0, ref q0, ref q1, ref q2, mask, hevThresh); - Store16x4(p3, p2, p1, p0, ref bRef, ref Unsafe.Add(ref bRef, 8 * stride), stride); - Store16x4(q0, q1, q2, q3, ref Unsafe.Add(ref pRef, offset), ref Unsafe.Add(ref pRef, offset + (8 * stride)), stride); + Store16x4(p3, p2, p1, p0, ref bRef, ref Unsafe.Add(ref bRef, 8 * (uint)stride), stride); + Store16x4(q0, q1, q2, q3, ref Unsafe.Add(ref pRef, (uint)offset), ref Unsafe.Add(ref pRef, (uint)(offset + (8 * stride))), stride); } else { @@ -1599,10 +1599,10 @@ internal static class LossyUtils if (Sse2.IsSupported) { ref byte pRef = ref MemoryMarshal.GetReference(p); - Vector128 p3 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset)); - Vector128 p2 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset + stride)); - Vector128 p1 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset + (2 * stride))); - Vector128 p0 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset + (3 * stride))); + Vector128 p3 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset))); + Vector128 p2 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + stride))); + Vector128 p1 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + (2 * stride)))); + Vector128 p0 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + (3 * stride)))); for (int k = 3; k > 0; k--) { @@ -1614,10 +1614,10 @@ internal static class LossyUtils mask = Sse2.Max(mask, Abs(p3, p2)); mask = Sse2.Max(mask, Abs(p2, p1)); - p3 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset)); - p2 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset + stride)); - Vector128 tmp1 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset + (2 * stride))); - Vector128 tmp2 = Unsafe.As>(ref Unsafe.Add(ref pRef, offset + (3 * stride))); + p3 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)offset)); + p2 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + stride))); + Vector128 tmp1 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + (2 * stride)))); + Vector128 tmp2 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + (3 * stride)))); mask = Sse2.Max(mask, Abs(tmp1, tmp2)); mask = Sse2.Max(mask, Abs(p3, p2)); @@ -1631,9 +1631,9 @@ internal static class LossyUtils // Store. ref byte outputRef = ref MemoryMarshal.GetReference(b); Unsafe.As>(ref outputRef) = p1.AsInt32(); - Unsafe.As>(ref Unsafe.Add(ref outputRef, stride)) = p0.AsInt32(); - Unsafe.As>(ref Unsafe.Add(ref outputRef, stride * 2)) = p3.AsInt32(); - Unsafe.As>(ref Unsafe.Add(ref outputRef, stride * 3)) = p2.AsInt32(); + Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)stride)) = p0.AsInt32(); + Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(stride * 2))) = p3.AsInt32(); + Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(stride * 3))) = p2.AsInt32(); // Rotate samples. p1 = tmp1; @@ -1655,13 +1655,13 @@ internal static class LossyUtils if (Sse2.IsSupported) { ref byte pRef = ref MemoryMarshal.GetReference(p); - Load16x4(ref Unsafe.Add(ref pRef, offset), ref Unsafe.Add(ref pRef, offset + (8 * stride)), stride, out Vector128 p3, out Vector128 p2, out Vector128 p1, out Vector128 p0); + Load16x4(ref Unsafe.Add(ref pRef, (uint)offset), ref Unsafe.Add(ref pRef, (uint)(offset + (8 * stride))), stride, out Vector128 p3, out Vector128 p2, out Vector128 p1, out Vector128 p0); Vector128 mask; for (int k = 3; k > 0; k--) { // Beginning of p1. - ref byte bRef = ref Unsafe.Add(ref pRef, offset + 2); + ref byte bRef = ref Unsafe.Add(ref pRef, (uint)offset + 2); // Beginning of q0 (and next span). offset += 4; @@ -1671,7 +1671,7 @@ internal static class LossyUtils mask = Sse2.Max(mask, Abs(p3, p2)); mask = Sse2.Max(mask, Abs(p2, p1)); - Load16x4(ref Unsafe.Add(ref pRef, offset), ref Unsafe.Add(ref pRef, offset + (8 * stride)), stride, out p3, out p2, out Vector128 tmp1, out Vector128 tmp2); + Load16x4(ref Unsafe.Add(ref pRef, (uint)offset), ref Unsafe.Add(ref pRef, (uint)(offset + (8 * stride))), stride, out p3, out p2, out Vector128 tmp1, out Vector128 tmp2); mask = Sse2.Max(mask, Abs(tmp1, tmp2)); mask = Sse2.Max(mask, Abs(p3, p2)); @@ -1680,7 +1680,7 @@ internal static class LossyUtils ComplexMask(p1, p0, p3, p2, thresh, ithresh, ref mask); DoFilter4Sse2(ref p1, ref p0, ref p3, ref p2, mask, hevThresh); - Store16x4(p1, p0, p3, p2, ref bRef, ref Unsafe.Add(ref bRef, 8 * stride), stride); + Store16x4(p1, p0, p3, p2, ref bRef, ref Unsafe.Add(ref bRef, 8 * (uint)stride), stride); // Rotate samples. p1 = tmp1; @@ -1749,13 +1749,13 @@ internal static class LossyUtils { ref byte uRef = ref MemoryMarshal.GetReference(u); ref byte vRef = ref MemoryMarshal.GetReference(v); - Load16x4(ref Unsafe.Add(ref uRef, offset - 4), ref Unsafe.Add(ref vRef, offset - 4), stride, out Vector128 p3, out Vector128 p2, out Vector128 p1, out Vector128 p0); + Load16x4(ref Unsafe.Add(ref uRef, (uint)offset - 4), ref Unsafe.Add(ref vRef, (uint)offset - 4), stride, out Vector128 p3, out Vector128 p2, out Vector128 p1, out Vector128 p0); Vector128 mask = Abs(p1, p0); mask = Sse2.Max(mask, Abs(p3, p2)); mask = Sse2.Max(mask, Abs(p2, p1)); - Load16x4(ref Unsafe.Add(ref uRef, offset), ref Unsafe.Add(ref vRef, offset), stride, out Vector128 q0, out Vector128 q1, out Vector128 q2, out Vector128 q3); + Load16x4(ref Unsafe.Add(ref uRef, (uint)offset), ref Unsafe.Add(ref vRef, (uint)offset), stride, out Vector128 q0, out Vector128 q1, out Vector128 q2, out Vector128 q3); mask = Sse2.Max(mask, Abs(q1, q0)); mask = Sse2.Max(mask, Abs(q3, q2)); @@ -1764,8 +1764,8 @@ internal static class LossyUtils ComplexMask(p1, p0, q0, q1, thresh, ithresh, ref mask); DoFilter6Sse2(ref p2, ref p1, ref p0, ref q0, ref q1, ref q2, mask, hevThresh); - Store16x4(p3, p2, p1, p0, ref Unsafe.Add(ref uRef, offset - 4), ref Unsafe.Add(ref vRef, offset - 4), stride); - Store16x4(q0, q1, q2, q3, ref Unsafe.Add(ref uRef, offset), ref Unsafe.Add(ref vRef, offset), stride); + Store16x4(p3, p2, p1, p0, ref Unsafe.Add(ref uRef, (uint)offset - 4), ref Unsafe.Add(ref vRef, (uint)offset - 4), stride); + Store16x4(q0, q1, q2, q3, ref Unsafe.Add(ref uRef, (uint)offset), ref Unsafe.Add(ref vRef, (uint)offset), stride); } else { @@ -1826,7 +1826,7 @@ internal static class LossyUtils { ref byte uRef = ref MemoryMarshal.GetReference(u); ref byte vRef = ref MemoryMarshal.GetReference(v); - Load16x4(ref Unsafe.Add(ref uRef, offset), ref Unsafe.Add(ref vRef, offset), stride, out Vector128 t2, out Vector128 t1, out Vector128 p1, out Vector128 p0); + Load16x4(ref Unsafe.Add(ref uRef, (uint)offset), ref Unsafe.Add(ref vRef, (uint)offset), stride, out Vector128 t2, out Vector128 t1, out Vector128 p1, out Vector128 p0); Vector128 mask = Abs(p1, p0); mask = Sse2.Max(mask, Abs(t2, t1)); @@ -1835,7 +1835,7 @@ internal static class LossyUtils // Beginning of q0. offset += 4; - Load16x4(ref Unsafe.Add(ref uRef, offset), ref Unsafe.Add(ref vRef, offset), stride, out Vector128 q0, out Vector128 q1, out t1, out t2); + Load16x4(ref Unsafe.Add(ref uRef, (uint)offset), ref Unsafe.Add(ref vRef, (uint)offset), stride, out Vector128 q0, out Vector128 q1, out t1, out t2); mask = Sse2.Max(mask, Abs(q1, q0)); mask = Sse2.Max(mask, Abs(t2, t1)); @@ -1846,7 +1846,7 @@ internal static class LossyUtils // Beginning of p1. offset -= 2; - Store16x4(p1, p0, q0, q1, ref Unsafe.Add(ref uRef, offset), ref Unsafe.Add(ref vRef, offset), stride); + Store16x4(p1, p0, q0, q1, ref Unsafe.Add(ref uRef, (uint)offset), ref Unsafe.Add(ref vRef, (uint)offset), stride); } else { @@ -2278,8 +2278,8 @@ internal static class LossyUtils // q0 = 73 63 53 43 33 23 13 03 72 62 52 42 32 22 12 02 // p0 = f1 e1 d1 c1 b1 a1 91 81 f0 e0 d0 c0 b0 a0 90 80 // q1 = f3 e3 d3 c3 b3 a3 93 83 f2 e2 d2 c2 b2 a2 92 82 - Load8x4(ref r0, stride, out Vector128 t1, out Vector128 t2); - Load8x4(ref r8, stride, out p0, out q1); + Load8x4(ref r0, (nint)(uint)stride, out Vector128 t1, out Vector128 t2); + Load8x4(ref r8, (nint)(uint)stride, out p0, out q1); // p1 = f0 e0 d0 c0 b0 a0 90 80 70 60 50 40 30 20 10 00 // p0 = f1 e1 d1 c1 b1 a1 91 81 71 61 51 41 31 21 11 01 @@ -2292,7 +2292,7 @@ internal static class LossyUtils } // Reads 8 rows across a vertical edge. - private static void Load8x4(ref byte bRef, int stride, out Vector128 p, out Vector128 q) + private static void Load8x4(ref byte bRef, nint stride, out Vector128 p, out Vector128 q) { // A0 = 63 62 61 60 23 22 21 20 43 42 41 40 03 02 01 00 // A1 = 73 72 71 70 33 32 31 30 53 52 51 50 13 12 11 10 @@ -2349,10 +2349,10 @@ internal static class LossyUtils q1s = Sse2.UnpackHigh(t1.AsInt16(), q1s.AsInt16()).AsByte(); Store4x4(p0s, ref r0Ref, stride); - Store4x4(q0s, ref Unsafe.Add(ref r0Ref, 4 * stride), stride); + Store4x4(q0s, ref Unsafe.Add(ref r0Ref, 4 * (uint)stride), stride); Store4x4(p1s, ref r8Ref, stride); - Store4x4(q1s, ref Unsafe.Add(ref r8Ref, 4 * stride), stride); + Store4x4(q1s, ref Unsafe.Add(ref r8Ref, 4 * (uint)stride), stride); } private static void Store4x4(Vector128 x, ref byte dstRef, int stride) @@ -2360,7 +2360,7 @@ internal static class LossyUtils int offset = 0; for (int i = 0; i < 4; i++) { - Unsafe.As(ref Unsafe.Add(ref dstRef, offset)) = Sse2.ConvertToInt32(x.AsInt32()); + Unsafe.As(ref Unsafe.Add(ref dstRef, (uint)offset)) = Sse2.ConvertToInt32(x.AsInt32()); x = Sse2.ShiftRightLogical128BitLane(x, 4); offset += stride; } @@ -2421,16 +2421,16 @@ internal static class LossyUtils [MethodImpl(InliningOptions.ShortMethod)] private static Vector128 LoadUvEdge(ref byte uRef, ref byte vRef, int offset) { - var uVec = Vector128.Create(Unsafe.As(ref Unsafe.Add(ref uRef, offset)), 0); - var vVec = Vector128.Create(Unsafe.As(ref Unsafe.Add(ref vRef, offset)), 0); + var uVec = Vector128.Create(Unsafe.As(ref Unsafe.Add(ref uRef, (uint)offset)), 0); + var vVec = Vector128.Create(Unsafe.As(ref Unsafe.Add(ref vRef, (uint)offset)), 0); return Sse2.UnpackLow(uVec, vVec).AsByte(); } [MethodImpl(InliningOptions.ShortMethod)] private static void StoreUv(Vector128 x, ref byte uRef, ref byte vRef, int offset) { - Unsafe.As>(ref Unsafe.Add(ref uRef, offset)) = x.GetLower(); - Unsafe.As>(ref Unsafe.Add(ref vRef, offset)) = x.GetUpper(); + Unsafe.As>(ref Unsafe.Add(ref uRef, (uint)offset)) = x.GetLower(); + Unsafe.As>(ref Unsafe.Add(ref vRef, (uint)offset)) = x.GetUpper(); } // Compute abs(p - q) = subs(p - q) OR subs(q - p) diff --git a/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs b/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs index fca0d03f23..75b92a1aaa 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs @@ -789,7 +789,7 @@ internal static unsafe class QuantEnc { int score = 0; ref short levelsRef = ref MemoryMarshal.GetReference(levels); - int offset = 0; + nint offset = 0; while (numBlocks-- > 0) { for (nint i = 1; i < 16; i++) diff --git a/src/ImageSharp/Formats/Webp/Lossy/YuvConversion.cs b/src/ImageSharp/Formats/Webp/Lossy/YuvConversion.cs index 5c6dde6224..8ef7fe9cba 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/YuvConversion.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/YuvConversion.cs @@ -138,8 +138,8 @@ internal static class YuvConversion { for (pos = 1, uvPos = 0; pos + 32 + 1 <= len; pos += 32, uvPos += 16) { - UpSample32Pixels(ref Unsafe.Add(ref topURef, uvPos), ref Unsafe.Add(ref curURef, uvPos), ru); - UpSample32Pixels(ref Unsafe.Add(ref topVRef, uvPos), ref Unsafe.Add(ref curVRef, uvPos), rv); + UpSample32Pixels(ref Unsafe.Add(ref topURef, (uint)uvPos), ref Unsafe.Add(ref curURef, (uint)uvPos), ru); + UpSample32Pixels(ref Unsafe.Add(ref topVRef, (uint)uvPos), ref Unsafe.Add(ref curVRef, (uint)uvPos), rv); ConvertYuvToBgrWithBottomYSse41(topY, bottomY, topDst, bottomDst, ru, rv, pos, xStep); } } @@ -147,8 +147,8 @@ internal static class YuvConversion { for (pos = 1, uvPos = 0; pos + 32 + 1 <= len; pos += 32, uvPos += 16) { - UpSample32Pixels(ref Unsafe.Add(ref topURef, uvPos), ref Unsafe.Add(ref curURef, uvPos), ru); - UpSample32Pixels(ref Unsafe.Add(ref topVRef, uvPos), ref Unsafe.Add(ref curVRef, uvPos), rv); + UpSample32Pixels(ref Unsafe.Add(ref topURef, (uint)uvPos), ref Unsafe.Add(ref curURef, (uint)uvPos), ru); + UpSample32Pixels(ref Unsafe.Add(ref topVRef, (uint)uvPos), ref Unsafe.Add(ref curVRef, (uint)uvPos), rv); ConvertYuvToBgrSse41(topY, topDst, ru, rv, pos, xStep); } } diff --git a/src/ImageSharp/Memory/Allocators/Internals/ManagedBufferBase.cs b/src/ImageSharp/Memory/Allocators/Internals/ManagedBufferBase.cs index a18bd34474..a6ed797d6d 100644 --- a/src/ImageSharp/Memory/Allocators/Internals/ManagedBufferBase.cs +++ b/src/ImageSharp/Memory/Allocators/Internals/ManagedBufferBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System.Buffers; diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs index d63fd2076c..9695c7f98f 100644 --- a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs +++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs @@ -252,7 +252,7 @@ internal abstract partial class MemoryGroup : IMemoryGroup, IDisposable { ref byte b0 = ref MemoryMarshal.GetReference(this.memoryGroupSpanCache.SingleArray); ref T e0 = ref Unsafe.As(ref b0); - e0 = ref Unsafe.Add(ref e0, y * width); + e0 = ref Unsafe.Add(ref e0, (uint)(y * width)); return MemoryMarshal.CreateSpan(ref e0, width); } diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs index 2db61a06f3..0792306760 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs @@ -52,7 +52,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -89,7 +89,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -157,7 +157,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -194,7 +194,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -262,7 +262,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -299,7 +299,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -367,7 +367,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -404,7 +404,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -472,7 +472,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -509,7 +509,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -577,7 +577,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -614,7 +614,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -682,7 +682,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -719,7 +719,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -787,7 +787,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -824,7 +824,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -892,7 +892,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -929,7 +929,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -997,7 +997,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1034,7 +1034,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1102,7 +1102,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1139,7 +1139,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1207,7 +1207,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1244,7 +1244,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1312,7 +1312,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1349,7 +1349,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1417,7 +1417,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1454,7 +1454,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1522,7 +1522,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1559,7 +1559,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1627,7 +1627,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1664,7 +1664,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1732,7 +1732,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1769,7 +1769,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1837,7 +1837,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1874,7 +1874,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1942,7 +1942,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -1979,7 +1979,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2047,7 +2047,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2084,7 +2084,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2152,7 +2152,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2189,7 +2189,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2257,7 +2257,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2294,7 +2294,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2362,7 +2362,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2399,7 +2399,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2467,7 +2467,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2504,7 +2504,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2572,7 +2572,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2609,7 +2609,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2677,7 +2677,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2714,7 +2714,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2782,7 +2782,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2819,7 +2819,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2887,7 +2887,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2924,7 +2924,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -2992,7 +2992,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3029,7 +3029,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3097,7 +3097,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3134,7 +3134,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3202,7 +3202,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3239,7 +3239,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3307,7 +3307,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3344,7 +3344,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3412,7 +3412,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3449,7 +3449,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3517,7 +3517,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3554,7 +3554,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3622,7 +3622,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3659,7 +3659,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3727,7 +3727,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3764,7 +3764,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3832,7 +3832,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3869,7 +3869,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3937,7 +3937,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -3974,7 +3974,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4042,7 +4042,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4079,7 +4079,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4147,7 +4147,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4184,7 +4184,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4252,7 +4252,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4289,7 +4289,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4357,7 +4357,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4394,7 +4394,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4462,7 +4462,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4499,7 +4499,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4567,7 +4567,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4604,7 +4604,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4672,7 +4672,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4709,7 +4709,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4777,7 +4777,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4814,7 +4814,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4882,7 +4882,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4919,7 +4919,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -4987,7 +4987,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5024,7 +5024,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5092,7 +5092,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5129,7 +5129,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5197,7 +5197,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5234,7 +5234,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5302,7 +5302,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5339,7 +5339,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5407,7 +5407,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5444,7 +5444,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5512,7 +5512,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5549,7 +5549,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5617,7 +5617,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5654,7 +5654,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5722,7 +5722,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5759,7 +5759,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5827,7 +5827,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5864,7 +5864,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5932,7 +5932,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -5969,7 +5969,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6037,7 +6037,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6074,7 +6074,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6142,7 +6142,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6179,7 +6179,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6247,7 +6247,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6284,7 +6284,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6352,7 +6352,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6389,7 +6389,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6457,7 +6457,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6494,7 +6494,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6562,7 +6562,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6599,7 +6599,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6667,7 +6667,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6704,7 +6704,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6772,7 +6772,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6809,7 +6809,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6877,7 +6877,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6914,7 +6914,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -6982,7 +6982,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7019,7 +7019,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7087,7 +7087,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7124,7 +7124,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7192,7 +7192,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7229,7 +7229,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7297,7 +7297,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7334,7 +7334,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7402,7 +7402,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7439,7 +7439,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7507,7 +7507,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7544,7 +7544,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7612,7 +7612,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7649,7 +7649,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7717,7 +7717,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7754,7 +7754,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7822,7 +7822,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7859,7 +7859,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7927,7 +7927,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -7964,7 +7964,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8032,7 +8032,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8069,7 +8069,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8137,7 +8137,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8174,7 +8174,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8242,7 +8242,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8279,7 +8279,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8347,7 +8347,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8384,7 +8384,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8452,7 +8452,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8489,7 +8489,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8557,7 +8557,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8594,7 +8594,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8662,7 +8662,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8699,7 +8699,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8767,7 +8767,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8804,7 +8804,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8872,7 +8872,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8909,7 +8909,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -8977,7 +8977,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9014,7 +9014,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9082,7 +9082,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9119,7 +9119,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9187,7 +9187,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9224,7 +9224,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9292,7 +9292,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9329,7 +9329,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9397,7 +9397,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9434,7 +9434,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9502,7 +9502,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9539,7 +9539,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9607,7 +9607,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9644,7 +9644,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9712,7 +9712,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9749,7 +9749,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9817,7 +9817,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9854,7 +9854,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9922,7 +9922,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -9959,7 +9959,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10027,7 +10027,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10064,7 +10064,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10132,7 +10132,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10169,7 +10169,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10237,7 +10237,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10274,7 +10274,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10342,7 +10342,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10379,7 +10379,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10447,7 +10447,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10484,7 +10484,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10552,7 +10552,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10589,7 +10589,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10657,7 +10657,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10694,7 +10694,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10762,7 +10762,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10799,7 +10799,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10867,7 +10867,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10904,7 +10904,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -10972,7 +10972,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -11009,7 +11009,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -11077,7 +11077,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -11114,7 +11114,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -11182,7 +11182,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -11219,7 +11219,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -11287,7 +11287,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -11324,7 +11324,7 @@ internal static class DefaultPixelBlenders { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt index 22b9ebf982..da6208eaa2 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt @@ -95,7 +95,7 @@ var blenders = new []{ { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -132,7 +132,7 @@ var blenders = new []{ { // Divide by 2 as 4 elements per Vector4 and 8 per Vector256 ref Vector256 destinationBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (IntPtr)((uint)destination.Length / 2u)); + ref Vector256 destinationLast = ref Unsafe.Add(ref destinationBase, (uint)destination.Length / 2u); ref Vector256 backgroundBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(background)); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs index ca68c5aaf9..4891abba8c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs @@ -216,7 +216,7 @@ public partial struct Abgr32 : IPixel, IPackedVector { // We can assign the Bgr24 value directly to last three bytes of this instance. ref byte thisRef = ref Unsafe.As(ref this); - ref byte thisRefFromB = ref Unsafe.AddByteOffset(ref thisRef, new IntPtr(1)); + ref byte thisRefFromB = ref Unsafe.AddByteOffset(ref thisRef, 1); Unsafe.As(ref thisRefFromB) = source; this.A = byte.MaxValue; } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs index 65b36059b8..aedf4ad198 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs @@ -190,7 +190,7 @@ public partial struct Bgr24 : IPixel { // We can assign this instances value directly to last three bytes of the Abgr32. ref byte sourceRef = ref Unsafe.As(ref source); - ref byte sourceRefFromB = ref Unsafe.AddByteOffset(ref sourceRef, new IntPtr(1)); + ref byte sourceRefFromB = ref Unsafe.AddByteOffset(ref sourceRef, 1); this = Unsafe.As(ref sourceRefFromB); } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs index cb67f7ffb6..9fca0cdc35 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs @@ -210,7 +210,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -231,7 +231,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -252,7 +252,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -273,7 +273,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -294,7 +294,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -315,7 +315,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -336,7 +336,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs index 5dcca2ad1e..e87926be8b 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs @@ -210,7 +210,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -231,7 +231,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -252,7 +252,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -273,7 +273,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -294,7 +294,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -315,7 +315,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -336,7 +336,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs index dbadb86014..32eed0ce40 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs @@ -210,7 +210,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -231,7 +231,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -252,7 +252,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -273,7 +273,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -294,7 +294,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -315,7 +315,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -336,7 +336,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs index b3643313c4..4e7800c624 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs @@ -210,7 +210,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -231,7 +231,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -252,7 +252,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -273,7 +273,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -294,7 +294,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -315,7 +315,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -336,7 +336,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs index 52022b0c78..62864ad209 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); @@ -113,7 +113,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -155,7 +155,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -176,7 +176,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -197,7 +197,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -218,7 +218,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); @@ -239,7 +239,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); @@ -260,7 +260,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -281,7 +281,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs index a1a59727ff..b37d9d86aa 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); @@ -113,7 +113,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -155,7 +155,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -176,7 +176,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -197,7 +197,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); @@ -218,7 +218,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); @@ -239,7 +239,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -260,7 +260,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -281,7 +281,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs index f0ada6459c..9d67d8741f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); @@ -113,7 +113,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -155,7 +155,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -176,7 +176,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -197,7 +197,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); @@ -218,7 +218,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); @@ -239,7 +239,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -260,7 +260,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -281,7 +281,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs index d0610037d5..5afea82021 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs index fd1cfd74de..519f1a6936 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs @@ -210,7 +210,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -231,7 +231,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -252,7 +252,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -273,7 +273,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -294,7 +294,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -315,7 +315,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -336,7 +336,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs index 417ed34334..e58818deac 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); @@ -113,7 +113,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -155,7 +155,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -176,7 +176,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -197,7 +197,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -218,7 +218,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); @@ -239,7 +239,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); @@ -260,7 +260,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -281,7 +281,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude index ab08bfa570..5a5d135db1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude @@ -103,7 +103,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils; ref <#=fromPixelType#> sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref <#=toPixelType#> destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref <#=fromPixelType#> sp = ref Unsafe.Add(ref sourceRef, i); ref <#=toPixelType#> dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs index 3fcb4bc610..ed1d3cb2bd 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs @@ -72,7 +72,7 @@ public partial struct RgbaVector ref Vector4 sourceBaseRef = ref Unsafe.As(ref MemoryMarshal.GetReference(sourcePixels)); ref L8 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Vector4 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref L8 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -91,7 +91,7 @@ public partial struct RgbaVector ref Vector4 sourceBaseRef = ref Unsafe.As(ref MemoryMarshal.GetReference(sourcePixels)); ref L16 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref Vector4 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref L16 dp = ref Unsafe.Add(ref destBaseRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs index a4c2fb7a0c..26ca4d1b5a 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs @@ -22,7 +22,7 @@ public partial class PixelOperations ref Argb32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -58,7 +58,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Argb32 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -94,7 +94,7 @@ public partial class PixelOperations ref Abgr32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -130,7 +130,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -166,7 +166,7 @@ public partial class PixelOperations ref Bgr24 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -202,7 +202,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -238,7 +238,7 @@ public partial class PixelOperations ref Bgra32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -274,7 +274,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -310,7 +310,7 @@ public partial class PixelOperations ref L8 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -346,7 +346,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref L8 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -382,7 +382,7 @@ public partial class PixelOperations ref L16 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -418,7 +418,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref L16 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -454,7 +454,7 @@ public partial class PixelOperations ref La16 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -490,7 +490,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref La16 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -526,7 +526,7 @@ public partial class PixelOperations ref La32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -562,7 +562,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref La32 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -598,7 +598,7 @@ public partial class PixelOperations ref Rgb24 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -634,7 +634,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -670,7 +670,7 @@ public partial class PixelOperations ref Rgba32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref Rgba32 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -706,7 +706,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -742,7 +742,7 @@ public partial class PixelOperations ref Rgb48 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -778,7 +778,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -814,7 +814,7 @@ public partial class PixelOperations ref Rgba64 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -850,7 +850,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -886,7 +886,7 @@ public partial class PixelOperations ref Bgra5551 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -922,7 +922,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destBaseRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt index 31bd0ce6d0..39cf873bfd 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt @@ -28,7 +28,7 @@ ref <#=pixelType#> sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref <#=pixelType#> sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -70,7 +70,7 @@ ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref <#=pixelType#> destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref <#=pixelType#> dp = ref Unsafe.Add(ref destBaseRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs index 2465493f58..b18e38f4d5 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs @@ -187,7 +187,7 @@ public partial class PixelOperations ref byte b = ref MemoryMarshal.GetReference(blueChannel); ref TPixel d = ref MemoryMarshal.GetReference(destination); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { rgb24.R = Unsafe.Add(ref r, i); rgb24.G = Unsafe.Add(ref g, i); @@ -218,7 +218,7 @@ public partial class PixelOperations ref float g = ref MemoryMarshal.GetReference(greenChannel); ref float b = ref MemoryMarshal.GetReference(blueChannel); ref TPixel src = ref MemoryMarshal.GetReference(source); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Unsafe.Add(ref src, i).ToRgba32(ref rgba32); Unsafe.Add(ref r, i) = rgba32.R; diff --git a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs index 251f8d64db..4d07a8a9b6 100644 --- a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs +++ b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.Default.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System.Numerics; @@ -88,7 +88,7 @@ internal static partial class Vector4Converters where TPixel : unmanaged, IPixel { ref Vector4 sourceStart = ref MemoryMarshal.GetReference(sourceVectors); - ref Vector4 sourceEnd = ref Unsafe.Add(ref sourceStart, sourceVectors.Length); + ref Vector4 sourceEnd = ref Unsafe.Add(ref sourceStart, (uint)sourceVectors.Length); ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels); while (Unsafe.IsAddressLessThan(ref sourceStart, ref sourceEnd)) @@ -107,7 +107,7 @@ internal static partial class Vector4Converters where TPixel : unmanaged, IPixel { ref TPixel sourceStart = ref MemoryMarshal.GetReference(sourcePixels); - ref TPixel sourceEnd = ref Unsafe.Add(ref sourceStart, sourcePixels.Length); + ref TPixel sourceEnd = ref Unsafe.Add(ref sourceStart, (uint)sourcePixels.Length); ref Vector4 destRef = ref MemoryMarshal.GetReference(destVectors); while (Unsafe.IsAddressLessThan(ref sourceStart, ref sourceEnd)) @@ -126,7 +126,7 @@ internal static partial class Vector4Converters where TPixel : unmanaged, IPixel { ref Vector4 sourceStart = ref MemoryMarshal.GetReference(sourceVectors); - ref Vector4 sourceEnd = ref Unsafe.Add(ref sourceStart, sourceVectors.Length); + ref Vector4 sourceEnd = ref Unsafe.Add(ref sourceStart, (uint)sourceVectors.Length); ref TPixel destRef = ref MemoryMarshal.GetReference(destinationColors); while (Unsafe.IsAddressLessThan(ref sourceStart, ref sourceEnd)) @@ -145,7 +145,7 @@ internal static partial class Vector4Converters where TPixel : unmanaged, IPixel { ref TPixel sourceStart = ref MemoryMarshal.GetReference(sourceColors); - ref TPixel sourceEnd = ref Unsafe.Add(ref sourceStart, sourceColors.Length); + ref TPixel sourceEnd = ref Unsafe.Add(ref sourceStart, (uint)sourceColors.Length); ref Vector4 destRef = ref MemoryMarshal.GetReference(destinationVectors); while (Unsafe.IsAddressLessThan(ref sourceStart, ref sourceEnd)) diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs index 0ceb5bc130..04653bd6ec 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs @@ -128,19 +128,19 @@ public sealed class BokehBlurProcessor : IImageProcessor int boundsWidth = this.bounds.Width; int kernelSize = this.kernel.Length; - ref int sampleRowBase = ref Unsafe.Add(ref MemoryMarshal.GetReference(this.map.GetRowOffsetSpan()), (y - this.bounds.Y) * kernelSize); + ref int sampleRowBase = ref Unsafe.Add(ref MemoryMarshal.GetReference(this.map.GetRowOffsetSpan()), (uint)((y - this.bounds.Y) * kernelSize)); // The target buffer is zeroed initially and then it accumulates the results // of each partial convolution, so we don't have to clear it here as well ref Vector4 targetBase = ref this.targetValues.GetElementUnsafe(boundsX, y); ref Complex64 kernelStart = ref this.kernel[0]; - ref Complex64 kernelEnd = ref Unsafe.Add(ref kernelStart, kernelSize); + ref Complex64 kernelEnd = ref Unsafe.Add(ref kernelStart, (uint)kernelSize); while (Unsafe.IsAddressLessThan(ref kernelStart, ref kernelEnd)) { // Get the precalculated source sample row for this kernel row and copy to our buffer ref ComplexVector4 sourceBase = ref this.sourceValues.GetElementUnsafe(0, sampleRowBase); - ref ComplexVector4 sourceEnd = ref Unsafe.Add(ref sourceBase, boundsWidth); + ref ComplexVector4 sourceEnd = ref Unsafe.Add(ref sourceBase, (uint)boundsWidth); ref Vector4 targetStart = ref targetBase; Complex64 factor = kernelStart; diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs index 55c03abe6a..2508a7da25 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs @@ -157,8 +157,8 @@ internal class BokehBlurProcessor : ImageProcessor for (int i = 0; i < this.kernels.Length; i++) { // Compute the resulting complex buffer for the current component - Complex64[] kernel = Unsafe.Add(ref baseRef, i); - Vector4 parameters = Unsafe.Add(ref paramsRef, i); + Complex64[] kernel = Unsafe.Add(ref baseRef, (uint)i); + Vector4 parameters = Unsafe.Add(ref paramsRef, (uint)i); // Horizontal convolution var horizontalOperation = new FirstPassConvolutionRowOperation( @@ -243,9 +243,9 @@ internal class BokehBlurProcessor : ImageProcessor ref Vector4 sourceBase = ref MemoryMarshal.GetReference(span); ref ComplexVector4 targetStart = ref MemoryMarshal.GetReference(targetBuffer); - ref ComplexVector4 targetEnd = ref Unsafe.Add(ref targetStart, span.Length); + ref ComplexVector4 targetEnd = ref Unsafe.Add(ref targetStart, (uint)span.Length); ref Complex64 kernelBase = ref this.kernel[0]; - ref Complex64 kernelEnd = ref Unsafe.Add(ref kernelBase, kernelSize); + ref Complex64 kernelEnd = ref Unsafe.Add(ref kernelBase, (uint)kernelSize); ref int sampleColumnBase = ref MemoryMarshal.GetReference(this.map.GetColumnOffsetSpan()); while (Unsafe.IsAddressLessThan(ref targetStart, ref targetEnd)) @@ -255,7 +255,7 @@ internal class BokehBlurProcessor : ImageProcessor while (Unsafe.IsAddressLessThan(ref kernelStart, ref kernelEnd)) { - Vector4 sample = Unsafe.Add(ref sourceBase, sampleColumnStart - boundsX); + Vector4 sample = Unsafe.Add(ref sourceBase, (uint)(sampleColumnStart - boundsX)); targetStart.Sum(kernelStart * sample); @@ -265,7 +265,7 @@ internal class BokehBlurProcessor : ImageProcessor // Shift the base column sampling reference by one row at the end of each outer // iteration so that the inner tight loop indexing can skip the multiplication - sampleColumnBase = ref Unsafe.Add(ref sampleColumnBase, kernelSize); + sampleColumnBase = ref Unsafe.Add(ref sampleColumnBase, (uint)kernelSize); targetStart = ref Unsafe.Add(ref targetStart, 1); } } @@ -309,7 +309,7 @@ internal class BokehBlurProcessor : ImageProcessor for (int x = 0; x < this.bounds.Width; x++) { - ref Vector4 v = ref Unsafe.Add(ref baseRef, x); + ref Vector4 v = ref Unsafe.Add(ref baseRef, (uint)x); v.X = MathF.Pow(v.X, this.gamma); v.Y = MathF.Pow(v.Y, this.gamma); v.Z = MathF.Pow(v.Z, this.gamma); @@ -399,7 +399,7 @@ internal class BokehBlurProcessor : ImageProcessor for (int x = 0; x < this.bounds.Width; x++) { - ref Vector4 v = ref Unsafe.Add(ref sourceRef, x); + ref Vector4 v = ref Unsafe.Add(ref sourceRef, (uint)x); Vector4 clamp = Numerics.Clamp(v, low, high); v.X = MathF.Pow(clamp.X, this.inverseGamma); v.Y = MathF.Pow(clamp.Y, this.inverseGamma); diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DRowOperation{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DRowOperation{TPixel}.cs index e5963bd390..91fc3a1b1d 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DRowOperation{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DRowOperation{TPixel}.cs @@ -90,7 +90,7 @@ internal readonly struct Convolution2DRowOperation : IRowOperation.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); @@ -99,13 +99,13 @@ internal readonly struct Convolution2DRowOperation : IRowOperation : IRowOperation targetRowSpan = this.targetPixels.DangerousGetRowSpan(y).Slice(boundsX, boundsWidth); @@ -155,7 +155,7 @@ internal readonly struct Convolution2DRowOperation : IRowOperation sourceRow = this.sourcePixels.DangerousGetRowSpan(sampleY).Slice(boundsX, boundsWidth); PixelOperations.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); @@ -165,13 +165,13 @@ internal readonly struct Convolution2DRowOperation : IRowOperation : IRowOperation ref Unsafe.Add(ref MemoryMarshal.GetReference(this.rowOffsetMap), row * this.kernelHeight); + => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.rowOffsetMap), (uint)(row * this.kernelHeight)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly ref int GetSampleColumn(int column) - => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.columnOffsetMap), column * this.kernelWidth); + => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.columnOffsetMap), (uint)(column * this.kernelWidth)); } diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs index 094a96f787..b09db9fa05 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs @@ -178,9 +178,9 @@ internal class Convolution2PassProcessor : ImageProcessor ref Vector4 sourceBase = ref MemoryMarshal.GetReference(sourceBuffer); ref Vector4 targetStart = ref MemoryMarshal.GetReference(targetBuffer); - ref Vector4 targetEnd = ref Unsafe.Add(ref targetStart, sourceBuffer.Length); + ref Vector4 targetEnd = ref Unsafe.Add(ref targetStart, (uint)sourceBuffer.Length); ref float kernelBase = ref this.kernel[0]; - ref float kernelEnd = ref Unsafe.Add(ref kernelBase, kernelSize); + ref float kernelEnd = ref Unsafe.Add(ref kernelBase, (uint)kernelSize); ref int sampleColumnBase = ref MemoryMarshal.GetReference(this.map.GetColumnOffsetSpan()); while (Unsafe.IsAddressLessThan(ref targetStart, ref targetEnd)) @@ -190,7 +190,7 @@ internal class Convolution2PassProcessor : ImageProcessor while (Unsafe.IsAddressLessThan(ref kernelStart, ref kernelEnd)) { - Vector4 sample = Unsafe.Add(ref sourceBase, sampleColumnStart - boundsX); + Vector4 sample = Unsafe.Add(ref sourceBase, (uint)(sampleColumnStart - boundsX)); targetStart += kernelStart * sample; @@ -199,7 +199,7 @@ internal class Convolution2PassProcessor : ImageProcessor } targetStart = ref Unsafe.Add(ref targetStart, 1); - sampleColumnBase = ref Unsafe.Add(ref sampleColumnBase, kernelSize); + sampleColumnBase = ref Unsafe.Add(ref sampleColumnBase, (uint)kernelSize); } // Now we need to copy the original alpha values from the source row. @@ -242,9 +242,9 @@ internal class Convolution2PassProcessor : ImageProcessor ref Vector4 sourceBase = ref MemoryMarshal.GetReference(sourceBuffer); ref Vector4 targetStart = ref MemoryMarshal.GetReference(targetBuffer); - ref Vector4 targetEnd = ref Unsafe.Add(ref targetStart, sourceBuffer.Length); + ref Vector4 targetEnd = ref Unsafe.Add(ref targetStart, (uint)sourceBuffer.Length); ref float kernelBase = ref this.kernel[0]; - ref float kernelEnd = ref Unsafe.Add(ref kernelBase, kernelSize); + ref float kernelEnd = ref Unsafe.Add(ref kernelBase, (uint)kernelSize); ref int sampleColumnBase = ref MemoryMarshal.GetReference(this.map.GetColumnOffsetSpan()); while (Unsafe.IsAddressLessThan(ref targetStart, ref targetEnd)) @@ -254,7 +254,7 @@ internal class Convolution2PassProcessor : ImageProcessor while (Unsafe.IsAddressLessThan(ref kernelStart, ref kernelEnd)) { - Vector4 sample = Unsafe.Add(ref sourceBase, sampleColumnStart - boundsX); + Vector4 sample = Unsafe.Add(ref sourceBase, (uint)(sampleColumnStart - boundsX)); targetStart += kernelStart * sample; @@ -263,7 +263,7 @@ internal class Convolution2PassProcessor : ImageProcessor } targetStart = ref Unsafe.Add(ref targetStart, 1); - sampleColumnBase = ref Unsafe.Add(ref sampleColumnBase, kernelSize); + sampleColumnBase = ref Unsafe.Add(ref sampleColumnBase, (uint)kernelSize); } Numerics.UnPremultiply(targetBuffer); @@ -335,14 +335,14 @@ internal class Convolution2PassProcessor : ImageProcessor Span sourceBuffer = span[..this.bounds.Width]; Span targetBuffer = span[this.bounds.Width..]; - ref int sampleRowBase = ref Unsafe.Add(ref MemoryMarshal.GetReference(this.map.GetRowOffsetSpan()), (y - this.bounds.Y) * kernelSize); + ref int sampleRowBase = ref Unsafe.Add(ref MemoryMarshal.GetReference(this.map.GetRowOffsetSpan()), (uint)((y - this.bounds.Y) * kernelSize)); // Clear the target buffer for each row run. targetBuffer.Clear(); ref Vector4 targetBase = ref MemoryMarshal.GetReference(targetBuffer); ref float kernelStart = ref this.kernel[0]; - ref float kernelEnd = ref Unsafe.Add(ref kernelStart, kernelSize); + ref float kernelEnd = ref Unsafe.Add(ref kernelStart, (uint)kernelSize); Span sourceRow; while (Unsafe.IsAddressLessThan(ref kernelStart, ref kernelEnd)) @@ -353,7 +353,7 @@ internal class Convolution2PassProcessor : ImageProcessor PixelOperations.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); ref Vector4 sourceBase = ref MemoryMarshal.GetReference(sourceBuffer); - ref Vector4 sourceEnd = ref Unsafe.Add(ref sourceBase, sourceBuffer.Length); + ref Vector4 sourceEnd = ref Unsafe.Add(ref sourceBase, (uint)sourceBuffer.Length); ref Vector4 targetStart = ref targetBase; float factor = kernelStart; @@ -374,7 +374,7 @@ internal class Convolution2PassProcessor : ImageProcessor PixelOperations.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); { ref Vector4 sourceBase = ref MemoryMarshal.GetReference(sourceBuffer); - ref Vector4 sourceEnd = ref Unsafe.Add(ref sourceBase, sourceBuffer.Length); + ref Vector4 sourceEnd = ref Unsafe.Add(ref sourceBase, (uint)sourceBuffer.Length); while (Unsafe.IsAddressLessThan(ref sourceBase, ref sourceEnd)) { @@ -400,14 +400,14 @@ internal class Convolution2PassProcessor : ImageProcessor Span sourceBuffer = span[..this.bounds.Width]; Span targetBuffer = span[this.bounds.Width..]; - ref int sampleRowBase = ref Unsafe.Add(ref MemoryMarshal.GetReference(this.map.GetRowOffsetSpan()), (y - this.bounds.Y) * kernelSize); + ref int sampleRowBase = ref Unsafe.Add(ref MemoryMarshal.GetReference(this.map.GetRowOffsetSpan()), (uint)((y - this.bounds.Y) * kernelSize)); // Clear the target buffer for each row run. targetBuffer.Clear(); ref Vector4 targetBase = ref MemoryMarshal.GetReference(targetBuffer); ref float kernelStart = ref this.kernel[0]; - ref float kernelEnd = ref Unsafe.Add(ref kernelStart, kernelSize); + ref float kernelEnd = ref Unsafe.Add(ref kernelStart, (uint)kernelSize); Span sourceRow; while (Unsafe.IsAddressLessThan(ref kernelStart, ref kernelEnd)) @@ -420,7 +420,7 @@ internal class Convolution2PassProcessor : ImageProcessor Numerics.Premultiply(sourceBuffer); ref Vector4 sourceBase = ref MemoryMarshal.GetReference(sourceBuffer); - ref Vector4 sourceEnd = ref Unsafe.Add(ref sourceBase, sourceBuffer.Length); + ref Vector4 sourceEnd = ref Unsafe.Add(ref sourceBase, (uint)sourceBuffer.Length); ref Vector4 targetStart = ref targetBase; float factor = kernelStart; diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs index 54dad64a6b..4cbca8d74e 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs @@ -135,7 +135,7 @@ internal class ConvolutionProcessor : ImageProcessor for (int kY = 0; kY < state.Kernel.Rows; kY++) { // Get the precalculated source sample row for this kernel row and copy to our buffer. - int offsetY = Unsafe.Add(ref sampleRowBase, kY); + int offsetY = Unsafe.Add(ref sampleRowBase, (uint)kY); sourceRow = this.sourcePixels.DangerousGetRowSpan(offsetY).Slice(boundsX, boundsWidth); PixelOperations.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); @@ -144,12 +144,12 @@ internal class ConvolutionProcessor : ImageProcessor for (int x = 0; x < sourceBuffer.Length; x++) { ref int sampleColumnBase = ref state.GetSampleColumn(x); - ref Vector4 target = ref Unsafe.Add(ref targetBase, x); + ref Vector4 target = ref Unsafe.Add(ref targetBase, (uint)x); for (int kX = 0; kX < state.Kernel.Columns; kX++) { - int offsetX = Unsafe.Add(ref sampleColumnBase, kX) - boundsX; - Vector4 sample = Unsafe.Add(ref sourceBase, offsetX); + int offsetX = Unsafe.Add(ref sampleColumnBase, (uint)kX) - boundsX; + Vector4 sample = Unsafe.Add(ref sourceBase, (uint)offsetX); target += state.Kernel[kY, kX] * sample; } } @@ -161,8 +161,8 @@ internal class ConvolutionProcessor : ImageProcessor for (int x = 0; x < sourceRow.Length; x++) { - ref Vector4 target = ref Unsafe.Add(ref targetBase, x); - target.W = Unsafe.Add(ref MemoryMarshal.GetReference(sourceBuffer), x).W; + ref Vector4 target = ref Unsafe.Add(ref targetBase, (uint)x); + target.W = Unsafe.Add(ref MemoryMarshal.GetReference(sourceBuffer), (uint)x).W; } } else @@ -174,7 +174,7 @@ internal class ConvolutionProcessor : ImageProcessor for (int kY = 0; kY < state.Kernel.Rows; kY++) { // Get the precalculated source sample row for this kernel row and copy to our buffer. - int offsetY = Unsafe.Add(ref sampleRowBase, kY); + int offsetY = Unsafe.Add(ref sampleRowBase, (uint)kY); Span sourceRow = this.sourcePixels.DangerousGetRowSpan(offsetY).Slice(boundsX, boundsWidth); PixelOperations.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); @@ -184,12 +184,12 @@ internal class ConvolutionProcessor : ImageProcessor for (int x = 0; x < sourceBuffer.Length; x++) { ref int sampleColumnBase = ref state.GetSampleColumn(x); - ref Vector4 target = ref Unsafe.Add(ref targetBase, x); + ref Vector4 target = ref Unsafe.Add(ref targetBase, (uint)x); for (int kX = 0; kX < state.Kernel.Columns; kX++) { - int offsetX = Unsafe.Add(ref sampleColumnBase, kX) - boundsX; - Vector4 sample = Unsafe.Add(ref sourceBase, offsetX); + int offsetX = Unsafe.Add(ref sampleColumnBase, (uint)kX) - boundsX; + Vector4 sample = Unsafe.Add(ref sourceBase, (uint)offsetX); target += state.Kernel[kY, kX] * sample; } } diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionState.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionState.cs index 3d0e551b68..dbf90d0170 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionState.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionState.cs @@ -35,9 +35,9 @@ internal readonly ref struct ConvolutionState [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly ref int GetSampleRow(int row) - => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.rowOffsetMap), row * this.kernelHeight); + => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.rowOffsetMap), (uint)(row * this.kernelHeight)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly ref int GetSampleColumn(int column) - => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.columnOffsetMap), column * this.kernelWidth); + => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.columnOffsetMap), (uint)(column * this.kernelWidth)); } diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs index 75e8e98e91..8de92bee81 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs @@ -123,8 +123,8 @@ internal class EdgeDetectorCompassProcessor : ImageProcessor for (int x = this.minX; x < this.maxX; x++) { // Grab the max components of the two pixels - ref TPixel currentPassPixel = ref Unsafe.Add(ref passPixelsBase, x); - ref TPixel currentTargetPixel = ref Unsafe.Add(ref targetPixelsBase, x); + ref TPixel currentPassPixel = ref Unsafe.Add(ref passPixelsBase, (uint)x); + ref TPixel currentTargetPixel = ref Unsafe.Add(ref targetPixelsBase, (uint)x); var pixelValue = Vector4.Max(currentPassPixel.ToVector4(), currentTargetPixel.ToVector4()); diff --git a/src/ImageSharp/Processing/Processors/Convolution/Kernel.cs b/src/ImageSharp/Processing/Processors/Convolution/Kernel.cs index 35aa933cf7..b225b55e5f 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Kernel.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Kernel.cs @@ -49,7 +49,7 @@ internal readonly ref struct Kernel { this.CheckCoordinates(row, column); ref T vBase = ref MemoryMarshal.GetReference(this.values); - return Unsafe.Add(ref vBase, (row * this.Columns) + column); + return Unsafe.Add(ref vBase, (uint)((row * this.Columns) + column)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -57,7 +57,7 @@ internal readonly ref struct Kernel { this.CheckCoordinates(row, column); ref T vBase = ref MemoryMarshal.GetReference(this.values); - Unsafe.Add(ref vBase, (row * this.Columns) + column) = value; + Unsafe.Add(ref vBase, (uint)((row * this.Columns) + column)) = value; } } @@ -66,7 +66,7 @@ internal readonly ref struct Kernel { this.CheckIndex(index); ref T vBase = ref MemoryMarshal.GetReference(this.values); - Unsafe.Add(ref vBase, index) = value; + Unsafe.Add(ref vBase, (uint)index) = value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/Processing/Processors/Convolution/KernelSamplingMap.cs b/src/ImageSharp/Processing/Processors/Convolution/KernelSamplingMap.cs index 8128d01196..7653aeaa96 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/KernelSamplingMap.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/KernelSamplingMap.cs @@ -92,7 +92,7 @@ internal sealed class KernelSamplingMap : IDisposable int chunkBase = chunk * kernelSize; for (int i = 0; i < kernelSize; i++) { - Unsafe.Add(ref spanBase, chunkBase + i) = chunk + i + min - radius; + Unsafe.Add(ref spanBase, (uint)(chunkBase + i)) = chunk + i + min - radius; } } diff --git a/src/ImageSharp/Processing/Processors/Convolution/MedianConvolutionState.cs b/src/ImageSharp/Processing/Processors/Convolution/MedianConvolutionState.cs index d557896e3c..137334c29e 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/MedianConvolutionState.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/MedianConvolutionState.cs @@ -36,9 +36,9 @@ internal readonly ref struct MedianConvolutionState [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly ref int GetSampleRow(int row) - => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.rowOffsetMap), row * this.kernelHeight); + => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.rowOffsetMap), (uint)(row * this.kernelHeight)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly ref int GetSampleColumn(int column) - => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.columnOffsetMap), column * this.kernelWidth); + => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.columnOffsetMap), (uint)(column * this.kernelWidth)); } diff --git a/src/ImageSharp/Processing/Processors/Convolution/MedianRowOperation{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/MedianRowOperation{TPixel}.cs index dbb62f0c58..ca2cabab55 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/MedianRowOperation{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/MedianRowOperation{TPixel}.cs @@ -75,7 +75,7 @@ internal readonly struct MedianRowOperation : IRowOperation // First convert the required source rows to Vector4. for (int i = 0; i < this.kernelSize; i++) { - int currentYIndex = Unsafe.Add(ref sampleRowBase, i); + int currentYIndex = Unsafe.Add(ref sampleRowBase, (uint)i); Span sourceRow = this.sourcePixels.DangerousGetRowSpan(currentYIndex).Slice(boundsX, boundsWidth); Span sourceVectorRow = sourceVectorBuffer.Slice(i * boundsWidth, boundsWidth); PixelOperations.Instance.ToVector4(this.configuration, sourceRow, sourceVectorRow); @@ -87,15 +87,15 @@ internal readonly struct MedianRowOperation : IRowOperation { int index = 0; ref int sampleColumnBase = ref state.GetSampleColumn(x); - ref Vector4 target = ref Unsafe.Add(ref targetBase, x); + ref Vector4 target = ref Unsafe.Add(ref targetBase, (uint)x); for (int kY = 0; kY < state.Kernel.Rows; kY++) { Span sourceRow = sourceVectorBuffer[(kY * boundsWidth)..]; ref Vector4 sourceRowBase = ref MemoryMarshal.GetReference(sourceRow); for (int kX = 0; kX < state.Kernel.Columns; kX++) { - int currentXIndex = Unsafe.Add(ref sampleColumnBase, kX) - boundsX; - Vector4 pixel = Unsafe.Add(ref sourceRowBase, currentXIndex); + int currentXIndex = Unsafe.Add(ref sampleColumnBase, (uint)kX) - boundsX; + Vector4 pixel = Unsafe.Add(ref sourceRowBase, (uint)currentXIndex); state.Kernel.SetValue(index, pixel); index++; } @@ -111,15 +111,15 @@ internal readonly struct MedianRowOperation : IRowOperation { int index = 0; ref int sampleColumnBase = ref state.GetSampleColumn(x); - ref Vector4 target = ref Unsafe.Add(ref targetBase, x); + ref Vector4 target = ref Unsafe.Add(ref targetBase, (uint)x); for (int kY = 0; kY < state.Kernel.Rows; kY++) { Span sourceRow = sourceVectorBuffer[(kY * boundsWidth)..]; ref Vector4 sourceRowBase = ref MemoryMarshal.GetReference(sourceRow); for (int kX = 0; kX < state.Kernel.Columns; kX++) { - int currentXIndex = Unsafe.Add(ref sampleColumnBase, kX) - boundsX; - Vector4 pixel = Unsafe.Add(ref sourceRowBase, currentXIndex); + int currentXIndex = Unsafe.Add(ref sampleColumnBase, (uint)kX) - boundsX; + Vector4 pixel = Unsafe.Add(ref sourceRowBase, (uint)currentXIndex); state.Kernel.SetValue(index, pixel); index++; } diff --git a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs index 08dee86a4e..8f501da23e 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs @@ -134,7 +134,7 @@ internal static class BokehBlurKernelDataProvider ref Vector4 baseRef = ref MemoryMarshal.GetReference(kernelParameters.AsSpan()); for (int i = 0; i < kernelParameters.Length; i++) { - ref Vector4 paramsRef = ref Unsafe.Add(ref baseRef, i); + ref Vector4 paramsRef = ref Unsafe.Add(ref baseRef, (uint)i); kernels[i] = CreateComplex1DKernel(radius, kernelSize, kernelsScale, paramsRef.X, paramsRef.Y); } @@ -167,7 +167,7 @@ internal static class BokehBlurKernelDataProvider value *= value; // Fill in the complex kernel values - Unsafe.Add(ref baseRef, i) = new Complex64( + Unsafe.Add(ref baseRef, (uint)i) = new Complex64( MathF.Exp(-a * value) * MathF.Cos(b * value), MathF.Exp(-a * value) * MathF.Sin(b * value)); } @@ -190,17 +190,17 @@ internal static class BokehBlurKernelDataProvider for (int i = 0; i < kernelParameters.Length; i++) { - ref Complex64[] kernelRef = ref Unsafe.Add(ref baseKernelsRef, i); + ref Complex64[] kernelRef = ref Unsafe.Add(ref baseKernelsRef, (uint)i); int length = kernelRef.Length; ref Complex64 valueRef = ref kernelRef[0]; - ref Vector4 paramsRef = ref Unsafe.Add(ref baseParamsRef, i); + ref Vector4 paramsRef = ref Unsafe.Add(ref baseParamsRef, (uint)i); for (int j = 0; j < length; j++) { for (int k = 0; k < length; k++) { - ref Complex64 jRef = ref Unsafe.Add(ref valueRef, j); - ref Complex64 kRef = ref Unsafe.Add(ref valueRef, k); + ref Complex64 jRef = ref Unsafe.Add(ref valueRef, (uint)j); + ref Complex64 kRef = ref Unsafe.Add(ref valueRef, (uint)k); total += (paramsRef.Z * ((jRef.Real * kRef.Real) - (jRef.Imaginary * kRef.Imaginary))) + (paramsRef.W * ((jRef.Real * kRef.Imaginary) + (jRef.Imaginary * kRef.Real))); @@ -212,13 +212,13 @@ internal static class BokehBlurKernelDataProvider float scalar = 1f / MathF.Sqrt(total); for (int i = 0; i < kernelsSpan.Length; i++) { - ref Complex64[] kernelsRef = ref Unsafe.Add(ref baseKernelsRef, i); + ref Complex64[] kernelsRef = ref Unsafe.Add(ref baseKernelsRef, (uint)i); int length = kernelsRef.Length; ref Complex64 valueRef = ref kernelsRef[0]; for (int j = 0; j < length; j++) { - Unsafe.Add(ref valueRef, j) *= scalar; + Unsafe.Add(ref valueRef, (uint)j) *= scalar; } } } diff --git a/src/ImageSharp/Processing/Processors/Convolution/ReadOnlyKernel.cs b/src/ImageSharp/Processing/Processors/Convolution/ReadOnlyKernel.cs index 641a8ae8b0..46c35c62c7 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ReadOnlyKernel.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ReadOnlyKernel.cs @@ -41,7 +41,7 @@ internal readonly ref struct ReadOnlyKernel { this.CheckCoordinates(row, column); ref float vBase = ref MemoryMarshal.GetReference(this.values); - return Unsafe.Add(ref vBase, (row * this.Columns) + column); + return Unsafe.Add(ref vBase, (uint)((row * this.Columns) + column)); } } diff --git a/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs b/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs index 3a869a0a28..754aac90ea 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs @@ -114,8 +114,8 @@ public readonly partial struct ErrorDither : IDither, IEquatable, I for (int x = bounds.Left; x < bounds.Right; x++) { - TPixel sourcePixel = Unsafe.Add(ref sourceRowRef, x); - Unsafe.Add(ref destinationRowRef, x - offsetX) = quantizer.GetQuantizedColor(sourcePixel, out TPixel transformed); + TPixel sourcePixel = Unsafe.Add(ref sourceRowRef, (uint)x); + Unsafe.Add(ref destinationRowRef, (uint)(x - offsetX)) = quantizer.GetQuantizedColor(sourcePixel, out TPixel transformed); this.Dither(source, bounds, sourcePixel, transformed, x, y, scale); } } @@ -142,7 +142,7 @@ public readonly partial struct ErrorDither : IDither, IEquatable, I ref TPixel sourceRowRef = ref MemoryMarshal.GetReference(sourceBuffer.DangerousGetRowSpan(y)); for (int x = bounds.Left; x < bounds.Right; x++) { - ref TPixel sourcePixel = ref Unsafe.Add(ref sourceRowRef, x); + ref TPixel sourcePixel = ref Unsafe.Add(ref sourceRowRef, (uint)x); TPixel transformed = Unsafe.AsRef(processor).GetPaletteColor(sourcePixel); this.Dither(source, bounds, sourcePixel, transformed, x, y, scale); sourcePixel = transformed; diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs index 67964f0ebd..6352230de2 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs @@ -107,9 +107,9 @@ internal class OilPaintingProcessor : ImageProcessor ref float binsRef = ref bins.GetReference(); ref int intensityBinRef = ref Unsafe.As(ref binsRef); - ref float redBinRef = ref Unsafe.Add(ref binsRef, this.levels); - ref float blueBinRef = ref Unsafe.Add(ref redBinRef, this.levels); - ref float greenBinRef = ref Unsafe.Add(ref blueBinRef, this.levels); + ref float redBinRef = ref Unsafe.Add(ref binsRef, (uint)this.levels); + ref float blueBinRef = ref Unsafe.Add(ref redBinRef, (uint)this.levels); + ref float greenBinRef = ref Unsafe.Add(ref blueBinRef, (uint)this.levels); for (int y = rows.Min; y < rows.Max; y++) { @@ -148,21 +148,21 @@ internal class OilPaintingProcessor : ImageProcessor int currentIntensity = (int)MathF.Round((sourceBlue + sourceGreen + sourceRed) / 3F * (this.levels - 1)); - Unsafe.Add(ref intensityBinRef, currentIntensity)++; - Unsafe.Add(ref redBinRef, currentIntensity) += sourceRed; - Unsafe.Add(ref blueBinRef, currentIntensity) += sourceBlue; - Unsafe.Add(ref greenBinRef, currentIntensity) += sourceGreen; + Unsafe.Add(ref intensityBinRef, (uint)currentIntensity)++; + Unsafe.Add(ref redBinRef, (uint)currentIntensity) += sourceRed; + Unsafe.Add(ref blueBinRef, (uint)currentIntensity) += sourceBlue; + Unsafe.Add(ref greenBinRef, (uint)currentIntensity) += sourceGreen; - if (Unsafe.Add(ref intensityBinRef, currentIntensity) > maxIntensity) + if (Unsafe.Add(ref intensityBinRef, (uint)currentIntensity) > maxIntensity) { - maxIntensity = Unsafe.Add(ref intensityBinRef, currentIntensity); + maxIntensity = Unsafe.Add(ref intensityBinRef, (uint)currentIntensity); maxIndex = currentIntensity; } } - float red = MathF.Abs(Unsafe.Add(ref redBinRef, maxIndex) / maxIntensity); - float blue = MathF.Abs(Unsafe.Add(ref blueBinRef, maxIndex) / maxIntensity); - float green = MathF.Abs(Unsafe.Add(ref greenBinRef, maxIndex) / maxIntensity); + float red = MathF.Abs(Unsafe.Add(ref redBinRef, (uint)maxIndex) / maxIntensity); + float blue = MathF.Abs(Unsafe.Add(ref blueBinRef, (uint)maxIndex) / maxIntensity); + float green = MathF.Abs(Unsafe.Add(ref greenBinRef, (uint)maxIndex) / maxIntensity); float alpha = sourceRowVector4Span[x].W; targetRowVector4Span[x] = new Vector4(red, green, blue, alpha); diff --git a/src/ImageSharp/Processing/Processors/Filters/OpaqueProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Filters/OpaqueProcessor{TPixel}.cs index 4b8fd9056e..93e600106a 100644 --- a/src/ImageSharp/Processing/Processors/Filters/OpaqueProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Filters/OpaqueProcessor{TPixel}.cs @@ -61,7 +61,7 @@ internal sealed class OpaqueProcessor : ImageProcessor for (int x = 0; x < this.bounds.Width; x++) { - ref Vector4 v = ref Unsafe.Add(ref baseRef, x); + ref Vector4 v = ref Unsafe.Add(ref baseRef, (uint)x); v.W = 1F; } diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs index 3aaf2631ae..f25db12c28 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs @@ -256,8 +256,8 @@ internal class AdaptiveHistogramEqualizationSlidingWindowProcessor : His { for (nint idx = 0; idx < length; idx++) { - int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); - Unsafe.Add(ref histogramBase, luminance)++; + int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, (uint)idx), luminanceLevels); + Unsafe.Add(ref histogramBase, (uint)luminance)++; } } @@ -273,8 +273,8 @@ internal class AdaptiveHistogramEqualizationSlidingWindowProcessor : His { for (int idx = 0; idx < length; idx++) { - int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); - Unsafe.Add(ref histogramBase, luminance)--; + int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, (uint)idx), luminanceLevels); + Unsafe.Add(ref histogramBase, (uint)luminance)--; } } @@ -382,7 +382,7 @@ internal class AdaptiveHistogramEqualizationSlidingWindowProcessor : His // Map the current pixel to the new equalized value. int luminance = GetLuminance(this.source[x, y], this.processor.LuminanceLevels); - float luminanceEqualized = Unsafe.Add(ref cdfBase, luminance) / numberOfPixelsMinusCdfMin; + float luminanceEqualized = Unsafe.Add(ref cdfBase, (uint)luminance) / numberOfPixelsMinusCdfMin; this.targetPixels[x, y].FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, this.source[x, y].ToVector4().W)); // Remove top most row from the histogram, mirroring rows which exceeds the borders. diff --git a/src/ImageSharp/Processing/Processors/Normalization/AutoLevelProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AutoLevelProcessor{TPixel}.cs index c07ac3aa34..6f4493f951 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AutoLevelProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AutoLevelProcessor{TPixel}.cs @@ -148,12 +148,12 @@ internal class AutoLevelProcessor : HistogramEqualizationProcessor.Instance.FromVector4Destructive(this.configuration, vectorBuffer, pixelRow); @@ -209,7 +209,7 @@ internal class AutoLevelProcessor : HistogramEqualizationProcessor : HistogramEqualizationProcessor.Instance.FromVector4Destructive(this.configuration, vectorBuffer, pixelRow); diff --git a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs index 7e9e064642..e7433899bf 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs @@ -129,10 +129,10 @@ internal class GlobalHistogramEqualizationProcessor : HistogramEqualizat for (int x = 0; x < this.bounds.Width; x++) { - var vector = Unsafe.Add(ref vectorRef, x); + var vector = Unsafe.Add(ref vectorRef, (uint)x); int luminance = ColorNumerics.GetBT709Luminance(ref vector, levels); - float luminanceEqualized = Unsafe.Add(ref cdfBase, luminance) / noOfPixelsMinusCdfMin; - Unsafe.Add(ref vectorRef, x) = new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, vector.W); + float luminanceEqualized = Unsafe.Add(ref cdfBase, (uint)luminance) / noOfPixelsMinusCdfMin; + Unsafe.Add(ref vectorRef, (uint)x) = new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, vector.W); } PixelOperations.Instance.FromVector4Destructive(this.configuration, vectorBuffer, pixelRow); diff --git a/src/ImageSharp/Processing/Processors/Normalization/GrayscaleLevelsRowOperation{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/GrayscaleLevelsRowOperation{TPixel}.cs index 8895fdc612..0a8690ba70 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/GrayscaleLevelsRowOperation{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/GrayscaleLevelsRowOperation{TPixel}.cs @@ -56,9 +56,9 @@ internal readonly struct GrayscaleLevelsRowOperation : IRowOperation : ImageProcessor< int cdfMin = 0; bool cdfMinFound = false; - for (int i = 0; i <= maxIdx; i++) + for (nint i = 0; i <= (uint)maxIdx; i++) { histSum += Unsafe.Add(ref histogramBase, i); if (!cdfMinFound && histSum != 0) @@ -101,7 +101,7 @@ internal abstract class HistogramEqualizationProcessor : ImageProcessor< int sumOverClip = 0; ref int histogramBase = ref MemoryMarshal.GetReference(histogram); - for (int i = 0; i < histogram.Length; i++) + for (nint i = 0; i < (uint)histogram.Length; i++) { ref int histogramLevel = ref Unsafe.Add(ref histogramBase, i); if (histogramLevel > clipLimit) @@ -115,7 +115,7 @@ internal abstract class HistogramEqualizationProcessor : ImageProcessor< int addToEachBin = sumOverClip > 0 ? (int)MathF.Floor(sumOverClip / this.luminanceLevelsFloat) : 0; if (addToEachBin > 0) { - for (int i = 0; i < histogram.Length; i++) + for (nint i = 0; i < (uint)histogram.Length; i++) { Unsafe.Add(ref histogramBase, i) += addToEachBin; } @@ -125,7 +125,7 @@ internal abstract class HistogramEqualizationProcessor : ImageProcessor< if (residual != 0) { int residualStep = Math.Max(this.LuminanceLevels / residual, 1); - for (int i = 0; i < this.LuminanceLevels && residual > 0; i += residualStep, residual--) + for (nint i = 0; i < (uint)this.LuminanceLevels && residual > 0; i += residualStep, residual--) { ref int histogramLevel = ref Unsafe.Add(ref histogramBase, i); histogramLevel++; diff --git a/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel}.cs index a8cf4d3e91..786248339b 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel}.cs @@ -75,7 +75,7 @@ internal sealed class EuclideanPixelMap : IDisposable return this.GetClosestColorSlow(rgba, ref paletteRef, out match); } - match = Unsafe.Add(ref paletteRef, index); + match = Unsafe.Add(ref paletteRef, (ushort)index); return index; } @@ -119,7 +119,7 @@ internal sealed class EuclideanPixelMap : IDisposable // Now I have the index, pop it into the cache for next time this.cache.Add(rgba, (byte)index); - match = Unsafe.Add(ref paletteRef, index); + match = Unsafe.Add(ref paletteRef, (uint)index); return index; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs index 5cd9976a58..10525641ca 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs @@ -134,7 +134,7 @@ internal sealed class ResizeWorker : IDisposable for (nint x = 0; x < (right - left); x++) { - ref Vector4 firstPassColumnBase = ref Unsafe.Add(ref fpBase, x * this.workerHeight); + ref Vector4 firstPassColumnBase = ref Unsafe.Add(ref fpBase, x * (nint)(uint)this.workerHeight); // Destination color components Unsafe.Add(ref tempRowBase, x) = kernel.ConvolveCore(ref firstPassColumnBase); @@ -186,13 +186,13 @@ internal sealed class ResizeWorker : IDisposable // Span firstPassSpan = transposedFirstPassBufferSpan.Slice(y - this.currentWindow.Min); ref Vector4 firstPassBaseRef = ref transposedFirstPassBufferSpan[y - this.currentWindow.Min]; - for (nint x = left, z = 0; x < right; x++, z++) + for (nint x = left, z = 0; x < (nint)(uint)right; x++, z++) { ResizeKernel kernel = this.horizontalKernelMap.GetKernel(x - targetOriginX); // optimization for: // firstPassSpan[x * this.workerHeight] = kernel.Convolve(tempRowSpan); - Unsafe.Add(ref firstPassBaseRef, z * this.workerHeight) = kernel.Convolve(tempRowSpan); + Unsafe.Add(ref firstPassBaseRef, z * (nint)(uint)this.workerHeight) = kernel.Convolve(tempRowSpan); } } } diff --git a/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs b/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs index 0637b33347..ed129fca2f 100644 --- a/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs +++ b/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs @@ -47,7 +47,7 @@ public abstract class FromVector4 { ref Vector4 s = ref MemoryMarshal.GetReference(this.source.GetSpan()); ref TPixel d = ref MemoryMarshal.GetReference(this.destination.GetSpan()); - for (int i = 0; i < this.Count; i++) + for (nint i = 0; i < (uint)this.Count; i++) { Unsafe.Add(ref d, i).FromVector4(Unsafe.Add(ref s, i)); } diff --git a/tests/ImageSharp.Benchmarks/Bulk/PremultiplyVector4.cs b/tests/ImageSharp.Benchmarks/Bulk/PremultiplyVector4.cs index d22fc18ac6..355216de34 100644 --- a/tests/ImageSharp.Benchmarks/Bulk/PremultiplyVector4.cs +++ b/tests/ImageSharp.Benchmarks/Bulk/PremultiplyVector4.cs @@ -17,7 +17,7 @@ public class PremultiplyVector4 { ref Vector4 baseRef = ref MemoryMarshal.GetReference(Vectors); - for (int i = 0; i < Vectors.Length; i++) + for (nint i = 0; i < (uint)Vectors.Length; i++) { ref Vector4 v = ref Unsafe.Add(ref baseRef, i); Premultiply(ref v); @@ -29,7 +29,7 @@ public class PremultiplyVector4 { ref Vector4 baseRef = ref MemoryMarshal.GetReference(Vectors); - for (int i = 0; i < Vectors.Length; i++) + for (nint i = 0; i < (uint)Vectors.Length; i++) { ref Vector4 v = ref Unsafe.Add(ref baseRef, i); Numerics.Premultiply(ref v); diff --git a/tests/ImageSharp.Benchmarks/Bulk/UnPremultiplyVector4.cs b/tests/ImageSharp.Benchmarks/Bulk/UnPremultiplyVector4.cs index 3dc8fdc9c6..309eea34fd 100644 --- a/tests/ImageSharp.Benchmarks/Bulk/UnPremultiplyVector4.cs +++ b/tests/ImageSharp.Benchmarks/Bulk/UnPremultiplyVector4.cs @@ -17,7 +17,7 @@ public class UnPremultiplyVector4 { ref Vector4 baseRef = ref MemoryMarshal.GetReference(Vectors); - for (int i = 0; i < Vectors.Length; i++) + for (nint i = 0; i < (uint)Vectors.Length; i++) { ref Vector4 v = ref Unsafe.Add(ref baseRef, i); @@ -30,7 +30,7 @@ public class UnPremultiplyVector4 { ref Vector4 baseRef = ref MemoryMarshal.GetReference(Vectors); - for (int i = 0; i < Vectors.Length; i++) + for (nint i = 0; i < (uint)Vectors.Length; i++) { ref Vector4 v = ref Unsafe.Add(ref baseRef, i); Numerics.UnPremultiply(ref v); diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo1x1.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo1x1.cs index f36f92e907..abdd6908da 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo1x1.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo1x1.cs @@ -72,8 +72,8 @@ public unsafe class Block8x8F_CopyTo1x1 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void CopyRowImpl(ref byte selfBase, ref byte destBase, int destStride, int row) { - ref byte s = ref Unsafe.Add(ref selfBase, row * 8 * sizeof(float)); - ref byte d = ref Unsafe.Add(ref destBase, row * destStride); + ref byte s = ref Unsafe.Add(ref selfBase, (uint)row * 8 * sizeof(float)); + ref byte d = ref Unsafe.Add(ref destBase, (uint)(row * destStride)); Unsafe.CopyBlock(ref d, ref s, 8 * sizeof(float)); } @@ -82,7 +82,7 @@ public unsafe class Block8x8F_CopyTo1x1 { ref Block8x8F s = ref this.block; ref float origin = ref Unsafe.AsRef(this.bufferPtr); - int stride = Width; + nint stride = (nint)(uint)Width; ref Vector d0 = ref Unsafe.As>(ref origin); ref Vector d1 = ref Unsafe.As>(ref Unsafe.Add(ref origin, stride)); @@ -117,7 +117,7 @@ public unsafe class Block8x8F_CopyTo1x1 { ref Block8x8F s = ref this.block; ref float origin = ref Unsafe.AsRef(this.bufferPtr); - int stride = Width; + nint stride = (nint)(uint)Width; ref Vector d0 = ref Unsafe.As>(ref origin); ref Vector d1 = ref Unsafe.As>(ref Unsafe.Add(ref origin, stride)); @@ -141,29 +141,29 @@ public unsafe class Block8x8F_CopyTo1x1 [Benchmark] public void UseVector8_V3() { - int stride = Width * sizeof(float); + nint stride = (nint)(uint)Width * sizeof(float); ref float d = ref this.unpinnedBuffer[0]; ref Vector s = ref Unsafe.As>(ref this.block); Vector v0 = s; - Vector v1 = Unsafe.AddByteOffset(ref s, (IntPtr)1); - Vector v2 = Unsafe.AddByteOffset(ref s, (IntPtr)2); - Vector v3 = Unsafe.AddByteOffset(ref s, (IntPtr)3); + Vector v1 = Unsafe.AddByteOffset(ref s, 1); + Vector v2 = Unsafe.AddByteOffset(ref s, 2); + Vector v3 = Unsafe.AddByteOffset(ref s, 3); Unsafe.As>(ref d) = v0; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)stride)) = v1; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 2))) = v2; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 3))) = v3; - - v0 = Unsafe.AddByteOffset(ref s, (IntPtr)4); - v1 = Unsafe.AddByteOffset(ref s, (IntPtr)5); - v2 = Unsafe.AddByteOffset(ref s, (IntPtr)6); - v3 = Unsafe.AddByteOffset(ref s, (IntPtr)7); - - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 4))) = v0; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 5))) = v1; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 6))) = v2; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 7))) = v3; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride)) = v1; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 2)) = v2; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 3)) = v3; + + v0 = Unsafe.AddByteOffset(ref s, 4); + v1 = Unsafe.AddByteOffset(ref s, 5); + v2 = Unsafe.AddByteOffset(ref s, 6); + v3 = Unsafe.AddByteOffset(ref s, 7); + + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 4)) = v0; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 5)) = v1; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 6)) = v2; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 7)) = v3; } [Benchmark] @@ -254,7 +254,7 @@ public unsafe class Block8x8F_CopyTo1x1 [Benchmark] public void UseVector256_Avx2_Variant3_RefCast() { - int stride = Width; + nint stride = (nint)(uint)Width; ref float d = ref this.unpinnedBuffer[0]; ref Vector256 s = ref Unsafe.As>(ref this.block); @@ -282,29 +282,29 @@ public unsafe class Block8x8F_CopyTo1x1 [Benchmark] public void UseVector256_Avx2_Variant3_RefCast_Mod() { - int stride = Width * sizeof(float); + nint stride = (nint)(uint)Width * sizeof(float); ref float d = ref this.unpinnedBuffer[0]; ref Vector256 s = ref Unsafe.As>(ref this.block); Vector256 v0 = s; - Vector256 v1 = Unsafe.AddByteOffset(ref s, (IntPtr)1); - Vector256 v2 = Unsafe.AddByteOffset(ref s, (IntPtr)2); - Vector256 v3 = Unsafe.AddByteOffset(ref s, (IntPtr)3); + Vector256 v1 = Unsafe.AddByteOffset(ref s, 1); + Vector256 v2 = Unsafe.AddByteOffset(ref s, 2); + Vector256 v3 = Unsafe.AddByteOffset(ref s, 3); Unsafe.As>(ref d) = v0; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)stride)) = v1; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 2))) = v2; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 3))) = v3; - - v0 = Unsafe.AddByteOffset(ref s, (IntPtr)4); - v1 = Unsafe.AddByteOffset(ref s, (IntPtr)5); - v2 = Unsafe.AddByteOffset(ref s, (IntPtr)6); - v3 = Unsafe.AddByteOffset(ref s, (IntPtr)7); - - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 4))) = v0; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 5))) = v1; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 6))) = v2; - Unsafe.As>(ref Unsafe.AddByteOffset(ref d, (IntPtr)(stride * 7))) = v3; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride)) = v1; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 2)) = v2; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 3)) = v3; + + v0 = Unsafe.AddByteOffset(ref s, 4); + v1 = Unsafe.AddByteOffset(ref s, 5); + v2 = Unsafe.AddByteOffset(ref s, 6); + v3 = Unsafe.AddByteOffset(ref s, 7); + + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 4)) = v0; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 5)) = v1; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 6)) = v2; + Unsafe.As>(ref Unsafe.AddByteOffset(ref d, stride * 7)) = v3; } // [Benchmark] diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo2x2.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo2x2.cs index 88c0098230..72b6bb72e8 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo2x2.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo2x2.cs @@ -47,9 +47,9 @@ public class Block8x8F_CopyTo2x2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void WidenCopyImpl2x2(ref Block8x8F src, ref float destBase, int row, int destStride) { - ref Vector4 selfLeft = ref Unsafe.Add(ref src.V0L, 2 * row); + ref Vector4 selfLeft = ref Unsafe.Add(ref src.V0L, 2 * (uint)row); ref Vector4 selfRight = ref Unsafe.Add(ref selfLeft, 1); - ref float destLocalOrigo = ref Unsafe.Add(ref destBase, row * 2 * destStride); + ref float destLocalOrigo = ref Unsafe.Add(ref destBase, (uint)(row * 2 * destStride)); Unsafe.Add(ref destLocalOrigo, 0) = selfLeft.X; Unsafe.Add(ref destLocalOrigo, 1) = selfLeft.X; @@ -69,23 +69,23 @@ public class Block8x8F_CopyTo2x2 Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, 8), 6) = selfRight.W; Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, 8), 7) = selfRight.W; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride), 0) = selfLeft.X; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride), 1) = selfLeft.X; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride), 2) = selfLeft.Y; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride), 3) = selfLeft.Y; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride), 4) = selfLeft.Z; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride), 5) = selfLeft.Z; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride), 6) = selfLeft.W; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride), 7) = selfLeft.W; - - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride + 8), 0) = selfRight.X; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride + 8), 1) = selfRight.X; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride + 8), 2) = selfRight.Y; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride + 8), 3) = selfRight.Y; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride + 8), 4) = selfRight.Z; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride + 8), 5) = selfRight.Z; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride + 8), 6) = selfRight.W; - Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, destStride + 8), 7) = selfRight.W; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride), 0) = selfLeft.X; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride), 1) = selfLeft.X; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride), 2) = selfLeft.Y; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride), 3) = selfLeft.Y; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride), 4) = selfLeft.Z; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride), 5) = selfLeft.Z; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride), 6) = selfLeft.W; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride), 7) = selfLeft.W; + + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride + 8), 0) = selfRight.X; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride + 8), 1) = selfRight.X; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride + 8), 2) = selfRight.Y; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride + 8), 3) = selfRight.Y; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride + 8), 4) = selfRight.Z; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride + 8), 5) = selfRight.Z; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride + 8), 6) = selfRight.W; + Unsafe.Add(ref Unsafe.Add(ref destLocalOrigo, (uint)destStride + 8), 7) = selfRight.W; } [Benchmark] @@ -109,9 +109,9 @@ public class Block8x8F_CopyTo2x2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void WidenCopyImpl2x2_V2(ref Block8x8F src, ref float destBase, int row, int destStride) { - ref Vector4 selfLeft = ref Unsafe.Add(ref src.V0L, 2 * row); + ref Vector4 selfLeft = ref Unsafe.Add(ref src.V0L, 2 * (uint)row); ref Vector4 selfRight = ref Unsafe.Add(ref selfLeft, 1); - ref float dest0 = ref Unsafe.Add(ref destBase, row * 2 * destStride); + ref float dest0 = ref Unsafe.Add(ref destBase, (uint)(row * 2 * destStride)); Unsafe.Add(ref dest0, 0) = selfLeft.X; Unsafe.Add(ref dest0, 1) = selfLeft.X; @@ -133,7 +133,7 @@ public class Block8x8F_CopyTo2x2 Unsafe.Add(ref dest1, 6) = selfRight.W; Unsafe.Add(ref dest1, 7) = selfRight.W; - ref float dest2 = ref Unsafe.Add(ref dest0, destStride); + ref float dest2 = ref Unsafe.Add(ref dest0, (uint)destStride); Unsafe.Add(ref dest2, 0) = selfLeft.X; Unsafe.Add(ref dest2, 1) = selfLeft.X; @@ -177,12 +177,12 @@ public class Block8x8F_CopyTo2x2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void WidenCopyImpl2x2_Vector2(ref Block8x8F src, ref Vector2 destBase, int row, int destStride) { - ref Vector4 sLeft = ref Unsafe.Add(ref src.V0L, 2 * row); + ref Vector4 sLeft = ref Unsafe.Add(ref src.V0L, 2 * (uint)row); ref Vector4 sRight = ref Unsafe.Add(ref sLeft, 1); - ref Vector2 dTopLeft = ref Unsafe.Add(ref destBase, 2 * row * destStride); + ref Vector2 dTopLeft = ref Unsafe.Add(ref destBase, (uint)(2 * row * destStride)); ref Vector2 dTopRight = ref Unsafe.Add(ref dTopLeft, 4); - ref Vector2 dBottomLeft = ref Unsafe.Add(ref dTopLeft, destStride); + ref Vector2 dBottomLeft = ref Unsafe.Add(ref dTopLeft, (uint)destStride); ref Vector2 dBottomRight = ref Unsafe.Add(ref dBottomLeft, 4); var xLeft = new Vector2(sLeft.X); @@ -237,12 +237,12 @@ public class Block8x8F_CopyTo2x2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void WidenCopyImpl2x2_Vector4(ref Block8x8F src, ref Vector2 destBase, int row, int destStride) { - ref Vector4 sLeft = ref Unsafe.Add(ref src.V0L, 2 * row); + ref Vector4 sLeft = ref Unsafe.Add(ref src.V0L, 2 * (uint)row); ref Vector4 sRight = ref Unsafe.Add(ref sLeft, 1); - ref Vector2 dTopLeft = ref Unsafe.Add(ref destBase, 2 * row * destStride); + ref Vector2 dTopLeft = ref Unsafe.Add(ref destBase, (uint)(2 * row * destStride)); ref Vector2 dTopRight = ref Unsafe.Add(ref dTopLeft, 4); - ref Vector2 dBottomLeft = ref Unsafe.Add(ref dTopLeft, destStride); + ref Vector2 dBottomLeft = ref Unsafe.Add(ref dTopLeft, (uint)destStride); ref Vector2 dBottomRight = ref Unsafe.Add(ref dBottomLeft, 4); var xLeft = new Vector4(sLeft.X); @@ -297,11 +297,11 @@ public class Block8x8F_CopyTo2x2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void WidenCopyImpl2x2_Vector4_SafeRightCorner(ref Block8x8F src, ref Vector2 destBase, int row, int destStride) { - ref Vector4 sLeft = ref Unsafe.Add(ref src.V0L, 2 * row); + ref Vector4 sLeft = ref Unsafe.Add(ref src.V0L, 2 * (uint)row); ref Vector4 sRight = ref Unsafe.Add(ref sLeft, 1); - ref Vector2 dTopLeft = ref Unsafe.Add(ref destBase, 2 * row * destStride); - ref Vector2 dBottomLeft = ref Unsafe.Add(ref dTopLeft, destStride); + ref Vector2 dTopLeft = ref Unsafe.Add(ref destBase, (uint)(2 * row * destStride)); + ref Vector2 dBottomLeft = ref Unsafe.Add(ref dTopLeft, (uint)destStride); var xLeft = new Vector4(sLeft.X); var yLeft = new Vector4(sLeft.Y); @@ -355,12 +355,12 @@ public class Block8x8F_CopyTo2x2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void WidenCopyImpl2x2_Vector4_V2(ref Block8x8F src, ref Vector2 destBase, int row, int destStride) { - ref Vector4 sLeft = ref Unsafe.Add(ref src.V0L, 2 * row); + ref Vector4 sLeft = ref Unsafe.Add(ref src.V0L, 2 * (uint)row); ref Vector4 sRight = ref Unsafe.Add(ref sLeft, 1); int offset = 2 * row * destStride; - ref Vector4 dTopLeft = ref Unsafe.As(ref Unsafe.Add(ref destBase, offset)); - ref Vector4 dBottomLeft = ref Unsafe.As(ref Unsafe.Add(ref destBase, offset + destStride)); + ref Vector4 dTopLeft = ref Unsafe.As(ref Unsafe.Add(ref destBase, (uint)offset)); + ref Vector4 dBottomLeft = ref Unsafe.As(ref Unsafe.Add(ref destBase, (uint)(offset + destStride))); var xyLeft = new Vector4(sLeft.X) { diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs index afe9d94ae8..2cc084885f 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs @@ -54,7 +54,7 @@ public unsafe class Block8x8F_Round { ref float b = ref Unsafe.As(ref this.block); - for (int i = 0; i < Block8x8F.Size; i++) + for (nint i = 0; i < Block8x8F.Size; i++) { ref float v = ref Unsafe.Add(ref b, i); v = (float)Math.Round(v); @@ -178,7 +178,7 @@ public unsafe class Block8x8F_Round { ref Vector128 p = ref Unsafe.As>(ref this.block); p = Sse41.RoundToNearestInteger(p); - var offset = (IntPtr)sizeof(Vector128); + nint offset = sizeof(Vector128); p = Sse41.RoundToNearestInteger(p); p = ref Unsafe.AddByteOffset(ref p, offset); @@ -218,7 +218,7 @@ public unsafe class Block8x8F_Round { ref Vector128 p = ref Unsafe.As>(ref this.block); p = Sse41.RoundToNearestInteger(p); - var offset = (IntPtr)sizeof(Vector128); + nint offset = sizeof(Vector128); for (int i = 0; i < 15; i++) { @@ -231,7 +231,7 @@ public unsafe class Block8x8F_Round public unsafe void Sse41_V4() { ref Vector128 p = ref Unsafe.As>(ref this.block); - var offset = (IntPtr)sizeof(Vector128); + nint offset = sizeof(Vector128); ref Vector128 a = ref p; ref Vector128 b = ref Unsafe.AddByteOffset(ref a, offset); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromRgba32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromRgba32.cs index d418c45fe3..29e03111b9 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromRgba32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromRgba32.cs @@ -34,7 +34,7 @@ public abstract class PixelConversion_ConvertFromRgba32 ref T destBaseRef = ref this.Dest[0]; ref Rgba32 sourceBaseRef = ref this.Source[0]; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i).FromRgba32(ref Unsafe.Add(ref sourceBaseRef, i)); } @@ -48,7 +48,7 @@ public abstract class PixelConversion_ConvertFromRgba32 ref T destBaseRef = ref this.Dest[0]; ref Rgba32 sourceBaseRef = ref this.Source[0]; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i).FromRgba32(Unsafe.Add(ref sourceBaseRef, i)); } @@ -62,7 +62,7 @@ public abstract class PixelConversion_ConvertFromRgba32 ref T destBaseRef = ref this.Dest[0]; ref Rgba32 sourceBaseRef = ref this.Source[0]; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgba32 s = ref Unsafe.Add(ref sourceBaseRef, i); Unsafe.Add(ref destBaseRef, i).FromBytes(s.R, s.G, s.B, s.A); @@ -111,7 +111,7 @@ public class PixelConversion_ConvertFromRgba32_Compatible : PixelConversion_Conv ref Rgba32 sBase = ref this.CompatibleMemLayoutRunner.Source[0]; ref Rgba32 dBase = ref Unsafe.As(ref this.CompatibleMemLayoutRunner.Dest[0]); - for (int i = 0; i < this.Count; i++) + for (nint i = 0; i < (uint)this.Count; i++) { Unsafe.Add(ref dBase, i) = Unsafe.Add(ref sBase, i); } @@ -151,7 +151,7 @@ public class PixelConversion_ConvertFromRgba32_Permuted_RgbaToArgb : PixelConver ref Rgba32 sBase = ref this.PermutedRunnerRgbaToArgb.Source[0]; ref TestArgb dBase = ref this.PermutedRunnerRgbaToArgb.Dest[0]; - for (int i = 0; i < this.Count; i++) + for (nint i = 0; i < (uint)this.Count; i++) { Rgba32 s = Unsafe.Add(ref sBase, i); ref TestArgb d = ref Unsafe.Add(ref dBase, i); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromVector4.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromVector4.cs index a167ade12b..faf23efe09 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromVector4.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromVector4.cs @@ -71,7 +71,7 @@ public class PixelConversion_ConvertFromVector4 ref T destBaseRef = ref this.dest[0]; ref Vector4 sourceBaseRef = ref this.source[0]; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i).FromVector4(ref Unsafe.Add(ref sourceBaseRef, i)); } @@ -85,7 +85,7 @@ public class PixelConversion_ConvertFromVector4 ref T destBaseRef = ref this.dest[0]; ref Vector4 sourceBaseRef = ref this.source[0]; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i).FromVector4(Unsafe.Add(ref sourceBaseRef, i)); } diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32.cs index cd8307614e..ef1ebdd429 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32.cs @@ -38,7 +38,7 @@ public class PixelConversion_ConvertToRgba32 ref T sourceBaseRef = ref this.source[0]; ref Rgba32 destBaseRef = ref this.dest[0]; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i) = Unsafe.Add(ref sourceBaseRef, i).ToRgba32(); } @@ -52,7 +52,7 @@ public class PixelConversion_ConvertToRgba32 ref T sourceBaseRef = ref this.source[0]; ref Rgba32 destBaseRef = ref this.dest[0]; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Unsafe.Add(ref sourceBaseRef, i).CopyToRgba32(ref Unsafe.Add(ref destBaseRef, i)); } diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation.cs index 9ea0c04c77..29412e6ed6 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation.cs @@ -33,7 +33,7 @@ public class PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation Rgba32 temp; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { temp = Unsafe.Add(ref sourceBaseRef, i).ToRgba32(); @@ -54,7 +54,7 @@ public class PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation Rgba32 temp = default; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Unsafe.Add(ref sourceBaseRef, i).CopyToRgba32(ref temp); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4.cs index c03560e106..29e8b00b6f 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4.cs @@ -30,7 +30,7 @@ public class PixelConversion_ConvertToVector4 ref T sourceBaseRef = ref this.source[0]; ref Vector4 destBaseRef = ref this.dest[0]; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i) = Unsafe.Add(ref sourceBaseRef, i).ToVector4(); } @@ -44,7 +44,7 @@ public class PixelConversion_ConvertToVector4 ref T sourceBaseRef = ref this.source[0]; ref Vector4 destBaseRef = ref this.dest[0]; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Unsafe.Add(ref sourceBaseRef, i).CopyToVector4(ref Unsafe.Add(ref destBaseRef, i)); } diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4_AsPartOfCompositeOperation.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4_AsPartOfCompositeOperation.cs index 462bbbf7b3..65b1717349 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4_AsPartOfCompositeOperation.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4_AsPartOfCompositeOperation.cs @@ -32,7 +32,7 @@ public class PixelConversion_ConvertToVector4_AsPartOfCompositeOperation Vector4 temp; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { temp = Unsafe.Add(ref sourceBaseRef, i).ToVector4(); @@ -53,7 +53,7 @@ public class PixelConversion_ConvertToVector4_AsPartOfCompositeOperation Vector4 temp = default; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { Unsafe.Add(ref sourceBaseRef, i).CopyToVector4(ref temp); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs index 061b1e1269..5c9bfd763a 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs @@ -92,7 +92,7 @@ public unsafe class PixelConversion_PackFromRgbPlanes ref byte b = ref this.rBuf[0]; ref Rgb24 rgb = ref this.rgbBuf[0]; - for (int i = 0; i < this.Count; i++) + for (nint i = 0; i < (uint)this.Count; i++) { ref Rgb24 d = ref Unsafe.Add(ref rgb, i); d.R = Unsafe.Add(ref r, i); @@ -110,7 +110,7 @@ public unsafe class PixelConversion_PackFromRgbPlanes ref Rgb24 rgb = ref this.rgbBuf[0]; int count = this.Count / 8; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb24 d0 = ref Unsafe.Add(ref rgb, i * 8); ref Rgb24 d1 = ref Unsafe.Add(ref d0, 1); @@ -168,7 +168,7 @@ public unsafe class PixelConversion_PackFromRgbPlanes ref Rgb24 rgb = ref this.rgbBuf[0]; int count = this.Count / 4; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref Rgb24 d0 = ref Unsafe.Add(ref rgb, i * 4); ref Rgb24 d1 = ref Unsafe.Add(ref d0, 1); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Argb32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Argb32.cs index 9ae36cc8b7..f1d08b9fb9 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Argb32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Argb32.cs @@ -31,7 +31,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref Rgba32 sBase = ref this.source[0]; ref Argb32 dBase = ref this.dest[0]; - for (int i = 0; i < this.Count; i++) + for (nint i = 0; i < (uint)this.Count; i++) { Rgba32 s = Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i).FromRgba32(s); @@ -45,7 +45,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref Rgba32 sBase = ref MemoryMarshal.GetReference(source); ref TPixel dBase = ref MemoryMarshal.GetReference(dest); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { Rgba32 s = Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i).FromRgba32(s); @@ -64,7 +64,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref Rgba32 sBase = ref this.source[0]; ref Argb32 dBase = ref this.dest[0]; - for (int i = 0; i < this.Count; i += 2) + for (nint i = 0; i < (uint)this.Count; i += 2) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); Rgba32 s1 = Unsafe.Add(ref s0, 1); @@ -81,7 +81,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref Rgba32 sBase = ref this.source[0]; ref Argb32 dBase = ref this.dest[0]; - for (int i = 0; i < this.Count; i += 4) + for (nint i = 0; i < (uint)this.Count; i += 4) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); ref Rgba32 s1 = ref Unsafe.Add(ref s0, 1); @@ -105,7 +105,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref uint sBase = ref Unsafe.As(ref this.source[0]); ref uint dBase = ref Unsafe.As(ref this.dest[0]); - for (int i = 0; i < this.Count; i++) + for (nint i = 0; i < (uint)this.Count; i++) { uint s = Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i) = FromRgba32.ToArgb32(s); @@ -118,7 +118,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref ulong sBase = ref Unsafe.As(ref this.source[0]); ref ulong dBase = ref Unsafe.As(ref this.dest[0]); - for (int i = 0; i < this.Count / 2; i++) + for (nint i = 0; i < (uint)this.Count / 2; i++) { ulong s = Unsafe.Add(ref sBase, i); uint lo = (uint)s; diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs index b7b9392379..0da28c897d 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs @@ -52,7 +52,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref this.source[0]; ref Bgra32 dBase = ref this.dest[0]; - for (int i = 0; i < this.Count; i++) + for (nint i = 0; i < (uint)this.Count; i++) { ref Rgba32 s = ref Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i).FromRgba32(s); @@ -66,7 +66,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref MemoryMarshal.GetReference(source); ref TPixel dBase = ref MemoryMarshal.GetReference(dest); - for (int i = 0; i < source.Length; i++) + for (nint i = 0; i < (uint)source.Length; i++) { ref Rgba32 s = ref Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i).FromRgba32(s); @@ -85,7 +85,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref this.source[0]; ref Bgra32 dBase = ref this.dest[0]; - for (int i = 0; i < this.Count; i += 2) + for (nint i = 0; i < (uint)this.Count; i += 2) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); Rgba32 s1 = Unsafe.Add(ref s0, 1); @@ -102,7 +102,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref this.source[0]; ref Bgra32 dBase = ref this.dest[0]; - for (int i = 0; i < this.Count; i += 4) + for (nint i = 0; i < (uint)this.Count; i += 4) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); ref Rgba32 s1 = ref Unsafe.Add(ref s0, 1); @@ -127,7 +127,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref MemoryMarshal.GetReference(source); ref TPixel dBase = ref MemoryMarshal.GetReference(dest); - for (int i = 0; i < source.Length; i += 4) + for (nint i = 0; i < (uint)source.Length; i += 4) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); ref Rgba32 s1 = ref Unsafe.Add(ref s0, 1); @@ -157,7 +157,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref this.source[0]; ref Bgra32 dBase = ref this.dest[0]; - for (int i = 0; i < this.Count / 4; i += 4) + for (nint i = 0; i < (uint)this.Count / 4; i += 4) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); ref Rgba32 s1 = ref Unsafe.Add(ref s0, 1); @@ -196,7 +196,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref uint sBase = ref Unsafe.As(ref this.source[0]); ref uint dBase = ref Unsafe.As(ref this.dest[0]); - for (int i = 0; i < this.Count; i++) + for (nint i = 0; i < (uint)this.Count; i++) { uint s = Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i) = FromRgba32.ToBgra32(s); @@ -209,7 +209,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Tuple4OfUInt32 sBase = ref Unsafe.As(ref this.source[0]); ref Tuple4OfUInt32 dBase = ref Unsafe.As(ref this.dest[0]); - for (int i = 0; i < this.Count / 4; i++) + for (nint i = 0; i < (uint)this.Count / 4; i++) { ref Tuple4OfUInt32 d = ref Unsafe.Add(ref dBase, i); d = Unsafe.Add(ref sBase, i); @@ -222,7 +222,7 @@ public class PixelConversion_Rgba32_To_Bgra32 { ref Tuple4OfUInt32 sBase = ref Unsafe.As(ref this.source[0]); - for (int i = 0; i < this.Count / 4; i++) + for (nint i = 0; i < (uint)this.Count / 4; i++) { Unsafe.Add(ref sBase, i).ConvertMe(); } @@ -234,7 +234,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Octet sBase = ref Unsafe.As>(ref this.source[0]); ref Octet dBase = ref Unsafe.As>(ref this.dest[0]); - for (int i = 0; i < this.Count / 8; i++) + for (nint i = 0; i < (uint)this.Count / 8; i++) { BitopsSimdImpl(ref Unsafe.Add(ref sBase, i), ref Unsafe.Add(ref dBase, i)); } @@ -289,7 +289,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref uint sBase = ref Unsafe.As(ref this.source[0]); ref uint dBase = ref Unsafe.As(ref this.dest[0]); - for (int i = 0; i < this.Count; i++) + for (nint i = 0; i < (uint)this.Count; i++) { ref uint s0 = ref Unsafe.Add(ref sBase, i); uint s1 = Unsafe.Add(ref s0, 1); @@ -306,7 +306,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref ulong sBase = ref Unsafe.As(ref this.source[0]); ref ulong dBase = ref Unsafe.As(ref this.dest[0]); - for (int i = 0; i < this.Count / 2; i++) + for (nint i = 0; i < (uint)this.Count / 2; i++) { ulong s = Unsafe.Add(ref sBase, i); uint lo = (uint)s; @@ -326,7 +326,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref ulong sBase = ref Unsafe.As(ref this.source[0]); ref ulong dBase = ref Unsafe.As(ref this.dest[0]); - for (int i = 0; i < this.Count / 2; i++) + for (nint i = 0; i < (uint)this.Count / 2; i++) { ulong s = Unsafe.Add(ref sBase, i); uint lo = (uint)s; diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs index 4615376a5f..586618fcb1 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs @@ -33,7 +33,7 @@ public class WidenBytesToUInt32 ref Octet sBase = ref Unsafe.As>(ref this.source[0]); ref Octet dBase = ref Unsafe.As>(ref this.dest[0]); - for (int i = 0; i < N; i++) + for (nint i = 0; i < N; i++) { Unsafe.Add(ref dBase, i).LoadFrom(ref Unsafe.Add(ref sBase, i)); } diff --git a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsSingleVector.cs b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsSingleVector.cs index fcf7e9dcce..33f5720aab 100644 --- a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsSingleVector.cs +++ b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsSingleVector.cs @@ -58,7 +58,7 @@ public class PorterDuffBulkVsSingleVector Vector256 result = default; Vector256 opacity = Vector256.Create(.5F); int count = this.backdrop.Length / 2; - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { result = PorterDuffFunctions.NormalSrcOver(Unsafe.Add(ref backdrop, i), Unsafe.Add(ref source, i), opacity); } diff --git a/tests/ImageSharp.Tests/Formats/Png/ReferenceImplementations.cs b/tests/ImageSharp.Tests/Formats/Png/ReferenceImplementations.cs index d57a775876..7610023afc 100644 --- a/tests/ImageSharp.Tests/Formats/Png/ReferenceImplementations.cs +++ b/tests/ImageSharp.Tests/Formats/Png/ReferenceImplementations.cs @@ -34,8 +34,8 @@ internal static partial class ReferenceImplementations // Paeth(x) = Raw(x) - PaethPredictor(Raw(x-bpp), Prior(x), Prior(x - bpp)) resultBaseRef = 4; - int x = 0; - for (; x < bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) + nint x = 0; + for (; x < (nint)(uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -45,7 +45,7 @@ internal static partial class ReferenceImplementations sum += Numerics.Abs(unchecked((sbyte)res)); } - for (int xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (nint)(uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte left = Unsafe.Add(ref scanBaseRef, xLeft); @@ -77,8 +77,8 @@ internal static partial class ReferenceImplementations // Sub(x) = Raw(x) - Raw(x-bpp) resultBaseRef = 1; - int x = 0; - for (; x < bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) + nint x = 0; + for (; x < (nint)(uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); ++x; @@ -87,7 +87,7 @@ internal static partial class ReferenceImplementations sum += Numerics.Abs(unchecked((sbyte)res)); } - for (int xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (nint)(uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte prev = Unsafe.Add(ref scanBaseRef, xLeft); @@ -119,9 +119,9 @@ internal static partial class ReferenceImplementations // Up(x) = Raw(x) - Prior(x) resultBaseRef = 2; - int x = 0; + nint x = 0; - for (; x < scanline.Length; /* Note: ++x happens in the body to avoid one add operation */) + for (; x < (nint)(uint)scanline.Length; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -154,8 +154,8 @@ internal static partial class ReferenceImplementations // Average(x) = Raw(x) - floor((Raw(x-bpp)+Prior(x))/2) resultBaseRef = 3; - int x = 0; - for (; x < bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) + nint x = 0; + for (; x < (nint)(uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -165,7 +165,7 @@ internal static partial class ReferenceImplementations sum += Numerics.Abs(unchecked((sbyte)res)); } - for (int xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (nint)(uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte left = Unsafe.Add(ref scanBaseRef, xLeft); diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs b/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs index 006cb9eb61..521270e3be 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs @@ -100,7 +100,7 @@ public abstract partial class PixelConverterTests if (typeof(TDestinationPixel) == typeof(L16)) { ref L16 l16Ref = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(destinationPixels)); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref TSourcePixel sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref l16Ref, i); @@ -113,7 +113,7 @@ public abstract partial class PixelConverterTests if (typeof(TDestinationPixel) == typeof(L8)) { ref L8 l8Ref = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(destinationPixels)); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref TSourcePixel sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref l8Ref, i); @@ -125,7 +125,7 @@ public abstract partial class PixelConverterTests // Normal conversion ref TDestinationPixel destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < count; i++) + for (nint i = 0; i < (uint)count; i++) { ref TSourcePixel sp = ref Unsafe.Add(ref sourceRef, i); ref TDestinationPixel dp = ref Unsafe.Add(ref destRef, i); diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index a9b3ee9a42..73305183f6 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -1184,7 +1184,7 @@ public abstract class PixelOperationsTests : MeasureFixture get { ref byte self = ref Unsafe.As(ref this); - return Unsafe.Add(ref self, idx); + return Unsafe.Add(ref self, (uint)idx); } } } From 1faf5a599d97c9851c999e68eafb15df2da49137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 13 Mar 2023 17:11:53 +0100 Subject: [PATCH 03/86] Removed some bound checks for arr[0] indexing to get a reference --- src/ImageSharp/Compression/Zlib/DeflaterEngine.cs | 5 +++-- .../Jpeg/Components/Decoder/ArithmeticScanDecoder.cs | 5 +++-- .../Jpeg/Components/Decoder/ArithmeticStatistics.cs | 4 +++- src/ImageSharp/Formats/Png/PngScanlineProcessor.cs | 4 ++-- src/ImageSharp/Formats/Tga/TgaDecoderCore.cs | 7 ++++--- .../Processors/Convolution/BokehBlurProcessor.cs | 2 +- .../Processors/Convolution/BokehBlurProcessor{TPixel}.cs | 2 +- .../Convolution/Convolution2PassProcessor{TPixel}.cs | 8 ++++---- .../Convolution/Parameters/BokehBlurKernelDataProvider.cs | 4 ++-- .../Processors/Quantization/WuQuantizer{TPixel}.cs | 2 +- 10 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/ImageSharp/Compression/Zlib/DeflaterEngine.cs b/src/ImageSharp/Compression/Zlib/DeflaterEngine.cs index 31fa0238bf..6009fdfbc0 100644 --- a/src/ImageSharp/Compression/Zlib/DeflaterEngine.cs +++ b/src/ImageSharp/Compression/Zlib/DeflaterEngine.cs @@ -3,6 +3,7 @@ using System.Buffers; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Compression.Zlib; @@ -426,8 +427,8 @@ internal sealed unsafe class DeflaterEngine : IDisposable private void SlideWindow() { Unsafe.CopyBlockUnaligned( - ref this.window.Span[0], - ref this.window.Span[DeflaterConstants.WSIZE], + ref MemoryMarshal.GetReference(this.window.Span), + ref Unsafe.Add(ref MemoryMarshal.GetReference(this.window.Span), DeflaterConstants.WSIZE), DeflaterConstants.WSIZE); this.matchStart -= DeflaterConstants.WSIZE; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs index 59789dcd25..1b043b68f2 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs @@ -53,7 +53,8 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder private ArithmeticDecodingTable[] acDecodingTables; - private readonly byte[] fixedBin = { 113, 0, 0, 0 }; + // Use C#'s optimization to refer to assembly's data segment, no allocation occurs. + private ReadOnlySpan fixedBin => new byte[] { 113, 0, 0, 0 }; private readonly CancellationToken cancellationToken; @@ -231,7 +232,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder } } - private ref byte GetFixedBinReference() => ref this.fixedBin[0]; + private ref byte GetFixedBinReference() => ref MemoryMarshal.GetReference(fixedBin); /// /// Decodes the entropy coded data. diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticStatistics.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticStatistics.cs index 1e890d8269..9bd4110d07 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticStatistics.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticStatistics.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Runtime.InteropServices; + namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; internal class ArithmeticStatistics @@ -18,7 +20,7 @@ internal class ArithmeticStatistics public int Identifier { get; private set; } - public ref byte GetReference() => ref this.statistics[0]; + public ref byte GetReference() => ref MemoryMarshal.GetArrayDataReference(this.statistics); public ref byte GetReference(int offset) => ref this.statistics[offset]; diff --git a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs index 25c4a0d700..51b23242c8 100644 --- a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs +++ b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs @@ -255,7 +255,7 @@ internal static class PngScanlineProcessor // If the alpha palette is not null and has one or more entries, this means, that the image contains an alpha // channel and we should try to read it. Rgba32 rgba = default; - ref byte paletteAlphaRef = ref paletteAlpha[0]; + ref byte paletteAlphaRef = ref MemoryMarshal.GetArrayDataReference(paletteAlpha); for (int x = 0; x < header.Width; x++) { @@ -301,7 +301,7 @@ internal static class PngScanlineProcessor // If the alpha palette is not null and has one or more entries, this means, that the image contains an alpha // channel and we should try to read it. Rgba32 rgba = default; - ref byte paletteAlphaRef = ref paletteAlpha[0]; + ref byte paletteAlphaRef = ref MemoryMarshal.GetArrayDataReference(paletteAlpha); for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o++) { int index = Unsafe.Add(ref scanlineSpanRef, (uint)o); diff --git a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs index ce4f566b87..e7dca00f79 100644 --- a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs @@ -4,6 +4,7 @@ using System.Buffers; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Metadata; @@ -429,11 +430,11 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals if (this.fileHeader.ImageType == TgaImageType.BlackAndWhite) { - color.FromLa16(Unsafe.As(ref this.scratchBuffer[0])); + color.FromLa16(Unsafe.As(ref MemoryMarshal.GetArrayDataReference(this.scratchBuffer))); } else { - color.FromBgra5551(Unsafe.As(ref this.scratchBuffer[0])); + color.FromBgra5551(Unsafe.As(ref MemoryMarshal.GetArrayDataReference(this.scratchBuffer))); } pixelSpan[x] = color; @@ -695,7 +696,7 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a bgr pixel"); } - color.FromBgr24(Unsafe.As(ref this.scratchBuffer[0])); + color.FromBgr24(Unsafe.As(ref MemoryMarshal.GetArrayDataReference(this.scratchBuffer))); pixelSpan[x] = color; } diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs index 04653bd6ec..bc023ec450 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs @@ -133,7 +133,7 @@ public sealed class BokehBlurProcessor : IImageProcessor // The target buffer is zeroed initially and then it accumulates the results // of each partial convolution, so we don't have to clear it here as well ref Vector4 targetBase = ref this.targetValues.GetElementUnsafe(boundsX, y); - ref Complex64 kernelStart = ref this.kernel[0]; + ref Complex64 kernelStart = ref MemoryMarshal.GetArrayDataReference(this.kernel); ref Complex64 kernelEnd = ref Unsafe.Add(ref kernelStart, (uint)kernelSize); while (Unsafe.IsAddressLessThan(ref kernelStart, ref kernelEnd)) diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs index 2508a7da25..e4b0a60ab0 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs @@ -244,7 +244,7 @@ internal class BokehBlurProcessor : ImageProcessor ref Vector4 sourceBase = ref MemoryMarshal.GetReference(span); ref ComplexVector4 targetStart = ref MemoryMarshal.GetReference(targetBuffer); ref ComplexVector4 targetEnd = ref Unsafe.Add(ref targetStart, (uint)span.Length); - ref Complex64 kernelBase = ref this.kernel[0]; + ref Complex64 kernelBase = ref MemoryMarshal.GetArrayDataReference(this.kernel); ref Complex64 kernelEnd = ref Unsafe.Add(ref kernelBase, (uint)kernelSize); ref int sampleColumnBase = ref MemoryMarshal.GetReference(this.map.GetColumnOffsetSpan()); diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs index b09db9fa05..cc6e1e5fb2 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs @@ -179,7 +179,7 @@ internal class Convolution2PassProcessor : ImageProcessor ref Vector4 sourceBase = ref MemoryMarshal.GetReference(sourceBuffer); ref Vector4 targetStart = ref MemoryMarshal.GetReference(targetBuffer); ref Vector4 targetEnd = ref Unsafe.Add(ref targetStart, (uint)sourceBuffer.Length); - ref float kernelBase = ref this.kernel[0]; + ref float kernelBase = ref MemoryMarshal.GetArrayDataReference(this.kernel); ref float kernelEnd = ref Unsafe.Add(ref kernelBase, (uint)kernelSize); ref int sampleColumnBase = ref MemoryMarshal.GetReference(this.map.GetColumnOffsetSpan()); @@ -243,7 +243,7 @@ internal class Convolution2PassProcessor : ImageProcessor ref Vector4 sourceBase = ref MemoryMarshal.GetReference(sourceBuffer); ref Vector4 targetStart = ref MemoryMarshal.GetReference(targetBuffer); ref Vector4 targetEnd = ref Unsafe.Add(ref targetStart, (uint)sourceBuffer.Length); - ref float kernelBase = ref this.kernel[0]; + ref float kernelBase = ref MemoryMarshal.GetArrayDataReference(this.kernel); ref float kernelEnd = ref Unsafe.Add(ref kernelBase, (uint)kernelSize); ref int sampleColumnBase = ref MemoryMarshal.GetReference(this.map.GetColumnOffsetSpan()); @@ -341,7 +341,7 @@ internal class Convolution2PassProcessor : ImageProcessor targetBuffer.Clear(); ref Vector4 targetBase = ref MemoryMarshal.GetReference(targetBuffer); - ref float kernelStart = ref this.kernel[0]; + ref float kernelStart = ref MemoryMarshal.GetArrayDataReference(this.kernel); ref float kernelEnd = ref Unsafe.Add(ref kernelStart, (uint)kernelSize); Span sourceRow; @@ -406,7 +406,7 @@ internal class Convolution2PassProcessor : ImageProcessor targetBuffer.Clear(); ref Vector4 targetBase = ref MemoryMarshal.GetReference(targetBuffer); - ref float kernelStart = ref this.kernel[0]; + ref float kernelStart = ref MemoryMarshal.GetArrayDataReference(this.kernel); ref float kernelEnd = ref Unsafe.Add(ref kernelStart, (uint)kernelSize); Span sourceRow; diff --git a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs index 8f501da23e..a680393c8c 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Parameters/BokehBlurKernelDataProvider.cs @@ -192,7 +192,7 @@ internal static class BokehBlurKernelDataProvider { ref Complex64[] kernelRef = ref Unsafe.Add(ref baseKernelsRef, (uint)i); int length = kernelRef.Length; - ref Complex64 valueRef = ref kernelRef[0]; + ref Complex64 valueRef = ref MemoryMarshal.GetArrayDataReference(kernelRef); ref Vector4 paramsRef = ref Unsafe.Add(ref baseParamsRef, (uint)i); for (int j = 0; j < length; j++) @@ -214,7 +214,7 @@ internal static class BokehBlurKernelDataProvider { ref Complex64[] kernelsRef = ref Unsafe.Add(ref baseKernelsRef, (uint)i); int length = kernelsRef.Length; - ref Complex64 valueRef = ref kernelsRef[0]; + ref Complex64 valueRef = ref MemoryMarshal.GetArrayDataReference(kernelsRef); for (int j = 0; j < length; j++) { diff --git a/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs index edf293d39e..a231d6dee7 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs @@ -684,7 +684,7 @@ internal struct WuQuantizer : IQuantizer using IMemoryOwner vvOwner = this.Configuration.MemoryAllocator.Allocate(this.maxColors); Span vv = vvOwner.GetSpan(); - ref Box cube = ref this.colorCube[0]; + ref Box cube = ref MemoryMarshal.GetArrayDataReference(this.colorCube); cube.RMin = cube.GMin = cube.BMin = cube.AMin = 0; cube.RMax = cube.GMax = cube.BMax = IndexCount - 1; cube.AMax = IndexAlphaCount - 1; From 9b7e41f6ca10dbd5cbded4d436f7ed8ebc487c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 13 Mar 2023 18:25:23 +0100 Subject: [PATCH 04/86] Optimized division by constants --- .../Converters/CieXyzToCieLabConverter.cs | 10 ++++--- src/ImageSharp/Common/Helpers/HexConverter.cs | 14 +++++----- .../Helpers/Shuffle/IComponentShuffle.cs | 10 +++---- .../SimdUtils.FallbackIntrinsics128.cs | 4 +-- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 4 +-- .../Compression/Zlib/DeflaterHuffman.cs | 6 ++--- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 2 +- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 2 +- .../Jpeg/Components/Block8x8F.Generated.cs | 4 +-- .../Jpeg/Components/Block8x8F.Generated.tt | 4 +-- .../ColorConverters/JpegColorConverterBase.cs | 2 +- .../DownScalingComponentProcessor2.cs | 2 +- .../DownScalingComponentProcessor4.cs | 2 +- .../DownScalingComponentProcessor8.cs | 2 +- .../Components/Encoder/HuffmanScanEncoder.cs | 2 +- .../Jpeg/Components/ScaledFloatingPointDCT.cs | 24 ++++++++--------- src/ImageSharp/Formats/Png/Adam7.cs | 26 ++++++++++++------- .../Tiff/Compression/TiffBaseCompression.cs | 2 +- .../Formats/Tiff/TiffDecoderCore.cs | 2 +- .../Writers/TiffBaseColorWriter{TPixel}.cs | 2 +- .../Formats/Webp/BitWriter/Vp8BitWriter.cs | 2 +- .../Formats/Webp/Lossless/HistogramEncoder.cs | 4 +-- .../Formats/Webp/Lossless/HuffmanUtils.cs | 4 +-- .../Formats/Webp/Lossless/LosslessUtils.cs | 7 ++++- .../Formats/Webp/Lossless/Vp8LEncoder.cs | 4 +-- .../Formats/Webp/Lossless/Vp8LHashChain.cs | 4 +-- .../Formats/Webp/Lossy/Vp8Encoder.cs | 6 ++--- .../Formats/Webp/Lossy/WebpLossyDecoder.cs | 2 +- src/ImageSharp/IO/ChunkedMemoryStream.cs | 2 +- ...iformUnmanagedMemoryPoolMemoryAllocator.cs | 2 +- src/ImageSharp/Primitives/Rectangle.cs | 2 +- .../BinaryThresholdProcessor{TPixel}.cs | 11 ++++---- ...eHistogramEqualizationProcessor{TPixel}.cs | 8 +++--- ...alizationSlidingWindowProcessor{TPixel}.cs | 2 +- .../Linear/FlipProcessor{TPixel}.cs | 2 +- .../Transforms/Resize/ResizeHelper.cs | 12 ++++----- 36 files changed, 106 insertions(+), 94 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs index df7686c316..0ce6e3c9ff 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System.Runtime.CompilerServices; @@ -42,9 +42,11 @@ internal sealed class CieXyzToCieLabConverter float xr = input.X / wx, yr = input.Y / wy, zr = input.Z / wz; - float fx = xr > CieConstants.Epsilon ? MathF.Pow(xr, 0.3333333F) : ((CieConstants.Kappa * xr) + 16F) / 116F; - float fy = yr > CieConstants.Epsilon ? MathF.Pow(yr, 0.3333333F) : ((CieConstants.Kappa * yr) + 16F) / 116F; - float fz = zr > CieConstants.Epsilon ? MathF.Pow(zr, 0.3333333F) : ((CieConstants.Kappa * zr) + 16F) / 116F; + const float inv116 = 1 / 116F; + + float fx = xr > CieConstants.Epsilon ? MathF.Pow(xr, 0.3333333F) : ((CieConstants.Kappa * xr) + 16F) * inv116; + float fy = yr > CieConstants.Epsilon ? MathF.Pow(yr, 0.3333333F) : ((CieConstants.Kappa * yr) + 16F) * inv116; + float fz = zr > CieConstants.Epsilon ? MathF.Pow(zr, 0.3333333F) : ((CieConstants.Kappa * zr) + 16F) * inv116; float l = (116F * fy) - 16F; float a = 500F * (fx - fy); diff --git a/src/ImageSharp/Common/Helpers/HexConverter.cs b/src/ImageSharp/Common/Helpers/HexConverter.cs index 7ec0ca625c..3c863cc37c 100644 --- a/src/ImageSharp/Common/Helpers/HexConverter.cs +++ b/src/ImageSharp/Common/Helpers/HexConverter.cs @@ -16,21 +16,19 @@ internal static class HexConverter /// The number of bytes written to . public static int HexStringToBytes(ReadOnlySpan chars, Span bytes) { - if ((chars.Length % 2) != 0) + if ((chars.Length & 1) != 0) // bit-hack for % 2 { throw new ArgumentException("Input string length must be a multiple of 2", nameof(chars)); } - if ((bytes.Length * 2) < chars.Length) + if ((bytes.Length << 1) < chars.Length) // bit-hack for * 2 { throw new ArgumentException("Output span must be at least half the length of the input string"); } - else - { - // Slightly better performance in the loop below, allows us to skip a bounds check - // while still supporting output buffers that are larger than necessary - bytes = bytes[..(chars.Length / 2)]; - } + + // Slightly better performance in the loop below, allows us to skip a bounds check + // while still supporting output buffers that are larger than necessary + bytes = bytes[..(chars.Length >> 1)]; // bit-hack for / 2 [MethodImpl(MethodImplOptions.AggressiveInlining)] static int FromChar(int c) diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index 18daaed481..f2135b7645 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -84,7 +84,7 @@ internal readonly struct WXYZShuffle4 : IShuffle4 { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; + int n = (int)((uint)source.Length / 4); for (nint i = 0; i < (uint)n; i++) { @@ -108,7 +108,7 @@ internal readonly struct WZYXShuffle4 : IShuffle4 { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; + int n = (int)((uint)source.Length / 4); for (nint i = 0; i < (uint)n; i++) { @@ -132,7 +132,7 @@ internal readonly struct YZWXShuffle4 : IShuffle4 { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; + int n = (int)((uint)source.Length / 4); for (nint i = 0; i < (uint)n; i++) { @@ -156,7 +156,7 @@ internal readonly struct ZYXWShuffle4 : IShuffle4 { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; + int n = (int)((uint)source.Length / 4); for (nint i = 0; i < (uint)n; i++) { @@ -187,7 +187,7 @@ internal readonly struct XWZYShuffle4 : IShuffle4 { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; + int n = (int)((uint)source.Length / 4); for (nint i = 0; i < (uint)n; i++) { diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs index 8c79b181ce..6fc36cd701 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs @@ -71,7 +71,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, 4); - int count = dest.Length / 4; + int count = (int)((uint)dest.Length / 4); if (count == 0) { return; @@ -105,7 +105,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, 4); - int count = source.Length / 4; + int count = (int)((uint)source.Length / 4); if (count == 0) { return; diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 654ae38103..06b61443f3 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -159,7 +159,7 @@ internal static partial class SimdUtils int remainder = source.Length % (Vector128.Count * 3); int sourceCount = source.Length - remainder; - int destCount = sourceCount * 4 / 3; + int destCount = (int)((uint)sourceCount * 4 / 3); if (sourceCount > 0) { @@ -192,7 +192,7 @@ internal static partial class SimdUtils int remainder = source.Length % (Vector128.Count * 4); int sourceCount = source.Length - remainder; - int destCount = sourceCount * 3 / 4; + int destCount = (int)((uint)sourceCount * 3 / 4); if (sourceCount > 0) { diff --git a/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs b/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs index d507d88c51..ebc43f8822 100644 --- a/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs +++ b/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs @@ -206,8 +206,8 @@ internal sealed unsafe class DeflaterHuffman : IDisposable int lc = Lcode(litlen); this.literalTree.WriteSymbol(pendingBuffer, lc); - int bits = (lc - 261) / 4; - if (bits > 0 && bits <= 5) + int bits = (int)(((uint)lc - 261) / 4); + if (bits is > 0 and <= 5) { this.Pending.WriteBits(litlen & ((1 << bits) - 1), bits); } @@ -364,7 +364,7 @@ internal sealed unsafe class DeflaterHuffman : IDisposable this.literalTree.Frequencies[lc]++; if (lc >= 265 && lc < 285) { - this.extraBits += (lc - 261) / 4; + this.extraBits += (int)(((uint)lc - 261) / 4); } int dc = Dcode(distance - 1); diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index dfc6bb9611..4a71dc8b89 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -489,7 +489,7 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals // If the second byte > 2, we are in 'absolute mode'. // The second byte contains the number of color indexes that follow. int max = cmd[1]; - int bytesToRead = (max + 1) / 2; + int bytesToRead = (int)(((uint)max + 1) / 2); byte[] run = new byte[bytesToRead]; diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index f30369d19b..a2c7058233 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -124,7 +124,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals this.bitsPerPixel ??= bmpMetadata.BitsPerPixel; short bpp = (short)this.bitsPerPixel; - int bytesPerLine = 4 * (((image.Width * bpp) + 31) / 32); + int bytesPerLine = (int)(4 * ((((uint)image.Width * (ushort)bpp) + 31) / 32)); this.padding = bytesPerLine - (int)(image.Width * (bpp / 8F)); int colorPaletteSize = this.bitsPerPixel switch diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs index d1cb3559b2..e5d252f432 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs @@ -16,7 +16,7 @@ internal partial struct Block8x8F { var CMin4 = new Vector4(0F); var CMax4 = new Vector4(maximum); - var COff4 = new Vector4(MathF.Ceiling(maximum / 2)); + var COff4 = new Vector4(MathF.Ceiling(maximum * 0.5F)); // /2 this.V0L = Numerics.Clamp(this.V0L + COff4, CMin4, CMax4); this.V0R = Numerics.Clamp(this.V0R + COff4, CMin4, CMax4); @@ -42,7 +42,7 @@ internal partial struct Block8x8F [MethodImpl(InliningOptions.ShortMethod)] public void NormalizeColorsAndRoundInPlaceVector8(float maximum) { - var off = new Vector(MathF.Ceiling(maximum / 2)); + var off = new Vector(MathF.Ceiling(maximum * 0.5F)); // /2 var max = new Vector(maximum); ref Vector row0 = ref Unsafe.As>(ref this.V0L); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt index aa211ea22b..7350edd38b 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt @@ -29,7 +29,7 @@ internal partial struct Block8x8F { var CMin4 = new Vector4(0F); var CMax4 = new Vector4(maximum); - var COff4 = new Vector4(MathF.Ceiling(maximum / 2)); + var COff4 = new Vector4(MathF.Ceiling(maximum * 0.5F)); // /2 <# @@ -53,7 +53,7 @@ internal partial struct Block8x8F [MethodImpl(InliningOptions.ShortMethod)] public void NormalizeColorsAndRoundInPlaceVector8(float maximum) { - var off = new Vector(MathF.Ceiling(maximum / 2)); + var off = new Vector(MathF.Ceiling(maximum * 0.5F)); // /2 var max = new Vector(maximum); <# diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs index 62f48af16e..1291beb47a 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs @@ -26,7 +26,7 @@ internal abstract partial class JpegColorConverterBase this.ColorSpace = colorSpace; this.Precision = precision; this.MaximumValue = MathF.Pow(2, precision) - 1; - this.HalfValue = MathF.Ceiling(this.MaximumValue / 2); + this.HalfValue = MathF.Ceiling(this.MaximumValue * 0.5F); // /2 } /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs index 51d8d03593..8b4256e3b9 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs @@ -25,7 +25,7 @@ internal sealed class DownScalingComponentProcessor2 : ComponentProcessor Buffer2D spectralBuffer = this.Component.SpectralBlocks; float maximumValue = this.Frame.MaxColorChannelValue; - float normalizationValue = MathF.Ceiling(maximumValue / 2); + float normalizationValue = MathF.Ceiling(maximumValue * 0.5F); // /2 int destAreaStride = this.ColorBuffer.Width; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs index b8a40f53b1..170cdbb3c8 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs @@ -25,7 +25,7 @@ internal sealed class DownScalingComponentProcessor4 : ComponentProcessor Buffer2D spectralBuffer = this.Component.SpectralBlocks; float maximumValue = this.Frame.MaxColorChannelValue; - float normalizationValue = MathF.Ceiling(maximumValue / 2); + float normalizationValue = MathF.Ceiling(maximumValue * 0.5F); // /2 int destAreaStride = this.ColorBuffer.Width; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs index 121b745465..81104d2f3d 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs @@ -22,7 +22,7 @@ internal sealed class DownScalingComponentProcessor8 : ComponentProcessor Buffer2D spectralBuffer = this.Component.SpectralBlocks; float maximumValue = this.Frame.MaxColorChannelValue; - float normalizationValue = MathF.Ceiling(maximumValue / 2); + float normalizationValue = MathF.Ceiling(maximumValue * 0.5F); // /2 int destAreaStride = this.ColorBuffer.Width; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs index f479df7e2d..1453b0a568 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs @@ -123,7 +123,7 @@ internal class HuffmanScanEncoder private bool IsStreamFlushNeeded { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.emitWriteIndex < (uint)this.emitBuffer.Length / 2; + get => this.emitWriteIndex < (int)((uint)this.emitBuffer.Length / 2); } public void BuildHuffmanTable(JpegHuffmanTableConfig tableConfig) diff --git a/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs b/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs index 369626a96b..4f67b7dfe9 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs @@ -103,10 +103,10 @@ internal static class ScaledFloatingPointDCT // temporal result is saved to +4 shifted indices // because result is saved into the top left 2x2 region of the // input block - block[(ctr * 8) + 0 + 4] = (tmp10 + tmp2) / 2; - block[(ctr * 8) + 3 + 4] = (tmp10 - tmp2) / 2; - block[(ctr * 8) + 1 + 4] = (tmp12 + tmp0) / 2; - block[(ctr * 8) + 2 + 4] = (tmp12 - tmp0) / 2; + block[(ctr * 8) + 0 + 4] = (tmp10 + tmp2) * 0.5F; + block[(ctr * 8) + 3 + 4] = (tmp10 - tmp2) * 0.5F; + block[(ctr * 8) + 1 + 4] = (tmp12 + tmp0) * 0.5F; + block[(ctr * 8) + 2 + 4] = (tmp12 - tmp0) * 0.5F; } for (int ctr = 0; ctr < 4; ctr++) @@ -136,10 +136,10 @@ internal static class ScaledFloatingPointDCT (z4 * FP32_2_562915447); // Save results to the top left 4x4 subregion - block[(ctr * 8) + 0] = MathF.Round(Numerics.Clamp(((tmp10 + tmp2) / 2) + normalizationValue, 0, maxValue)); - block[(ctr * 8) + 3] = MathF.Round(Numerics.Clamp(((tmp10 - tmp2) / 2) + normalizationValue, 0, maxValue)); - block[(ctr * 8) + 1] = MathF.Round(Numerics.Clamp(((tmp12 + tmp0) / 2) + normalizationValue, 0, maxValue)); - block[(ctr * 8) + 2] = MathF.Round(Numerics.Clamp(((tmp12 - tmp0) / 2) + normalizationValue, 0, maxValue)); + block[(ctr * 8) + 0] = MathF.Round(Numerics.Clamp(((tmp10 + tmp2) * 0.5F) + normalizationValue, 0, maxValue)); + block[(ctr * 8) + 3] = MathF.Round(Numerics.Clamp(((tmp10 - tmp2) * 0.5F) + normalizationValue, 0, maxValue)); + block[(ctr * 8) + 1] = MathF.Round(Numerics.Clamp(((tmp12 + tmp0) * 0.5F) + normalizationValue, 0, maxValue)); + block[(ctr * 8) + 2] = MathF.Round(Numerics.Clamp(((tmp12 - tmp0) * 0.5F) + normalizationValue, 0, maxValue)); } } @@ -183,8 +183,8 @@ internal static class ScaledFloatingPointDCT // temporal result is saved to +2 shifted indices // because result is saved into the top left 2x2 region of the // input block - block[(ctr * 8) + 2] = (tmp10 + tmp0) / 4; - block[(ctr * 8) + 3] = (tmp10 - tmp0) / 4; + block[(ctr * 8) + 2] = (tmp10 + tmp0) * 0.25F; // /4 + block[(ctr * 8) + 3] = (tmp10 - tmp0) * 0.25F; // /4 } for (int ctr = 0; ctr < 2; ctr++) @@ -199,8 +199,8 @@ internal static class ScaledFloatingPointDCT (block[ctr + (8 * 1) + 2] * FP32_3_624509785); // Save results to the top left 2x2 subregion - block[(ctr * 8) + 0] = MathF.Round(Numerics.Clamp(((tmp10 + tmp0) / 4) + normalizationValue, 0, maxValue)); - block[(ctr * 8) + 1] = MathF.Round(Numerics.Clamp(((tmp10 - tmp0) / 4) + normalizationValue, 0, maxValue)); + block[(ctr * 8) + 0] = MathF.Round(Numerics.Clamp(((tmp10 + tmp0) * 0.25F) + normalizationValue, 0, maxValue)); + block[(ctr * 8) + 1] = MathF.Round(Numerics.Clamp(((tmp10 - tmp0) * 0.25F) + normalizationValue, 0, maxValue)); } } diff --git a/src/ImageSharp/Formats/Png/Adam7.cs b/src/ImageSharp/Formats/Png/Adam7.cs index f52a66c265..8310ca64c8 100644 --- a/src/ImageSharp/Formats/Png/Adam7.cs +++ b/src/ImageSharp/Formats/Png/Adam7.cs @@ -67,16 +67,22 @@ internal static class Adam7 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int ComputeColumns(int width, int passIndex) { - switch (passIndex) + uint w = (uint)width; + + uint result = passIndex switch { - case 0: return (width + 7) / 8; - case 1: return (width + 3) / 8; - case 2: return (width + 3) / 4; - case 3: return (width + 1) / 4; - case 4: return (width + 1) / 2; - case 5: return width / 2; - case 6: return width; - default: throw new ArgumentException($"Not a valid pass index: {passIndex}"); - } + 0 => (w + 7) / 8, + 1 => (w + 3) / 8, + 2 => (w + 3) / 4, + 3 => (w + 1) / 4, + 4 => (w + 1) / 2, + 5 => w / 2, + 6 => w, + _ => Throw(passIndex) + }; + + return (int)result; + + static uint Throw(int passIndex) => throw new ArgumentException($"Not a valid pass index: {passIndex}"); } } diff --git a/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs index 36f8c20d72..d57dea994f 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs @@ -16,7 +16,7 @@ internal abstract class TiffBaseCompression : IDisposable this.Width = width; this.BitsPerPixel = bitsPerPixel; this.Predictor = predictor; - this.BytesPerRow = ((width * bitsPerPixel) + 7) / 8; + this.BytesPerRow = (int)(((uint)(width * bitsPerPixel) + 7) / 8); } /// diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs index 45bbed12d5..4499c55833 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs @@ -793,7 +793,7 @@ internal class TiffDecoderCore : IImageDecoderInternals } } - int bytesPerRow = ((width * bitsPerPixel) + 7) / 8; + int bytesPerRow = (int)(((uint)(width * bitsPerPixel) + 7) / 8); return bytesPerRow * height; } diff --git a/src/ImageSharp/Formats/Tiff/Writers/TiffBaseColorWriter{TPixel}.cs b/src/ImageSharp/Formats/Tiff/Writers/TiffBaseColorWriter{TPixel}.cs index 189c8fd6ac..c4a7492553 100644 --- a/src/ImageSharp/Formats/Tiff/Writers/TiffBaseColorWriter{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/Writers/TiffBaseColorWriter{TPixel}.cs @@ -29,7 +29,7 @@ internal abstract class TiffBaseColorWriter : IDisposable /// /// Gets the bytes per row. /// - public int BytesPerRow => ((this.Image.Width * this.BitsPerPixel) + 7) / 8; + public int BytesPerRow => (int)(((uint)(this.Image.Width * this.BitsPerPixel) + 7) / 8); protected ImageFrame Image { get; } diff --git a/src/ImageSharp/Formats/Webp/BitWriter/Vp8BitWriter.cs b/src/ImageSharp/Formats/Webp/BitWriter/Vp8BitWriter.cs index b83b44fa14..5b4eab64a3 100644 --- a/src/ImageSharp/Formats/Webp/BitWriter/Vp8BitWriter.cs +++ b/src/ImageSharp/Formats/Webp/BitWriter/Vp8BitWriter.cs @@ -457,7 +457,7 @@ internal class Vp8BitWriter : BitWriterBase this.Finish(); uint numBytes = (uint)this.NumBytes(); int mbSize = this.enc.Mbw * this.enc.Mbh; - int expectedSize = mbSize * 7 / 8; + int expectedSize = (int)((uint)mbSize * 7 / 8); Vp8BitWriter bitWriterPartZero = new(expectedSize, this.enc); diff --git a/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs index 1395181634..5eec2a2ca3 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs @@ -316,7 +316,7 @@ internal class HistogramEncoder int triesWithNoSuccess = 0; int numUsed = histograms.Count(h => h != null); int outerIters = numUsed; - int numTriesNoSuccess = outerIters / 2; + int numTriesNoSuccess = (int)((uint)outerIters / 2); var stats = new Vp8LStreaks(); var bitsEntropy = new Vp8LBitEntropy(); @@ -346,7 +346,7 @@ internal class HistogramEncoder for (int iter = 0; iter < outerIters && numUsed >= minClusterSize && ++triesWithNoSuccess < numTriesNoSuccess; iter++) { double bestCost = histoPriorityList.Count == 0 ? 0.0d : histoPriorityList[0].CostDiff; - int numTries = numUsed / 2; + int numTries = (int)((uint)numUsed / 2); uint randRange = (uint)((numUsed - 1) * numUsed); // Pick random samples. diff --git a/src/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs index 5cee6bc396..18104331ce 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs @@ -100,7 +100,7 @@ internal static class HuffmanUtils uint k; // The stride must end, collapse what we have, if we have enough (4). - uint count = (uint)((sum + (stride / 2)) / stride); + uint count = (sum + ((uint)stride / 2)) / (uint)stride; if (count < 1) { count = 1; @@ -144,7 +144,7 @@ internal static class HuffmanUtils sum += counts[i]; if (stride >= 4) { - limit = (uint)((sum + (stride / 2)) / stride); + limit = (sum + ((uint)stride / 2)) / (uint)stride; } } } diff --git a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs index d4db3db53b..8a5ec162fb 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs @@ -1440,7 +1440,12 @@ internal static unsafe class LosslessUtils } [MethodImpl(InliningOptions.ShortMethod)] - private static int AddSubtractComponentHalf(int a, int b) => (int)Clip255((uint)(a + ((a - b) / 2))); + private static int AddSubtractComponentHalf(int a, int b) + { + uint ua = (uint)a; + uint ub = (uint)b; + return (int)Clip255(ua + ((ua - ub) / 2)); + } [MethodImpl(InliningOptions.ShortMethod)] private static int AddSubtractComponentFull(int a, int b, int c) => (int)Clip255((uint)(a + b - c)); diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs index e714a77253..7be0e69f72 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs @@ -963,7 +963,7 @@ internal class Vp8LEncoder : IDisposable else { int nBits = BitOperations.Log2((uint)trimmedLength - 2); - int nBitPairs = (nBits / 2) + 1; + int nBitPairs = (int)(((uint)nBits / 2) + 1); this.bitWriter.PutBits((uint)nBitPairs - 1, 3); this.bitWriter.PutBits((uint)trimmedLength - 2, nBitPairs * 2); } @@ -1820,7 +1820,7 @@ internal class Vp8LEncoder : IDisposable { // VP8LResidualImage needs room for 2 scanlines of uint32 pixels with an extra // pixel in each, plus 2 regular scanlines of bytes. - int bgraScratchSize = this.UsePredictorTransform ? ((width + 1) * 2) + (((width * 2) + 4 - 1) / 4) : 0; + int bgraScratchSize = this.UsePredictorTransform ? (int)((((uint)width + 1) * 2) + ((((uint)width * 2) + 4 - 1) / 4)) : 0; int transformDataSize = this.UsePredictorTransform || this.UseCrossColorTransform ? LosslessUtils.SubSampleSize(width, this.TransformBits) * LosslessUtils.SubSampleSize(height, this.TransformBits) : 0; this.BgraScratch = this.memoryAllocator.Allocate(bgraScratchSize); diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs index 527242906b..32d4fcbb68 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs @@ -59,7 +59,7 @@ internal sealed class Vp8LHashChain : IDisposable public void Fill(ReadOnlySpan bgra, int quality, int xSize, int ySize, bool lowEffort) { int size = xSize * ySize; - int iterMax = GetMaxItersForQuality(quality); + int iterMax = GetMaxItersForQuality((uint)quality); int windowSize = GetWindowSizeForHashChain(quality, xSize); int pos; @@ -272,7 +272,7 @@ internal sealed class Vp8LHashChain : IDisposable /// The quality. /// Number of hash chain lookups. [MethodImpl(InliningOptions.ShortMethod)] - private static int GetMaxItersForQuality(int quality) => 8 + (quality * quality / 128); + private static int GetMaxItersForQuality(uint quality) => (int)(8 + (quality * quality / 128)); [MethodImpl(InliningOptions.ShortMethod)] private static int GetWindowSizeForHashChain(int quality, int xSize) diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs index 16b4c827ef..186aa6c216 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs @@ -683,7 +683,7 @@ internal class Vp8Encoder : IDisposable { if (accum[n] != 0) { - int newCenter = (distAccum[n] + (accum[n] / 2)) / accum[n]; + int newCenter = (distAccum[n] + (accum[n] >> 1)) / accum[n]; // >> 1 is bit-hack for / 2 displaced += Math.Abs(centers[n] - newCenter); centers[n] = newCenter; weightedAverage += newCenter * accum[n]; @@ -691,7 +691,7 @@ internal class Vp8Encoder : IDisposable } } - weightedAverage = (weightedAverage + (totalWeight / 2)) / totalWeight; + weightedAverage = (weightedAverage + (totalWeight >> 1)) / totalWeight; // >> 1 is bit-hack for / 2 if (displaced < 5) { break; // no need to keep on looping... @@ -1177,6 +1177,6 @@ internal class Vp8Encoder : IDisposable { int total = a + b; return total == 0 ? 255 // that's the default probability. - : ((255 * a) + (total / 2)) / total; // rounded proba + : ((255 * a) + (int)((uint)total / 2)) / total; // rounded proba } } diff --git a/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs b/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs index e63a7ef74e..36f3abcd9d 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs @@ -731,7 +731,7 @@ internal sealed class WebpLossyDecoder Span dst = buf[dstStartIdx..]; int yEnd = io.MbY + io.MbH; int mbw = io.MbW; - int uvw = (mbw + 1) / 2; + int uvw = (int)(((uint)mbw + 1) / 2); int y = io.MbY; byte[] uvBuffer = new byte[(14 * 32) + 15]; diff --git a/src/ImageSharp/IO/ChunkedMemoryStream.cs b/src/ImageSharp/IO/ChunkedMemoryStream.cs index da52f7ca85..2534548141 100644 --- a/src/ImageSharp/IO/ChunkedMemoryStream.cs +++ b/src/ImageSharp/IO/ChunkedMemoryStream.cs @@ -547,7 +547,7 @@ internal sealed class ChunkedMemoryStream : Stream #pragma warning disable IDE1006 // Naming Styles const int _128K = 1 << 17; const int _4M = 1 << 22; - return i < 16 ? _128K * (1 << (i / 4)) : _4M; + return i < 16 ? _128K * (1 << (int)((uint)i / 4)) : _4M; #pragma warning restore IDE1006 // Naming Styles } diff --git a/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs b/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs index 2cb4421d5e..798edf9b22 100644 --- a/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs +++ b/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs @@ -156,7 +156,7 @@ internal sealed class UniformUnmanagedMemoryPoolMemoryAllocator : MemoryAllocato // Workaround for https://github.com/dotnet/runtime/issues/65466 if (total > 0) { - return total / 8; + return (long)((ulong)total / 8); } } diff --git a/src/ImageSharp/Primitives/Rectangle.cs b/src/ImageSharp/Primitives/Rectangle.cs index baffbc7f49..2f0df3574e 100644 --- a/src/ImageSharp/Primitives/Rectangle.cs +++ b/src/ImageSharp/Primitives/Rectangle.cs @@ -195,7 +195,7 @@ public struct Rectangle : IEquatable /// The rectangle. /// The . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Point Center(Rectangle rectangle) => new(rectangle.Left + (rectangle.Width / 2), rectangle.Top + (rectangle.Height / 2)); + public static Point Center(Rectangle rectangle) => new(rectangle.Left + (rectangle.Width & 1), rectangle.Top + (rectangle.Height & 1)); // & 1 is bit-hack for / 2 /// /// Creates a rectangle that represents the intersection between and diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs index b710243a56..1c76ea6a45 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs @@ -132,7 +132,7 @@ internal class BinaryThresholdProcessor : ImageProcessor case BinaryThresholdMode.MaxChroma: { - float threshold = this.threshold / 2F; + float threshold = this.threshold * 0.5F; // /2 for (int x = 0; x < rowSpan.Length; x++) { float chroma = GetMaxChroma(span[x]); @@ -149,9 +149,10 @@ internal class BinaryThresholdProcessor : ImageProcessor private static float GetSaturation(Rgb24 rgb) { // Slimmed down RGB => HSL formula. See HslAndRgbConverter. - float r = rgb.R / 255F; - float g = rgb.G / 255F; - float b = rgb.B / 255F; + const float inv255 = 1 / 255F; + float r = rgb.R * inv255; + float g = rgb.G * inv255; + float b = rgb.B * inv255; float max = MathF.Max(r, MathF.Max(g, b)); float min = MathF.Min(r, MathF.Min(g, b)); @@ -162,7 +163,7 @@ internal class BinaryThresholdProcessor : ImageProcessor return 0F; } - float l = (max + min) / 2F; + float l = (max + min) * 0.5F; // /2 if (l <= .5F) { diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs index e2272db039..0baa87a611 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs @@ -59,8 +59,8 @@ internal class AdaptiveHistogramEqualizationProcessor : HistogramEqualiz int tileWidth = (int)MathF.Ceiling(sourceWidth / (float)this.Tiles); int tileHeight = (int)MathF.Ceiling(sourceHeight / (float)this.Tiles); int tileCount = this.Tiles; - int halfTileWidth = tileWidth / 2; - int halfTileHeight = tileHeight / 2; + int halfTileWidth = (int)((uint)tileWidth / 2); + int halfTileHeight = (int)((uint)tileHeight / 2); int luminanceLevels = this.LuminanceLevels; // The image is split up into tiles. For each tile the cumulative distribution function will be calculated. @@ -176,7 +176,7 @@ internal class AdaptiveHistogramEqualizationProcessor : HistogramEqualiz int xEnd, int luminanceLevels) { - int halfTileHeight = tileHeight / 2; + int halfTileHeight = (int)((uint)tileHeight / 2); int cdfY = 0; int y = halfTileHeight; @@ -228,7 +228,7 @@ internal class AdaptiveHistogramEqualizationProcessor : HistogramEqualiz int yEnd, int luminanceLevels) { - int halfTileWidth = tileWidth / 2; + int halfTileWidth = (int)((uint)tileWidth / 2); int cdfX = 0; int x = halfTileWidth; diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs index f25db12c28..bbac9b9d8e 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs @@ -59,7 +59,7 @@ internal class AdaptiveHistogramEqualizationSlidingWindowProcessor : His int tileWidth = source.Width / this.Tiles; int tileHeight = tileWidth; int pixelInTile = tileWidth * tileHeight; - int halfTileHeight = tileHeight / 2; + int halfTileHeight = (int)((uint)tileHeight / 2); int halfTileWidth = halfTileHeight; SlidingWindowInfos slidingWindowInfos = new(tileWidth, tileHeight, halfTileWidth, halfTileHeight, pixelInTile); diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/FlipProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/FlipProcessor{TPixel}.cs index 11befd5dac..14da3ac890 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/FlipProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/FlipProcessor{TPixel}.cs @@ -54,7 +54,7 @@ internal class FlipProcessor : ImageProcessor using IMemoryOwner tempBuffer = configuration.MemoryAllocator.Allocate(source.Width); Span temp = tempBuffer.Memory.Span; - for (int yTop = 0; yTop < height / 2; yTop++) + for (int yTop = 0; yTop < (int)((uint)height / 2); yTop++) { int yBottom = height - yTop - 1; Span topRow = source.DangerousGetRowSpan(yBottom); diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs index d03a694ba5..d90f948b6f 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs @@ -105,11 +105,11 @@ internal static class ResizeHelper switch (options.Position) { case AnchorPositionMode.Left: - targetY = (height - sourceHeight) / 2; + targetY = (int)((uint)(height - sourceHeight) / 2); targetX = 0; break; case AnchorPositionMode.Right: - targetY = (height - sourceHeight) / 2; + targetY = (int)((uint)(height - sourceHeight) / 2); targetX = width - sourceWidth; break; case AnchorPositionMode.TopRight: @@ -118,7 +118,7 @@ internal static class ResizeHelper break; case AnchorPositionMode.Top: targetY = 0; - targetX = (width - sourceWidth) / 2; + targetX = (int)((uint)(width - sourceWidth) / 2); break; case AnchorPositionMode.TopLeft: targetY = 0; @@ -130,15 +130,15 @@ internal static class ResizeHelper break; case AnchorPositionMode.Bottom: targetY = height - sourceHeight; - targetX = (width - sourceWidth) / 2; + targetX = (int)((uint)(width - sourceWidth) / 2); break; case AnchorPositionMode.BottomLeft: targetY = height - sourceHeight; targetX = 0; break; default: - targetY = (height - sourceHeight) / 2; - targetX = (width - sourceWidth) / 2; + targetY = (int)((uint)(height - sourceHeight) / 2); + targetX = (int)((uint)(width - sourceWidth) / 2); break; } From 957ee98259d615fe5df7cd3f95b091ae0b0d48c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 13 Mar 2023 19:45:09 +0100 Subject: [PATCH 05/86] Fixed warnings from CI --- src/ImageSharp/Common/Helpers/HexConverter.cs | 4 ++-- .../Decoder/ArithmeticScanDecoder.cs | 19 +++++++++++-------- src/ImageSharp/Formats/Webp/AlphaDecoder.cs | 2 +- .../Formats/Webp/Lossy/LossyUtils.cs | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/HexConverter.cs b/src/ImageSharp/Common/Helpers/HexConverter.cs index 3c863cc37c..590b9d63c7 100644 --- a/src/ImageSharp/Common/Helpers/HexConverter.cs +++ b/src/ImageSharp/Common/Helpers/HexConverter.cs @@ -16,12 +16,12 @@ internal static class HexConverter /// The number of bytes written to . public static int HexStringToBytes(ReadOnlySpan chars, Span bytes) { - if ((chars.Length & 1) != 0) // bit-hack for % 2 + if ((chars.Length & 1 /* bit-hack for % 2 */) != 0) { throw new ArgumentException("Input string length must be a multiple of 2", nameof(chars)); } - if ((bytes.Length << 1) < chars.Length) // bit-hack for * 2 + if ((bytes.Length << 1 /* bit-hack for * 2 */) < chars.Length) { throw new ArgumentException("Output span must be at least half the length of the input string"); } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs index 1b043b68f2..423e56378a 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs @@ -53,9 +53,6 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder private ArithmeticDecodingTable[] acDecodingTables; - // Use C#'s optimization to refer to assembly's data segment, no allocation occurs. - private ReadOnlySpan fixedBin => new byte[] { 113, 0, 0, 0 }; - private readonly CancellationToken cancellationToken; private static readonly int[] ArithmeticTable = @@ -232,7 +229,13 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder } } - private ref byte GetFixedBinReference() => ref MemoryMarshal.GetReference(fixedBin); + private static ref byte GetFixedBinReference() + { + // This uses C#'s optimization to refer to the static data segment of the assembly. + // No allocation occurs. + ReadOnlySpan fixedBin = new byte[] { 113, 0, 0, 0 }; + return ref MemoryMarshal.GetReference(fixedBin); + } /// /// Decodes the entropy coded data. @@ -776,7 +779,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder else { // Refinement scan. - ref byte st = ref this.GetFixedBinReference(); + ref byte st = ref GetFixedBinReference(); blockDataRef |= (short)(this.DecodeBinaryDecision(ref reader, ref st) << this.SuccessiveLow); } @@ -822,7 +825,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder // Figure F.21: Decoding nonzero value v. // Figure F.22: Decoding the sign of v. - int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()); + int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference()); st = ref Unsafe.Add(ref st, 2); // Figure F.23: Decoding the magnitude category of v. @@ -918,7 +921,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder if (this.DecodeBinaryDecision(ref reader, ref Unsafe.Add(ref st, 1)) != 0) { - bool flag = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()) != 0; + bool flag = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference()) != 0; coef = (short)(coef + (flag ? m1 : p1)); break; @@ -1048,7 +1051,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder // Figure F.21: Decoding nonzero value v. // Figure F.22: Decoding the sign of v. - int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()); + int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference()); st = ref Unsafe.Add(ref st, 2); // Figure F.23: Decoding the magnitude category of v. diff --git a/src/ImageSharp/Formats/Webp/AlphaDecoder.cs b/src/ImageSharp/Formats/Webp/AlphaDecoder.cs index 637a38d1e4..2678a6f70f 100644 --- a/src/ImageSharp/Formats/Webp/AlphaDecoder.cs +++ b/src/ImageSharp/Formats/Webp/AlphaDecoder.cs @@ -376,7 +376,7 @@ internal class AlphaDecoder : IDisposable Unsafe.As>(ref outputRef) = c0; } - for (; i < (uint) width; i++) + for (; i < (uint)width; i++) { dst[(int)i] = (byte)(prev[(int)i] + input[(int)i]); } diff --git a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs index 565e4c0293..2dc2881b03 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs @@ -1553,7 +1553,7 @@ internal static class LossyUtils Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset - (3 * stride)))) = p2.AsInt32(); Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset - (2 * stride)))) = p1.AsInt32(); Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset - stride))) = p0.AsInt32(); - Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset))) = q0.AsInt32(); + Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)offset)) = q0.AsInt32(); Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset + stride))) = q1.AsInt32(); Unsafe.As>(ref Unsafe.Add(ref outputRef, (uint)(offset + (2 * stride)))) = q2.AsInt32(); } @@ -1599,7 +1599,7 @@ internal static class LossyUtils if (Sse2.IsSupported) { ref byte pRef = ref MemoryMarshal.GetReference(p); - Vector128 p3 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset))); + Vector128 p3 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)offset)); Vector128 p2 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + stride))); Vector128 p1 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + (2 * stride)))); Vector128 p0 = Unsafe.As>(ref Unsafe.Add(ref pRef, (uint)(offset + (3 * stride)))); From bc6178167f92d8c77df8c70901b3cd5529542944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 13 Mar 2023 21:03:24 +0100 Subject: [PATCH 06/86] Fixed bugs --- .../Decoder/ArithmeticScanDecoder.cs | 18 +++++++----------- src/ImageSharp/Primitives/Rectangle.cs | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs index 423e56378a..73de430730 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs @@ -53,6 +53,8 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder private ArithmeticDecodingTable[] acDecodingTables; + private static readonly byte[] FixedBin = { 113, 0, 0, 0 }; + private readonly CancellationToken cancellationToken; private static readonly int[] ArithmeticTable = @@ -229,13 +231,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder } } - private static ref byte GetFixedBinReference() - { - // This uses C#'s optimization to refer to the static data segment of the assembly. - // No allocation occurs. - ReadOnlySpan fixedBin = new byte[] { 113, 0, 0, 0 }; - return ref MemoryMarshal.GetReference(fixedBin); - } + private static ref byte GetFixedBinReference() => ref MemoryMarshal.GetArrayDataReference(FixedBin); /// /// Decodes the entropy coded data. @@ -765,7 +761,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder } } - v += 1; + v++; if (sign != 0) { v = -v; @@ -860,7 +856,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder } } - v += 1; + v++; if (sign != 0) { v = -v; @@ -1016,7 +1012,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder } } - v += 1; + v++; if (sign != 0) { v = -v; @@ -1086,7 +1082,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder } } - v += 1; + v++; if (sign != 0) { v = -v; diff --git a/src/ImageSharp/Primitives/Rectangle.cs b/src/ImageSharp/Primitives/Rectangle.cs index 2f0df3574e..e2ae5071ef 100644 --- a/src/ImageSharp/Primitives/Rectangle.cs +++ b/src/ImageSharp/Primitives/Rectangle.cs @@ -195,7 +195,7 @@ public struct Rectangle : IEquatable /// The rectangle. /// The . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Point Center(Rectangle rectangle) => new(rectangle.Left + (rectangle.Width & 1), rectangle.Top + (rectangle.Height & 1)); // & 1 is bit-hack for / 2 + public static Point Center(Rectangle rectangle) => new(rectangle.Left + (rectangle.Width >> 1), rectangle.Top + (rectangle.Height >> 1)); // >> 1 is bit-hack for / 2 /// /// Creates a rectangle that represents the intersection between and From deaabf1571c190209ec1c4a98e01cd56bd70d38c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 13 Mar 2023 22:11:18 +0100 Subject: [PATCH 07/86] Fixed Bug Pt. II --- .../Jpeg/Components/Decoder/ArithmeticScanDecoder.cs | 12 ++++++------ .../Formats/Webp/Lossless/LosslessUtils.cs | 7 +------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs index 73de430730..fcefe542d4 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs @@ -53,7 +53,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder private ArithmeticDecodingTable[] acDecodingTables; - private static readonly byte[] FixedBin = { 113, 0, 0, 0 }; + private readonly byte[] fixedBin = { 113, 0, 0, 0 }; private readonly CancellationToken cancellationToken; @@ -231,7 +231,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder } } - private static ref byte GetFixedBinReference() => ref MemoryMarshal.GetArrayDataReference(FixedBin); + private ref byte GetFixedBinReference() => ref MemoryMarshal.GetArrayDataReference(this.fixedBin); /// /// Decodes the entropy coded data. @@ -775,7 +775,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder else { // Refinement scan. - ref byte st = ref GetFixedBinReference(); + ref byte st = ref this.GetFixedBinReference(); blockDataRef |= (short)(this.DecodeBinaryDecision(ref reader, ref st) << this.SuccessiveLow); } @@ -821,7 +821,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder // Figure F.21: Decoding nonzero value v. // Figure F.22: Decoding the sign of v. - int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference()); + int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()); st = ref Unsafe.Add(ref st, 2); // Figure F.23: Decoding the magnitude category of v. @@ -917,7 +917,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder if (this.DecodeBinaryDecision(ref reader, ref Unsafe.Add(ref st, 1)) != 0) { - bool flag = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference()) != 0; + bool flag = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()) != 0; coef = (short)(coef + (flag ? m1 : p1)); break; @@ -1047,7 +1047,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder // Figure F.21: Decoding nonzero value v. // Figure F.22: Decoding the sign of v. - int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference()); + int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()); st = ref Unsafe.Add(ref st, 2); // Figure F.23: Decoding the magnitude category of v. diff --git a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs index 8a5ec162fb..5a8137754b 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs @@ -1440,12 +1440,7 @@ internal static unsafe class LosslessUtils } [MethodImpl(InliningOptions.ShortMethod)] - private static int AddSubtractComponentHalf(int a, int b) - { - uint ua = (uint)a; - uint ub = (uint)b; - return (int)Clip255(ua + ((ua - ub) / 2)); - } + private static int AddSubtractComponentHalf(int a, int b) => (int)Clip255((uint)(a + ((a - b) >> 1))); // >> 1 is bit-hack for / 2 [MethodImpl(InliningOptions.ShortMethod)] private static int AddSubtractComponentFull(int a, int b, int c) => (int)Clip255((uint)(a + b - c)); From f746e686df7ac0287118ac4ec143f2ac1bd9f62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 20 Mar 2023 20:04:02 +0100 Subject: [PATCH 08/86] PR feedback + use nuint instead of nint --- .../Conversion/ColorSpaceConverter.CieLab.cs | 26 +-- .../Conversion/ColorSpaceConverter.CieLch.cs | 26 +-- .../ColorSpaceConverter.CieLchuv.cs | 26 +-- .../Conversion/ColorSpaceConverter.CieLuv.cs | 26 +-- .../Conversion/ColorSpaceConverter.CieXyy.cs | 26 +-- .../Conversion/ColorSpaceConverter.CieXyz.cs | 26 +-- .../Conversion/ColorSpaceConverter.Cmyk.cs | 26 +-- .../Conversion/ColorSpaceConverter.Hsl.cs | 26 +-- .../Conversion/ColorSpaceConverter.Hsv.cs | 26 +-- .../ColorSpaceConverter.HunterLab.cs | 26 +-- .../ColorSpaceConverter.LinearRgb.cs | 26 +-- .../Conversion/ColorSpaceConverter.Lms.cs | 26 +-- .../Conversion/ColorSpaceConverter.Rgb.cs | 26 +-- .../Conversion/ColorSpaceConverter.YCbCr.cs | 24 +-- .../VonKriesChromaticAdaptation.cs | 2 +- src/ImageSharp/Common/Helpers/HexConverter.cs | 6 +- .../Helpers/Shuffle/IComponentShuffle.cs | 22 +-- .../Common/Helpers/Shuffle/IPad3Shuffle4.cs | 12 +- .../Common/Helpers/Shuffle/IShuffle3.cs | 10 +- .../Common/Helpers/Shuffle/IShuffle4Slice3.cs | 10 +- .../Helpers/SimdUtils.ExtendedIntrinsics.cs | 8 +- .../SimdUtils.FallbackIntrinsics128.cs | 4 +- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 48 ++--- .../Common/Helpers/SimdUtils.Pack.cs | 14 +- .../Common/Helpers/SimdUtils.Shuffle.cs | 46 ++--- .../Compression/Zlib/DeflaterHuffman.cs | 8 +- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 8 +- .../Formats/ImageExtensions.Save.tt | 8 +- .../Jpeg/Components/Block8x8F.Generated.cs | 4 +- .../Jpeg/Components/Block8x8F.Generated.tt | 4 +- .../Jpeg/Components/Block8x8F.Intrinsic.cs | 6 +- .../Jpeg/Components/Block8x8F.ScaledCopy.cs | 28 +-- .../Formats/Jpeg/Components/Block8x8F.cs | 22 ++- .../JpegColorConverter.CmykAvx.cs | 8 +- .../JpegColorConverter.CmykVector.cs | 8 +- .../JpegColorConverter.GrayScaleAvx.cs | 8 +- .../JpegColorConverter.GrayScaleScalar.cs | 2 +- .../JpegColorConverter.GrayScaleVector.cs | 8 +- .../JpegColorConverter.RgbArm.cs | 4 +- .../JpegColorConverter.RgbAvx.cs | 4 +- .../JpegColorConverter.RgbVector.cs | 4 +- .../JpegColorConverter.YCbCrAvx.cs | 8 +- .../JpegColorConverter.YCbCrVector.cs | 8 +- .../JpegColorConverter.YccKAvx.cs | 8 +- .../JpegColorConverter.YccKVector.cs | 8 +- .../Decoder/ArithmeticScanDecoder.cs | 16 +- .../DownScalingComponentProcessor2.cs | 22 +-- .../DownScalingComponentProcessor4.cs | 22 +-- .../DownScalingComponentProcessor8.cs | 12 +- .../Components/Encoder/ComponentProcessor.cs | 28 +-- .../Components/Encoder/HuffmanScanEncoder.cs | 32 +-- .../Jpeg/Components/FloatingPointDCT.cs | 4 +- .../Jpeg/Components/ScaledFloatingPointDCT.cs | 2 +- .../Formats/Png/Filters/AverageFilter.cs | 26 +-- .../Formats/Png/Filters/PaethFilter.cs | 26 +-- .../Formats/Png/Filters/SubFilter.cs | 26 +-- .../Formats/Png/Filters/UpFilter.cs | 30 +-- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 28 +-- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 4 +- .../Formats/Png/PngScanlineProcessor.cs | 187 ++++++++++-------- .../Decompressors/T6TiffCompression.cs | 2 +- .../Tiff/Compression/TiffBaseCompression.cs | 2 +- .../BlackIsZero1TiffColor{TPixel}.cs | 14 +- .../WhiteIsZero1TiffColor{TPixel}.cs | 14 +- .../Formats/Tiff/TiffDecoderCore.cs | 2 +- src/ImageSharp/Formats/Webp/AlphaDecoder.cs | 16 +- .../Webp/Lossless/ColorSpaceTransformUtils.cs | 24 +-- .../Formats/Webp/Lossless/LosslessUtils.cs | 94 +++++---- .../Formats/Webp/Lossless/Vp8LHistogram.cs | 4 +- .../Formats/Webp/Lossy/LossyUtils.cs | 10 +- src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs | 6 +- .../Abgr32.PixelOperations.Generated.cs | 44 ++--- .../Argb32.PixelOperations.Generated.cs | 44 ++--- .../Bgr24.PixelOperations.Generated.cs | 44 ++--- .../Bgra32.PixelOperations.Generated.cs | 44 ++--- .../Bgra5551.PixelOperations.Generated.cs | 24 +-- .../L16.PixelOperations.Generated.cs | 24 +-- .../Generated/L8.PixelOperations.Generated.cs | 24 +-- .../La16.PixelOperations.Generated.cs | 24 +-- .../La32.PixelOperations.Generated.cs | 24 +-- .../Rgb24.PixelOperations.Generated.cs | 44 ++--- .../Rgb48.PixelOperations.Generated.cs | 24 +-- .../Rgba32.PixelOperations.Generated.cs | 44 ++--- .../Rgba64.PixelOperations.Generated.cs | 24 +-- .../Generated/_Common.ttinclude | 2 +- .../RgbaVector.PixelOperations.cs | 4 +- .../PixelOperations{TPixel}.Generated.cs | 52 ++--- .../PixelOperations{TPixel}.Generated.tt | 4 +- .../PixelFormats/PixelOperations{TPixel}.cs | 4 +- ...alizationSlidingWindowProcessor{TPixel}.cs | 8 +- .../HistogramEqualizationProcessor{TPixel}.cs | 10 +- .../Transforms/Resize/ResizeKernelMap.cs | 2 +- .../Transforms/Resize/ResizeWorker.cs | 16 +- .../ImageSharp.Benchmarks/Bulk/FromVector4.cs | 6 +- .../Bulk/PremultiplyVector4.cs | 4 +- .../Bulk/ToVector4_Rgba32.cs | 12 +- .../Bulk/UnPremultiplyVector4.cs | 4 +- .../BlockOperations/Block8x8F_CopyTo1x1.cs | 10 +- .../Jpeg/BlockOperations/Block8x8F_Round.cs | 8 +- .../PixelConversion_ConvertFromRgba32.cs | 10 +- .../PixelConversion_ConvertFromVector4.cs | 4 +- .../PixelConversion_ConvertToRgba32.cs | 4 +- ...vertToRgba32_AsPartOfCompositeOperation.cs | 4 +- .../PixelConversion_ConvertToVector4.cs | 4 +- ...ertToVector4_AsPartOfCompositeOperation.cs | 4 +- .../PixelConversion_PackFromRgbPlanes.cs | 10 +- .../PixelConversion_Rgba32_To_Argb32.cs | 12 +- .../PixelConversion_Rgba32_To_Bgra32.cs | 26 +-- .../General/Vectorization/UInt32ToSingle.cs | 16 +- .../General/Vectorization/VectorFetching.cs | 12 +- .../Vectorization/WidenBytesToUInt32.cs | 6 +- .../PorterDuffBulkVsSingleVector.cs | 2 +- .../Common/SimdUtilsTests.Shuffle.cs | 48 ++--- .../Formats/Png/PngEncoderFilterTests.cs | 2 +- .../Formats/Png/ReferenceImplementations.cs | 22 +-- ...ConverterTests.ReferenceImplementations.cs | 6 +- .../PixelOperations/PixelOperationsTests.cs | 2 +- .../Transforms/ResizeKernelMapTests.cs | 4 +- 118 files changed, 1090 insertions(+), 1049 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs index 88343cbab4..54667ca2af 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs @@ -37,7 +37,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -70,7 +70,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -103,7 +103,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -136,7 +136,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -169,7 +169,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -266,7 +266,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -299,7 +299,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -332,7 +332,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -365,7 +365,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -398,7 +398,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); @@ -431,7 +431,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieLab dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs index dcd6be185c..9949b5d91b 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -168,7 +168,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -200,7 +200,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -233,7 +233,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -266,7 +266,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -299,7 +299,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -332,7 +332,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -365,7 +365,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -398,7 +398,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); @@ -431,7 +431,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieLch destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieLch dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs index eb21394a09..4b856d1189 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -168,7 +168,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -267,7 +267,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -300,7 +300,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -333,7 +333,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -366,7 +366,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -399,7 +399,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); @@ -431,7 +431,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieLchuv dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs index 1b6735e623..2e8029f64a 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs @@ -35,7 +35,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -67,7 +67,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -169,7 +169,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -233,7 +233,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -265,7 +265,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -297,7 +297,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -329,7 +329,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -361,7 +361,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -393,7 +393,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); @@ -425,7 +425,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieLuv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieLuv dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs index 2b34e66f2e..13b2a225c3 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -163,7 +163,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -196,7 +196,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -229,7 +229,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -262,7 +262,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -295,7 +295,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -328,7 +328,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -361,7 +361,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -394,7 +394,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); @@ -427,7 +427,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyy destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyy dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs index 1495a28b64..2212ca2e58 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs @@ -41,7 +41,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -76,7 +76,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -111,7 +111,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -146,7 +146,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -177,7 +177,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -210,7 +210,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -243,7 +243,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -277,7 +277,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -310,7 +310,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -345,7 +345,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -374,7 +374,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -407,7 +407,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); @@ -440,7 +440,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs index 068583e82f..ea9a5d734b 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -168,7 +168,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -267,7 +267,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -300,7 +300,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -333,7 +333,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -366,7 +366,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -394,7 +394,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); @@ -427,7 +427,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref Cmyk destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref Cmyk dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs index f40544b7a9..67ec162917 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -168,7 +168,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -267,7 +267,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -300,7 +300,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -333,7 +333,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -366,7 +366,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -394,7 +394,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); @@ -427,7 +427,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref Hsl destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref Hsl dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs index 8bd014ed96..47ee42dc5a 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs @@ -36,7 +36,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -69,7 +69,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -102,7 +102,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -135,7 +135,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -168,7 +168,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -201,7 +201,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -267,7 +267,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -300,7 +300,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -333,7 +333,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -366,7 +366,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -394,7 +394,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); @@ -427,7 +427,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref Hsv destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref Hsv dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs index 2890594651..0604027760 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs @@ -24,7 +24,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -45,7 +45,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -66,7 +66,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -87,7 +87,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -108,7 +108,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -129,7 +129,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -150,7 +150,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -171,7 +171,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -192,7 +192,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -213,7 +213,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -255,7 +255,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); @@ -276,7 +276,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref HunterLab destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref HunterLab dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs index 897ec02a0f..fd385a15b0 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs @@ -24,7 +24,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -45,7 +45,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -66,7 +66,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -87,7 +87,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -108,7 +108,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -129,7 +129,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -150,7 +150,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -171,7 +171,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -192,7 +192,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -213,7 +213,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -255,7 +255,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); @@ -276,7 +276,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref LinearRgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref LinearRgb dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs index 291f3a5fac..56f61ef80b 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs @@ -24,7 +24,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -45,7 +45,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -66,7 +66,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -87,7 +87,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -108,7 +108,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -129,7 +129,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -150,7 +150,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -171,7 +171,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -192,7 +192,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -213,7 +213,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -255,7 +255,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); @@ -276,7 +276,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref Lms destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref Lms dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs index 557c294992..080e1fc4bf 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs @@ -24,7 +24,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -45,7 +45,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -66,7 +66,7 @@ public partial class ColorSpaceConverter ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -87,7 +87,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -108,7 +108,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -129,7 +129,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -150,7 +150,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -171,7 +171,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -192,7 +192,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -213,7 +213,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -255,7 +255,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); @@ -276,7 +276,7 @@ public partial class ColorSpaceConverter ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source); ref Rgb destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs index 8ea875a3d7..da8e046ff7 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs @@ -24,7 +24,7 @@ public partial class ColorSpaceConverter ref CieLab sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLab sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -45,7 +45,7 @@ public partial class ColorSpaceConverter ref CieLch sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLch sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -66,7 +66,7 @@ public partial class ColorSpaceConverter ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -87,7 +87,7 @@ public partial class ColorSpaceConverter ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -108,7 +108,7 @@ public partial class ColorSpaceConverter ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -129,7 +129,7 @@ public partial class ColorSpaceConverter ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -150,7 +150,7 @@ public partial class ColorSpaceConverter ref Hsl sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsl sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -171,7 +171,7 @@ public partial class ColorSpaceConverter ref Hsv sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Hsv sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -192,7 +192,7 @@ public partial class ColorSpaceConverter ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -213,7 +213,7 @@ public partial class ColorSpaceConverter ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -234,7 +234,7 @@ public partial class ColorSpaceConverter ref Lms sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Lms sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); @@ -255,7 +255,7 @@ public partial class ColorSpaceConverter ref Rgb sourceRef = ref MemoryMarshal.GetReference(source); ref YCbCr destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb sp = ref Unsafe.Add(ref sourceRef, i); ref YCbCr dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs index 55ed41220d..97e9cee813 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs @@ -81,7 +81,7 @@ public sealed class VonKriesChromaticAdaptation : IChromaticAdaptation ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source); ref CieXyz destRef = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i); ref CieXyz dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/Common/Helpers/HexConverter.cs b/src/ImageSharp/Common/Helpers/HexConverter.cs index 590b9d63c7..8c473688f3 100644 --- a/src/ImageSharp/Common/Helpers/HexConverter.cs +++ b/src/ImageSharp/Common/Helpers/HexConverter.cs @@ -16,12 +16,12 @@ internal static class HexConverter /// The number of bytes written to . public static int HexStringToBytes(ReadOnlySpan chars, Span bytes) { - if ((chars.Length & 1 /* bit-hack for % 2 */) != 0) + if (Numerics.Modulo2(chars.Length) != 0) { throw new ArgumentException("Input string length must be a multiple of 2", nameof(chars)); } - if ((bytes.Length << 1 /* bit-hack for * 2 */) < chars.Length) + if ((bytes.Length << 1 /* bit-hack for *2 */) < chars.Length) { throw new ArgumentException("Output span must be at least half the length of the input string"); } @@ -55,7 +55,7 @@ internal static class HexConverter 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 255 }; - return c >= charToHexLookup.Length ? 0xFF : charToHexLookup[c]; + return (uint)c >= (uint)charToHexLookup.Length ? 0xFF : charToHexLookup[c]; } // See https://source.dot.net/#System.Private.CoreLib/HexConverter.cs,4681d45a0aa0b361 diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index f2135b7645..a86355135e 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -61,14 +61,14 @@ internal readonly struct DefaultShuffle4 : IShuffle4 ref byte sBase = ref MemoryMarshal.GetReference(source); ref byte dBase = ref MemoryMarshal.GetReference(dest); - Shuffle.InverseMMShuffle(this.Control, out int p3, out int p2, out int p1, out int p0); + Shuffle.InverseMMShuffle(this.Control, out uint p3, out uint p2, out uint p1, out uint p0); - for (nint i = 0; i < (uint)source.Length; i += 4) + for (nuint i = 0; i < (uint)source.Length; i += 4) { - Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, (nint)(uint)p0 + i); - Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, (nint)(uint)p1 + i); - Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, (nint)(uint)p2 + i); - Unsafe.Add(ref dBase, i + 3) = Unsafe.Add(ref sBase, (nint)(uint)p3 + i); + Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, p0 + i); + Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, p1 + i); + Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, p2 + i); + Unsafe.Add(ref dBase, i + 3) = Unsafe.Add(ref sBase, p3 + i); } } } @@ -86,7 +86,7 @@ internal readonly struct WXYZShuffle4 : IShuffle4 ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = (int)((uint)source.Length / 4); - for (nint i = 0; i < (uint)n; i++) + for (nuint i = 0; i < (uint)n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -110,7 +110,7 @@ internal readonly struct WZYXShuffle4 : IShuffle4 ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = (int)((uint)source.Length / 4); - for (nint i = 0; i < (uint)n; i++) + for (nuint i = 0; i < (uint)n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -134,7 +134,7 @@ internal readonly struct YZWXShuffle4 : IShuffle4 ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = (int)((uint)source.Length / 4); - for (nint i = 0; i < (uint)n; i++) + for (nuint i = 0; i < (uint)n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -158,7 +158,7 @@ internal readonly struct ZYXWShuffle4 : IShuffle4 ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = (int)((uint)source.Length / 4); - for (nint i = 0; i < (uint)n; i++) + for (nuint i = 0; i < (uint)n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -189,7 +189,7 @@ internal readonly struct XWZYShuffle4 : IShuffle4 ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); int n = (int)((uint)source.Length / 4); - for (nint i = 0; i < (uint)n; i++) + for (nuint i = 0; i < (uint)n; i++) { uint packed = Unsafe.Add(ref sBase, i); diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs b/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs index 3e1084d313..6cf6eef08e 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs @@ -29,21 +29,21 @@ internal readonly struct DefaultPad3Shuffle4 : IPad3Shuffle4 ref byte sBase = ref MemoryMarshal.GetReference(source); ref byte dBase = ref MemoryMarshal.GetReference(dest); - Shuffle.InverseMMShuffle(this.Control, out int p3, out int p2, out int p1, out int p0); + Shuffle.InverseMMShuffle(this.Control, out uint p3, out uint p2, out uint p1, out uint p0); Span temp = stackalloc byte[4]; ref byte t = ref MemoryMarshal.GetReference(temp); ref uint tu = ref Unsafe.As(ref t); - for (nint i = 0, j = 0; i < (uint)source.Length; i += 3, j += 4) + for (nuint i = 0, j = 0; i < (uint)source.Length; i += 3, j += 4) { ref byte s = ref Unsafe.Add(ref sBase, i); tu = Unsafe.As(ref s) | 0xFF000000; - Unsafe.Add(ref dBase, j + 0) = Unsafe.Add(ref t, (uint)p0); - Unsafe.Add(ref dBase, j + 1) = Unsafe.Add(ref t, (uint)p1); - Unsafe.Add(ref dBase, j + 2) = Unsafe.Add(ref t, (uint)p2); - Unsafe.Add(ref dBase, j + 3) = Unsafe.Add(ref t, (uint)p3); + Unsafe.Add(ref dBase, j + 0) = Unsafe.Add(ref t, p0); + Unsafe.Add(ref dBase, j + 1) = Unsafe.Add(ref t, p1); + Unsafe.Add(ref dBase, j + 2) = Unsafe.Add(ref t, p2); + Unsafe.Add(ref dBase, j + 3) = Unsafe.Add(ref t, p3); } } } diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs index b149bde09d..2cd586212e 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs @@ -29,13 +29,13 @@ internal readonly struct DefaultShuffle3 : IShuffle3 ref byte sBase = ref MemoryMarshal.GetReference(source); ref byte dBase = ref MemoryMarshal.GetReference(dest); - Shuffle.InverseMMShuffle(this.Control, out _, out int p2, out int p1, out int p0); + Shuffle.InverseMMShuffle(this.Control, out _, out uint p2, out uint p1, out uint p0); - for (nint i = 0; i < (uint)source.Length; i += 3) + for (nuint i = 0; i < (uint)source.Length; i += 3) { - Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, (nint)(uint)p0 + i); - Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, (nint)(uint)p1 + i); - Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, (nint)(uint)p2 + i); + Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, p0 + i); + Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, p1 + i); + Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, p2 + i); } } } diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs index 1f12cea257..5e82973e33 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs @@ -29,13 +29,13 @@ internal readonly struct DefaultShuffle4Slice3 : IShuffle4Slice3 ref byte sBase = ref MemoryMarshal.GetReference(source); ref byte dBase = ref MemoryMarshal.GetReference(dest); - Shuffle.InverseMMShuffle(this.Control, out _, out int p2, out int p1, out int p0); + Shuffle.InverseMMShuffle(this.Control, out _, out uint p2, out uint p1, out uint p0); - for (nint i = 0, j = 0; i < (uint)dest.Length; i += 3, j += 4) + for (nuint i = 0, j = 0; i < (uint)dest.Length; i += 3, j += 4) { - Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, (nint)(uint)p0 + j); - Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, (nint)(uint)p1 + j); - Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, (nint)(uint)p2 + j); + Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, p0 + j); + Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, p1 + j); + Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, p2 + j); } } } diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs index 9d2da7dc83..43998d0ec9 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs @@ -97,12 +97,12 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector.Count); - nint n = (nint)(uint)dest.Length / Vector.Count; + nuint n = (uint)(dest.Length / Vector.Count); ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { Vector b = Unsafe.Add(ref sourceBase, i); @@ -132,13 +132,13 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector.Count); - nint n = (nint)(uint)dest.Length / Vector.Count; + nuint n = (uint)(dest.Length / Vector.Count); ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { ref Vector s = ref Unsafe.Add(ref sourceBase, i * 4); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs index 6fc36cd701..d456d8e42f 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs @@ -83,7 +83,7 @@ internal static partial class SimdUtils const float scale = 1f / 255f; Vector4 d = default; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref ByteVector4 s = ref Unsafe.Add(ref sBase, i); d.X = s.X; @@ -117,7 +117,7 @@ internal static partial class SimdUtils var half = new Vector4(0.5f); var maxBytes = new Vector4(255f); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Vector4 s = Unsafe.Add(ref sBase, i); s *= maxBytes; diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 06b61443f3..5f83ccd6be 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -221,7 +221,7 @@ internal static partial class SimdUtils ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)(uint)dest.Length / Vector256.Count; + nint n = (nint)(uint)(dest.Length / Vector256.Count); nint m = Numerics.Modulo4(n); nint u = n - m; @@ -391,9 +391,9 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)(uint)source.Length / Vector128.Count; + nuint n = (uint)(source.Length / Vector128.Count); - for (nint i = 0; i < n; i += 3) + for (nuint i = 0; i < n; i += 3) { ref Vector128 vs = ref Unsafe.Add(ref sourceBase, i); @@ -454,9 +454,9 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)(uint)source.Length / Vector128.Count; + nuint n = (uint)(source.Length / Vector128.Count); - for (nint i = 0, j = 0; i < n; i += 3, j += 4) + for (nuint i = 0, j = 0; i < n; i += 3, j += 4) { ref Vector128 v0 = ref Unsafe.Add(ref sourceBase, i); Vector128 v1 = Unsafe.Add(ref v0, 1); @@ -498,9 +498,9 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)(uint)source.Length / Vector128.Count; + nuint n = (uint)(source.Length / Vector128.Count); - for (nint i = 0, j = 0; i < n; i += 4, j += 3) + for (nuint i = 0, j = 0; i < n; i += 4, j += 3) { ref Vector128 vs = ref Unsafe.Add(ref sourceBase, i); @@ -650,16 +650,16 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector256.Count); - nint n = (nint)(uint)dest.Length / Vector256.Count; + nuint n = (uint)(dest.Length / Vector256.Count); ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); var scale = Vector256.Create(1 / (float)byte.MaxValue); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - nint si = Vector256.Count * i; + nuint si = (uint)Vector256.Count * i; Vector256 i0 = Avx2.ConvertToVector256Int32(sourceBase + si); Vector256 i1 = Avx2.ConvertToVector256Int32(sourceBase + si + Vector256.Count); Vector256 i2 = Avx2.ConvertToVector256Int32(sourceBase + si + (Vector256.Count * 2)); @@ -683,7 +683,7 @@ internal static partial class SimdUtils // Sse VerifySpanInput(source, dest, Vector128.Count); - nint n = (nint)(uint)dest.Length / Vector128.Count; + nuint n = (uint)(dest.Length / Vector128.Count); ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); @@ -691,9 +691,9 @@ internal static partial class SimdUtils var scale = Vector128.Create(1 / (float)byte.MaxValue); Vector128 zero = Vector128.Zero; - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - nint si = Vector128.Count * i; + nuint si = (uint)Vector128.Count * i; Vector128 i0, i1, i2, i3; if (Sse41.IsSupported) @@ -782,7 +782,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector256.Count); - nint n = (nint)(uint)dest.Length / Vector256.Count; + nuint n = (uint)(dest.Length / Vector256.Count); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -794,7 +794,7 @@ internal static partial class SimdUtils ref byte maskBase = ref MemoryMarshal.GetReference(PermuteMaskDeinterleave8x32); Vector256 mask = Unsafe.As>(ref maskBase); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { ref Vector256 s = ref Unsafe.Add(ref sourceBase, i * 4); @@ -821,7 +821,7 @@ internal static partial class SimdUtils // Sse VerifySpanInput(source, dest, Vector128.Count); - nint n = (nint)(uint)dest.Length / Vector128.Count; + nuint n = (uint)(dest.Length / Vector128.Count); ref Vector128 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -831,7 +831,7 @@ internal static partial class SimdUtils var scale = Vector128.Create((float)byte.MaxValue); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { ref Vector128 s = ref Unsafe.Add(ref sourceBase, i * 4); @@ -864,7 +864,7 @@ internal static partial class SimdUtils ref Vector256 bBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(blueChannel)); ref byte dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(destination)); - nint count = (nint)(uint)redChannel.Length / Vector256.Count; + nuint count = (uint)(redChannel.Length / Vector256.Count); ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32); Vector256 control1 = Unsafe.As>(ref control1Bytes); @@ -875,7 +875,7 @@ internal static partial class SimdUtils Vector256 shuffleAlpha = Unsafe.As>(ref MemoryMarshal.GetReference(ShuffleMaskShiftAlpha)); - for (nint i = 0; i < count; i++) + for (nuint i = 0; i < count; i++) { Vector256 r0 = Unsafe.Add(ref rBase, i); Vector256 g0 = Unsafe.Add(ref gBase, i); @@ -936,12 +936,12 @@ internal static partial class SimdUtils ref Vector256 bBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(blueChannel)); ref Vector256 dBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - nint count = (nint)(uint)redChannel.Length / Vector256.Count; + nuint count = (uint)(redChannel.Length / Vector256.Count); ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32); Vector256 control1 = Unsafe.As>(ref control1Bytes); var a = Vector256.Create((byte)255); - for (nint i = 0; i < count; i++) + for (nuint i = 0; i < count; i++) { Vector256 r0 = Unsafe.Add(ref rBase, i); Vector256 g0 = Unsafe.Add(ref gBase, i); @@ -994,8 +994,8 @@ internal static partial class SimdUtils Vector256 r, g, b; const int bytesPerRgbStride = 24; - int count = (int)((uint)source.Length / 8); - for (nint i = 0; i < (uint)count; i++) + nuint count = (uint)source.Length / 8; + for (nuint i = 0; i < count; i++) { rgb = Avx2.PermuteVar8x32(Unsafe.AddByteOffset(ref rgbByteSpan, (uint)(bytesPerRgbStride * i)).AsUInt32(), extractToLanesMask).AsByte(); @@ -1013,7 +1013,7 @@ internal static partial class SimdUtils Unsafe.Add(ref destBRef, i) = b; } - int sliceCount = count * 8; + int sliceCount = (int)(count * 8); redChannel = redChannel.Slice(sliceCount); greenChannel = greenChannel.Slice(sliceCount); blueChannel = blueChannel.Slice(sliceCount); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs b/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs index ff8323df03..f471d0231b 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs @@ -86,8 +86,8 @@ internal static partial class SimdUtils ref ByteTuple4 b = ref Unsafe.As(ref MemoryMarshal.GetReference(blueChannel)); ref Rgb24 rgb = ref MemoryMarshal.GetReference(destination); - uint count = (uint)redChannel.Length / 4; - for (nint i = 0; i < count; i++) + nuint count = (uint)redChannel.Length / 4; + for (nuint i = 0; i < count; i++) { ref Rgb24 d0 = ref Unsafe.Add(ref rgb, i * 4); ref Rgb24 d1 = ref Unsafe.Add(ref d0, 1); @@ -133,9 +133,9 @@ internal static partial class SimdUtils ref ByteTuple4 b = ref Unsafe.As(ref MemoryMarshal.GetReference(blueChannel)); ref Rgba32 rgb = ref MemoryMarshal.GetReference(destination); - uint count = (uint)redChannel.Length / 4; + nuint count = (uint)redChannel.Length / 4; destination.Fill(new Rgba32(0, 0, 0, 255)); - for (nint i = 0; i < count; i++) + for (nuint i = 0; i < count; i++) { ref Rgba32 d0 = ref Unsafe.Add(ref rgb, i * 4); ref Rgba32 d1 = ref Unsafe.Add(ref d0, 1); @@ -181,7 +181,7 @@ internal static partial class SimdUtils ref byte b = ref MemoryMarshal.GetReference(blueChannel); ref Rgb24 rgb = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)destination.Length; i++) + for (nuint i = 0; i < (uint)destination.Length; i++) { ref Rgb24 d = ref Unsafe.Add(ref rgb, i); d.R = Unsafe.Add(ref r, i); @@ -201,7 +201,7 @@ internal static partial class SimdUtils ref byte b = ref MemoryMarshal.GetReference(blueChannel); ref Rgba32 rgba = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)destination.Length; i++) + for (nuint i = 0; i < (uint)destination.Length; i++) { ref Rgba32 d = ref Unsafe.Add(ref rgba, i); d.R = Unsafe.Add(ref r, i); @@ -226,7 +226,7 @@ internal static partial class SimdUtils ref float b = ref MemoryMarshal.GetReference(blueChannel); ref Rgb24 rgb = ref MemoryMarshal.GetReference(source); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref Rgb24 src = ref Unsafe.Add(ref rgb, i); Unsafe.Add(ref r, i) = src.R; diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs b/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs index 532f9d4fab..c1437c05e6 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs @@ -145,14 +145,14 @@ internal static partial class SimdUtils { ref float sBase = ref MemoryMarshal.GetReference(source); ref float dBase = ref MemoryMarshal.GetReference(dest); - Shuffle.InverseMMShuffle(control, out int p3, out int p2, out int p1, out int p0); + Shuffle.InverseMMShuffle(control, out uint p3, out uint p2, out uint p1, out uint p0); - for (nint i = 0; i < (uint)source.Length; i += 4) + for (nuint i = 0; i < (uint)source.Length; i += 4) { - Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, (nint)(uint)p0 + i); - Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, (nint)(uint)p1 + i); - Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, (nint)(uint)p2 + i); - Unsafe.Add(ref dBase, i + 3) = Unsafe.Add(ref sBase, (nint)(uint)p3 + i); + Unsafe.Add(ref dBase, i + 0) = Unsafe.Add(ref sBase, p0 + i); + Unsafe.Add(ref dBase, i + 1) = Unsafe.Add(ref sBase, p1 + i); + Unsafe.Add(ref dBase, i + 2) = Unsafe.Add(ref sBase, p2 + i); + Unsafe.Add(ref dBase, i + 3) = Unsafe.Add(ref sBase, p3 + i); } } @@ -492,34 +492,34 @@ internal static partial class SimdUtils { InverseMMShuffle( control, - out int p3, - out int p2, - out int p1, - out int p0); + out uint p3, + out uint p2, + out uint p1, + out uint p0); ref byte spanBase = ref MemoryMarshal.GetReference(span); - for (int i = 0; i < span.Length; i += 4) + for (nuint i = 0; i < (uint)span.Length; i += 4) { - Unsafe.Add(ref spanBase, (uint)(i + 0)) = (byte)(p0 + i); - Unsafe.Add(ref spanBase, (uint)(i + 1)) = (byte)(p1 + i); - Unsafe.Add(ref spanBase, (uint)(i + 2)) = (byte)(p2 + i); - Unsafe.Add(ref spanBase, (uint)(i + 3)) = (byte)(p3 + i); + Unsafe.Add(ref spanBase, i + 0) = (byte)(p0 + i); + Unsafe.Add(ref spanBase, i + 1) = (byte)(p1 + i); + Unsafe.Add(ref spanBase, i + 2) = (byte)(p2 + i); + Unsafe.Add(ref spanBase, i + 3) = (byte)(p3 + i); } } [MethodImpl(InliningOptions.ShortMethod)] public static void InverseMMShuffle( byte control, - out int p3, - out int p2, - out int p1, - out int p0) + out uint p3, + out uint p2, + out uint p1, + out uint p0) { - p3 = (control >> 6) & 0x3; - p2 = (control >> 4) & 0x3; - p1 = (control >> 2) & 0x3; - p0 = (control >> 0) & 0x3; + p3 = (uint)((control >> 6) & 0x3); + p2 = (uint)((control >> 4) & 0x3); + p1 = (uint)((control >> 2) & 0x3); + p0 = (uint)((control >> 0) & 0x3); } } } diff --git a/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs b/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs index ebc43f8822..e4dc1945a8 100644 --- a/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs +++ b/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs @@ -286,13 +286,13 @@ internal sealed unsafe class DeflaterHuffman : IDisposable int static_len = this.extraBits; ref byte staticLLengthRef = ref MemoryMarshal.GetReference(StaticLLength); - for (nint i = 0; i < LiteralNumber; i++) + for (nuint i = 0; i < LiteralNumber; i++) { static_len += this.literalTree.Frequencies[i] * Unsafe.Add(ref staticLLengthRef, i); } ref byte staticDLengthRef = ref MemoryMarshal.GetReference(StaticDLength); - for (nint i = 0; i < DistanceNumber; i++) + for (nuint i = 0; i < DistanceNumber; i++) { static_len += this.distTree.Frequencies[i] * Unsafe.Add(ref staticDLengthRef, i); } @@ -625,10 +625,10 @@ internal sealed unsafe class DeflaterHuffman : IDisposable ref int valuesRef = ref MemoryMarshal.GetReference(valuesMemoryOwner.Memory.Span); int numNodes = numLeafs; - for (nint i = 0; i < (uint)heapLen; i++) + for (nuint i = 0; i < (uint)heapLen; i++) { int node = Unsafe.Add(ref heapRef, i); - nint i2 = 2 * i; + nuint i2 = 2 * i; Unsafe.Add(ref childrenRef, i2) = node; Unsafe.Add(ref childrenRef, i2 + 1) = -1; Unsafe.Add(ref valuesRef, i) = this.Frequencies[node] << 8; diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index a2c7058233..60f18c8023 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -123,8 +123,8 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals BmpMetadata bmpMetadata = metadata.GetBmpMetadata(); this.bitsPerPixel ??= bmpMetadata.BitsPerPixel; - short bpp = (short)this.bitsPerPixel; - int bytesPerLine = (int)(4 * ((((uint)image.Width * (ushort)bpp) + 31) / 32)); + ushort bpp = (ushort)this.bitsPerPixel; + int bytesPerLine = (int)(4 * ((((uint)image.Width * bpp) + 31) / 32)); this.padding = bytesPerLine - (int)(image.Width * (bpp / 8F)); int colorPaletteSize = this.bitsPerPixel switch @@ -176,7 +176,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals /// The metadata. /// The icc profile data. /// The bitmap information header. - private BmpInfoHeader CreateBmpInfoHeader(int width, int height, int infoHeaderSize, short bpp, int bytesPerLine, ImageMetadata metadata, byte[]? iccProfileData) + private BmpInfoHeader CreateBmpInfoHeader(int width, int height, int infoHeaderSize, ushort bpp, int bytesPerLine, ImageMetadata metadata, byte[]? iccProfileData) { int hResolution = 0; int vResolution = 0; @@ -212,7 +212,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals width: width, height: height, planes: 1, - bitsPerPixel: bpp, + bitsPerPixel: (short)bpp, imageSize: height * bytesPerLine, xPelsPerMeter: hResolution, yPelsPerMeter: vResolution, diff --git a/src/ImageSharp/Formats/ImageExtensions.Save.tt b/src/ImageSharp/Formats/ImageExtensions.Save.tt index 7498aa7c3b..64f3bde9cc 100644 --- a/src/ImageSharp/Formats/ImageExtensions.Save.tt +++ b/src/ImageSharp/Formats/ImageExtensions.Save.tt @@ -77,7 +77,7 @@ public static partial class ImageExtensions public static void SaveAs<#= fmt #>(this Image source, string path, <#= fmt #>Encoder encoder) => source.Save( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(<#= fmt #>Format.Instance)); + encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance)); /// /// Saves the image to the given stream with the <#= fmt #> format. @@ -91,7 +91,7 @@ public static partial class ImageExtensions public static Task SaveAs<#= fmt #>Async(this Image source, string path, <#= fmt #>Encoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, - encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(<#= fmt #>Format.Instance), + encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance), cancellationToken); /// @@ -124,7 +124,7 @@ public static partial class ImageExtensions public static void SaveAs<#= fmt #>(this Image source, Stream stream, <#= fmt #>Encoder encoder) => source.Save( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(<#= fmt #>Format.Instance)); + encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance)); /// /// Saves the image to the given stream with the <#= fmt #> format. @@ -138,7 +138,7 @@ public static partial class ImageExtensions public static Task SaveAs<#= fmt #>Async(this Image source, Stream stream, <#= fmt #>Encoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, - encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(<#= fmt #>Format.Instance), + encoder ?? source.GetConfiguration().ImageFormatsManager.GetEncoder(<#= fmt #>Format.Instance), cancellationToken); <# diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs index e5d252f432..93bb7be36e 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs @@ -16,7 +16,7 @@ internal partial struct Block8x8F { var CMin4 = new Vector4(0F); var CMax4 = new Vector4(maximum); - var COff4 = new Vector4(MathF.Ceiling(maximum * 0.5F)); // /2 + var COff4 = new Vector4(MathF.Ceiling(maximum * 0.5F)); this.V0L = Numerics.Clamp(this.V0L + COff4, CMin4, CMax4); this.V0R = Numerics.Clamp(this.V0R + COff4, CMin4, CMax4); @@ -42,7 +42,7 @@ internal partial struct Block8x8F [MethodImpl(InliningOptions.ShortMethod)] public void NormalizeColorsAndRoundInPlaceVector8(float maximum) { - var off = new Vector(MathF.Ceiling(maximum * 0.5F)); // /2 + var off = new Vector(MathF.Ceiling(maximum * 0.5F)); var max = new Vector(maximum); ref Vector row0 = ref Unsafe.As>(ref this.V0L); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt index 7350edd38b..19b795c23a 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt @@ -29,7 +29,7 @@ internal partial struct Block8x8F { var CMin4 = new Vector4(0F); var CMax4 = new Vector4(maximum); - var COff4 = new Vector4(MathF.Ceiling(maximum * 0.5F)); // /2 + var COff4 = new Vector4(MathF.Ceiling(maximum * 0.5F)); <# @@ -53,7 +53,7 @@ internal partial struct Block8x8F [MethodImpl(InliningOptions.ShortMethod)] public void NormalizeColorsAndRoundInPlaceVector8(float maximum) { - var off = new Vector(MathF.Ceiling(maximum * 0.5F)); // /2 + var off = new Vector(MathF.Ceiling(maximum * 0.5F)); var max = new Vector(maximum); <# diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs index 7611d403ac..63be76f00f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs @@ -41,9 +41,9 @@ internal partial struct Block8x8F ref Vector256 bBase = ref b.V0; ref Vector256 destRef = ref dest.V01; - var multiplyIntoInt16ShuffleMask = Vector256.Create(0, 1, 4, 5, 2, 3, 6, 7); + Vector256 multiplyIntoInt16ShuffleMask = Vector256.Create(0, 1, 4, 5, 2, 3, 6, 7); - for (nint i = 0; i < 8; i += 2) + for (nuint i = 0; i < 8; i += 2) { Vector256 row0 = Avx.ConvertToVector256Int32(Avx.Multiply(Unsafe.Add(ref aBase, i + 0), Unsafe.Add(ref bBase, i + 0))); Vector256 row1 = Avx.ConvertToVector256Int32(Avx.Multiply(Unsafe.Add(ref aBase, i + 1), Unsafe.Add(ref bBase, i + 1))); @@ -64,7 +64,7 @@ internal partial struct Block8x8F ref Vector128 destBase = ref Unsafe.As>(ref dest); - for (nint i = 0; i < 16; i += 2) + for (nuint i = 0; i < 16; i += 2) { Vector128 left = Sse2.ConvertToVector128Int32(Sse.Multiply(Unsafe.Add(ref aBase, i + 0), Unsafe.Add(ref bBase, i + 0))); Vector128 right = Sse2.ConvertToVector128Int32(Sse.Multiply(Unsafe.Add(ref aBase, i + 1), Unsafe.Add(ref bBase, i + 1))); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs index e68ede9fbb..652c064ad5 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs @@ -30,13 +30,13 @@ internal partial struct Block8x8F } // TODO: Optimize: implement all cases with scale-specific, loopless code! - this.CopyArbitraryScale(ref areaOrigin, areaStride, horizontalScale, verticalScale); + this.CopyArbitraryScale(ref areaOrigin, (uint)areaStride, (uint)horizontalScale, (uint)verticalScale); } private void CopyTo2x2Scale(ref float areaOrigin, int areaStride) { ref Vector2 destBase = ref Unsafe.As(ref areaOrigin); - int destStride = (int)((uint)areaStride / 2); + nuint destStride = (uint)areaStride / 2; WidenCopyRowImpl2x2(ref this.V0L, ref destBase, 0, destStride); WidenCopyRowImpl2x2(ref this.V0L, ref destBase, 1, destStride); @@ -48,12 +48,12 @@ internal partial struct Block8x8F WidenCopyRowImpl2x2(ref this.V0L, ref destBase, 7, destStride); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static void WidenCopyRowImpl2x2(ref Vector4 selfBase, ref Vector2 destBase, nint row, nint destStride) + static void WidenCopyRowImpl2x2(ref Vector4 selfBase, ref Vector2 destBase, nuint row, nuint destStride) { ref Vector4 sLeft = ref Unsafe.Add(ref selfBase, 2 * row); ref Vector4 sRight = ref Unsafe.Add(ref sLeft, 1); - nint offset = 2 * row * destStride; + nuint offset = 2 * row * destStride; ref Vector4 dTopLeft = ref Unsafe.As(ref Unsafe.Add(ref destBase, offset)); ref Vector4 dBottomLeft = ref Unsafe.As(ref Unsafe.Add(ref destBase, offset + destStride)); @@ -86,23 +86,23 @@ internal partial struct Block8x8F } [MethodImpl(InliningOptions.ColdPath)] - private void CopyArbitraryScale(ref float areaOrigin, int areaStride, int horizontalScale, int verticalScale) + private void CopyArbitraryScale(ref float areaOrigin, uint areaStride, uint horizontalScale, uint verticalScale) { - for (int y = 0; y < 8; y++) + for (nuint y = 0; y < 8; y++) { - int yy = y * verticalScale; - int y8 = y * 8; + nuint yy = y * verticalScale; + nuint y8 = y * 8; - for (int x = 0; x < 8; x++) + for (nuint x = 0; x < 8; x++) { - int xx = x * horizontalScale; + nuint xx = x * horizontalScale; - float value = this[y8 + x]; - nint baseIdx = (nint)(uint)((yy * areaStride) + xx); + float value = this[(int)(y8 + x)]; + nuint baseIdx = (uint)((yy * areaStride) + xx); - for (nint i = 0; i < verticalScale; i++, baseIdx += areaStride) + for (nuint i = 0; i < verticalScale; i++, baseIdx += areaStride) { - for (nint j = 0; j < (uint)horizontalScale; j++) + for (nuint j = 0; j < horizontalScale; j++) { // area[xx + j, yy + i] = value; Unsafe.Add(ref areaOrigin, baseIdx + j) = value; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs index a0a8cd28e2..21971a8c7d 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs @@ -71,28 +71,34 @@ internal partial struct Block8x8F : IEquatable /// The index /// The float value at the specified index public float this[int idx] + { + get => this[(uint)idx]; + set => this[(uint)idx] = value; + } + + internal float this[nuint idx] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - DebugGuard.MustBeBetweenOrEqualTo(idx, 0, Size - 1, nameof(idx)); + DebugGuard.MustBeBetweenOrEqualTo((int)idx, 0, Size - 1, nameof(idx)); ref float selfRef = ref Unsafe.As(ref this); - return Unsafe.Add(ref selfRef, (nint)(uint)idx); + return Unsafe.Add(ref selfRef, idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] set { - DebugGuard.MustBeBetweenOrEqualTo(idx, 0, Size - 1, nameof(idx)); + DebugGuard.MustBeBetweenOrEqualTo((int)idx, 0, Size - 1, nameof(idx)); ref float selfRef = ref Unsafe.As(ref this); - Unsafe.Add(ref selfRef, (nint)(uint)idx) = value; + Unsafe.Add(ref selfRef, idx) = value; } } public float this[int x, int y] { - get => this[(y * 8) + x]; - set => this[(y * 8) + x] = value; + get => this[((uint)y * 8) + (uint)x]; + set => this[((uint)y * 8) + (uint)x] = value; } public static Block8x8F Load(Span data) @@ -425,7 +431,7 @@ internal partial struct Block8x8F : IEquatable Vector256 targetVector = Vector256.Create(value); ref Vector256 blockStride = ref this.V0; - for (nint i = 0; i < RowCount; i++) + for (nuint i = 0; i < RowCount; i++) { Vector256 areEqual = Avx2.CompareEqual(Avx.ConvertToVector256Int32WithTruncation(Unsafe.Add(ref this.V0, i)), targetVector); if (Avx2.MoveMask(areEqual.AsByte()) != equalityMask) @@ -439,7 +445,7 @@ internal partial struct Block8x8F : IEquatable ref float scalars = ref Unsafe.As(ref this); - for (nint i = 0; i < Size; i++) + for (nuint i = 0; i < Size; i++) { if ((int)Unsafe.Add(ref scalars, i) != value) { diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs index 3144afa76b..07ba3648c4 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs @@ -32,8 +32,8 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / (this.MaximumValue * this.MaximumValue)); - nint n = (nint)(uint)values.Component0.Length / Vector256.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector256.Count); + for (nuint i = 0; i < n; i++) { ref Vector256 c = ref Unsafe.Add(ref c0Base, i); ref Vector256 m = ref Unsafe.Add(ref c1Base, i); @@ -71,8 +71,8 @@ internal abstract partial class JpegColorConverterBase var scale = Vector256.Create(maxValue); - nint n = (nint)(uint)values.Component0.Length / Vector256.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector256.Count); + for (nuint i = 0; i < n; i++) { Vector256 ctmp = Avx.Subtract(scale, Unsafe.Add(ref srcR, i)); Vector256 mtmp = Avx.Subtract(scale, Unsafe.Add(ref srcG, i)); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs index 03d9a1532a..2e2ff08bf9 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs @@ -30,8 +30,8 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / (this.MaximumValue * this.MaximumValue)); - nint n = (nint)(uint)values.Component0.Length / Vector.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector.Count); + for (nuint i = 0; i < n; i++) { ref Vector c = ref Unsafe.Add(ref cBase, i); ref Vector m = ref Unsafe.Add(ref mBase, i); @@ -78,8 +78,8 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = new Vector(maxValue); - nint n = (nint)(uint)values.Component0.Length / Vector.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector.Count); + for (nuint i = 0; i < n; i++) { Vector ctmp = scale - Unsafe.Add(ref srcR, i); Vector mtmp = scale - Unsafe.Add(ref srcG, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs index 4bb9869728..80ae6621c4 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs @@ -27,8 +27,8 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / this.MaximumValue); - nint n = (nint)(uint)values.Component0.Length / Vector256.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector256.Count); + for (nuint i = 0; i < n; i++) { ref Vector256 c0 = ref Unsafe.Add(ref c0Base, i); c0 = Avx.Multiply(c0, scale); @@ -53,8 +53,8 @@ internal abstract partial class JpegColorConverterBase var f0587 = Vector256.Create(0.587f); var f0114 = Vector256.Create(0.114f); - nint n = (nint)(uint)values.Component0.Length / Vector256.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector256.Count); + for (nuint i = 0; i < n; i++) { ref Vector256 r = ref Unsafe.Add(ref srcRed, i); ref Vector256 g = ref Unsafe.Add(ref srcGreen, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleScalar.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleScalar.cs index df511594af..4d3b5c60bd 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleScalar.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleScalar.cs @@ -28,7 +28,7 @@ internal abstract partial class JpegColorConverterBase ref float valuesRef = ref MemoryMarshal.GetReference(values); float scale = 1 / maxValue; - for (nint i = 0; i < (uint)values.Length; i++) + for (nuint i = 0; i < (uint)values.Length; i++) { Unsafe.Add(ref valuesRef, i) *= scale; } diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs index d8ba115d24..018e0ca442 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs @@ -24,8 +24,8 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / this.MaximumValue); - nint n = (nint)(uint)values.Component0.Length / Vector.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector.Count); + for (nuint i = 0; i < n; i++) { ref Vector c0 = ref Unsafe.Add(ref cBase, i); c0 *= scale; @@ -53,8 +53,8 @@ internal abstract partial class JpegColorConverterBase var gMult = new Vector(0.587f); var bMult = new Vector(0.114f); - nint n = (nint)(uint)values.Component0.Length / Vector.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector.Count); + for (nuint i = 0; i < n; i++) { Vector r = Unsafe.Add(ref srcR, i); Vector g = Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs index 4a2112592f..72d8340a0f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs @@ -30,8 +30,8 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector128.Create(1 / this.MaximumValue); - nint n = (nint)(uint)values.Component0.Length / Vector128.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector128.Count); + for (nuint i = 0; i < n; i++) { ref Vector128 r = ref Unsafe.Add(ref rBase, i); ref Vector128 g = ref Unsafe.Add(ref gBase, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs index 76b2e9936c..8c095309c7 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs @@ -29,8 +29,8 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / this.MaximumValue); - nint n = (nint)(uint)values.Component0.Length / Vector256.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector256.Count); + for (nuint i = 0; i < n; i++) { ref Vector256 r = ref Unsafe.Add(ref rBase, i); ref Vector256 g = ref Unsafe.Add(ref gBase, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs index 5d85bb0482..cbba796440 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs @@ -28,8 +28,8 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / this.MaximumValue); - nint n = (nint)(uint)values.Component0.Length / Vector.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector.Count); + for (nuint i = 0; i < n; i++) { ref Vector r = ref Unsafe.Add(ref rBase, i); ref Vector g = ref Unsafe.Add(ref gBase, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs index 59f24493a1..e828ba1179 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs @@ -38,8 +38,8 @@ internal abstract partial class JpegColorConverterBase var bCbMult = Vector256.Create(YCbCrScalar.BCbMult); // Walking 8 elements at one step: - nint n = (nint)(uint)values.Component0.Length / Vector256.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector256.Count); + for (nuint i = 0; i < n; i++) { // y = yVals[i]; // cb = cbVals[i] - 128F; @@ -98,8 +98,8 @@ internal abstract partial class JpegColorConverterBase var fn0081312F = Vector256.Create(-0.081312F); var f05 = Vector256.Create(0.5f); - nint n = (nint)(uint)values.Component0.Length / Vector256.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector256.Count); + for (nuint i = 0; i < n; i++) { Vector256 r = Unsafe.Add(ref srcR, i); Vector256 g = Unsafe.Add(ref srcG, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs index 0f7a364868..e3b4be235f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs @@ -35,8 +35,8 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(-YCbCrScalar.GCrMult); var bCbMult = new Vector(YCbCrScalar.BCbMult); - nint n = (nint)(uint)values.Component0.Length / Vector.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector.Count); + for (nuint i = 0; i < n; i++) { // y = yVals[i]; // cb = cbVals[i] - 128F; @@ -103,8 +103,8 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(0.418688f); var bCrMult = new Vector(0.081312f); - nint n = (nint)(uint)values.Component0.Length / Vector.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector.Count); + for (nuint i = 0; i < n; i++) { Vector r = Unsafe.Add(ref srcR, i); Vector g = Unsafe.Add(ref srcG, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs index 0cfb3201b4..8ab2dd3d67 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs @@ -40,8 +40,8 @@ internal abstract partial class JpegColorConverterBase var bCbMult = Vector256.Create(YCbCrScalar.BCbMult); // Walking 8 elements at one step: - nint n = (nint)(uint)values.Component0.Length / Vector256.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector256.Count); + for (nuint i = 0; i < n; i++) { // y = yVals[i]; // cb = cbVals[i] - 128F; @@ -109,8 +109,8 @@ internal abstract partial class JpegColorConverterBase var fn0081312F = Vector256.Create(-0.081312F); var f05 = Vector256.Create(0.5f); - nint n = (nint)(uint)values.Component0.Length / Vector256.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector256.Count); + for (nuint i = 0; i < n; i++) { Vector256 r = Avx.Subtract(maxSampleValue, Unsafe.Add(ref srcR, i)); Vector256 g = Avx.Subtract(maxSampleValue, Unsafe.Add(ref srcG, i)); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs index feefe3021d..711b0fe3bb 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs @@ -36,8 +36,8 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(-YCbCrScalar.GCrMult); var bCbMult = new Vector(YCbCrScalar.BCbMult); - nint n = (nint)(uint)values.Component0.Length / Vector.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector.Count); + for (nuint i = 0; i < n; i++) { // y = yVals[i]; // cb = cbVals[i] - 128F; @@ -107,8 +107,8 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(0.418688f); var bCrMult = new Vector(0.081312f); - nint n = (nint)(uint)values.Component0.Length / Vector.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)(values.Component0.Length / Vector.Count); + for (nuint i = 0; i < n; i++) { Vector r = maxSampleValue - Unsafe.Add(ref srcR, i); Vector g = maxSampleValue - Unsafe.Add(ref srcG, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs index fcefe542d4..5ecf779615 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs @@ -470,7 +470,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder this.DecodeBlockBaseline( component, - ref Unsafe.Add(ref blockRef, (nint)(uint)blockCol), + ref Unsafe.Add(ref blockRef, (uint)blockCol), ref acDecodingTable, ref dcDecodingTable); } @@ -521,7 +521,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder this.DecodeBlockBaseline( component, - ref Unsafe.Add(ref blockRef, (nint)(uint)k), + ref Unsafe.Add(ref blockRef, (uint)k), ref acDecodingTable, ref dcDecodingTable); @@ -560,7 +560,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder this.DecodeBlockBaseline( component, - ref Unsafe.Add(ref blockRef, (nint)(uint)i), + ref Unsafe.Add(ref blockRef, (uint)i), ref acDecodingTable, ref dcDecodingTable); @@ -611,7 +611,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder this.DecodeBlockProgressiveDc( component, - ref Unsafe.Add(ref blockRef, (nint)(uint)blockCol), + ref Unsafe.Add(ref blockRef, (uint)blockCol), ref dcDecodingTable); } } @@ -653,7 +653,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder this.DecodeBlockProgressiveDc( component, - ref Unsafe.Add(ref blockRef, (nint)(uint)i), + ref Unsafe.Add(ref blockRef, (uint)i), ref dcDecodingTable); this.HandleRestart(); @@ -680,7 +680,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder this.DecodeBlockProgressiveAc( component, - ref Unsafe.Add(ref blockRef, (nint)(uint)i), + ref Unsafe.Add(ref blockRef, (uint)i), ref acDecodingTable); this.HandleRestart(); @@ -717,7 +717,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder // Figure F.21: Decoding nonzero value v. // Figure F.22: Decoding the sign of v. int sign = this.DecodeBinaryDecision(ref reader, ref Unsafe.Add(ref st, 1)); - st = ref Unsafe.Add(ref st, (nint)(uint)(2 + sign)); + st = ref Unsafe.Add(ref st, (uint)(2 + sign)); // Figure F.23: Decoding the magnitude category of v. int m = this.DecodeBinaryDecision(ref reader, ref st); @@ -967,7 +967,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder // Figure F.21: Decoding nonzero value v // Figure F.22: Decoding the sign of v int sign = this.DecodeBinaryDecision(ref reader, ref Unsafe.Add(ref st, 1)); - st = ref Unsafe.Add(ref st, (nint)(uint)(2 + sign)); + st = ref Unsafe.Add(ref st, (uint)(2 + sign)); // Figure F.23: Decoding the magnitude category of v. int m = this.DecodeBinaryDecision(ref reader, ref st); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs index 8b4256e3b9..0ec7500e0d 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs @@ -67,30 +67,30 @@ internal sealed class DownScalingComponentProcessor2 : ComponentProcessor public static void ScaledCopyTo(ref Block8x8F block, ref float destRef, int destStrideWidth, int horizontalScale, int verticalScale) { // TODO: Optimize: implement all cases with scale-specific, loopless code! - CopyArbitraryScale(ref block, ref destRef, destStrideWidth, horizontalScale, verticalScale); + CopyArbitraryScale(ref block, ref destRef, (uint)destStrideWidth, (uint)horizontalScale, (uint)verticalScale); [MethodImpl(InliningOptions.ColdPath)] - static void CopyArbitraryScale(ref Block8x8F block, ref float areaOrigin, int areaStride, int horizontalScale, int verticalScale) + static void CopyArbitraryScale(ref Block8x8F block, ref float areaOrigin, uint areaStride, uint horizontalScale, uint verticalScale) { - for (int y = 0; y < 4; y++) + for (nuint y = 0; y < 4; y++) { - int yy = y * verticalScale; - int y8 = y * 8; + nuint yy = y * verticalScale; + nuint y8 = y * 8; - for (int x = 0; x < 4; x++) + for (nuint x = 0; x < 4; x++) { - int xx = x * horizontalScale; + nuint xx = x * horizontalScale; float value = block[y8 + x]; - for (int i = 0; i < verticalScale; i++) + for (nuint i = 0; i < verticalScale; i++) { - int baseIdx = ((yy + i) * areaStride) + xx; + nuint baseIdx = ((yy + i) * areaStride) + xx; - for (int j = 0; j < horizontalScale; j++) + for (nuint j = 0; j < horizontalScale; j++) { // area[xx + j, yy + i] = value; - Unsafe.Add(ref areaOrigin, (nint)(uint)(baseIdx + j)) = value; + Unsafe.Add(ref areaOrigin, baseIdx + j) = value; } } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs index 170cdbb3c8..99daaa49e7 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs @@ -67,30 +67,30 @@ internal sealed class DownScalingComponentProcessor4 : ComponentProcessor public static void ScaledCopyTo(ref Block8x8F block, ref float destRef, int destStrideWidth, int horizontalScale, int verticalScale) { // TODO: Optimize: implement all cases with scale-specific, loopless code! - CopyArbitraryScale(ref block, ref destRef, destStrideWidth, horizontalScale, verticalScale); + CopyArbitraryScale(ref block, ref destRef, (uint)destStrideWidth, (uint)horizontalScale, (uint)verticalScale); [MethodImpl(InliningOptions.ColdPath)] - static void CopyArbitraryScale(ref Block8x8F block, ref float areaOrigin, int areaStride, int horizontalScale, int verticalScale) + static void CopyArbitraryScale(ref Block8x8F block, ref float areaOrigin, uint areaStride, uint horizontalScale, uint verticalScale) { - for (int y = 0; y < 2; y++) + for (nuint y = 0; y < 2; y++) { - int yy = y * verticalScale; - int y8 = y * 8; + nuint yy = y * verticalScale; + nuint y8 = y * 8; - for (int x = 0; x < 2; x++) + for (nuint x = 0; x < 2; x++) { - int xx = x * horizontalScale; + nuint xx = x * horizontalScale; float value = block[y8 + x]; - for (int i = 0; i < verticalScale; i++) + for (nuint i = 0; i < verticalScale; i++) { - int baseIdx = ((yy + i) * areaStride) + xx; + nuint baseIdx = ((yy + i) * areaStride) + xx; - for (int j = 0; j < horizontalScale; j++) + for (nuint j = 0; j < horizontalScale; j++) { // area[xx + j, yy + i] = value; - Unsafe.Add(ref areaOrigin, (nint)(uint)(baseIdx + j)) = value; + Unsafe.Add(ref areaOrigin, baseIdx + j) = value; } } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs index 81104d2f3d..cf321d7cd9 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs @@ -67,20 +67,20 @@ internal sealed class DownScalingComponentProcessor8 : ComponentProcessor { destRef = value; Unsafe.Add(ref destRef, 1) = value; - Unsafe.Add(ref destRef, 0 + (nint)(uint)destStrideWidth) = value; - Unsafe.Add(ref destRef, 1 + (nint)(uint)destStrideWidth) = value; + Unsafe.Add(ref destRef, 0 + (uint)destStrideWidth) = value; + Unsafe.Add(ref destRef, 1 + (uint)destStrideWidth) = value; return; } // TODO: Optimize: implement all cases with scale-specific, loopless code! - for (int y = 0; y < verticalScale; y++) + for (nuint y = 0; y < (uint)verticalScale; y++) { - for (int x = 0; x < horizontalScale; x++) + for (nuint x = 0; x < (uint)horizontalScale; x++) { - Unsafe.Add(ref destRef, (nint)(uint)x) = value; + Unsafe.Add(ref destRef, x) = value; } - destRef = ref Unsafe.Add(ref destRef, (nint)(uint)destStrideWidth); + destRef = ref Unsafe.Add(ref destRef, (uint)destStrideWidth); } } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs index 3c89ab1fb6..9b08175051 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs @@ -122,8 +122,8 @@ internal class ComponentProcessor : IDisposable ref Vector256 sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed - nint count = (nint)(uint)source.Length / Vector256.Count; - for (nint i = 0; i < count; i++) + nuint count = (uint)(source.Length / Vector256.Count); + for (nuint i = 0; i < count; i++) { Unsafe.Add(ref targetVectorRef, i) = Avx.Add(Unsafe.Add(ref targetVectorRef, i), Unsafe.Add(ref sourceVectorRef, i)); } @@ -133,15 +133,15 @@ internal class ComponentProcessor : IDisposable ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); ref Vector sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); - nint count = (nint)(uint)source.Length / Vector.Count; - for (nint i = 0; i < count; i++) + nuint count = (uint)(source.Length / Vector.Count); + for (nuint i = 0; i < count; i++) { Unsafe.Add(ref targetVectorRef, i) += Unsafe.Add(ref sourceVectorRef, i); } ref float targetRef = ref MemoryMarshal.GetReference(target); ref float sourceRef = ref MemoryMarshal.GetReference(source); - for (nint i = count * Vector.Count; i < (uint)source.Length; i++) + for (nuint i = count * (uint)Vector.Count; i < (uint)source.Length; i++) { Unsafe.Add(ref targetRef, i) += Unsafe.Add(ref sourceRef, i); } @@ -166,16 +166,16 @@ internal class ComponentProcessor : IDisposable source = source.Slice(touchedCount); target = target.Slice(touchedCount / factor); - nint length = (nint)(uint)touchedCount / Vector256.Count; + nuint length = (uint)(touchedCount / Vector256.Count); for (int i = 0; i < haddIterationsCount; i++) { length /= 2; - for (nint j = 0; j < length; j++) + for (nuint j = 0; j < length; j++) { - nint indexLeft = j * 2; - nint indexRight = indexLeft + 1; + nuint indexLeft = j * 2; + nuint indexRight = indexLeft + 1; Vector256 sum = Avx.HorizontalAdd(Unsafe.Add(ref targetRef, indexLeft), Unsafe.Add(ref targetRef, indexRight)); Unsafe.Add(ref targetRef, j) = Avx2.Permute4x64(sum.AsDouble(), 0b11_01_10_00).AsSingle(); } @@ -200,9 +200,9 @@ internal class ComponentProcessor : IDisposable ref Vector256 targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed - nint count = (nint)(uint)target.Length / Vector256.Count; + nuint count = (uint)(target.Length / Vector256.Count); var multiplierVector = Vector256.Create(multiplier); - for (nint i = 0; i < count; i++) + for (nuint i = 0; i < count; i++) { Unsafe.Add(ref targetVectorRef, i) = Avx.Multiply(Unsafe.Add(ref targetVectorRef, i), multiplierVector); } @@ -211,15 +211,15 @@ internal class ComponentProcessor : IDisposable { ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); - nint count = (nint)(uint)target.Length / Vector.Count; + nuint count = (uint)(target.Length / Vector.Count); var multiplierVector = new Vector(multiplier); - for (nint i = 0; i < count; i++) + for (nuint i = 0; i < count; i++) { Unsafe.Add(ref targetVectorRef, i) *= multiplierVector; } ref float targetRef = ref MemoryMarshal.GetReference(target); - for (nint i = count * Vector.Count; i < (uint)target.Length; i++) + for (nuint i = count * (uint)Vector.Count; i < (uint)target.Length; i++) { Unsafe.Add(ref targetRef, i) *= multiplier; } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs index 1453b0a568..d74494f9e5 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs @@ -180,7 +180,7 @@ internal class HuffmanScanEncoder Span blockSpan = component.SpectralBlocks.DangerousGetRowSpan(y: 0); ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan); - for (nint k = 0; k < (uint)w; k++) + for (nuint k = 0; k < (uint)w; k++) { this.WriteBlock( component, @@ -219,7 +219,7 @@ internal class HuffmanScanEncoder Span blockSpan = component.SpectralBlocks.DangerousGetRowSpan(y: i); ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan); - for (nint k = 0; k < (uint)w; k++) + for (nuint k = 0; k < (uint)w; k++) { this.WriteBlock( component, @@ -246,9 +246,9 @@ internal class HuffmanScanEncoder private void EncodeScanBaselineInterleaved(JpegFrame frame, SpectralConverter converter, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { - nint mcu = 0; - nint mcusPerColumn = frame.McusPerColumn; - nint mcusPerLine = frame.McusPerLine; + int mcu = 0; + int mcusPerColumn = frame.McusPerColumn; + int mcusPerLine = frame.McusPerLine; for (int j = 0; j < mcusPerColumn; j++) { @@ -258,21 +258,21 @@ internal class HuffmanScanEncoder converter.ConvertStrideBaseline(); // Encode spectral to binary - for (nint i = 0; i < mcusPerLine; i++) + for (int i = 0; i < mcusPerLine; i++) { // Scan an interleaved mcu... process components in order - nint mcuCol = mcu % mcusPerLine; - for (nint k = 0; k < frame.Components.Length; k++) + int mcuCol = mcu % mcusPerLine; + for (int k = 0; k < frame.Components.Length; k++) { Component component = frame.Components[k]; ref HuffmanLut dcHuffmanTable = ref this.dcHuffmanTables[component.DcTableId]; ref HuffmanLut acHuffmanTable = ref this.acHuffmanTables[component.AcTableId]; - nint h = component.HorizontalSamplingFactor; + int h = component.HorizontalSamplingFactor; int v = component.VerticalSamplingFactor; - nint blockColBase = mcuCol * h; + nuint blockColBase = (uint)(mcuCol * h); // Scan out an mcu's worth of this component; that's just determined // by the basic H and V specified for the component @@ -281,9 +281,9 @@ internal class HuffmanScanEncoder Span blockSpan = component.SpectralBlocks.DangerousGetRowSpan(y); ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan); - for (nint x = 0; x < h; x++) + for (nuint x = 0; x < (uint)h; x++) { - nint blockCol = blockColBase + x; + nuint blockCol = blockColBase + x; this.WriteBlock( component, @@ -315,8 +315,8 @@ internal class HuffmanScanEncoder private void EncodeThreeComponentBaselineInterleavedScanNoSubsampling(JpegFrame frame, SpectralConverter converter, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { - nint mcusPerColumn = frame.McusPerColumn; - nint mcusPerLine = frame.McusPerLine; + nuint mcusPerColumn = (uint)frame.McusPerColumn; + nuint mcusPerLine = (uint)frame.McusPerLine; Component c2 = frame.Components[2]; Component c1 = frame.Components[1]; @@ -333,7 +333,7 @@ internal class HuffmanScanEncoder ref Block8x8 c1BlockRef = ref MemoryMarshal.GetReference(c1.SpectralBlocks.DangerousGetRowSpan(y: 0)); ref Block8x8 c2BlockRef = ref MemoryMarshal.GetReference(c2.SpectralBlocks.DangerousGetRowSpan(y: 0)); - for (nint j = 0; j < mcusPerColumn; j++) + for (nuint j = 0; j < mcusPerColumn; j++) { cancellationToken.ThrowIfCancellationRequested(); @@ -341,7 +341,7 @@ internal class HuffmanScanEncoder converter.ConvertStrideBaseline(); // Encode spectral to binary - for (nint i = 0; i < mcusPerLine; i++) + for (nuint i = 0; i < mcusPerLine; i++) { this.WriteBlock( c0, diff --git a/src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.cs b/src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.cs index 15348d4474..0aca33b4c9 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.cs @@ -69,7 +69,7 @@ internal static partial class FloatingPointDCT { ref float tableRef = ref Unsafe.As(ref quantTable); ref float multipliersRef = ref MemoryMarshal.GetReference(AdjustmentCoefficients); - for (nint i = 0; i < Block8x8F.Size; i++) + for (nuint i = 0; i < Block8x8F.Size; i++) { ref float elemRef = ref Unsafe.Add(ref tableRef, i); elemRef = 0.125f * elemRef * Unsafe.Add(ref multipliersRef, i); @@ -88,7 +88,7 @@ internal static partial class FloatingPointDCT { ref float tableRef = ref Unsafe.As(ref quantTable); ref float multipliersRef = ref MemoryMarshal.GetReference(AdjustmentCoefficients); - for (nint i = 0; i < Block8x8F.Size; i++) + for (nuint i = 0; i < Block8x8F.Size; i++) { ref float elemRef = ref Unsafe.Add(ref tableRef, i); elemRef = 0.125f / (elemRef * Unsafe.Add(ref multipliersRef, i)); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs b/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs index 4f67b7dfe9..1a2767308f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs @@ -40,7 +40,7 @@ internal static class ScaledFloatingPointDCT public static void AdjustToIDCT(ref Block8x8F quantTable) { ref float tableRef = ref Unsafe.As(ref quantTable); - for (nint i = 0; i < Block8x8F.Size; i++) + for (nuint i = 0; i < Block8x8F.Size; i++) { ref float elemRef = ref Unsafe.Add(ref tableRef, i); elemRef = 0.125f * elemRef; diff --git a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs index 0e601f5262..2750aa6808 100644 --- a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs @@ -42,7 +42,7 @@ internal static class AverageFilter } else { - DecodeScalar(scanline, previousScanline, (nint)(uint)bytesPerPixel); + DecodeScalar(scanline, previousScanline, (uint)bytesPerPixel); } } @@ -56,7 +56,7 @@ internal static class AverageFilter Vector128 ones = Vector128.Create((byte)1); int rb = scanline.Length; - nint offset = 1; + nuint offset = 1; while (rb >= 4) { ref byte scanRef = ref Unsafe.Add(ref scanBaseRef, offset); @@ -88,7 +88,7 @@ internal static class AverageFilter Vector64 d = Vector64.Zero; int rb = scanline.Length; - nint offset = 1; + nuint offset = 1; const int bytesPerBatch = 4; while (rb >= bytesPerBatch) { @@ -108,12 +108,12 @@ internal static class AverageFilter } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void DecodeScalar(Span scanline, Span previousScanline, nint bytesPerPixel) + private static void DecodeScalar(Span scanline, Span previousScanline, uint bytesPerPixel) { ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline); ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline); - nint x = 1; + nuint x = 1; for (; x <= bytesPerPixel /* Note the <= because x starts at 1 */; ++x) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); @@ -139,7 +139,7 @@ internal static class AverageFilter /// The bytes per pixel. /// The sum of the total variance of the filtered row. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Encode(ReadOnlySpan scanline, ReadOnlySpan previousScanline, Span result, int bytesPerPixel, out int sum) + public static void Encode(ReadOnlySpan scanline, ReadOnlySpan previousScanline, Span result, uint bytesPerPixel, out int sum) { DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result)); @@ -152,8 +152,8 @@ internal static class AverageFilter // Average(x) = Raw(x) - floor((Raw(x-bpp)+Prior(x))/2) resultBaseRef = (byte)FilterType.Average; - nint x = 0; - for (; x < (uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) + nuint x = 0; + for (; x < bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -169,7 +169,7 @@ internal static class AverageFilter Vector256 sumAccumulator = Vector256.Zero; Vector256 allBitsSet = Avx2.CompareEqual(sumAccumulator, sumAccumulator).AsByte(); - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (uint)scanline.Length - Vector256.Count; xLeft += Vector256.Count) + for (nuint xLeft = x - bytesPerPixel; x <= (uint)(scanline.Length - Vector256.Count); xLeft += (uint)Vector256.Count) { Vector256 scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector256 left = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); @@ -179,7 +179,7 @@ internal static class AverageFilter Vector256 res = Avx2.Subtract(scan, avg); Unsafe.As>(ref Unsafe.Add(ref resultBaseRef, x + 1)) = res; // +1 to skip filter type - x += Vector256.Count; + x += (uint)Vector256.Count; sumAccumulator = Avx2.Add(sumAccumulator, Avx2.SumAbsoluteDifferences(Avx2.Abs(res.AsSByte()), zero).AsInt32()); } @@ -192,7 +192,7 @@ internal static class AverageFilter Vector128 sumAccumulator = Vector128.Zero; Vector128 allBitsSet = Sse2.CompareEqual(sumAccumulator, sumAccumulator).AsByte(); - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (uint)scanline.Length - Vector128.Count; xLeft += Vector128.Count) + for (nuint xLeft = x - bytesPerPixel; x <= (uint)(scanline.Length - Vector128.Count); xLeft += (uint)Vector128.Count) { Vector128 scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector128 left = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); @@ -202,7 +202,7 @@ internal static class AverageFilter Vector128 res = Sse2.Subtract(scan, avg); Unsafe.As>(ref Unsafe.Add(ref resultBaseRef, x + 1)) = res; // +1 to skip filter type - x += Vector128.Count; + x += (uint)Vector128.Count; Vector128 absRes; if (Ssse3.IsSupported) @@ -221,7 +221,7 @@ internal static class AverageFilter sum += Numerics.EvenReduceSum(sumAccumulator); } - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (nuint xLeft = x - bytesPerPixel; x < (uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte left = Unsafe.Add(ref scanBaseRef, xLeft); diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs index 540ec63231..f2226974c9 100644 --- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs @@ -45,7 +45,7 @@ internal static class PaethFilter } else { - DecodeScalar(scanline, previousScanline, bytesPerPixel); + DecodeScalar(scanline, previousScanline, (uint)bytesPerPixel); } } @@ -59,7 +59,7 @@ internal static class PaethFilter Vector128 d = Vector128.Zero; int rb = scanline.Length; - nint offset = 1; + nuint offset = 1; while (rb >= 4) { ref byte scanRef = ref Unsafe.Add(ref scanBaseRef, offset); @@ -113,7 +113,7 @@ internal static class PaethFilter Vector128 d = Vector128.Zero; int rb = scanline.Length; - nint offset = 1; + nuint offset = 1; const int bytesPerBatch = 4; while (rb >= bytesPerBatch) { @@ -179,15 +179,15 @@ internal static class PaethFilter } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void DecodeScalar(Span scanline, Span previousScanline, int bytesPerPixel) + private static void DecodeScalar(Span scanline, Span previousScanline, uint bytesPerPixel) { ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline); ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline); // Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp)) - int offset = bytesPerPixel + 1; // Add one because x starts at one. - nint x = 1; - for (; x < (uint)offset; x++) + nuint offset = bytesPerPixel + 1; // Add one because x starts at one. + nuint x = 1; + for (; x < offset; x++) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -226,7 +226,7 @@ internal static class PaethFilter // Paeth(x) = Raw(x) - PaethPredictor(Raw(x-bpp), Prior(x), Prior(x - bpp)) resultBaseRef = (byte)FilterType.Paeth; - nint x = 0; + nuint x = 0; for (; x < (uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); @@ -242,7 +242,7 @@ internal static class PaethFilter Vector256 zero = Vector256.Zero; Vector256 sumAccumulator = Vector256.Zero; - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (nint)(uint)scanline.Length - Vector256.Count; xLeft += Vector256.Count) + for (nuint xLeft = x - (uint)bytesPerPixel; (int)x <= scanline.Length - Vector256.Count; xLeft += (uint)Vector256.Count) { Vector256 scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector256 left = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); @@ -251,7 +251,7 @@ internal static class PaethFilter Vector256 res = Avx2.Subtract(scan, PaethPredictor(left, above, upperLeft)); Unsafe.As>(ref Unsafe.Add(ref resultBaseRef, x + 1)) = res; // +1 to skip filter type - x += Vector256.Count; + x += (uint)Vector256.Count; sumAccumulator = Avx2.Add(sumAccumulator, Avx2.SumAbsoluteDifferences(Avx2.Abs(res.AsSByte()), zero).AsInt32()); } @@ -262,7 +262,7 @@ internal static class PaethFilter { Vector sumAccumulator = Vector.Zero; - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (nint)(uint)scanline.Length - Vector.Count; xLeft += Vector.Count) + for (nuint xLeft = x - (uint)bytesPerPixel; (int)x <= scanline.Length - Vector.Count; xLeft += (uint)Vector.Count) { Vector scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector left = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); @@ -271,7 +271,7 @@ internal static class PaethFilter Vector res = scan - PaethPredictor(left, above, upperLeft); Unsafe.As>(ref Unsafe.Add(ref resultBaseRef, x + 1)) = res; // +1 to skip filter type - x += Vector.Count; + x += (uint)Vector.Count; Numerics.Accumulate(ref sumAccumulator, Vector.AsVectorByte(Vector.Abs(Vector.AsVectorSByte(res)))); } @@ -282,7 +282,7 @@ internal static class PaethFilter } } - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (nint)(uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (nuint xLeft = x - (uint)bytesPerPixel; (int)x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte left = Unsafe.Add(ref scanBaseRef, xLeft); diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs index 5dc7b15d74..d58ac6fb7b 100644 --- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs @@ -36,7 +36,7 @@ internal static class SubFilter } else { - DecodeScalar(scanline, (nint)(uint)bytesPerPixel); + DecodeScalar(scanline, (uint)bytesPerPixel); } } @@ -47,7 +47,7 @@ internal static class SubFilter Vector128 d = Vector128.Zero; int rb = scanline.Length; - nint offset = 1; + nuint offset = 1; while (rb >= 4) { ref byte scanRef = ref Unsafe.Add(ref scanBaseRef, offset); @@ -70,7 +70,7 @@ internal static class SubFilter Vector64 d = Vector64.Zero; int rb = scanline.Length; - nint offset = 1; + nuint offset = 1; const int bytesPerBatch = 4; while (rb >= bytesPerBatch) { @@ -87,14 +87,14 @@ internal static class SubFilter } } - private static void DecodeScalar(Span scanline, nint bytesPerPixel) + private static void DecodeScalar(Span scanline, nuint bytesPerPixel) { ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline); // Sub(x) + Raw(x-bpp) - nint x = bytesPerPixel + 1; + nuint x = bytesPerPixel + 1; Unsafe.Add(ref scanBaseRef, x); - for (; x < scanline.Length; ++x) + for (; x < (uint)scanline.Length; ++x) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); byte prev = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel); @@ -121,8 +121,8 @@ internal static class SubFilter // Sub(x) = Raw(x) - Raw(x-bpp) resultBaseRef = (byte)FilterType.Sub; - nint x = 0; - for (; x < (nint)(uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) + nuint x = 0; + for (; x < (uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); ++x; @@ -136,14 +136,14 @@ internal static class SubFilter Vector256 zero = Vector256.Zero; Vector256 sumAccumulator = Vector256.Zero; - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (nint)(uint)scanline.Length - Vector256.Count; xLeft += Vector256.Count) + for (nuint xLeft = x - (uint)bytesPerPixel; x <= (uint)(scanline.Length - Vector256.Count); xLeft += (uint)Vector256.Count) { Vector256 scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector256 prev = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); Vector256 res = Avx2.Subtract(scan, prev); Unsafe.As>(ref Unsafe.Add(ref resultBaseRef, x + 1)) = res; // +1 to skip filter type - x += Vector256.Count; + x += (uint)Vector256.Count; sumAccumulator = Avx2.Add(sumAccumulator, Avx2.SumAbsoluteDifferences(Avx2.Abs(res.AsSByte()), zero).AsInt32()); } @@ -154,14 +154,14 @@ internal static class SubFilter { Vector sumAccumulator = Vector.Zero; - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x <= (nint)(uint)scanline.Length - Vector.Count; xLeft += Vector.Count) + for (nuint xLeft = x - (uint)bytesPerPixel; x <= (uint)(scanline.Length - Vector.Count); xLeft += (uint)Vector.Count) { Vector scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector prev = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, xLeft)); Vector res = scan - prev; Unsafe.As>(ref Unsafe.Add(ref resultBaseRef, x + 1)) = res; // +1 to skip filter type - x += Vector.Count; + x += (uint)Vector.Count; Numerics.Accumulate(ref sumAccumulator, Vector.AsVectorByte(Vector.Abs(Vector.AsVectorSByte(res)))); } @@ -172,7 +172,7 @@ internal static class SubFilter } } - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (nint)(uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (nuint xLeft = x - (uint)bytesPerPixel; x < (uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte prev = Unsafe.Add(ref scanBaseRef, xLeft); diff --git a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs index 55cc9ad6eb..dd3c2d8612 100644 --- a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs @@ -52,7 +52,7 @@ internal static class UpFilter // Up(x) + Prior(x) int rb = scanline.Length; - nint offset = 1; + nuint offset = 1; while (rb >= Vector256.Count) { ref byte scanRef = ref Unsafe.Add(ref scanBaseRef, offset); @@ -61,12 +61,12 @@ internal static class UpFilter Unsafe.As>(ref scanRef) = Avx2.Add(up, prior); - offset += Vector256.Count; + offset += (uint)Vector256.Count; rb -= Vector256.Count; } // Handle left over. - for (nint i = offset; i < (uint)scanline.Length; i++) + for (nuint i = offset; i < (uint)scanline.Length; i++) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, offset); byte above = Unsafe.Add(ref prevBaseRef, offset); @@ -82,7 +82,7 @@ internal static class UpFilter // Up(x) + Prior(x) int rb = scanline.Length; - nint offset = 1; + nuint offset = 1; while (rb >= Vector128.Count) { ref byte scanRef = ref Unsafe.Add(ref scanBaseRef, offset); @@ -91,12 +91,12 @@ internal static class UpFilter Unsafe.As>(ref scanRef) = Sse2.Add(up, prior); - offset += Vector128.Count; + offset += (uint)Vector128.Count; rb -= Vector128.Count; } // Handle left over. - for (nint i = offset; i < (uint)scanline.Length; i++) + for (nuint i = offset; i < (uint)scanline.Length; i++) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, offset); byte above = Unsafe.Add(ref prevBaseRef, offset); @@ -112,7 +112,7 @@ internal static class UpFilter // Up(x) + Prior(x) int rb = scanline.Length; - nint offset = 1; + nuint offset = 1; const int bytesPerBatch = 16; while (rb >= bytesPerBatch) { @@ -127,7 +127,7 @@ internal static class UpFilter } // Handle left over. - for (nint i = offset; i < (uint)scanline.Length; i++) + for (nuint i = offset; i < (uint)scanline.Length; i++) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, offset); byte above = Unsafe.Add(ref prevBaseRef, offset); @@ -143,7 +143,7 @@ internal static class UpFilter ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline); // Up(x) + Prior(x) - for (nint x = 1; x < (uint)scanline.Length; x++) + for (nuint x = 1; x < (uint)scanline.Length; x++) { ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -172,21 +172,21 @@ internal static class UpFilter // Up(x) = Raw(x) - Prior(x) resultBaseRef = (byte)FilterType.Up; - nint x = 0; + nuint x = 0; if (Avx2.IsSupported) { Vector256 zero = Vector256.Zero; Vector256 sumAccumulator = Vector256.Zero; - for (; x <= (nint)(uint)(scanline.Length - Vector256.Count);) + for (; x <= (uint)(scanline.Length - Vector256.Count);) { Vector256 scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector256 above = Unsafe.As>(ref Unsafe.Add(ref prevBaseRef, x)); Vector256 res = Avx2.Subtract(scan, above); Unsafe.As>(ref Unsafe.Add(ref resultBaseRef, x + 1)) = res; // +1 to skip filter type - x += Vector256.Count; + x += (uint)Vector256.Count; sumAccumulator = Avx2.Add(sumAccumulator, Avx2.SumAbsoluteDifferences(Avx2.Abs(res.AsSByte()), zero).AsInt32()); } @@ -197,14 +197,14 @@ internal static class UpFilter { Vector sumAccumulator = Vector.Zero; - for (; x <= (nint)(uint)(scanline.Length - Vector.Count);) + for (; x <= (uint)(scanline.Length - Vector.Count);) { Vector scan = Unsafe.As>(ref Unsafe.Add(ref scanBaseRef, x)); Vector above = Unsafe.As>(ref Unsafe.Add(ref prevBaseRef, x)); Vector res = scan - above; Unsafe.As>(ref Unsafe.Add(ref resultBaseRef, x + 1)) = res; // +1 to skip filter type - x += Vector.Count; + x += (uint)Vector.Count; Numerics.Accumulate(ref sumAccumulator, Vector.AsVectorByte(Vector.Abs(Vector.AsVectorSByte(res)))); } @@ -215,7 +215,7 @@ internal static class UpFilter } } - for (; x < (nint)(uint)scanline.Length; /* Note: ++x happens in the body to avoid one add operation */) + for (; x < (uint)scanline.Length; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index ea8120a5c1..3ecc363fa4 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -777,8 +777,8 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.header, scanlineSpan, rowSpan, - this.bytesPerPixel, - this.bytesPerSample); + (uint)this.bytesPerPixel, + (uint)this.bytesPerSample); break; @@ -858,8 +858,8 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.header, scanlineSpan, rowSpan, - pixelOffset, - increment, + (uint)pixelOffset, + (uint)increment, pngMetadata.HasTransparency, pngMetadata.TransparentL16.GetValueOrDefault(), pngMetadata.TransparentL8.GetValueOrDefault()); @@ -871,10 +871,10 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.header, scanlineSpan, rowSpan, - pixelOffset, - increment, - this.bytesPerPixel, - this.bytesPerSample); + (uint)pixelOffset, + (uint)increment, + (uint)this.bytesPerPixel, + (uint)this.bytesPerSample); break; @@ -883,8 +883,8 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.header, scanlineSpan, rowSpan, - pixelOffset, - increment, + (uint)pixelOffset, + (uint)increment, this.palette, this.paletteAlpha); @@ -895,8 +895,8 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.header, scanlineSpan, rowSpan, - pixelOffset, - increment, + (uint)pixelOffset, + (uint)increment, this.bytesPerPixel, this.bytesPerSample, pngMetadata.HasTransparency, @@ -910,8 +910,8 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.header, scanlineSpan, rowSpan, - pixelOffset, - increment, + (uint)pixelOffset, + (uint)increment, this.bytesPerPixel, this.bytesPerSample); diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 4657ab17bb..5794da3d56 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -455,7 +455,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable break; case PngFilterMethod.Average: - AverageFilter.Encode(this.currentScanline.GetSpan(), this.previousScanline.GetSpan(), filter, this.bytesPerPixel, out int _); + AverageFilter.Encode(this.currentScanline.GetSpan(), this.previousScanline.GetSpan(), filter, (uint)this.bytesPerPixel, out int _); break; case PngFilterMethod.Paeth: @@ -547,7 +547,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable RuntimeUtility.Swap(ref filter, ref attempt); } - AverageFilter.Encode(current, previous, attempt, this.bytesPerPixel, out sum); + AverageFilter.Encode(current, previous, attempt, (uint)this.bytesPerPixel, out sum); if (sum < min) { min = sum; diff --git a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs index 51b23242c8..04a23308cc 100644 --- a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs +++ b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs @@ -32,20 +32,21 @@ internal static class PngScanlineProcessor { if (header.BitDepth == 16) { - for (int x = 0, o = 0; x < header.Width; x++, o += 2) + int o = 0; + for (nuint x = 0; x < (uint)header.Width; x++, o += 2) { ushort luminance = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, 2)); pixel.FromL16(Unsafe.As(ref luminance)); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else { - for (int x = 0; x < header.Width; x++) + for (nuint x = 0; x < (uint)header.Width; x++) { - byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, (uint)x) * scaleFactor); + byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, x) * scaleFactor); pixel.FromL8(Unsafe.As(ref luminance)); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } @@ -55,28 +56,29 @@ internal static class PngScanlineProcessor if (header.BitDepth == 16) { La32 source = default; - for (int x = 0, o = 0; x < header.Width; x++, o += 2) + int o = 0; + for (nuint x = 0; x < (uint)header.Width; x++, o += 2) { ushort luminance = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, 2)); source.L = luminance; source.A = luminance.Equals(luminance16Trans.PackedValue) ? ushort.MinValue : ushort.MaxValue; pixel.FromLa32(source); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else { La16 source = default; byte scaledLuminanceTrans = (byte)(luminanceTrans.PackedValue * scaleFactor); - for (int x = 0; x < header.Width; x++) + for (nuint x = 0; x < (uint)header.Width; x++) { - byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, (uint)x) * scaleFactor); + byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, x) * scaleFactor); source.L = luminance; source.A = luminance.Equals(scaledLuminanceTrans) ? byte.MinValue : byte.MaxValue; pixel.FromLa16(source); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } } @@ -85,8 +87,8 @@ internal static class PngScanlineProcessor in PngHeader header, ReadOnlySpan scanlineSpan, Span rowSpan, - int pixelOffset, - int increment, + uint pixelOffset, + uint increment, bool hasTrans, L16 luminance16Trans, L8 luminanceTrans) @@ -101,20 +103,21 @@ internal static class PngScanlineProcessor { if (header.BitDepth == 16) { - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += 2) + int o = 0; + for (nuint x = pixelOffset; x < (uint)header.Width; x += increment, o += 2) { ushort luminance = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, 2)); pixel.FromL16(Unsafe.As(ref luminance)); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else { - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o++) + for (nuint x = pixelOffset, o = 0; x < (uint)header.Width; x += increment, o++) { - byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, (uint)o) * scaleFactor); + byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, o) * scaleFactor); pixel.FromL8(Unsafe.As(ref luminance)); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } @@ -124,28 +127,29 @@ internal static class PngScanlineProcessor if (header.BitDepth == 16) { La32 source = default; - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += 2) + int o = 0; + for (nuint x = pixelOffset; x < (uint)header.Width; x += increment, o += 2) { ushort luminance = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, 2)); source.L = luminance; source.A = luminance.Equals(luminance16Trans.PackedValue) ? ushort.MinValue : ushort.MaxValue; pixel.FromLa32(source); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else { La16 source = default; byte scaledLuminanceTrans = (byte)(luminanceTrans.PackedValue * scaleFactor); - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o++) + for (nuint x = pixelOffset, o = 0; x < (uint)header.Width; x += increment, o++) { - byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, (uint)o) * scaleFactor); + byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, o) * scaleFactor); source.L = luminance; source.A = luminance.Equals(scaledLuminanceTrans) ? byte.MinValue : byte.MaxValue; pixel.FromLa16(source); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } } @@ -154,8 +158,8 @@ internal static class PngScanlineProcessor in PngHeader header, ReadOnlySpan scanlineSpan, Span rowSpan, - int bytesPerPixel, - int bytesPerSample) + uint bytesPerPixel, + uint bytesPerSample) where TPixel : unmanaged, IPixel { TPixel pixel = default; @@ -165,26 +169,27 @@ internal static class PngScanlineProcessor if (header.BitDepth == 16) { La32 source = default; - for (int x = 0, o = 0; x < header.Width; x++, o += 4) + int o = 0; + for (nuint x = 0; x < (uint)header.Width; x++, o += 4) { source.L = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, 2)); source.A = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + 2, 2)); pixel.FromLa32(source); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else { La16 source = default; - for (int x = 0; x < header.Width; x++) + for (nuint x = 0; x < (uint)header.Width; x++) { - int offset = x * bytesPerPixel; - source.L = Unsafe.Add(ref scanlineSpanRef, (uint)offset); - source.A = Unsafe.Add(ref scanlineSpanRef, (uint)(offset + bytesPerSample)); + nuint offset = x * bytesPerPixel; + source.L = Unsafe.Add(ref scanlineSpanRef, offset); + source.A = Unsafe.Add(ref scanlineSpanRef, offset + bytesPerSample); pixel.FromLa16(source); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } } @@ -193,10 +198,10 @@ internal static class PngScanlineProcessor in PngHeader header, ReadOnlySpan scanlineSpan, Span rowSpan, - int pixelOffset, - int increment, - int bytesPerPixel, - int bytesPerSample) + uint pixelOffset, + uint increment, + uint bytesPerPixel, + uint bytesPerSample) where TPixel : unmanaged, IPixel { TPixel pixel = default; @@ -206,7 +211,8 @@ internal static class PngScanlineProcessor if (header.BitDepth == 16) { La32 source = default; - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += 4) + int o = 0; + for (nuint x = pixelOffset; x < (uint)header.Width; x += increment, o += 4) { source.L = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, 2)); source.A = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + 2, 2)); @@ -217,15 +223,15 @@ internal static class PngScanlineProcessor } else { - int offset = 0; La16 source = default; - for (int x = pixelOffset; x < header.Width; x += increment) + nuint offset = 0; + for (nuint x = pixelOffset; x < (uint)header.Width; x += increment) { - source.L = Unsafe.Add(ref scanlineSpanRef, (uint)offset); - source.A = Unsafe.Add(ref scanlineSpanRef, (uint)(offset + bytesPerSample)); + source.L = Unsafe.Add(ref scanlineSpanRef, offset); + source.A = Unsafe.Add(ref scanlineSpanRef, offset + bytesPerSample); pixel.FromLa16(source); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; offset += bytesPerPixel; } } @@ -257,25 +263,25 @@ internal static class PngScanlineProcessor Rgba32 rgba = default; ref byte paletteAlphaRef = ref MemoryMarshal.GetArrayDataReference(paletteAlpha); - for (int x = 0; x < header.Width; x++) + for (nuint x = 0; x < (uint)header.Width; x++) { - int index = Unsafe.Add(ref scanlineSpanRef, (uint)x); - rgba.Rgb = Unsafe.Add(ref palettePixelsRef, (uint)index); - rgba.A = paletteAlpha.Length > index ? Unsafe.Add(ref paletteAlphaRef, (uint)index) : byte.MaxValue; + uint index = Unsafe.Add(ref scanlineSpanRef, x); + rgba.Rgb = Unsafe.Add(ref palettePixelsRef, index); + rgba.A = paletteAlpha.Length > index ? Unsafe.Add(ref paletteAlphaRef, index) : byte.MaxValue; pixel.FromRgba32(rgba); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else { - for (int x = 0; x < header.Width; x++) + for (nuint x = 0; x < (uint)header.Width; x++) { - int index = Unsafe.Add(ref scanlineSpanRef, (uint)x); - Rgb24 rgb = Unsafe.Add(ref palettePixelsRef, (uint)index); + int index = Unsafe.Add(ref scanlineSpanRef, x); + Rgb24 rgb = Unsafe.Add(ref palettePixelsRef, index); pixel.FromRgb24(rgb); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } } @@ -284,8 +290,8 @@ internal static class PngScanlineProcessor in PngHeader header, ReadOnlySpan scanlineSpan, Span rowSpan, - int pixelOffset, - int increment, + uint pixelOffset, + uint increment, ReadOnlySpan palette, byte[] paletteAlpha) where TPixel : unmanaged, IPixel @@ -302,25 +308,25 @@ internal static class PngScanlineProcessor // channel and we should try to read it. Rgba32 rgba = default; ref byte paletteAlphaRef = ref MemoryMarshal.GetArrayDataReference(paletteAlpha); - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o++) + for (nuint x = pixelOffset, o = 0; x < (uint)header.Width; x += increment, o++) { - int index = Unsafe.Add(ref scanlineSpanRef, (uint)o); - rgba.A = paletteAlpha.Length > index ? Unsafe.Add(ref paletteAlphaRef, (uint)index) : byte.MaxValue; - rgba.Rgb = Unsafe.Add(ref palettePixelsRef, (uint)index); + uint index = Unsafe.Add(ref scanlineSpanRef, o); + rgba.A = paletteAlpha.Length > index ? Unsafe.Add(ref paletteAlphaRef, index) : byte.MaxValue; + rgba.Rgb = Unsafe.Add(ref palettePixelsRef, index); pixel.FromRgba32(rgba); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else { - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o++) + for (nuint x = pixelOffset, o = 0; x < (uint)header.Width; x += increment, o++) { - int index = Unsafe.Add(ref scanlineSpanRef, (uint)o); - Rgb24 rgb = Unsafe.Add(ref palettePixelsRef, (uint)index); + int index = Unsafe.Add(ref scanlineSpanRef, o); + Rgb24 rgb = Unsafe.Add(ref palettePixelsRef, index); pixel.FromRgb24(rgb); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } } @@ -345,14 +351,15 @@ internal static class PngScanlineProcessor if (header.BitDepth == 16) { Rgb48 rgb48 = default; - for (int x = 0, o = 0; x < header.Width; x++, o += bytesPerPixel) + int o = 0; + for (nuint x = 0; x < (uint)header.Width; x++, o += bytesPerPixel) { rgb48.R = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, bytesPerSample)); rgb48.G = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + bytesPerSample, bytesPerSample)); rgb48.B = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + (2 * bytesPerSample), bytesPerSample)); pixel.FromRgb48(rgb48); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else @@ -367,7 +374,8 @@ internal static class PngScanlineProcessor { Rgb48 rgb48 = default; Rgba64 rgba64 = default; - for (int x = 0, o = 0; x < header.Width; x++, o += bytesPerPixel) + int o = 0; + for (nuint x = 0; x < (uint)header.Width; x++, o += bytesPerPixel) { rgb48.R = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, bytesPerSample)); rgb48.G = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + bytesPerSample, bytesPerSample)); @@ -377,7 +385,7 @@ internal static class PngScanlineProcessor rgba64.A = rgb48.Equals(rgb48Trans) ? ushort.MinValue : ushort.MaxValue; pixel.FromRgba64(rgba64); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else @@ -385,14 +393,14 @@ internal static class PngScanlineProcessor Rgba32 rgba32 = default; ReadOnlySpan rgb24Span = MemoryMarshal.Cast(scanlineSpan); ref Rgb24 rgb24SpanRef = ref MemoryMarshal.GetReference(rgb24Span); - for (int x = 0; x < header.Width; x++) + for (nuint x = 0; x < (uint)header.Width; x++) { - ref readonly Rgb24 rgb24 = ref Unsafe.Add(ref rgb24SpanRef, (uint)x); + ref readonly Rgb24 rgb24 = ref Unsafe.Add(ref rgb24SpanRef, x); rgba32.Rgb = rgb24; rgba32.A = rgb24.Equals(rgb24Trans) ? byte.MinValue : byte.MaxValue; pixel.FromRgba32(rgba32); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } } @@ -401,8 +409,8 @@ internal static class PngScanlineProcessor in PngHeader header, ReadOnlySpan scanlineSpan, Span rowSpan, - int pixelOffset, - int increment, + uint pixelOffset, + uint increment, int bytesPerPixel, int bytesPerSample, bool hasTrans, @@ -420,7 +428,8 @@ internal static class PngScanlineProcessor { Rgb48 rgb48 = default; Rgba64 rgba64 = default; - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += bytesPerPixel) + int o = 0; + for (nuint x = pixelOffset; x < (uint)header.Width; x += increment, o += bytesPerPixel) { rgb48.R = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, bytesPerSample)); rgb48.G = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + bytesPerSample, bytesPerSample)); @@ -430,20 +439,21 @@ internal static class PngScanlineProcessor rgba64.A = rgb48.Equals(rgb48Trans) ? ushort.MinValue : ushort.MaxValue; pixel.FromRgba64(rgba64); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else { Rgb48 rgb48 = default; - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += bytesPerPixel) + int o = 0; + for (nuint x = pixelOffset; x < (uint)header.Width; x += increment, o += bytesPerPixel) { rgb48.R = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, bytesPerSample)); rgb48.G = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + bytesPerSample, bytesPerSample)); rgb48.B = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + (2 * bytesPerSample), bytesPerSample)); pixel.FromRgb48(rgb48); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } @@ -453,7 +463,8 @@ internal static class PngScanlineProcessor if (hasTrans) { Rgba32 rgba = default; - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += bytesPerPixel) + int o = 0; + for (nuint x = pixelOffset; x < (uint)header.Width; x += increment, o += bytesPerPixel) { rgba.R = Unsafe.Add(ref scanlineSpanRef, (uint)o); rgba.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample)); @@ -461,20 +472,21 @@ internal static class PngScanlineProcessor rgba.A = rgb24Trans.Equals(rgba.Rgb) ? byte.MinValue : byte.MaxValue; pixel.FromRgba32(rgba); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else { Rgb24 rgb = default; - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += bytesPerPixel) + int o = 0; + for (nuint x = pixelOffset; x < (uint)header.Width; x += increment, o += bytesPerPixel) { rgb.R = Unsafe.Add(ref scanlineSpanRef, (uint)o); rgb.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample)); rgb.B = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (2 * bytesPerSample))); pixel.FromRgb24(rgb); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } } @@ -494,7 +506,8 @@ internal static class PngScanlineProcessor if (header.BitDepth == 16) { Rgba64 rgba64 = default; - for (int x = 0, o = 0; x < header.Width; x++, o += bytesPerPixel) + int o = 0; + for (nuint x = 0; x < (uint)header.Width; x++, o += bytesPerPixel) { rgba64.R = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, bytesPerSample)); rgba64.G = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + bytesPerSample, bytesPerSample)); @@ -502,7 +515,7 @@ internal static class PngScanlineProcessor rgba64.A = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + (3 * bytesPerSample), bytesPerSample)); pixel.FromRgba64(rgba64); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else @@ -515,8 +528,8 @@ internal static class PngScanlineProcessor in PngHeader header, ReadOnlySpan scanlineSpan, Span rowSpan, - int pixelOffset, - int increment, + uint pixelOffset, + uint increment, int bytesPerPixel, int bytesPerSample) where TPixel : unmanaged, IPixel @@ -528,7 +541,8 @@ internal static class PngScanlineProcessor if (header.BitDepth == 16) { Rgba64 rgba64 = default; - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += bytesPerPixel) + int o = 0; + for (nuint x = pixelOffset; x < (uint)header.Width; x += increment, o += bytesPerPixel) { rgba64.R = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o, bytesPerSample)); rgba64.G = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + bytesPerSample, bytesPerSample)); @@ -536,13 +550,14 @@ internal static class PngScanlineProcessor rgba64.A = BinaryPrimitives.ReadUInt16BigEndian(scanlineSpan.Slice(o + (3 * bytesPerSample), bytesPerSample)); pixel.FromRgba64(rgba64); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } else { Rgba32 rgba = default; - for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o += bytesPerPixel) + int o = 0; + for (nuint x = pixelOffset; x < (uint)header.Width; x += increment, o += bytesPerPixel) { rgba.R = Unsafe.Add(ref scanlineSpanRef, (uint)o); rgba.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample)); @@ -550,7 +565,7 @@ internal static class PngScanlineProcessor rgba.A = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (3 * bytesPerSample))); pixel.FromRgba32(rgba); - Unsafe.Add(ref rowSpanRef, (uint)x) = pixel; + Unsafe.Add(ref rowSpanRef, x) = pixel; } } } diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6TiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6TiffCompression.cs index 1cd8e0dc80..c868fec626 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6TiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6TiffCompression.cs @@ -78,7 +78,7 @@ internal sealed class T6TiffCompression : TiffBaseDecompressor nint bitPos = Numerics.Modulo8(bitsWritten); nint bufferPos = bitsWritten / 8; ref byte scanLineRef = ref MemoryMarshal.GetReference(scanLine); - for (nint i = 0; i < (uint)scanLine.Length; i++) + for (nuint i = 0; i < (uint)scanLine.Length; i++) { if (Unsafe.Add(ref scanLineRef, i) != this.white) { diff --git a/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs index d57dea994f..36f8c20d72 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs @@ -16,7 +16,7 @@ internal abstract class TiffBaseCompression : IDisposable this.Width = width; this.BitsPerPixel = bitsPerPixel; this.Predictor = predictor; - this.BytesPerRow = (int)(((uint)(width * bitsPerPixel) + 7) / 8); + this.BytesPerRow = ((width * bitsPerPixel) + 7) / 8; } /// diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs index a5a04d19d5..a8a70f7272 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs @@ -18,21 +18,21 @@ internal class BlackIsZero1TiffColor : TiffBaseColorDecoder /// public override void Decode(ReadOnlySpan data, Buffer2D pixels, int left, int top, int width, int height) { - nint offset = 0; - var colorBlack = default(TPixel); - var colorWhite = default(TPixel); + nuint offset = 0; + TPixel colorBlack = default; + TPixel colorWhite = default; colorBlack.FromRgba32(Color.Black); colorWhite.FromRgba32(Color.White); ref byte dataRef = ref MemoryMarshal.GetReference(data); - for (nint y = top; y < top + height; y++) + for (nuint y = (uint)top; y < (uint)(top + height); y++) { Span pixelRowSpan = pixels.DangerousGetRowSpan((int)y); ref TPixel pixelRowRef = ref MemoryMarshal.GetReference(pixelRowSpan); - for (nint x = (nint)(uint)left; x < (nint)(uint)(left + width); x += 8) + for (nuint x = (uint)left; x < (uint)(left + width); x += 8) { byte b = Unsafe.Add(ref dataRef, offset++); - nint maxShift = Math.Min(left + width - x, 8); + nuint maxShift = Math.Min((uint)(left + width) - x, 8); if (maxShift == 8) { @@ -70,7 +70,7 @@ internal class BlackIsZero1TiffColor : TiffBaseColorDecoder } else { - for (nint shift = 0; shift < maxShift; shift++) + for (nuint shift = 0; shift < maxShift; shift++) { int bit = (b >> (7 - (int)shift)) & 1; diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs index 737f957676..c5b662979e 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs @@ -17,21 +17,21 @@ internal class WhiteIsZero1TiffColor : TiffBaseColorDecoder /// public override void Decode(ReadOnlySpan data, Buffer2D pixels, int left, int top, int width, int height) { - nint offset = 0; + nuint offset = 0; var colorBlack = default(TPixel); var colorWhite = default(TPixel); colorBlack.FromRgba32(Color.Black); colorWhite.FromRgba32(Color.White); ref byte dataRef = ref MemoryMarshal.GetReference(data); - for (nint y = top; y < (nint)(uint)(top + height); y++) + for (nuint y = (uint)top; y < (uint)(top + height); y++) { Span pixelRowSpan = pixels.DangerousGetRowSpan((int)y); ref TPixel pixelRowRef = ref MemoryMarshal.GetReference(pixelRowSpan); - for (nint x = left; x < (nint)(uint)(left + width); x += 8) + for (nuint x = (uint)left; x < (uint)(left + width); x += 8) { byte b = Unsafe.Add(ref dataRef, offset++); - nint maxShift = Math.Min(left + width - x, 8); + nuint maxShift = Math.Min((uint)(left + width) - x, 8); if (maxShift == 8) { @@ -69,11 +69,11 @@ internal class WhiteIsZero1TiffColor : TiffBaseColorDecoder } else { - for (int shift = 0; shift < maxShift; shift++) + for (nuint shift = 0; shift < maxShift; shift++) { - int bit = (b >> (7 - shift)) & 1; + int bit = (b >> (7 - (int)shift)) & 1; - ref TPixel pixel = ref Unsafe.Add(ref pixelRowRef, x + (nint)(uint)shift); + ref TPixel pixel = ref Unsafe.Add(ref pixelRowRef, x + shift); pixel = bit == 0 ? colorWhite : colorBlack; } } diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs index 4499c55833..45bbed12d5 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs @@ -793,7 +793,7 @@ internal class TiffDecoderCore : IImageDecoderInternals } } - int bytesPerRow = (int)(((uint)(width * bitsPerPixel) + 7) / 8); + int bytesPerRow = ((width * bitsPerPixel) + 7) / 8; return bytesPerRow * height; } diff --git a/src/ImageSharp/Formats/Webp/AlphaDecoder.cs b/src/ImageSharp/Formats/Webp/AlphaDecoder.cs index 2678a6f70f..289ebd35ca 100644 --- a/src/ImageSharp/Formats/Webp/AlphaDecoder.cs +++ b/src/ImageSharp/Formats/Webp/AlphaDecoder.cs @@ -319,7 +319,7 @@ internal class AlphaDecoder : IDisposable return; } - nint i; + nuint i; Vector128 last = Vector128.Zero.WithElement(0, dst[0]); ref byte srcRef = ref MemoryMarshal.GetReference(input); ref byte dstRef = ref MemoryMarshal.GetReference(dst); @@ -365,20 +365,24 @@ internal class AlphaDecoder : IDisposable } else if (Avx2.IsSupported) { - nint i; + ref byte inputRef = ref MemoryMarshal.GetReference(input); + ref byte prevRef = ref MemoryMarshal.GetReference(prev); + ref byte dstRef = ref MemoryMarshal.GetReference(dst); + + nuint i; int maxPos = width & ~31; for (i = 0; i < (uint)maxPos; i += 32) { - Vector256 a0 = Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(input), i)); - Vector256 b0 = Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(prev), i)); + Vector256 a0 = Unsafe.As>(ref Unsafe.Add(ref inputRef, i)); + Vector256 b0 = Unsafe.As>(ref Unsafe.Add(ref prevRef, i)); Vector256 c0 = Avx2.Add(a0.AsByte(), b0.AsByte()); - ref byte outputRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(dst), i); + ref byte outputRef = ref Unsafe.Add(ref dstRef, i); Unsafe.As>(ref outputRef) = c0; } for (; i < (uint)width; i++) { - dst[(int)i] = (byte)(prev[(int)i] + input[(int)i]); + Unsafe.Add(ref dstRef, i) = (byte)(Unsafe.Add(ref prevRef, i) + Unsafe.Add(ref inputRef, i)); } } else diff --git a/src/ImageSharp/Formats/Webp/Lossless/ColorSpaceTransformUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/ColorSpaceTransformUtils.cs index 45de1b9553..9a6dfb66e8 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/ColorSpaceTransformUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/ColorSpaceTransformUtils.cs @@ -27,10 +27,10 @@ internal static class ColorSpaceTransformUtils { Span srcSpan = bgra[(y * stride)..]; ref uint inputRef = ref MemoryMarshal.GetReference(srcSpan); - for (nint x = 0; x <= tileWidth - span; x += span) + for (nuint x = 0; x <= (uint)tileWidth - span; x += span) { - nint input0Idx = x; - nint input1Idx = x + (span / 2); + nuint input0Idx = x; + nuint input1Idx = x + (span / 2); Vector256 input0 = Unsafe.As>(ref Unsafe.Add(ref inputRef, input0Idx)).AsByte(); Vector256 input1 = Unsafe.As>(ref Unsafe.Add(ref inputRef, input1Idx)).AsByte(); Vector256 r0 = Avx2.Shuffle(input0, collectColorBlueTransformsShuffleLowMask256); @@ -77,10 +77,10 @@ internal static class ColorSpaceTransformUtils { Span srcSpan = bgra[(y * stride)..]; ref uint inputRef = ref MemoryMarshal.GetReference(srcSpan); - for (nint x = 0; x <= tileWidth - span; x += span) + for (nuint x = 0; (int)x <= tileWidth - span; x += span) { - nint input0Idx = x; - nint input1Idx = x + (span / 2); + nuint input0Idx = x; + nuint input1Idx = x + (span / 2); Vector128 input0 = Unsafe.As>(ref Unsafe.Add(ref inputRef, input0Idx)).AsByte(); Vector128 input1 = Unsafe.As>(ref Unsafe.Add(ref inputRef, input1Idx)).AsByte(); Vector128 r0 = Ssse3.Shuffle(input0, collectColorBlueTransformsShuffleLowMask); @@ -146,10 +146,10 @@ internal static class ColorSpaceTransformUtils { Span srcSpan = bgra[(y * stride)..]; ref uint inputRef = ref MemoryMarshal.GetReference(srcSpan); - for (nint x = 0; x <= tileWidth - span; x += span) + for (nuint x = 0; x <= (uint)tileWidth - span; x += span) { - nint input0Idx = x; - nint input1Idx = x + (span / 2); + nuint input0Idx = x; + nuint input1Idx = x + (span / 2); Vector256 input0 = Unsafe.As>(ref Unsafe.Add(ref inputRef, input0Idx)).AsByte(); Vector256 input1 = Unsafe.As>(ref Unsafe.Add(ref inputRef, input1Idx)).AsByte(); Vector256 g0 = Avx2.And(input0, collectColorRedTransformsGreenMask256); // 0 0 | g 0 @@ -189,10 +189,10 @@ internal static class ColorSpaceTransformUtils { Span srcSpan = bgra[(y * stride)..]; ref uint inputRef = ref MemoryMarshal.GetReference(srcSpan); - for (nint x = 0; x <= tileWidth - span; x += span) + for (nuint x = 0; (int)x <= tileWidth - span; x += span) { - nint input0Idx = x; - nint input1Idx = x + (span / 2); + nuint input0Idx = x; + nuint input1Idx = x + (span / 2); Vector128 input0 = Unsafe.As>(ref Unsafe.Add(ref inputRef, input0Idx)).AsByte(); Vector128 input1 = Unsafe.As>(ref Unsafe.Add(ref inputRef, input1Idx)).AsByte(); Vector128 g0 = Sse2.And(input0, collectColorRedTransformsGreenMask); // 0 0 | g 0 diff --git a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs index 5a8137754b..05b6001c91 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs @@ -94,49 +94,53 @@ internal static unsafe class LosslessUtils /// The pixel data to apply the transformation. public static void AddGreenToBlueAndRed(Span pixelData) { - if (Avx2.IsSupported) + if (Avx2.IsSupported && pixelData.Length >= 8) { Vector256 addGreenToBlueAndRedMaskAvx2 = Vector256.Create(1, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 13, 255, 17, 255, 17, 255, 21, 255, 21, 255, 25, 255, 25, 255, 29, 255, 29, 255); - int numPixels = pixelData.Length; - nint i; - for (i = 0; i <= (nint)(uint)numPixels - 8; i += 8) + nuint numPixels = (uint)pixelData.Length; + nuint i = 0; + do { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector256 input = Unsafe.As>(ref pos).AsByte(); Vector256 in0g0g = Avx2.Shuffle(input, addGreenToBlueAndRedMaskAvx2); Vector256 output = Avx2.Add(input, in0g0g); Unsafe.As>(ref pos) = output.AsUInt32(); + i += 8; } + while (i <= numPixels - 8); if (i != numPixels) { AddGreenToBlueAndRedScalar(pixelData[(int)i..]); } } - else if (Ssse3.IsSupported) + else if (Ssse3.IsSupported && pixelData.Length >= 4) { Vector128 addGreenToBlueAndRedMaskSsse3 = Vector128.Create(1, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 13, 255); - int numPixels = pixelData.Length; - nint i; - for (i = 0; i <= (nint)(uint)numPixels - 4; i += 4) + nuint numPixels = (uint)pixelData.Length; + nuint i = 0; + do { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector128 input = Unsafe.As>(ref pos).AsByte(); Vector128 in0g0g = Ssse3.Shuffle(input, addGreenToBlueAndRedMaskSsse3); Vector128 output = Sse2.Add(input, in0g0g); Unsafe.As>(ref pos) = output.AsUInt32(); + i += 4; } + while (i <= numPixels - 4); if (i != numPixels) { AddGreenToBlueAndRedScalar(pixelData[(int)i..]); } } - else if (Sse2.IsSupported) + else if (Sse2.IsSupported && pixelData.Length >= 4) { - int numPixels = pixelData.Length; - nint i; - for (i = 0; i <= (nint)(uint)numPixels - 4; i += 4) + nuint numPixels = (uint)pixelData.Length; + nuint i = 0; + do { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector128 input = Unsafe.As>(ref pos).AsByte(); @@ -145,7 +149,9 @@ internal static unsafe class LosslessUtils Vector128 c = Sse2.ShuffleHigh(b, SimdUtils.Shuffle.MMShuffle2200); // 0g0g Vector128 output = Sse2.Add(input.AsByte(), c.AsByte()); Unsafe.As>(ref pos) = output.AsUInt32(); + i += 4; } + while (i <= numPixels - 4); if (i != numPixels) { @@ -174,49 +180,53 @@ internal static unsafe class LosslessUtils public static void SubtractGreenFromBlueAndRed(Span pixelData) { - if (Avx2.IsSupported) + if (Avx2.IsSupported && pixelData.Length >= 8) { Vector256 subtractGreenFromBlueAndRedMaskAvx2 = Vector256.Create(1, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 13, 255, 17, 255, 17, 255, 21, 255, 21, 255, 25, 255, 25, 255, 29, 255, 29, 255); - int numPixels = pixelData.Length; - nint i; - for (i = 0; i <= (nint)(uint)numPixels - 8; i += 8) + nuint numPixels = (uint)pixelData.Length; + nuint i = 0; + do { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector256 input = Unsafe.As>(ref pos).AsByte(); Vector256 in0g0g = Avx2.Shuffle(input, subtractGreenFromBlueAndRedMaskAvx2); Vector256 output = Avx2.Subtract(input, in0g0g); Unsafe.As>(ref pos) = output.AsUInt32(); + i += 8; } + while (i <= numPixels - 8); if (i != numPixels) { SubtractGreenFromBlueAndRedScalar(pixelData[(int)i..]); } } - else if (Ssse3.IsSupported) + else if (Ssse3.IsSupported && pixelData.Length >= 4) { Vector128 subtractGreenFromBlueAndRedMaskSsse3 = Vector128.Create(1, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 13, 255); - int numPixels = pixelData.Length; - nint i; - for (i = 0; i <= (nint)(uint)numPixels - 4; i += 4) + nuint numPixels = (uint)pixelData.Length; + nuint i = 0; + do { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector128 input = Unsafe.As>(ref pos).AsByte(); Vector128 in0g0g = Ssse3.Shuffle(input, subtractGreenFromBlueAndRedMaskSsse3); Vector128 output = Sse2.Subtract(input, in0g0g); Unsafe.As>(ref pos) = output.AsUInt32(); + i += 4; } + while (i <= numPixels - 4); if (i != numPixels) { SubtractGreenFromBlueAndRedScalar(pixelData[(int)i..]); } } - else if (Sse2.IsSupported) + else if (Sse2.IsSupported && pixelData.Length >= 4) { - int numPixels = pixelData.Length; - nint i; - for (i = 0; i <= (nint)(uint)numPixels - 4; i += 4) + nuint numPixels = (uint)pixelData.Length; + nuint i = 0; + do { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), i); Vector128 input = Unsafe.As>(ref pos).AsByte(); @@ -225,7 +235,9 @@ internal static unsafe class LosslessUtils Vector128 c = Sse2.ShuffleHigh(b, SimdUtils.Shuffle.MMShuffle2200); // 0g0g Vector128 output = Sse2.Subtract(input.AsByte(), c.AsByte()); Unsafe.As>(ref pos) = output.AsUInt32(); + i += 4; } + while (i <= numPixels - 4); if (i != numPixels) { @@ -372,8 +384,8 @@ internal static unsafe class LosslessUtils Vector256 multsrb = MkCst32(Cst5b(m.GreenToRed), Cst5b(m.GreenToBlue)); Vector256 multsb2 = MkCst32(Cst5b(m.RedToBlue), 0); - nint idx; - for (idx = 0; idx <= (nint)(uint)numPixels - 8; idx += 8) + nuint idx = 0; + do { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), idx); Vector256 input = Unsafe.As>(ref pos); @@ -388,21 +400,23 @@ internal static unsafe class LosslessUtils Vector256 i = Avx2.And(h, transformColorRedBlueMask256); Vector256 output = Avx2.Subtract(input.AsByte(), i); Unsafe.As>(ref pos) = output.AsUInt32(); + idx += 8; } + while (idx <= (uint)numPixels - 8); - if (idx != numPixels) + if (idx != (uint)numPixels) { TransformColorScalar(m, pixelData[(int)idx..], numPixels - (int)idx); } } - else if (Sse2.IsSupported) + else if (Sse2.IsSupported && numPixels >= 4) { Vector128 transformColorAlphaGreenMask = Vector128.Create(0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255); Vector128 transformColorRedBlueMask = Vector128.Create(255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0); Vector128 multsrb = MkCst16(Cst5b(m.GreenToRed), Cst5b(m.GreenToBlue)); Vector128 multsb2 = MkCst16(Cst5b(m.RedToBlue), 0); - nint idx; - for (idx = 0; idx <= (nint)(uint)numPixels - 4; idx += 4) + nuint idx = 0; + do { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), idx); Vector128 input = Unsafe.As>(ref pos); @@ -417,9 +431,11 @@ internal static unsafe class LosslessUtils Vector128 i = Sse2.And(h, transformColorRedBlueMask); Vector128 output = Sse2.Subtract(input.AsByte(), i); Unsafe.As>(ref pos) = output.AsUInt32(); + idx += 4; } + while ((int)idx <= numPixels - 4); - if (idx != numPixels) + if ((int)idx != numPixels) { TransformColorScalar(m, pixelData[(int)idx..], numPixels - (int)idx); } @@ -460,8 +476,8 @@ internal static unsafe class LosslessUtils Vector256 transformColorInverseAlphaGreenMask256 = Vector256.Create(0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255); Vector256 multsrb = MkCst32(Cst5b(m.GreenToRed), Cst5b(m.GreenToBlue)); Vector256 multsb2 = MkCst32(Cst5b(m.RedToBlue), 0); - nint idx; - for (idx = 0; idx <= (nint)(uint)pixelData.Length - 8; idx += 8) + nuint idx; + for (idx = 0; idx <= (uint)pixelData.Length - 8; idx += 8) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), idx); Vector256 input = Unsafe.As>(ref pos); @@ -479,19 +495,19 @@ internal static unsafe class LosslessUtils Unsafe.As>(ref pos) = output.AsUInt32(); } - if (idx != pixelData.Length) + if (idx != (uint)pixelData.Length) { TransformColorInverseScalar(m, pixelData[(int)idx..]); } } - else if (Sse2.IsSupported) + else if (Sse2.IsSupported && pixelData.Length >= 4) { Vector128 transformColorInverseAlphaGreenMask = Vector128.Create(0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255); Vector128 multsrb = MkCst16(Cst5b(m.GreenToRed), Cst5b(m.GreenToBlue)); Vector128 multsb2 = MkCst16(Cst5b(m.RedToBlue), 0); - nint idx; - for (idx = 0; idx <= (nint)(uint)pixelData.Length - 4; idx += 4) + nuint idx; + for (idx = 0; idx <= (uint)pixelData.Length - 4; idx += 4) { ref uint pos = ref Unsafe.Add(ref MemoryMarshal.GetReference(pixelData), idx); Vector128 input = Unsafe.As>(ref pos); @@ -509,7 +525,7 @@ internal static unsafe class LosslessUtils Unsafe.As>(ref pos) = output.AsUInt32(); } - if (idx != pixelData.Length) + if (idx != (uint)pixelData.Length) { TransformColorInverseScalar(m, pixelData[(int)idx..]); } @@ -740,7 +756,7 @@ internal static unsafe class LosslessUtils Vector256 sumXY256 = Vector256.Zero; Vector256 sumX256 = Vector256.Zero; ref int tmpRef = ref Unsafe.As, int>(ref tmp); - for (nint i = 0; i < 256; i += 8) + for (nuint i = 0; i < 256; i += 8) { Vector256 xVec = Unsafe.As>(ref Unsafe.Add(ref xRef, i)); Vector256 yVec = Unsafe.As>(ref Unsafe.Add(ref yRef, i)); diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs index 3f44a1bc05..3df979f96b 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs @@ -518,9 +518,9 @@ internal sealed class Vp8LHistogram : IDeepCloneable ref uint aRef = ref MemoryMarshal.GetReference(a); ref uint bRef = ref MemoryMarshal.GetReference(b); ref uint outputRef = ref MemoryMarshal.GetReference(output); - nint idx; + nuint idx; - for (idx = 0; idx <= (nint)(uint)count - 32; idx += 32) + for (idx = 0; idx <= (uint)count - 32; idx += 32) { // Load values. Vector256 a0 = Unsafe.As>(ref Unsafe.Add(ref aRef, idx)); diff --git a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs index 2dc2881b03..de3f1586af 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs @@ -161,7 +161,7 @@ internal static class LossyUtils private static int Vp8_Sse16xN_Sse2(Span a, Span b, int numPairs) { Vector128 sum = Vector128.Zero; - nint offset = 0; + nuint offset = 0; ref byte aRef = ref MemoryMarshal.GetReference(a); ref byte bRef = ref MemoryMarshal.GetReference(b); for (int i = 0; i < numPairs; i++) @@ -186,7 +186,7 @@ internal static class LossyUtils private static int Vp8_Sse16xN_Avx2(Span a, Span b, int numPairs) { Vector256 sum = Vector256.Zero; - nint offset = 0; + nuint offset = 0; ref byte aRef = ref MemoryMarshal.GetReference(a); ref byte bRef = ref MemoryMarshal.GetReference(b); for (int i = 0; i < numPairs; i++) @@ -2278,8 +2278,8 @@ internal static class LossyUtils // q0 = 73 63 53 43 33 23 13 03 72 62 52 42 32 22 12 02 // p0 = f1 e1 d1 c1 b1 a1 91 81 f0 e0 d0 c0 b0 a0 90 80 // q1 = f3 e3 d3 c3 b3 a3 93 83 f2 e2 d2 c2 b2 a2 92 82 - Load8x4(ref r0, (nint)(uint)stride, out Vector128 t1, out Vector128 t2); - Load8x4(ref r8, (nint)(uint)stride, out p0, out q1); + Load8x4(ref r0, (uint)stride, out Vector128 t1, out Vector128 t2); + Load8x4(ref r8, (uint)stride, out p0, out q1); // p1 = f0 e0 d0 c0 b0 a0 90 80 70 60 50 40 30 20 10 00 // p0 = f1 e1 d1 c1 b1 a1 91 81 71 61 51 41 31 21 11 01 @@ -2292,7 +2292,7 @@ internal static class LossyUtils } // Reads 8 rows across a vertical edge. - private static void Load8x4(ref byte bRef, nint stride, out Vector128 p, out Vector128 q) + private static void Load8x4(ref byte bRef, nuint stride, out Vector128 p, out Vector128 q) { // A0 = 63 62 61 60 23 22 21 20 43 42 41 40 03 02 01 00 // A1 = 73 72 71 70 33 32 31 30 53 52 51 50 13 12 11 10 diff --git a/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs b/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs index 75b92a1aaa..76de2e8f4a 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs @@ -770,7 +770,7 @@ internal static unsafe class QuantEnc { uint v = src[0] * 0x01010101u; Span vSpan = BitConverter.GetBytes(v).AsSpan(); - for (nint i = 0; i < 16; i++) + for (nuint i = 0; i < 16; i++) { if (!src[..4].SequenceEqual(vSpan) || !src.Slice(4, 4).SequenceEqual(vSpan) || !src.Slice(8, 4).SequenceEqual(vSpan) || !src.Slice(12, 4).SequenceEqual(vSpan)) @@ -789,10 +789,10 @@ internal static unsafe class QuantEnc { int score = 0; ref short levelsRef = ref MemoryMarshal.GetReference(levels); - nint offset = 0; + nuint offset = 0; while (numBlocks-- > 0) { - for (nint i = 1; i < 16; i++) + for (nuint i = 1; i < 16; i++) { // omit DC, we're only interested in AC score += Unsafe.Add(ref levelsRef, offset) != 0 ? 1 : 0; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs index 9fca0cdc35..f24ed6fae8 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs @@ -57,7 +57,7 @@ public partial struct Abgr32 { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); } - + /// public override void ToRgba32( Configuration configuration, @@ -71,7 +71,7 @@ public partial struct Abgr32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromAbgr32.ToRgba32(source, dest); } - + /// public override void FromRgba32( Configuration configuration, @@ -84,8 +84,8 @@ public partial struct Abgr32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToAbgr32(source, dest); - } - + } + /// public override void ToArgb32( Configuration configuration, @@ -99,7 +99,7 @@ public partial struct Abgr32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromAbgr32.ToArgb32(source, dest); } - + /// public override void FromArgb32( Configuration configuration, @@ -112,8 +112,8 @@ public partial struct Abgr32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToAbgr32(source, dest); - } - + } + /// public override void ToBgra32( Configuration configuration, @@ -127,7 +127,7 @@ public partial struct Abgr32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromAbgr32.ToBgra32(source, dest); } - + /// public override void FromBgra32( Configuration configuration, @@ -140,8 +140,8 @@ public partial struct Abgr32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToAbgr32(source, dest); - } - + } + /// public override void ToRgb24( Configuration configuration, @@ -155,7 +155,7 @@ public partial struct Abgr32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromAbgr32.ToRgb24(source, dest); } - + /// public override void FromRgb24( Configuration configuration, @@ -168,8 +168,8 @@ public partial struct Abgr32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToAbgr32(source, dest); - } - + } + /// public override void ToBgr24( Configuration configuration, @@ -183,7 +183,7 @@ public partial struct Abgr32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromAbgr32.ToBgr24(source, dest); } - + /// public override void FromBgr24( Configuration configuration, @@ -196,7 +196,7 @@ public partial struct Abgr32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToAbgr32(source, dest); - } + } /// public override void ToL8( @@ -210,7 +210,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -231,7 +231,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -252,7 +252,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -273,7 +273,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -294,7 +294,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -315,7 +315,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -336,7 +336,7 @@ public partial struct Abgr32 ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs index e87926be8b..37ac39a851 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs @@ -57,7 +57,7 @@ public partial struct Argb32 { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); } - + /// public override void ToRgba32( Configuration configuration, @@ -71,7 +71,7 @@ public partial struct Argb32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgba32(source, dest); } - + /// public override void FromRgba32( Configuration configuration, @@ -84,8 +84,8 @@ public partial struct Argb32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToArgb32(source, dest); - } - + } + /// public override void ToAbgr32( Configuration configuration, @@ -99,7 +99,7 @@ public partial struct Argb32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToAbgr32(source, dest); } - + /// public override void FromAbgr32( Configuration configuration, @@ -112,8 +112,8 @@ public partial struct Argb32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromAbgr32.ToArgb32(source, dest); - } - + } + /// public override void ToBgra32( Configuration configuration, @@ -127,7 +127,7 @@ public partial struct Argb32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgra32(source, dest); } - + /// public override void FromBgra32( Configuration configuration, @@ -140,8 +140,8 @@ public partial struct Argb32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToArgb32(source, dest); - } - + } + /// public override void ToRgb24( Configuration configuration, @@ -155,7 +155,7 @@ public partial struct Argb32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgb24(source, dest); } - + /// public override void FromRgb24( Configuration configuration, @@ -168,8 +168,8 @@ public partial struct Argb32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToArgb32(source, dest); - } - + } + /// public override void ToBgr24( Configuration configuration, @@ -183,7 +183,7 @@ public partial struct Argb32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgr24(source, dest); } - + /// public override void FromBgr24( Configuration configuration, @@ -196,7 +196,7 @@ public partial struct Argb32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToArgb32(source, dest); - } + } /// public override void ToL8( @@ -210,7 +210,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -231,7 +231,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -252,7 +252,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -273,7 +273,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -294,7 +294,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -315,7 +315,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -336,7 +336,7 @@ public partial struct Argb32 ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs index 32eed0ce40..f604d6f970 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs @@ -57,7 +57,7 @@ public partial struct Bgr24 { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } - + /// public override void ToRgba32( Configuration configuration, @@ -71,7 +71,7 @@ public partial struct Bgr24 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToRgba32(source, dest); } - + /// public override void FromRgba32( Configuration configuration, @@ -84,8 +84,8 @@ public partial struct Bgr24 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgr24(source, dest); - } - + } + /// public override void ToArgb32( Configuration configuration, @@ -99,7 +99,7 @@ public partial struct Bgr24 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToArgb32(source, dest); } - + /// public override void FromArgb32( Configuration configuration, @@ -112,8 +112,8 @@ public partial struct Bgr24 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgr24(source, dest); - } - + } + /// public override void ToAbgr32( Configuration configuration, @@ -127,7 +127,7 @@ public partial struct Bgr24 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToAbgr32(source, dest); } - + /// public override void FromAbgr32( Configuration configuration, @@ -140,8 +140,8 @@ public partial struct Bgr24 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromAbgr32.ToBgr24(source, dest); - } - + } + /// public override void ToBgra32( Configuration configuration, @@ -155,7 +155,7 @@ public partial struct Bgr24 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToBgra32(source, dest); } - + /// public override void FromBgra32( Configuration configuration, @@ -168,8 +168,8 @@ public partial struct Bgr24 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToBgr24(source, dest); - } - + } + /// public override void ToRgb24( Configuration configuration, @@ -183,7 +183,7 @@ public partial struct Bgr24 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToRgb24(source, dest); } - + /// public override void FromRgb24( Configuration configuration, @@ -196,7 +196,7 @@ public partial struct Bgr24 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToBgr24(source, dest); - } + } /// public override void ToL8( @@ -210,7 +210,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -231,7 +231,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -252,7 +252,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -273,7 +273,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -294,7 +294,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -315,7 +315,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -336,7 +336,7 @@ public partial struct Bgr24 ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs index 4e7800c624..b9f7a49e11 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs @@ -57,7 +57,7 @@ public partial struct Bgra32 { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); } - + /// public override void ToRgba32( Configuration configuration, @@ -71,7 +71,7 @@ public partial struct Bgra32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgba32(source, dest); } - + /// public override void FromRgba32( Configuration configuration, @@ -84,8 +84,8 @@ public partial struct Bgra32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgra32(source, dest); - } - + } + /// public override void ToArgb32( Configuration configuration, @@ -99,7 +99,7 @@ public partial struct Bgra32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToArgb32(source, dest); } - + /// public override void FromArgb32( Configuration configuration, @@ -112,8 +112,8 @@ public partial struct Bgra32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgra32(source, dest); - } - + } + /// public override void ToAbgr32( Configuration configuration, @@ -127,7 +127,7 @@ public partial struct Bgra32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToAbgr32(source, dest); } - + /// public override void FromAbgr32( Configuration configuration, @@ -140,8 +140,8 @@ public partial struct Bgra32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromAbgr32.ToBgra32(source, dest); - } - + } + /// public override void ToRgb24( Configuration configuration, @@ -155,7 +155,7 @@ public partial struct Bgra32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgb24(source, dest); } - + /// public override void FromRgb24( Configuration configuration, @@ -168,8 +168,8 @@ public partial struct Bgra32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToBgra32(source, dest); - } - + } + /// public override void ToBgr24( Configuration configuration, @@ -183,7 +183,7 @@ public partial struct Bgra32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToBgr24(source, dest); } - + /// public override void FromBgr24( Configuration configuration, @@ -196,7 +196,7 @@ public partial struct Bgra32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToBgra32(source, dest); - } + } /// public override void ToL8( @@ -210,7 +210,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -231,7 +231,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -252,7 +252,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -273,7 +273,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -294,7 +294,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -315,7 +315,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -336,7 +336,7 @@ public partial struct Bgra32 ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs index 62864ad209..c1ba4f0618 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); @@ -113,7 +113,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -155,7 +155,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -176,7 +176,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -197,7 +197,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -218,7 +218,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); @@ -239,7 +239,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); @@ -260,7 +260,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -281,7 +281,7 @@ public partial struct Bgra5551 ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs index b37d9d86aa..c38d752ea6 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); @@ -113,7 +113,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -155,7 +155,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -176,7 +176,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -197,7 +197,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); @@ -218,7 +218,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); @@ -239,7 +239,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -260,7 +260,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -281,7 +281,7 @@ public partial struct L16 ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs index 9d67d8741f..656a0546ba 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); @@ -113,7 +113,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -155,7 +155,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -176,7 +176,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -197,7 +197,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); @@ -218,7 +218,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); @@ -239,7 +239,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -260,7 +260,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -281,7 +281,7 @@ public partial struct L8 ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs index 5afea82021..82be1323cd 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); @@ -113,7 +113,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -155,7 +155,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -176,7 +176,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -197,7 +197,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); @@ -218,7 +218,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); @@ -239,7 +239,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -260,7 +260,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -281,7 +281,7 @@ public partial struct La16 ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs index 76da66a1ad..a9ee9d6b78 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); @@ -113,7 +113,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -155,7 +155,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -176,7 +176,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -197,7 +197,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); @@ -218,7 +218,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); @@ -239,7 +239,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -260,7 +260,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -281,7 +281,7 @@ public partial struct La32 ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs index 519f1a6936..1d87121e92 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs @@ -57,7 +57,7 @@ public partial struct Rgb24 { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } - + /// public override void ToRgba32( Configuration configuration, @@ -71,7 +71,7 @@ public partial struct Rgb24 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToRgba32(source, dest); } - + /// public override void FromRgba32( Configuration configuration, @@ -84,8 +84,8 @@ public partial struct Rgb24 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToRgb24(source, dest); - } - + } + /// public override void ToArgb32( Configuration configuration, @@ -99,7 +99,7 @@ public partial struct Rgb24 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToArgb32(source, dest); } - + /// public override void FromArgb32( Configuration configuration, @@ -112,8 +112,8 @@ public partial struct Rgb24 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgb24(source, dest); - } - + } + /// public override void ToAbgr32( Configuration configuration, @@ -127,7 +127,7 @@ public partial struct Rgb24 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToAbgr32(source, dest); } - + /// public override void FromAbgr32( Configuration configuration, @@ -140,8 +140,8 @@ public partial struct Rgb24 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromAbgr32.ToRgb24(source, dest); - } - + } + /// public override void ToBgra32( Configuration configuration, @@ -155,7 +155,7 @@ public partial struct Rgb24 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToBgra32(source, dest); } - + /// public override void FromBgra32( Configuration configuration, @@ -168,8 +168,8 @@ public partial struct Rgb24 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgb24(source, dest); - } - + } + /// public override void ToBgr24( Configuration configuration, @@ -183,7 +183,7 @@ public partial struct Rgb24 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToBgr24(source, dest); } - + /// public override void FromBgr24( Configuration configuration, @@ -196,7 +196,7 @@ public partial struct Rgb24 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToRgb24(source, dest); - } + } /// public override void ToL8( @@ -210,7 +210,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -231,7 +231,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -252,7 +252,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -273,7 +273,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -294,7 +294,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -315,7 +315,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -336,7 +336,7 @@ public partial struct Rgb24 ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs index e58818deac..60cfdad4b6 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); @@ -113,7 +113,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -155,7 +155,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -176,7 +176,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -197,7 +197,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -218,7 +218,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); @@ -239,7 +239,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); @@ -260,7 +260,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -281,7 +281,7 @@ public partial struct Rgb48 ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs index c635a4d6a4..da7c9a6c91 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs @@ -37,7 +37,7 @@ public partial struct Rgba32 sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - + /// public override void ToArgb32( Configuration configuration, @@ -51,7 +51,7 @@ public partial struct Rgba32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToArgb32(source, dest); } - + /// public override void FromArgb32( Configuration configuration, @@ -64,8 +64,8 @@ public partial struct Rgba32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgba32(source, dest); - } - + } + /// public override void ToAbgr32( Configuration configuration, @@ -79,7 +79,7 @@ public partial struct Rgba32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToAbgr32(source, dest); } - + /// public override void FromAbgr32( Configuration configuration, @@ -92,8 +92,8 @@ public partial struct Rgba32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromAbgr32.ToRgba32(source, dest); - } - + } + /// public override void ToBgra32( Configuration configuration, @@ -107,7 +107,7 @@ public partial struct Rgba32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgra32(source, dest); } - + /// public override void FromBgra32( Configuration configuration, @@ -120,8 +120,8 @@ public partial struct Rgba32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgba32(source, dest); - } - + } + /// public override void ToRgb24( Configuration configuration, @@ -135,7 +135,7 @@ public partial struct Rgba32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToRgb24(source, dest); } - + /// public override void FromRgb24( Configuration configuration, @@ -148,8 +148,8 @@ public partial struct Rgba32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToRgba32(source, dest); - } - + } + /// public override void ToBgr24( Configuration configuration, @@ -163,7 +163,7 @@ public partial struct Rgba32 Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgr24(source, dest); } - + /// public override void FromBgr24( Configuration configuration, @@ -176,7 +176,7 @@ public partial struct Rgba32 ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToRgba32(source, dest); - } + } /// public override void ToL8( @@ -190,7 +190,7 @@ public partial struct Rgba32 ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -211,7 +211,7 @@ public partial struct Rgba32 ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -232,7 +232,7 @@ public partial struct Rgba32 ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -253,7 +253,7 @@ public partial struct Rgba32 ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -274,7 +274,7 @@ public partial struct Rgba32 ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -295,7 +295,7 @@ public partial struct Rgba32 ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); @@ -316,7 +316,7 @@ public partial struct Rgba32 ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs index 395f7e88e0..b6236f8a66 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs @@ -50,7 +50,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref Argb32 dp = ref Unsafe.Add(ref destRef, i); @@ -71,7 +71,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); @@ -92,7 +92,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); @@ -113,7 +113,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); @@ -134,7 +134,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref destRef, i); @@ -155,7 +155,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref destRef, i); @@ -176,7 +176,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref La16 dp = ref Unsafe.Add(ref destRef, i); @@ -197,7 +197,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref La32 dp = ref Unsafe.Add(ref destRef, i); @@ -218,7 +218,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); @@ -239,7 +239,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); @@ -260,7 +260,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); @@ -281,7 +281,7 @@ public partial struct Rgba64 ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude index 5a5d135db1..f7e178d7f2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude @@ -103,7 +103,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils; ref <#=fromPixelType#> sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref <#=toPixelType#> destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref <#=fromPixelType#> sp = ref Unsafe.Add(ref sourceRef, i); ref <#=toPixelType#> dp = ref Unsafe.Add(ref destRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs index ed1d3cb2bd..a3833583fc 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs @@ -72,7 +72,7 @@ public partial struct RgbaVector ref Vector4 sourceBaseRef = ref Unsafe.As(ref MemoryMarshal.GetReference(sourcePixels)); ref L8 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Vector4 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref L8 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -91,7 +91,7 @@ public partial struct RgbaVector ref Vector4 sourceBaseRef = ref Unsafe.As(ref MemoryMarshal.GetReference(sourcePixels)); ref L16 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref Vector4 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref L16 dp = ref Unsafe.Add(ref destBaseRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs index 26ca4d1b5a..7e84bd6392 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs @@ -22,7 +22,7 @@ public partial class PixelOperations ref Argb32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref Argb32 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -58,7 +58,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Argb32 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -94,7 +94,7 @@ public partial class PixelOperations ref Abgr32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref Abgr32 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -130,7 +130,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Abgr32 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -166,7 +166,7 @@ public partial class PixelOperations ref Bgr24 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref Bgr24 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -202,7 +202,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Bgr24 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -238,7 +238,7 @@ public partial class PixelOperations ref Bgra32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref Bgra32 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -274,7 +274,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Bgra32 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -310,7 +310,7 @@ public partial class PixelOperations ref L8 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref L8 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -346,7 +346,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref L8 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -382,7 +382,7 @@ public partial class PixelOperations ref L16 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref L16 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -418,7 +418,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref L16 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -454,7 +454,7 @@ public partial class PixelOperations ref La16 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref La16 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -490,7 +490,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref La16 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -526,7 +526,7 @@ public partial class PixelOperations ref La32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref La32 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -562,7 +562,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref La32 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -598,7 +598,7 @@ public partial class PixelOperations ref Rgb24 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref Rgb24 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -634,7 +634,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Rgb24 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -670,7 +670,7 @@ public partial class PixelOperations ref Rgba32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref Rgba32 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -706,7 +706,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Rgba32 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -742,7 +742,7 @@ public partial class PixelOperations ref Rgb48 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref Rgb48 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -778,7 +778,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Rgb48 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -814,7 +814,7 @@ public partial class PixelOperations ref Rgba64 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref Rgba64 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -850,7 +850,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Rgba64 dp = ref Unsafe.Add(ref destBaseRef, i); @@ -886,7 +886,7 @@ public partial class PixelOperations ref Bgra5551 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref Bgra5551 sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -922,7 +922,7 @@ public partial class PixelOperations ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref Bgra5551 dp = ref Unsafe.Add(ref destBaseRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt index 39cf873bfd..8ba3398e39 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt @@ -28,7 +28,7 @@ ref <#=pixelType#> sourceBaseRef = ref MemoryMarshal.GetReference(source); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref <#=pixelType#> sp = ref Unsafe.Add(ref sourceBaseRef, i); ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); @@ -70,7 +70,7 @@ ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref <#=pixelType#> destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)sourcePixels.Length; i++) + for (nuint i = 0; i < (uint)sourcePixels.Length; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); ref <#=pixelType#> dp = ref Unsafe.Add(ref destBaseRef, i); diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs index b18e38f4d5..9d93d27aca 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs @@ -187,7 +187,7 @@ public partial class PixelOperations ref byte b = ref MemoryMarshal.GetReference(blueChannel); ref TPixel d = ref MemoryMarshal.GetReference(destination); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { rgb24.R = Unsafe.Add(ref r, i); rgb24.G = Unsafe.Add(ref g, i); @@ -218,7 +218,7 @@ public partial class PixelOperations ref float g = ref MemoryMarshal.GetReference(greenChannel); ref float b = ref MemoryMarshal.GetReference(blueChannel); ref TPixel src = ref MemoryMarshal.GetReference(source); - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Unsafe.Add(ref src, i).ToRgba32(ref rgba32); Unsafe.Add(ref r, i) = rgba32.R; diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs index bbac9b9d8e..d2bec0b49b 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs @@ -254,9 +254,9 @@ internal class AdaptiveHistogramEqualizationSlidingWindowProcessor : His [MethodImpl(InliningOptions.ShortMethod)] private static void AddPixelsToHistogram(ref Vector4 greyValuesBase, ref int histogramBase, int luminanceLevels, int length) { - for (nint idx = 0; idx < length; idx++) + for (nuint idx = 0; idx < (uint)length; idx++) { - int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, (uint)idx), luminanceLevels); + int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); Unsafe.Add(ref histogramBase, (uint)luminance)++; } } @@ -271,9 +271,9 @@ internal class AdaptiveHistogramEqualizationSlidingWindowProcessor : His [MethodImpl(InliningOptions.ShortMethod)] private static void RemovePixelsFromHistogram(ref Vector4 greyValuesBase, ref int histogramBase, int luminanceLevels, int length) { - for (int idx = 0; idx < length; idx++) + for (nuint idx = 0; idx < (uint)length; idx++) { - int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, (uint)idx), luminanceLevels); + int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels); Unsafe.Add(ref histogramBase, (uint)luminance)--; } } diff --git a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs index 80f2b15bc1..6ac36f3ce0 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs @@ -73,7 +73,7 @@ internal abstract class HistogramEqualizationProcessor : ImageProcessor< int cdfMin = 0; bool cdfMinFound = false; - for (nint i = 0; i <= (uint)maxIdx; i++) + for (nuint i = 0; i <= (uint)maxIdx; i++) { histSum += Unsafe.Add(ref histogramBase, i); if (!cdfMinFound && histSum != 0) @@ -101,7 +101,7 @@ internal abstract class HistogramEqualizationProcessor : ImageProcessor< int sumOverClip = 0; ref int histogramBase = ref MemoryMarshal.GetReference(histogram); - for (nint i = 0; i < (uint)histogram.Length; i++) + for (nuint i = 0; i < (uint)histogram.Length; i++) { ref int histogramLevel = ref Unsafe.Add(ref histogramBase, i); if (histogramLevel > clipLimit) @@ -115,7 +115,7 @@ internal abstract class HistogramEqualizationProcessor : ImageProcessor< int addToEachBin = sumOverClip > 0 ? (int)MathF.Floor(sumOverClip / this.luminanceLevelsFloat) : 0; if (addToEachBin > 0) { - for (nint i = 0; i < (uint)histogram.Length; i++) + for (nuint i = 0; i < (uint)histogram.Length; i++) { Unsafe.Add(ref histogramBase, i) += addToEachBin; } @@ -124,8 +124,8 @@ internal abstract class HistogramEqualizationProcessor : ImageProcessor< int residual = sumOverClip - (addToEachBin * this.LuminanceLevels); if (residual != 0) { - int residualStep = Math.Max(this.LuminanceLevels / residual, 1); - for (nint i = 0; i < (uint)this.LuminanceLevels && residual > 0; i += residualStep, residual--) + uint residualStep = (uint)Math.Max(this.LuminanceLevels / residual, 1); + for (nuint i = 0; i < (uint)this.LuminanceLevels && residual > 0; i += residualStep, residual--) { ref int histogramLevel = ref Unsafe.Add(ref histogramBase, i); histogramLevel++; diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs index e492011788..c1907bb520 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs @@ -100,7 +100,7 @@ internal partial class ResizeKernelMap : IDisposable /// Returns a for an index value between 0 and DestinationSize - 1. /// [MethodImpl(InliningOptions.ShortMethod)] - internal ref ResizeKernel GetKernel(nint destIdx) => ref this.kernels[destIdx]; + internal ref ResizeKernel GetKernel(nuint destIdx) => ref this.kernels[(int)destIdx]; /// /// Computes the weights to apply at each pixel when resizing. diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs index 10525641ca..cce27a401c 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs @@ -119,7 +119,7 @@ internal sealed class ResizeWorker : IDisposable for (int y = rowInterval.Min; y < rowInterval.Max; y++) { // Ensure offsets are normalized for cropping and padding. - ResizeKernel kernel = this.verticalKernelMap.GetKernel(y - this.targetOrigin.Y); + ResizeKernel kernel = this.verticalKernelMap.GetKernel((uint)(y - this.targetOrigin.Y)); while (kernel.StartIndex + kernel.Length > this.currentWindow.Max) { @@ -132,9 +132,9 @@ internal sealed class ResizeWorker : IDisposable ref Vector4 fpBase = ref transposedFirstPassBufferSpan[top]; - for (nint x = 0; x < (right - left); x++) + for (nuint x = 0; x < (uint)(right - left); x++) { - ref Vector4 firstPassColumnBase = ref Unsafe.Add(ref fpBase, x * (nint)(uint)this.workerHeight); + ref Vector4 firstPassColumnBase = ref Unsafe.Add(ref fpBase, x * (uint)this.workerHeight); // Destination color components Unsafe.Add(ref tempRowBase, x) = kernel.ConvolveCore(ref firstPassColumnBase); @@ -169,9 +169,9 @@ internal sealed class ResizeWorker : IDisposable Span tempRowSpan = this.tempRowBuffer.GetSpan(); Span transposedFirstPassBufferSpan = this.transposedFirstPassBuffer.DangerousGetSingleSpan(); - int left = this.targetWorkingRect.Left; - int right = this.targetWorkingRect.Right; - int targetOriginX = this.targetOrigin.X; + nuint left = (uint)this.targetWorkingRect.Left; + nuint right = (uint)this.targetWorkingRect.Right; + nuint targetOriginX = (uint)this.targetOrigin.X; for (int y = calculationInterval.Min; y < calculationInterval.Max; y++) { Span sourceRow = this.source.DangerousGetRowSpan(y); @@ -186,13 +186,13 @@ internal sealed class ResizeWorker : IDisposable // Span firstPassSpan = transposedFirstPassBufferSpan.Slice(y - this.currentWindow.Min); ref Vector4 firstPassBaseRef = ref transposedFirstPassBufferSpan[y - this.currentWindow.Min]; - for (nint x = left, z = 0; x < (nint)(uint)right; x++, z++) + for (nuint x = left, z = 0; x < right; x++, z++) { ResizeKernel kernel = this.horizontalKernelMap.GetKernel(x - targetOriginX); // optimization for: // firstPassSpan[x * this.workerHeight] = kernel.Convolve(tempRowSpan); - Unsafe.Add(ref firstPassBaseRef, z * (nint)(uint)this.workerHeight) = kernel.Convolve(tempRowSpan); + Unsafe.Add(ref firstPassBaseRef, z * (uint)this.workerHeight) = kernel.Convolve(tempRowSpan); } } } diff --git a/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs b/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs index ed129fca2f..f0eeb5afb7 100644 --- a/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs +++ b/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs @@ -47,7 +47,7 @@ public abstract class FromVector4 { ref Vector4 s = ref MemoryMarshal.GetReference(this.source.GetSpan()); ref TPixel d = ref MemoryMarshal.GetReference(this.destination.GetSpan()); - for (nint i = 0; i < (uint)this.Count; i++) + for (nuint i = 0; i < (uint)this.Count; i++) { Unsafe.Add(ref d, i).FromVector4(Unsafe.Add(ref s, i)); } @@ -103,7 +103,7 @@ public class FromVector4Rgba32 : FromVector4 Span src = MemoryMarshal.Cast(this.source.GetSpan()); Span dest = MemoryMarshal.Cast(this.destination.GetSpan()); - nint n = (nint)(uint)dest.Length / Vector.Count; + nuint n = (uint)(dest.Length / Vector.Count); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(src)); @@ -114,7 +114,7 @@ public class FromVector4Rgba32 : FromVector4 var maxBytes = Vector256.Create(255f); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { ref Vector256 s = ref Unsafe.Add(ref sourceBase, i * 4); diff --git a/tests/ImageSharp.Benchmarks/Bulk/PremultiplyVector4.cs b/tests/ImageSharp.Benchmarks/Bulk/PremultiplyVector4.cs index 355216de34..4e2d2d36e9 100644 --- a/tests/ImageSharp.Benchmarks/Bulk/PremultiplyVector4.cs +++ b/tests/ImageSharp.Benchmarks/Bulk/PremultiplyVector4.cs @@ -17,7 +17,7 @@ public class PremultiplyVector4 { ref Vector4 baseRef = ref MemoryMarshal.GetReference(Vectors); - for (nint i = 0; i < (uint)Vectors.Length; i++) + for (nuint i = 0; i < (uint)Vectors.Length; i++) { ref Vector4 v = ref Unsafe.Add(ref baseRef, i); Premultiply(ref v); @@ -29,7 +29,7 @@ public class PremultiplyVector4 { ref Vector4 baseRef = ref MemoryMarshal.GetReference(Vectors); - for (nint i = 0; i < (uint)Vectors.Length; i++) + for (nuint i = 0; i < (uint)Vectors.Length; i++) { ref Vector4 v = ref Unsafe.Add(ref baseRef, i); Numerics.Premultiply(ref v); diff --git a/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs b/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs index 913ab24dc1..ce3fb70c88 100644 --- a/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs +++ b/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs @@ -54,13 +54,13 @@ public class ToVector4_Rgba32 : ToVector4 Span sBytes = MemoryMarshal.Cast(this.source.GetSpan()); Span dFloats = MemoryMarshal.Cast(this.destination.GetSpan()); - nint n = (nint)(uint)dFloats.Length / Vector.Count; + nuint n = (uint)(dFloats.Length / Vector.Count); ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference((ReadOnlySpan)sBytes)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dFloats)); ref Vector destBaseU = ref Unsafe.As, Vector>(ref destBase); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { Vector b = Unsafe.Add(ref sourceBase, i); @@ -75,10 +75,10 @@ public class ToVector4_Rgba32 : ToVector4 Unsafe.Add(ref d, 3) = w3; } - n = (nint)(uint)dFloats.Length / Vector.Count; + n = (uint)(dFloats.Length / Vector.Count); var scale = new Vector(1f / 255f); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { ref Vector dRef = ref Unsafe.Add(ref destBase, i); @@ -96,13 +96,13 @@ public class ToVector4_Rgba32 : ToVector4 Span sBytes = MemoryMarshal.Cast(this.source.GetSpan()); Span dFloats = MemoryMarshal.Cast(this.destination.GetSpan()); - nint n = (nint)(uint)dFloats.Length / Vector.Count; + nuint n = (uint)(dFloats.Length / Vector.Count); ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference((ReadOnlySpan)sBytes)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dFloats)); var scale = new Vector(1f / 255f); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { Vector b = Unsafe.Add(ref sourceBase, i); diff --git a/tests/ImageSharp.Benchmarks/Bulk/UnPremultiplyVector4.cs b/tests/ImageSharp.Benchmarks/Bulk/UnPremultiplyVector4.cs index 309eea34fd..95fdd9a8c3 100644 --- a/tests/ImageSharp.Benchmarks/Bulk/UnPremultiplyVector4.cs +++ b/tests/ImageSharp.Benchmarks/Bulk/UnPremultiplyVector4.cs @@ -17,7 +17,7 @@ public class UnPremultiplyVector4 { ref Vector4 baseRef = ref MemoryMarshal.GetReference(Vectors); - for (nint i = 0; i < (uint)Vectors.Length; i++) + for (nuint i = 0; i < (uint)Vectors.Length; i++) { ref Vector4 v = ref Unsafe.Add(ref baseRef, i); @@ -30,7 +30,7 @@ public class UnPremultiplyVector4 { ref Vector4 baseRef = ref MemoryMarshal.GetReference(Vectors); - for (nint i = 0; i < (uint)Vectors.Length; i++) + for (nuint i = 0; i < (uint)Vectors.Length; i++) { ref Vector4 v = ref Unsafe.Add(ref baseRef, i); Numerics.UnPremultiply(ref v); diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo1x1.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo1x1.cs index abdd6908da..14598c747a 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo1x1.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo1x1.cs @@ -82,7 +82,7 @@ public unsafe class Block8x8F_CopyTo1x1 { ref Block8x8F s = ref this.block; ref float origin = ref Unsafe.AsRef(this.bufferPtr); - nint stride = (nint)(uint)Width; + nuint stride = (uint)Width; ref Vector d0 = ref Unsafe.As>(ref origin); ref Vector d1 = ref Unsafe.As>(ref Unsafe.Add(ref origin, stride)); @@ -117,7 +117,7 @@ public unsafe class Block8x8F_CopyTo1x1 { ref Block8x8F s = ref this.block; ref float origin = ref Unsafe.AsRef(this.bufferPtr); - nint stride = (nint)(uint)Width; + nuint stride = (uint)Width; ref Vector d0 = ref Unsafe.As>(ref origin); ref Vector d1 = ref Unsafe.As>(ref Unsafe.Add(ref origin, stride)); @@ -141,7 +141,7 @@ public unsafe class Block8x8F_CopyTo1x1 [Benchmark] public void UseVector8_V3() { - nint stride = (nint)(uint)Width * sizeof(float); + nuint stride = (uint)Width * sizeof(float); ref float d = ref this.unpinnedBuffer[0]; ref Vector s = ref Unsafe.As>(ref this.block); @@ -254,7 +254,7 @@ public unsafe class Block8x8F_CopyTo1x1 [Benchmark] public void UseVector256_Avx2_Variant3_RefCast() { - nint stride = (nint)(uint)Width; + nuint stride = (uint)Width; ref float d = ref this.unpinnedBuffer[0]; ref Vector256 s = ref Unsafe.As>(ref this.block); @@ -282,7 +282,7 @@ public unsafe class Block8x8F_CopyTo1x1 [Benchmark] public void UseVector256_Avx2_Variant3_RefCast_Mod() { - nint stride = (nint)(uint)Width * sizeof(float); + nuint stride = (uint)Width * sizeof(float); ref float d = ref this.unpinnedBuffer[0]; ref Vector256 s = ref Unsafe.As>(ref this.block); diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs index 2cc084885f..8a520b22d3 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs @@ -54,7 +54,7 @@ public unsafe class Block8x8F_Round { ref float b = ref Unsafe.As(ref this.block); - for (nint i = 0; i < Block8x8F.Size; i++) + for (nuint i = 0; i < Block8x8F.Size; i++) { ref float v = ref Unsafe.Add(ref b, i); v = (float)Math.Round(v); @@ -178,7 +178,7 @@ public unsafe class Block8x8F_Round { ref Vector128 p = ref Unsafe.As>(ref this.block); p = Sse41.RoundToNearestInteger(p); - nint offset = sizeof(Vector128); + nuint offset = (uint)sizeof(Vector128); p = Sse41.RoundToNearestInteger(p); p = ref Unsafe.AddByteOffset(ref p, offset); @@ -218,7 +218,7 @@ public unsafe class Block8x8F_Round { ref Vector128 p = ref Unsafe.As>(ref this.block); p = Sse41.RoundToNearestInteger(p); - nint offset = sizeof(Vector128); + nuint offset = (uint)sizeof(Vector128); for (int i = 0; i < 15; i++) { @@ -231,7 +231,7 @@ public unsafe class Block8x8F_Round public unsafe void Sse41_V4() { ref Vector128 p = ref Unsafe.As>(ref this.block); - nint offset = sizeof(Vector128); + nuint offset = (uint)sizeof(Vector128); ref Vector128 a = ref p; ref Vector128 b = ref Unsafe.AddByteOffset(ref a, offset); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromRgba32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromRgba32.cs index 29e03111b9..8d16849825 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromRgba32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromRgba32.cs @@ -34,7 +34,7 @@ public abstract class PixelConversion_ConvertFromRgba32 ref T destBaseRef = ref this.Dest[0]; ref Rgba32 sourceBaseRef = ref this.Source[0]; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i).FromRgba32(ref Unsafe.Add(ref sourceBaseRef, i)); } @@ -48,7 +48,7 @@ public abstract class PixelConversion_ConvertFromRgba32 ref T destBaseRef = ref this.Dest[0]; ref Rgba32 sourceBaseRef = ref this.Source[0]; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i).FromRgba32(Unsafe.Add(ref sourceBaseRef, i)); } @@ -62,7 +62,7 @@ public abstract class PixelConversion_ConvertFromRgba32 ref T destBaseRef = ref this.Dest[0]; ref Rgba32 sourceBaseRef = ref this.Source[0]; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgba32 s = ref Unsafe.Add(ref sourceBaseRef, i); Unsafe.Add(ref destBaseRef, i).FromBytes(s.R, s.G, s.B, s.A); @@ -111,7 +111,7 @@ public class PixelConversion_ConvertFromRgba32_Compatible : PixelConversion_Conv ref Rgba32 sBase = ref this.CompatibleMemLayoutRunner.Source[0]; ref Rgba32 dBase = ref Unsafe.As(ref this.CompatibleMemLayoutRunner.Dest[0]); - for (nint i = 0; i < (uint)this.Count; i++) + for (nuint i = 0; i < (uint)this.Count; i++) { Unsafe.Add(ref dBase, i) = Unsafe.Add(ref sBase, i); } @@ -151,7 +151,7 @@ public class PixelConversion_ConvertFromRgba32_Permuted_RgbaToArgb : PixelConver ref Rgba32 sBase = ref this.PermutedRunnerRgbaToArgb.Source[0]; ref TestArgb dBase = ref this.PermutedRunnerRgbaToArgb.Dest[0]; - for (nint i = 0; i < (uint)this.Count; i++) + for (nuint i = 0; i < (uint)this.Count; i++) { Rgba32 s = Unsafe.Add(ref sBase, i); ref TestArgb d = ref Unsafe.Add(ref dBase, i); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromVector4.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromVector4.cs index faf23efe09..dd85d06417 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromVector4.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertFromVector4.cs @@ -71,7 +71,7 @@ public class PixelConversion_ConvertFromVector4 ref T destBaseRef = ref this.dest[0]; ref Vector4 sourceBaseRef = ref this.source[0]; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i).FromVector4(ref Unsafe.Add(ref sourceBaseRef, i)); } @@ -85,7 +85,7 @@ public class PixelConversion_ConvertFromVector4 ref T destBaseRef = ref this.dest[0]; ref Vector4 sourceBaseRef = ref this.source[0]; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i).FromVector4(Unsafe.Add(ref sourceBaseRef, i)); } diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32.cs index ef1ebdd429..1a03a0c04f 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32.cs @@ -38,7 +38,7 @@ public class PixelConversion_ConvertToRgba32 ref T sourceBaseRef = ref this.source[0]; ref Rgba32 destBaseRef = ref this.dest[0]; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i) = Unsafe.Add(ref sourceBaseRef, i).ToRgba32(); } @@ -52,7 +52,7 @@ public class PixelConversion_ConvertToRgba32 ref T sourceBaseRef = ref this.source[0]; ref Rgba32 destBaseRef = ref this.dest[0]; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Unsafe.Add(ref sourceBaseRef, i).CopyToRgba32(ref Unsafe.Add(ref destBaseRef, i)); } diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation.cs index 29412e6ed6..69a71734a3 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation.cs @@ -33,7 +33,7 @@ public class PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation Rgba32 temp; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { temp = Unsafe.Add(ref sourceBaseRef, i).ToRgba32(); @@ -54,7 +54,7 @@ public class PixelConversion_ConvertToRgba32_AsPartOfCompositeOperation Rgba32 temp = default; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Unsafe.Add(ref sourceBaseRef, i).CopyToRgba32(ref temp); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4.cs index 29e8b00b6f..9b498b0f2e 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4.cs @@ -30,7 +30,7 @@ public class PixelConversion_ConvertToVector4 ref T sourceBaseRef = ref this.source[0]; ref Vector4 destBaseRef = ref this.dest[0]; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Unsafe.Add(ref destBaseRef, i) = Unsafe.Add(ref sourceBaseRef, i).ToVector4(); } @@ -44,7 +44,7 @@ public class PixelConversion_ConvertToVector4 ref T sourceBaseRef = ref this.source[0]; ref Vector4 destBaseRef = ref this.dest[0]; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Unsafe.Add(ref sourceBaseRef, i).CopyToVector4(ref Unsafe.Add(ref destBaseRef, i)); } diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4_AsPartOfCompositeOperation.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4_AsPartOfCompositeOperation.cs index 65b1717349..50c3d0d131 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4_AsPartOfCompositeOperation.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4_AsPartOfCompositeOperation.cs @@ -32,7 +32,7 @@ public class PixelConversion_ConvertToVector4_AsPartOfCompositeOperation Vector4 temp; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { temp = Unsafe.Add(ref sourceBaseRef, i).ToVector4(); @@ -53,7 +53,7 @@ public class PixelConversion_ConvertToVector4_AsPartOfCompositeOperation Vector4 temp = default; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { Unsafe.Add(ref sourceBaseRef, i).CopyToVector4(ref temp); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs index 5c9bfd763a..e3677d238d 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs @@ -92,7 +92,7 @@ public unsafe class PixelConversion_PackFromRgbPlanes ref byte b = ref this.rBuf[0]; ref Rgb24 rgb = ref this.rgbBuf[0]; - for (nint i = 0; i < (uint)this.Count; i++) + for (nuint i = 0; i < (uint)this.Count; i++) { ref Rgb24 d = ref Unsafe.Add(ref rgb, i); d.R = Unsafe.Add(ref r, i); @@ -110,7 +110,7 @@ public unsafe class PixelConversion_PackFromRgbPlanes ref Rgb24 rgb = ref this.rgbBuf[0]; int count = this.Count / 8; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb24 d0 = ref Unsafe.Add(ref rgb, i * 8); ref Rgb24 d1 = ref Unsafe.Add(ref d0, 1); @@ -168,7 +168,7 @@ public unsafe class PixelConversion_PackFromRgbPlanes ref Rgb24 rgb = ref this.rgbBuf[0]; int count = this.Count / 4; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { ref Rgb24 d0 = ref Unsafe.Add(ref rgb, i * 4); ref Rgb24 d1 = ref Unsafe.Add(ref d0, 1); @@ -205,14 +205,14 @@ public unsafe class PixelConversion_PackFromRgbPlanes ref Vector256 bBase = ref Unsafe.As>(ref this.bFloat[0]); ref Vector256 resultBase = ref Unsafe.As>(ref this.rgbaFloat[0]); - nint count = (nint)(uint)this.Count / Vector256.Count; + nuint count = (uint)(this.Count / Vector256.Count); ref byte control = ref MemoryMarshal.GetReference(SimdUtils.HwIntrinsics.PermuteMaskEvenOdd8x32); Vector256 vcontrol = Unsafe.As>(ref control); var va = Vector256.Create(1F); - for (nint i = 0; i < count; i++) + for (nuint i = 0; i < count; i++) { Vector256 r = Unsafe.Add(ref rBase, i); Vector256 g = Unsafe.Add(ref gBase, i); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Argb32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Argb32.cs index f1d08b9fb9..0ee507832a 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Argb32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Argb32.cs @@ -31,7 +31,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref Rgba32 sBase = ref this.source[0]; ref Argb32 dBase = ref this.dest[0]; - for (nint i = 0; i < (uint)this.Count; i++) + for (nuint i = 0; i < (uint)this.Count; i++) { Rgba32 s = Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i).FromRgba32(s); @@ -45,7 +45,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref Rgba32 sBase = ref MemoryMarshal.GetReference(source); ref TPixel dBase = ref MemoryMarshal.GetReference(dest); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { Rgba32 s = Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i).FromRgba32(s); @@ -64,7 +64,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref Rgba32 sBase = ref this.source[0]; ref Argb32 dBase = ref this.dest[0]; - for (nint i = 0; i < (uint)this.Count; i += 2) + for (nuint i = 0; i < (uint)this.Count; i += 2) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); Rgba32 s1 = Unsafe.Add(ref s0, 1); @@ -81,7 +81,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref Rgba32 sBase = ref this.source[0]; ref Argb32 dBase = ref this.dest[0]; - for (nint i = 0; i < (uint)this.Count; i += 4) + for (nuint i = 0; i < (uint)this.Count; i += 4) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); ref Rgba32 s1 = ref Unsafe.Add(ref s0, 1); @@ -105,7 +105,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref uint sBase = ref Unsafe.As(ref this.source[0]); ref uint dBase = ref Unsafe.As(ref this.dest[0]); - for (nint i = 0; i < (uint)this.Count; i++) + for (nuint i = 0; i < (uint)this.Count; i++) { uint s = Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i) = FromRgba32.ToArgb32(s); @@ -118,7 +118,7 @@ public class PixelConversion_Rgba32_To_Argb32 ref ulong sBase = ref Unsafe.As(ref this.source[0]); ref ulong dBase = ref Unsafe.As(ref this.dest[0]); - for (nint i = 0; i < (uint)this.Count / 2; i++) + for (nuint i = 0; i < (uint)this.Count / 2; i++) { ulong s = Unsafe.Add(ref sBase, i); uint lo = (uint)s; diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs index 0da28c897d..499f3483dc 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs @@ -52,7 +52,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref this.source[0]; ref Bgra32 dBase = ref this.dest[0]; - for (nint i = 0; i < (uint)this.Count; i++) + for (nuint i = 0; i < (uint)this.Count; i++) { ref Rgba32 s = ref Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i).FromRgba32(s); @@ -66,7 +66,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref MemoryMarshal.GetReference(source); ref TPixel dBase = ref MemoryMarshal.GetReference(dest); - for (nint i = 0; i < (uint)source.Length; i++) + for (nuint i = 0; i < (uint)source.Length; i++) { ref Rgba32 s = ref Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i).FromRgba32(s); @@ -85,7 +85,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref this.source[0]; ref Bgra32 dBase = ref this.dest[0]; - for (nint i = 0; i < (uint)this.Count; i += 2) + for (nuint i = 0; i < (uint)this.Count; i += 2) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); Rgba32 s1 = Unsafe.Add(ref s0, 1); @@ -102,7 +102,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref this.source[0]; ref Bgra32 dBase = ref this.dest[0]; - for (nint i = 0; i < (uint)this.Count; i += 4) + for (nuint i = 0; i < (uint)this.Count; i += 4) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); ref Rgba32 s1 = ref Unsafe.Add(ref s0, 1); @@ -127,7 +127,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref MemoryMarshal.GetReference(source); ref TPixel dBase = ref MemoryMarshal.GetReference(dest); - for (nint i = 0; i < (uint)source.Length; i += 4) + for (nuint i = 0; i < (uint)source.Length; i += 4) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); ref Rgba32 s1 = ref Unsafe.Add(ref s0, 1); @@ -157,7 +157,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Rgba32 sBase = ref this.source[0]; ref Bgra32 dBase = ref this.dest[0]; - for (nint i = 0; i < (uint)this.Count / 4; i += 4) + for (nuint i = 0; i < (uint)this.Count / 4; i += 4) { ref Rgba32 s0 = ref Unsafe.Add(ref sBase, i); ref Rgba32 s1 = ref Unsafe.Add(ref s0, 1); @@ -196,7 +196,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref uint sBase = ref Unsafe.As(ref this.source[0]); ref uint dBase = ref Unsafe.As(ref this.dest[0]); - for (nint i = 0; i < (uint)this.Count; i++) + for (nuint i = 0; i < (uint)this.Count; i++) { uint s = Unsafe.Add(ref sBase, i); Unsafe.Add(ref dBase, i) = FromRgba32.ToBgra32(s); @@ -209,7 +209,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Tuple4OfUInt32 sBase = ref Unsafe.As(ref this.source[0]); ref Tuple4OfUInt32 dBase = ref Unsafe.As(ref this.dest[0]); - for (nint i = 0; i < (uint)this.Count / 4; i++) + for (nuint i = 0; i < (uint)this.Count / 4; i++) { ref Tuple4OfUInt32 d = ref Unsafe.Add(ref dBase, i); d = Unsafe.Add(ref sBase, i); @@ -222,7 +222,7 @@ public class PixelConversion_Rgba32_To_Bgra32 { ref Tuple4OfUInt32 sBase = ref Unsafe.As(ref this.source[0]); - for (nint i = 0; i < (uint)this.Count / 4; i++) + for (nuint i = 0; i < (uint)this.Count / 4; i++) { Unsafe.Add(ref sBase, i).ConvertMe(); } @@ -234,7 +234,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref Octet sBase = ref Unsafe.As>(ref this.source[0]); ref Octet dBase = ref Unsafe.As>(ref this.dest[0]); - for (nint i = 0; i < (uint)this.Count / 8; i++) + for (nuint i = 0; i < (uint)this.Count / 8; i++) { BitopsSimdImpl(ref Unsafe.Add(ref sBase, i), ref Unsafe.Add(ref dBase, i)); } @@ -289,7 +289,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref uint sBase = ref Unsafe.As(ref this.source[0]); ref uint dBase = ref Unsafe.As(ref this.dest[0]); - for (nint i = 0; i < (uint)this.Count; i++) + for (nuint i = 0; i < (uint)this.Count; i++) { ref uint s0 = ref Unsafe.Add(ref sBase, i); uint s1 = Unsafe.Add(ref s0, 1); @@ -306,7 +306,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref ulong sBase = ref Unsafe.As(ref this.source[0]); ref ulong dBase = ref Unsafe.As(ref this.dest[0]); - for (nint i = 0; i < (uint)this.Count / 2; i++) + for (nuint i = 0; i < (uint)this.Count / 2; i++) { ulong s = Unsafe.Add(ref sBase, i); uint lo = (uint)s; @@ -326,7 +326,7 @@ public class PixelConversion_Rgba32_To_Bgra32 ref ulong sBase = ref Unsafe.As(ref this.source[0]); ref ulong dBase = ref Unsafe.As(ref this.dest[0]); - for (nint i = 0; i < (uint)this.Count / 2; i++) + for (nuint i = 0; i < (uint)this.Count / 2; i++) { ulong s = Unsafe.Add(ref sBase, i); uint lo = (uint)s; diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs index 57c7b6faf7..010e1f52b3 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs @@ -25,14 +25,14 @@ public class UInt32ToSingle { ref Vector b = ref Unsafe.As>(ref this.data[0]); - nint n = Count / Vector.Count; + nuint n = (uint)(Count / Vector.Count); var bVec = new Vector(256.0f / 255.0f); var magicFloat = new Vector(32768.0f); var magicInt = new Vector(1191182336); // reinterpreted value of 32768.0f var mask = new Vector(255); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { ref Vector df = ref Unsafe.Add(ref b, i); @@ -50,14 +50,14 @@ public class UInt32ToSingle [Benchmark] public void StandardSimd() { - nint n = Count / Vector.Count; + nuint n = (uint)(Count / Vector.Count); ref Vector bf = ref Unsafe.As>(ref this.data[0]); ref Vector bu = ref Unsafe.As, Vector>(ref bf); var scale = new Vector(1f / 255f); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { Vector u = Unsafe.Add(ref bu, i); Vector v = Vector.ConvertToSingle(u); @@ -69,14 +69,14 @@ public class UInt32ToSingle [Benchmark] public void StandardSimdFromInt() { - nint n = Count / Vector.Count; + nuint n = (uint)(Count / Vector.Count); ref Vector bf = ref Unsafe.As>(ref this.data[0]); ref Vector bu = ref Unsafe.As, Vector>(ref bf); var scale = new Vector(1f / 255f); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { Vector u = Unsafe.Add(ref bu, i); Vector v = Vector.ConvertToSingle(u); @@ -88,12 +88,12 @@ public class UInt32ToSingle [Benchmark] public void StandardSimdFromInt_RefCast() { - nint n = Count / Vector.Count; + nuint n = (uint)(Count / Vector.Count); ref Vector bf = ref Unsafe.As>(ref this.data[0]); var scale = new Vector(1f / 255f); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { ref Vector fRef = ref Unsafe.Add(ref bf, i); diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs index 7da2626dcc..32027729b2 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs @@ -63,9 +63,9 @@ public class VectorFetching var v = new Vector(this.testValue); ref Vector start = ref Unsafe.As>(ref this.data[0]); - nint n = (nint)(uint)this.InputSize / Vector.Count; + nuint n = (uint)(this.InputSize / Vector.Count); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { ref Vector p = ref Unsafe.Add(ref start, i); @@ -82,9 +82,9 @@ public class VectorFetching var v = new Vector(this.testValue); ref Vector start = ref Unsafe.As>(ref this.data[0]); - nint n = (nint)(uint)this.InputSize / Vector.Count; + nuint n = (uint)(this.InputSize / Vector.Count); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { ref Vector a = ref Unsafe.Add(ref start, i); a *= v; @@ -100,9 +100,9 @@ public class VectorFetching ref Vector start = ref Unsafe.As>(ref MemoryMarshal.GetReference(span)); - nint n = (nint)(uint)this.InputSize / Vector.Count; + nuint n = (uint)(this.InputSize / Vector.Count); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { ref Vector a = ref Unsafe.Add(ref start, i); a *= v; diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs index 586618fcb1..6ad7827eb1 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs @@ -33,7 +33,7 @@ public class WidenBytesToUInt32 ref Octet sBase = ref Unsafe.As>(ref this.source[0]); ref Octet dBase = ref Unsafe.As>(ref this.dest[0]); - for (nint i = 0; i < N; i++) + for (nuint i = 0; i < N; i++) { Unsafe.Add(ref dBase, i).LoadFrom(ref Unsafe.Add(ref sBase, i)); } @@ -42,12 +42,12 @@ public class WidenBytesToUInt32 [Benchmark] public void Simd() { - nint n = Count / Vector.Count; + nuint n = (uint)(Count / Vector.Count); ref Vector sBase = ref Unsafe.As>(ref this.source[0]); ref Vector dBase = ref Unsafe.As>(ref this.dest[0]); - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { Vector b = Unsafe.Add(ref sBase, i); diff --git a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsSingleVector.cs b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsSingleVector.cs index 33f5720aab..ecf8b125f7 100644 --- a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsSingleVector.cs +++ b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsSingleVector.cs @@ -58,7 +58,7 @@ public class PorterDuffBulkVsSingleVector Vector256 result = default; Vector256 opacity = Vector256.Create(.5F); int count = this.backdrop.Length / 2; - for (nint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < (uint)count; i++) { result = PorterDuffFunctions.NormalSrcOver(Unsafe.Add(ref backdrop, i), Unsafe.Add(ref source, i), opacity); } diff --git a/tests/ImageSharp.Tests/Common/SimdUtilsTests.Shuffle.cs b/tests/ImageSharp.Tests/Common/SimdUtilsTests.Shuffle.cs index 960b0613e6..ba37ee1661 100644 --- a/tests/ImageSharp.Tests/Common/SimdUtilsTests.Shuffle.cs +++ b/tests/ImageSharp.Tests/Common/SimdUtilsTests.Shuffle.cs @@ -493,10 +493,10 @@ public partial class SimdUtilsTests SimdUtils.Shuffle.InverseMMShuffle( control, - out int p3, - out int p2, - out int p1, - out int p0); + out uint p3, + out uint p2, + out uint p1, + out uint p0); for (int i = 0; i < expected.Length; i += 4) { @@ -524,10 +524,10 @@ public partial class SimdUtilsTests SimdUtils.Shuffle.InverseMMShuffle( control, - out int p3, - out int p2, - out int p1, - out int p0); + out uint p3, + out uint p2, + out uint p1, + out uint p0); for (int i = 0; i < expected.Length; i += 4) { @@ -555,10 +555,10 @@ public partial class SimdUtilsTests SimdUtils.Shuffle.InverseMMShuffle( control, - out int _, - out int p2, - out int p1, - out int p0); + out uint _, + out uint p2, + out uint p1, + out uint p0); for (int i = 0; i < expected.Length; i += 3) { @@ -586,10 +586,10 @@ public partial class SimdUtilsTests SimdUtils.Shuffle.InverseMMShuffle( control, - out int p3, - out int p2, - out int p1, - out int p0); + out uint p3, + out uint p2, + out uint p1, + out uint p0); for (int i = 0, j = 0; i < expected.Length; i += 4, j += 3) { @@ -607,10 +607,10 @@ public partial class SimdUtilsTests temp[2] = source[j + 2]; temp[3] = byte.MaxValue; - expected[i] = temp[p0]; - expected[i + 1] = temp[p1]; - expected[i + 2] = temp[p2]; - expected[i + 3] = temp[p3]; + expected[i] = temp[(int)p0]; + expected[i + 1] = temp[(int)p1]; + expected[i + 2] = temp[(int)p2]; + expected[i + 3] = temp[(int)p3]; } convert(source, result); @@ -637,10 +637,10 @@ public partial class SimdUtilsTests SimdUtils.Shuffle.InverseMMShuffle( control, - out int _, - out int p2, - out int p1, - out int p0); + out uint _, + out uint p2, + out uint p1, + out uint p0); for (int i = 0, j = 0; i < expected.Length; i += 3, j += 4) { diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderFilterTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderFilterTests.cs index e50e40bd22..796d35bf72 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderFilterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderFilterTests.cs @@ -287,7 +287,7 @@ public class PngEncoderFilterTests : MeasureFixture break; case PngFilterMethod.Average: - AverageFilter.Encode(this.previousScanline, this.scanline, this.resultBuffer, this.bpp, out sum); + AverageFilter.Encode(this.previousScanline, this.scanline, this.resultBuffer, (uint)this.bpp, out sum); break; case PngFilterMethod.Paeth: diff --git a/tests/ImageSharp.Tests/Formats/Png/ReferenceImplementations.cs b/tests/ImageSharp.Tests/Formats/Png/ReferenceImplementations.cs index 7610023afc..d57a775876 100644 --- a/tests/ImageSharp.Tests/Formats/Png/ReferenceImplementations.cs +++ b/tests/ImageSharp.Tests/Formats/Png/ReferenceImplementations.cs @@ -34,8 +34,8 @@ internal static partial class ReferenceImplementations // Paeth(x) = Raw(x) - PaethPredictor(Raw(x-bpp), Prior(x), Prior(x - bpp)) resultBaseRef = 4; - nint x = 0; - for (; x < (nint)(uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) + int x = 0; + for (; x < bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -45,7 +45,7 @@ internal static partial class ReferenceImplementations sum += Numerics.Abs(unchecked((sbyte)res)); } - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (nint)(uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (int xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte left = Unsafe.Add(ref scanBaseRef, xLeft); @@ -77,8 +77,8 @@ internal static partial class ReferenceImplementations // Sub(x) = Raw(x) - Raw(x-bpp) resultBaseRef = 1; - nint x = 0; - for (; x < (nint)(uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) + int x = 0; + for (; x < bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); ++x; @@ -87,7 +87,7 @@ internal static partial class ReferenceImplementations sum += Numerics.Abs(unchecked((sbyte)res)); } - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (nint)(uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (int xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte prev = Unsafe.Add(ref scanBaseRef, xLeft); @@ -119,9 +119,9 @@ internal static partial class ReferenceImplementations // Up(x) = Raw(x) - Prior(x) resultBaseRef = 2; - nint x = 0; + int x = 0; - for (; x < (nint)(uint)scanline.Length; /* Note: ++x happens in the body to avoid one add operation */) + for (; x < scanline.Length; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -154,8 +154,8 @@ internal static partial class ReferenceImplementations // Average(x) = Raw(x) - floor((Raw(x-bpp)+Prior(x))/2) resultBaseRef = 3; - nint x = 0; - for (; x < (nint)(uint)bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) + int x = 0; + for (; x < bytesPerPixel; /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte above = Unsafe.Add(ref prevBaseRef, x); @@ -165,7 +165,7 @@ internal static partial class ReferenceImplementations sum += Numerics.Abs(unchecked((sbyte)res)); } - for (nint xLeft = x - (nint)(uint)bytesPerPixel; x < (nint)(uint)scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) + for (int xLeft = x - bytesPerPixel; x < scanline.Length; ++xLeft /* Note: ++x happens in the body to avoid one add operation */) { byte scan = Unsafe.Add(ref scanBaseRef, x); byte left = Unsafe.Add(ref scanBaseRef, xLeft); diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs b/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs index 521270e3be..006cb9eb61 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs @@ -100,7 +100,7 @@ public abstract partial class PixelConverterTests if (typeof(TDestinationPixel) == typeof(L16)) { ref L16 l16Ref = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(destinationPixels)); - for (nint i = 0; i < (uint)count; i++) + for (int i = 0; i < count; i++) { ref TSourcePixel sp = ref Unsafe.Add(ref sourceRef, i); ref L16 dp = ref Unsafe.Add(ref l16Ref, i); @@ -113,7 +113,7 @@ public abstract partial class PixelConverterTests if (typeof(TDestinationPixel) == typeof(L8)) { ref L8 l8Ref = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(destinationPixels)); - for (nint i = 0; i < (uint)count; i++) + for (int i = 0; i < count; i++) { ref TSourcePixel sp = ref Unsafe.Add(ref sourceRef, i); ref L8 dp = ref Unsafe.Add(ref l8Ref, i); @@ -125,7 +125,7 @@ public abstract partial class PixelConverterTests // Normal conversion ref TDestinationPixel destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (nint i = 0; i < (uint)count; i++) + for (int i = 0; i < count; i++) { ref TSourcePixel sp = ref Unsafe.Add(ref sourceRef, i); ref TDestinationPixel dp = ref Unsafe.Add(ref destRef, i); diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index 73305183f6..a9b3ee9a42 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -1184,7 +1184,7 @@ public abstract class PixelOperationsTests : MeasureFixture get { ref byte self = ref Unsafe.As(ref this); - return Unsafe.Add(ref self, (uint)idx); + return Unsafe.Add(ref self, idx); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs index 3cea431fbb..c6da46ee2f 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs @@ -128,7 +128,7 @@ public partial class ResizeKernelMapTests for (int i = 0; i < kernelMap.DestinationLength; i++) { - ResizeKernel kernel = kernelMap.GetKernel(i); + ResizeKernel kernel = kernelMap.GetKernel((uint)i); ReferenceKernel referenceKernel = referenceMap.GetKernel(i); @@ -153,7 +153,7 @@ public partial class ResizeKernelMapTests } private static string PrintKernelMap(ResizeKernelMap kernelMap) - => PrintKernelMap(kernelMap, km => km.DestinationLength, (km, i) => km.GetKernel(i)); + => PrintKernelMap(kernelMap, km => km.DestinationLength, (km, i) => km.GetKernel((uint)i)); private static string PrintKernelMap(ReferenceKernelMap kernelMap) => PrintKernelMap(kernelMap, km => km.DestinationSize, (km, i) => km.GetKernel(i)); From a95ab1768086d46f5fd70d713d7d88b934bfc9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 20 Mar 2023 22:56:23 +0100 Subject: [PATCH 09/86] Removed unnecessary comments --- .../ComponentProcessors/DownScalingComponentProcessor2.cs | 2 +- .../ComponentProcessors/DownScalingComponentProcessor4.cs | 2 +- .../ComponentProcessors/DownScalingComponentProcessor8.cs | 2 +- .../Formats/Jpeg/Components/ScaledFloatingPointDCT.cs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs index 0ec7500e0d..300a773311 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs @@ -25,7 +25,7 @@ internal sealed class DownScalingComponentProcessor2 : ComponentProcessor Buffer2D spectralBuffer = this.Component.SpectralBlocks; float maximumValue = this.Frame.MaxColorChannelValue; - float normalizationValue = MathF.Ceiling(maximumValue * 0.5F); // /2 + float normalizationValue = MathF.Ceiling(maximumValue * 0.5F); int destAreaStride = this.ColorBuffer.Width; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs index 99daaa49e7..7984169902 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs @@ -25,7 +25,7 @@ internal sealed class DownScalingComponentProcessor4 : ComponentProcessor Buffer2D spectralBuffer = this.Component.SpectralBlocks; float maximumValue = this.Frame.MaxColorChannelValue; - float normalizationValue = MathF.Ceiling(maximumValue * 0.5F); // /2 + float normalizationValue = MathF.Ceiling(maximumValue * 0.5F); int destAreaStride = this.ColorBuffer.Width; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs index cf321d7cd9..f3b09e6b49 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs @@ -22,7 +22,7 @@ internal sealed class DownScalingComponentProcessor8 : ComponentProcessor Buffer2D spectralBuffer = this.Component.SpectralBlocks; float maximumValue = this.Frame.MaxColorChannelValue; - float normalizationValue = MathF.Ceiling(maximumValue * 0.5F); // /2 + float normalizationValue = MathF.Ceiling(maximumValue * 0.5F); int destAreaStride = this.ColorBuffer.Width; diff --git a/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs b/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs index 1a2767308f..98e3857973 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs @@ -183,8 +183,8 @@ internal static class ScaledFloatingPointDCT // temporal result is saved to +2 shifted indices // because result is saved into the top left 2x2 region of the // input block - block[(ctr * 8) + 2] = (tmp10 + tmp0) * 0.25F; // /4 - block[(ctr * 8) + 3] = (tmp10 - tmp0) * 0.25F; // /4 + block[(ctr * 8) + 2] = (tmp10 + tmp0) * 0.25F; + block[(ctr * 8) + 3] = (tmp10 - tmp0) * 0.25F; } for (int ctr = 0; ctr < 2; ctr++) From d6aeba1501e391f17d6b5f5c605e9ba8e0711eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 20 Mar 2023 22:57:16 +0100 Subject: [PATCH 10/86] Switched from for-loop to if + do-while in Vp8LHistogram --- src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs index 3df979f96b..765c84e602 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs @@ -513,14 +513,14 @@ internal sealed class Vp8LHistogram : IDeepCloneable DebugGuard.MustBeGreaterThanOrEqualTo(b.Length, count, nameof(b.Length)); DebugGuard.MustBeGreaterThanOrEqualTo(output.Length, count, nameof(output.Length)); - if (Avx2.IsSupported) + if (Avx2.IsSupported && count >= 32) { ref uint aRef = ref MemoryMarshal.GetReference(a); ref uint bRef = ref MemoryMarshal.GetReference(b); ref uint outputRef = ref MemoryMarshal.GetReference(output); - nuint idx; - for (idx = 0; idx <= (uint)count - 32; idx += 32) + nuint idx = 0; + do { // Load values. Vector256 a0 = Unsafe.As>(ref Unsafe.Add(ref aRef, idx)); @@ -538,7 +538,9 @@ internal sealed class Vp8LHistogram : IDeepCloneable Unsafe.As>(ref Unsafe.Add(ref outputRef, idx + 8)) = Avx2.Add(a1, b1); Unsafe.As>(ref Unsafe.Add(ref outputRef, idx + 16)) = Avx2.Add(a2, b2); Unsafe.As>(ref Unsafe.Add(ref outputRef, idx + 24)) = Avx2.Add(a3, b3); + idx += 32; } + while (idx <= (uint)count - 32); int i = (int)idx; for (; i < count; i++) From a4fe64abb7f0abf718ba5502b75c633121938999 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Wed, 22 Mar 2023 18:52:13 +0100 Subject: [PATCH 11/86] Port GrayscalConverter to Arm --- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 29 ++++++++ .../JpegColorConverter.GrayScaleArm.cs | 68 +++++++++++++++++++ .../GrayscaleColorConversion.cs | 8 +++ .../Formats/Jpg/JpegColorConverterTests.cs | 19 +++++- 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 3841b64b4d..819837be13 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -4,6 +4,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.X86; using SixLabors.ImageSharp.PixelFormats; @@ -554,6 +555,34 @@ internal static partial class SimdUtils return Avx.Add(Avx.Multiply(vm0, vm1), va); } + /// + /// Performs a multiplication and an addition of the . + /// TODO: Fix. The arguments are in a different order to the FMA intrinsic. + /// + /// ret = (vm0 * vm1) + va + /// The vector to add to the intermediate result. + /// The first vector to multiply. + /// The second vector to multiply. + /// The . + [MethodImpl(InliningOptions.AlwaysInline)] + public static Vector128 MultiplyAdd( + in Vector128 va, + in Vector128 vm0, + in Vector128 vm1) + { + if (Fma.IsSupported) + { + return Fma.MultiplyAdd(vm1, vm0, va); + } + + if (AdvSimd.IsSupported) + { + return AdvSimd.Add(AdvSimd.Multiply(vm0, vm1), va); + } + + return Avx.Add(Avx.Multiply(vm0, vm1), va); + } + /// /// Performs a multiplication and a subtraction of the . /// TODO: Fix. The arguments are in a different order to the FMA intrinsic. diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs new file mode 100644 index 0000000000..56e51eb53f --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs @@ -0,0 +1,68 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.Arm; +using static SixLabors.ImageSharp.SimdUtils; + +namespace SixLabors.ImageSharp.Formats.Jpeg.Components; + +internal abstract partial class JpegColorConverterBase +{ + internal sealed class GrayscaleArm : JpegColorConverterArm + { + public GrayscaleArm(int precision) + : base(JpegColorSpace.Grayscale, precision) + { + } + + /// + public override void ConvertToRgbInplace(in ComponentValues values) + { + ref Vector128 c0Base = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component0)); + + // Used for the color conversion + var scale = Vector128.Create(1 / this.MaximumValue); + + nint n = values.Component0.Length / Vector128.Count; + for (nint i = 0; i < n; i++) + { + ref Vector128 c0 = ref Unsafe.Add(ref c0Base, i); + c0 = AdvSimd.Multiply(c0, scale); + } + } + + /// + public override void ConvertFromRgb(in ComponentValues values, Span rLane, Span gLane, Span bLane) + { + ref Vector128 destLuminance = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component0)); + + ref Vector128 srcRed = + ref Unsafe.As>(ref MemoryMarshal.GetReference(rLane)); + ref Vector128 srcGreen = + ref Unsafe.As>(ref MemoryMarshal.GetReference(gLane)); + ref Vector128 srcBlue = + ref Unsafe.As>(ref MemoryMarshal.GetReference(bLane)); + + // Used for the color conversion + var f0299 = Vector128.Create(0.299f); + var f0587 = Vector128.Create(0.587f); + var f0114 = Vector128.Create(0.114f); + + nint n = values.Component0.Length / Vector128.Count; + for (nint i = 0; i < n; i++) + { + ref Vector128 r = ref Unsafe.Add(ref srcRed, i); + ref Vector128 g = ref Unsafe.Add(ref srcGreen, i); + ref Vector128 b = ref Unsafe.Add(ref srcBlue, i); + + // luminocity = (0.299 * r) + (0.587 * g) + (0.114 * b) + Unsafe.Add(ref destLuminance, i) = HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(f0114, b), f0587, g), f0299, r); + } + } + } +} diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/GrayscaleColorConversion.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/GrayscaleColorConversion.cs index 47aac3464e..8bf26d721d 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/GrayscaleColorConversion.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/GrayscaleColorConversion.cs @@ -29,4 +29,12 @@ public class GrayscaleColorConversion : ColorConversionBenchmark new JpegColorConverterBase.GrayscaleAvx(8).ConvertToRgbInplace(values); } + + [Benchmark] + public void SimdVectorArm() + { + var values = new JpegColorConverterBase.ComponentValues(this.Input, 0); + + new JpegColorConverterBase.GrayscaleArm(8).ConvertToRgbInplace(values); + } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index 44675aaea2..c71c70c336 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -307,6 +307,23 @@ public class JpegColorConverterTests new JpegColorConverterBase.GrayscaleScalar(8), precísion: 3); + [Theory] + [MemberData(nameof(Seeds))] + public void FromGrayscaleArm(int seed) => + this.TestConversionToRgb(new JpegColorConverterBase.GrayscaleArm(8), + 1, + seed, + new JpegColorConverterBase.GrayscaleScalar(8)); + + [Theory] + [MemberData(nameof(Seeds))] + public void FromRgbToGrayscaleArm(int seed) => + this.TestConversionFromRgb(new JpegColorConverterBase.GrayscaleArm(8), + 1, + seed, + new JpegColorConverterBase.GrayscaleScalar(8), + precísion: 3); + [Theory] [MemberData(nameof(Seeds))] public void FromRgbAvx2(int seed) => @@ -480,7 +497,7 @@ public class JpegColorConverterTests JpegColorConverterBase baseLineConverter, int precision = 4) { - // arrange + // arrange JpegColorConverterBase.ComponentValues actual = CreateRandomValues(TestBufferLength, componentCount, seed); JpegColorConverterBase.ComponentValues expected = CreateRandomValues(TestBufferLength, componentCount, seed); Random rnd = new(seed); From 210a3d6e67ff99a1fc43b75bfc43aa0aeaef9c7a Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Thu, 23 Mar 2023 13:50:57 +0100 Subject: [PATCH 12/86] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Günther Foidl --- src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs | 6 +++--- .../ColorConverters/JpegColorConverter.GrayScaleArm.cs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 819837be13..2cb205a7d5 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -566,9 +566,9 @@ internal static partial class SimdUtils /// The . [MethodImpl(InliningOptions.AlwaysInline)] public static Vector128 MultiplyAdd( - in Vector128 va, - in Vector128 vm0, - in Vector128 vm1) + Vector128 va, + Vector128 vm0, + Vector128 vm1) { if (Fma.IsSupported) { diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs index 56e51eb53f..a8d5f49c24 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs @@ -27,8 +27,8 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector128.Create(1 / this.MaximumValue); - nint n = values.Component0.Length / Vector128.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)values.Component0.Length / (uint)Vector128.Count; + for (nuint i = 0; i < n; i++) { ref Vector128 c0 = ref Unsafe.Add(ref c0Base, i); c0 = AdvSimd.Multiply(c0, scale); @@ -53,8 +53,8 @@ internal abstract partial class JpegColorConverterBase var f0587 = Vector128.Create(0.587f); var f0114 = Vector128.Create(0.114f); - nint n = values.Component0.Length / Vector128.Count; - for (nint i = 0; i < n; i++) + nuint n = (uint)values.Component0.Length / (uint)Vector128.Count; + for (nuint i = 0; i < n; i++) { ref Vector128 r = ref Unsafe.Add(ref srcRed, i); ref Vector128 g = ref Unsafe.Add(ref srcGreen, i); From e234b003efeaad9b9527ad6afcfa675c0fb2de38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Thu, 23 Mar 2023 20:33:52 +0100 Subject: [PATCH 13/86] PR feedback --- .../Helpers/Shuffle/IComponentShuffle.cs | 20 ++++---- .../SimdUtils.FallbackIntrinsics128.cs | 8 ++-- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 2 +- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 2 +- src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs | 20 ++++---- .../Components/Encoder/ComponentProcessor.cs | 4 +- .../Webp/Lossless/BackwardReferenceEncoder.cs | 4 +- .../Formats/Webp/Lossless/HistogramEncoder.cs | 4 +- .../Formats/Webp/Lossless/PredictorEncoder.cs | 12 ++--- .../Formats/Webp/Lossless/Vp8LEncoder.cs | 10 ++-- .../Formats/Webp/Lossless/Vp8LHashChain.cs | 12 ++--- .../Formats/Webp/Lossless/Vp8LHistogram.cs | 6 +-- .../Formats/Webp/Lossy/PassStats.cs | 2 +- .../Formats/Webp/Lossy/Vp8EncIterator.cs | 6 +-- .../Formats/Webp/Lossy/Vp8Encoder.cs | 8 ++-- .../Formats/Webp/Lossy/WebpLossyDecoder.cs | 2 +- .../Formats/Webp/WebpEncoderCore.cs | 4 +- .../Convolution2DRowOperation{TPixel}.cs | 48 +++++++++---------- .../Convolution/Convolution2DState.cs | 16 +++---- .../ConvolutionProcessor{TPixel}.cs | 32 ++++++------- .../Convolution/ConvolutionState.cs | 16 +++---- .../EdgeDetectorCompassProcessor{TPixel}.cs | 14 +++--- .../Processors/Convolution/ReadOnlyKernel.cs | 18 +++---- 23 files changed, 135 insertions(+), 135 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index a86355135e..683ac518b8 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -84,9 +84,9 @@ internal readonly struct WXYZShuffle4 : IShuffle4 { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = (int)((uint)source.Length / 4); + uint n = (uint)source.Length / 4; - for (nuint i = 0; i < (uint)n; i++) + for (nuint i = 0; i < n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -108,9 +108,9 @@ internal readonly struct WZYXShuffle4 : IShuffle4 { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = (int)((uint)source.Length / 4); + uint n = (uint)source.Length / 4; - for (nuint i = 0; i < (uint)n; i++) + for (nuint i = 0; i < n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -132,9 +132,9 @@ internal readonly struct YZWXShuffle4 : IShuffle4 { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = (int)((uint)source.Length / 4); + uint n = (uint)source.Length / 4; - for (nuint i = 0; i < (uint)n; i++) + for (nuint i = 0; i < n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -156,9 +156,9 @@ internal readonly struct ZYXWShuffle4 : IShuffle4 { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = (int)((uint)source.Length / 4); + uint n = (uint)source.Length / 4; - for (nuint i = 0; i < (uint)n; i++) + for (nuint i = 0; i < n; i++) { uint packed = Unsafe.Add(ref sBase, i); @@ -187,9 +187,9 @@ internal readonly struct XWZYShuffle4 : IShuffle4 { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = (int)((uint)source.Length / 4); + uint n = (uint)source.Length / 4; - for (nuint i = 0; i < (uint)n; i++) + for (nuint i = 0; i < n; i++) { uint packed = Unsafe.Add(ref sBase, i); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs index d456d8e42f..a551cebd05 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs @@ -71,7 +71,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, 4); - int count = (int)((uint)dest.Length / 4); + uint count = (uint)dest.Length / 4; if (count == 0) { return; @@ -83,7 +83,7 @@ internal static partial class SimdUtils const float scale = 1f / 255f; Vector4 d = default; - for (nuint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < count; i++) { ref ByteVector4 s = ref Unsafe.Add(ref sBase, i); d.X = s.X; @@ -105,7 +105,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, 4); - int count = (int)((uint)source.Length / 4); + uint count = (uint)source.Length / 4; if (count == 0) { return; @@ -117,7 +117,7 @@ internal static partial class SimdUtils var half = new Vector4(0.5f); var maxBytes = new Vector4(255f); - for (nuint i = 0; i < (uint)count; i++) + for (nuint i = 0; i < count; i++) { Vector4 s = Unsafe.Add(ref sBase, i); s *= maxBytes; diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 4a71dc8b89..0c1b273f77 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -1361,7 +1361,7 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals this.metadata.VerticalResolution = Math.Round(UnitConverter.InchToMeter(ImageMetadata.DefaultVerticalResolution)); } - short bitsPerPixel = this.infoHeader.BitsPerPixel; + ushort bitsPerPixel = this.infoHeader.BitsPerPixel; this.bmpMetadata = this.metadata.GetBmpMetadata(); this.bmpMetadata.InfoHeaderType = infoHeaderType; this.bmpMetadata.BitsPerPixel = (BmpBitsPerPixel)bitsPerPixel; diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 60f18c8023..fd23a29e37 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -212,7 +212,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals width: width, height: height, planes: 1, - bitsPerPixel: (short)bpp, + bitsPerPixel: bpp, imageSize: height * bytesPerLine, xPelsPerMeter: hResolution, yPelsPerMeter: vResolution, diff --git a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs index ff02131497..c15e785730 100644 --- a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs +++ b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs @@ -70,7 +70,7 @@ internal struct BmpInfoHeader int width, int height, short planes, - short bitsPerPixel, + ushort bitsPerPixel, BmpCompression compression = default, int imageSize = 0, int xPelsPerMeter = 0, @@ -157,7 +157,7 @@ internal struct BmpInfoHeader /// Gets or sets the number of bits per pixel, which is the color depth of the image. /// Typical values are 1, 4, 8, 16, 24 and 32. /// - public short BitsPerPixel { get; set; } + public ushort BitsPerPixel { get; set; } /// /// Gets or sets the compression method being used. @@ -311,7 +311,7 @@ internal struct BmpInfoHeader width: BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(4, 2)), height: BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(6, 2)), planes: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(8, 2)), - bitsPerPixel: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(10, 2))); + bitsPerPixel: BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(10, 2))); /// /// Parses a short variant of the OS22XBITMAPHEADER. It is identical to the BITMAPCOREHEADER, except that the width and height @@ -325,7 +325,7 @@ internal struct BmpInfoHeader width: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(4, 4)), height: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(8, 4)), planes: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(12, 2)), - bitsPerPixel: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(14, 2))); + bitsPerPixel: BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(14, 2))); /// /// Parses the full BMP Version 3 BITMAPINFOHEADER header (40 bytes). @@ -338,7 +338,7 @@ internal struct BmpInfoHeader width: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(4, 4)), height: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(8, 4)), planes: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(12, 2)), - bitsPerPixel: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(14, 2)), + bitsPerPixel: BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(14, 2)), compression: (BmpCompression)BinaryPrimitives.ReadInt32LittleEndian(data.Slice(16, 4)), imageSize: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(20, 4)), xPelsPerMeter: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(24, 4)), @@ -359,7 +359,7 @@ internal struct BmpInfoHeader width: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(4, 4)), height: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(8, 4)), planes: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(12, 2)), - bitsPerPixel: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(14, 2)), + bitsPerPixel: BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(14, 2)), compression: (BmpCompression)BinaryPrimitives.ReadInt32LittleEndian(data.Slice(16, 4)), imageSize: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(20, 4)), xPelsPerMeter: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(24, 4)), @@ -386,7 +386,7 @@ internal struct BmpInfoHeader width: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(4, 4)), height: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(8, 4)), planes: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(12, 2)), - bitsPerPixel: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(14, 2))); + bitsPerPixel: BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(14, 2))); // The compression value in OS/2 bitmap has a different meaning than in windows bitmaps. // Map the OS/2 value to the windows values. @@ -431,7 +431,7 @@ internal struct BmpInfoHeader width: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(4, 4)), height: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(8, 4)), planes: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(12, 2)), - bitsPerPixel: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(14, 2)), + bitsPerPixel: BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(14, 2)), compression: (BmpCompression)BinaryPrimitives.ReadInt32LittleEndian(data.Slice(16, 4)), imageSize: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(20, 4)), xPelsPerMeter: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(24, 4)), @@ -484,7 +484,7 @@ internal struct BmpInfoHeader BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(4, 4), this.Width); BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(8, 4), this.Height); BinaryPrimitives.WriteInt16LittleEndian(buffer.Slice(12, 2), this.Planes); - BinaryPrimitives.WriteInt16LittleEndian(buffer.Slice(14, 2), this.BitsPerPixel); + BinaryPrimitives.WriteUInt16LittleEndian(buffer.Slice(14, 2), this.BitsPerPixel); BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(16, 4), (int)this.Compression); BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(20, 4), this.ImageSize); BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(24, 4), this.XPelsPerMeter); @@ -504,7 +504,7 @@ internal struct BmpInfoHeader BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(4, 4), this.Width); BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(8, 4), this.Height); BinaryPrimitives.WriteInt16LittleEndian(buffer.Slice(12, 2), this.Planes); - BinaryPrimitives.WriteInt16LittleEndian(buffer.Slice(14, 2), this.BitsPerPixel); + BinaryPrimitives.WriteUInt16LittleEndian(buffer.Slice(14, 2), this.BitsPerPixel); BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(16, 4), (int)this.Compression); BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(20, 4), this.ImageSize); BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(24, 4), this.XPelsPerMeter); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs index 9b08175051..c7d9498b6b 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs @@ -157,7 +157,7 @@ internal class ComponentProcessor : IDisposable // Ideally we need to use log2: Numerics.Log2((uint)factor) // but division by 2 works just fine in this case - int haddIterationsCount = (int)((uint)factor / 2); + uint haddIterationsCount = (uint)factor / 2; // Transform spans so that it only contains 'remainder' // values for the scalar fallback code @@ -168,7 +168,7 @@ internal class ComponentProcessor : IDisposable nuint length = (uint)(touchedCount / Vector256.Count); - for (int i = 0; i < haddIterationsCount; i++) + for (uint i = 0; i < haddIterationsCount; i++) { length /= 2; diff --git a/src/ImageSharp/Formats/Webp/Lossless/BackwardReferenceEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/BackwardReferenceEncoder.cs index df19c26e0b..61133142bf 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/BackwardReferenceEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/BackwardReferenceEncoder.cs @@ -38,7 +38,7 @@ internal static class BackwardReferenceEncoder int width, int height, ReadOnlySpan bgra, - int quality, + uint quality, int lz77TypesToTry, ref int cacheBits, MemoryAllocator memoryAllocator, @@ -123,7 +123,7 @@ internal static class BackwardReferenceEncoder /// The local color cache is also disabled for the lower (smaller then 25) quality. /// /// Best cache size. - private static int CalculateBestCacheSize(ReadOnlySpan bgra, int quality, Vp8LBackwardRefs refs, int bestCacheBits) + private static int CalculateBestCacheSize(ReadOnlySpan bgra, uint quality, Vp8LBackwardRefs refs, int bestCacheBits) { int cacheBitsMax = quality <= 25 ? 0 : bestCacheBits; if (cacheBitsMax == 0) diff --git a/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs index 5eec2a2ca3..5ac3301519 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs @@ -27,7 +27,7 @@ internal class HistogramEncoder private const ushort InvalidHistogramSymbol = ushort.MaxValue; - public static void GetHistoImageSymbols(int xSize, int ySize, Vp8LBackwardRefs refs, int quality, int histoBits, int cacheBits, List imageHisto, Vp8LHistogram tmpHisto, ushort[] histogramSymbols) + public static void GetHistoImageSymbols(int xSize, int ySize, Vp8LBackwardRefs refs, uint quality, int histoBits, int cacheBits, List imageHisto, Vp8LHistogram tmpHisto, ushort[] histogramSymbols) { int histoXSize = histoBits > 0 ? LosslessUtils.SubSampleSize(xSize, histoBits) : 1; int histoYSize = histoBits > 0 ? LosslessUtils.SubSampleSize(ySize, histoBits) : 1; @@ -660,7 +660,7 @@ internal class HistogramEncoder output.TrivialSymbol = a.TrivialSymbol == b.TrivialSymbol ? a.TrivialSymbol : NonTrivialSym; } - private static double GetCombineCostFactor(int histoSize, int quality) + private static double GetCombineCostFactor(int histoSize, uint quality) { double combineCostFactor = 0.16d; if (quality < 90) diff --git a/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs index 5d8d3203b1..689c63f5b1 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs @@ -113,7 +113,7 @@ internal static unsafe class PredictorEncoder lowEffort); } - public static void ColorSpaceTransform(int width, int height, int bits, int quality, Span bgra, Span image, Span scratch) + public static void ColorSpaceTransform(int width, int height, int bits, uint quality, Span bgra, Span image, Span scratch) { int maxTileSize = 1 << bits; int tileXSize = LosslessUtils.SubSampleSize(width, bits); @@ -837,7 +837,7 @@ internal static unsafe class PredictorEncoder int bits, Vp8LMultipliers prevX, Vp8LMultipliers prevY, - int quality, + uint quality, int xSize, int ySize, int[] accumulatedRedHisto, @@ -871,14 +871,14 @@ internal static unsafe class PredictorEncoder int tileHeight, Vp8LMultipliers prevX, Vp8LMultipliers prevY, - int quality, + uint quality, int[] accumulatedRedHisto, ref Vp8LMultipliers bestTx) { - int maxIters = 4 + ((7 * quality) >> 8); // in range [4..6] + uint maxIters = 4 + ((7 * quality) / 256); // in range [4..6] int greenToRedBest = 0; double bestDiff = GetPredictionCostCrossColorRed(argb, stride, scratch, tileWidth, tileHeight, prevX, prevY, greenToRedBest, accumulatedRedHisto); - for (int iter = 0; iter < maxIters; iter++) + for (int iter = 0; iter < (int)maxIters; iter++) { // ColorTransformDelta is a 3.5 bit fixed point, so 32 is equal to // one in color computation. Having initial delta here as 1 is sufficient @@ -901,7 +901,7 @@ internal static unsafe class PredictorEncoder bestTx.GreenToRed = (byte)(greenToRedBest & 0xff); } - private static void GetBestGreenRedToBlue(Span argb, int stride, Span scratch, int tileWidth, int tileHeight, Vp8LMultipliers prevX, Vp8LMultipliers prevY, int quality, int[] accumulatedBlueHisto, ref Vp8LMultipliers bestTx) + private static void GetBestGreenRedToBlue(Span argb, int stride, Span scratch, int tileWidth, int tileHeight, Vp8LMultipliers prevX, Vp8LMultipliers prevY, uint quality, int[] accumulatedBlueHisto, ref Vp8LMultipliers bestTx) { int iters = (quality < 25) ? 1 : (quality > 50) ? GreenRedToBlueMaxIters : 4; int greenToBlueBest = 0; diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs index 7be0e69f72..d678da6028 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs @@ -57,7 +57,7 @@ internal class Vp8LEncoder : IDisposable /// /// The quality, that will be used to encode the image. /// - private readonly int quality; + private readonly uint quality; /// /// Quality/speed trade-off (0=fast, 6=slower-better). @@ -110,7 +110,7 @@ internal class Vp8LEncoder : IDisposable Configuration configuration, int width, int height, - int quality, + uint quality, bool skipMetadata, WebpEncodingMethod method, WebpTransparentColorMode transparentColorMode, @@ -122,7 +122,7 @@ internal class Vp8LEncoder : IDisposable this.memoryAllocator = memoryAllocator; this.configuration = configuration; - this.quality = Numerics.Clamp(quality, 0, 100); + this.quality = Math.Min(quality, 100u); this.skipMetadata = skipMetadata; this.method = method; this.transparentColorMode = transparentColorMode; @@ -772,7 +772,7 @@ internal class Vp8LEncoder : IDisposable this.EncodeImageNoHuffman(this.TransformData.GetSpan(), this.HashChain, this.Refs[0], this.Refs[1], transformWidth, transformHeight, this.quality, lowEffort); } - private void EncodeImageNoHuffman(Span bgra, Vp8LHashChain hashChain, Vp8LBackwardRefs refsTmp1, Vp8LBackwardRefs refsTmp2, int width, int height, int quality, bool lowEffort) + private void EncodeImageNoHuffman(Span bgra, Vp8LHashChain hashChain, Vp8LBackwardRefs refsTmp1, Vp8LBackwardRefs refsTmp2, int width, int height, uint quality, bool lowEffort) { int cacheBits = 0; ushort[] histogramSymbols = new ushort[1]; // Only one tree, one symbol. @@ -1820,7 +1820,7 @@ internal class Vp8LEncoder : IDisposable { // VP8LResidualImage needs room for 2 scanlines of uint32 pixels with an extra // pixel in each, plus 2 regular scanlines of bytes. - int bgraScratchSize = this.UsePredictorTransform ? (int)((((uint)width + 1) * 2) + ((((uint)width * 2) + 4 - 1) / 4)) : 0; + int bgraScratchSize = this.UsePredictorTransform ? ((width + 1) * 2) + (((width * 2) + 4 - 1) / 4) : 0; int transformDataSize = this.UsePredictorTransform || this.UseCrossColorTransform ? LosslessUtils.SubSampleSize(width, this.TransformBits) * LosslessUtils.SubSampleSize(height, this.TransformBits) : 0; this.BgraScratch = this.memoryAllocator.Allocate(bgraScratchSize); diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs index 32d4fcbb68..3b3864a49d 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs @@ -56,10 +56,10 @@ internal sealed class Vp8LHashChain : IDisposable /// public int Size { get; } - public void Fill(ReadOnlySpan bgra, int quality, int xSize, int ySize, bool lowEffort) + public void Fill(ReadOnlySpan bgra, uint quality, int xSize, int ySize, bool lowEffort) { int size = xSize * ySize; - int iterMax = GetMaxItersForQuality((uint)quality); + int iterMax = GetMaxItersForQuality(quality); int windowSize = GetWindowSizeForHashChain(quality, xSize); int pos; @@ -275,11 +275,11 @@ internal sealed class Vp8LHashChain : IDisposable private static int GetMaxItersForQuality(uint quality) => (int)(8 + (quality * quality / 128)); [MethodImpl(InliningOptions.ShortMethod)] - private static int GetWindowSizeForHashChain(int quality, int xSize) + private static int GetWindowSizeForHashChain(uint quality, int xSize) { - int maxWindowSize = quality > 75 ? WindowSize - : quality > 50 ? xSize << 8 - : quality > 25 ? xSize << 6 + int maxWindowSize = quality > 75u ? WindowSize + : quality > 50u ? xSize << 8 + : quality > 25u ? xSize << 6 : xSize << 4; return maxWindowSize > WindowSize ? WindowSize : maxWindowSize; diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs index 765c84e602..5ec3f0d53d 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs @@ -523,18 +523,18 @@ internal sealed class Vp8LHistogram : IDeepCloneable do { // Load values. - Vector256 a0 = Unsafe.As>(ref Unsafe.Add(ref aRef, idx)); + Vector256 a0 = Unsafe.As>(ref Unsafe.Add(ref aRef, idx + 0)); Vector256 a1 = Unsafe.As>(ref Unsafe.Add(ref aRef, idx + 8)); Vector256 a2 = Unsafe.As>(ref Unsafe.Add(ref aRef, idx + 16)); Vector256 a3 = Unsafe.As>(ref Unsafe.Add(ref aRef, idx + 24)); - Vector256 b0 = Unsafe.As>(ref Unsafe.Add(ref bRef, idx)); + Vector256 b0 = Unsafe.As>(ref Unsafe.Add(ref bRef, idx + 0)); Vector256 b1 = Unsafe.As>(ref Unsafe.Add(ref bRef, idx + 8)); Vector256 b2 = Unsafe.As>(ref Unsafe.Add(ref bRef, idx + 16)); Vector256 b3 = Unsafe.As>(ref Unsafe.Add(ref bRef, idx + 24)); // Note we are adding uint32_t's as *signed* int32's (using _mm_add_epi32). But // that's ok since the histogram values are less than 1<<28 (max picture count). - Unsafe.As>(ref Unsafe.Add(ref outputRef, idx)) = Avx2.Add(a0, b0); + Unsafe.As>(ref Unsafe.Add(ref outputRef, idx + 0)) = Avx2.Add(a0, b0); Unsafe.As>(ref Unsafe.Add(ref outputRef, idx + 8)) = Avx2.Add(a1, b1); Unsafe.As>(ref Unsafe.Add(ref outputRef, idx + 16)) = Avx2.Add(a2, b2); Unsafe.As>(ref Unsafe.Add(ref outputRef, idx + 24)) = Avx2.Add(a3, b3); diff --git a/src/ImageSharp/Formats/Webp/Lossy/PassStats.cs b/src/ImageSharp/Formats/Webp/Lossy/PassStats.cs index ba554866e3..470c9c1042 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/PassStats.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/PassStats.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// internal class PassStats { - public PassStats(long targetSize, float targetPsnr, int qMin, int qMax, int quality) + public PassStats(long targetSize, float targetPsnr, int qMin, int qMax, uint quality) { bool doSizeSearch = targetSize != 0; diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs index fa5fe51c79..b33ef57a6b 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs @@ -347,12 +347,12 @@ internal class Vp8EncIterator } } - public int FastMbAnalyze(int quality) + public int FastMbAnalyze(uint quality) { // Empirical cut-off value, should be around 16 (~=block size). We use the // [8-17] range and favor intra4 at high quality, intra16 for low quality. - int q = quality; - int kThreshold = 8 + ((17 - 8) * q / 100); + uint q = quality; + uint kThreshold = 8 + ((17 - 8) * q / 100); int k; Span dc = stackalloc uint[16]; uint m; diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs index 186aa6c216..ed3c1cd60d 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs @@ -31,7 +31,7 @@ internal class Vp8Encoder : IDisposable /// /// The quality, that will be used to encode the image. /// - private readonly int quality; + private readonly uint quality; /// /// Quality/speed trade-off (0=fast, 6=slower-better). @@ -113,7 +113,7 @@ internal class Vp8Encoder : IDisposable Configuration configuration, int width, int height, - int quality, + uint quality, bool skipMetadata, WebpEncodingMethod method, int entropyPasses, @@ -125,7 +125,7 @@ internal class Vp8Encoder : IDisposable this.configuration = configuration; this.Width = width; this.Height = height; - this.quality = Numerics.Clamp(quality, 0, 100); + this.quality = Math.Min(quality, 100); this.skipMetadata = skipMetadata; this.method = method; this.entropyPasses = Numerics.Clamp(entropyPasses, 1, 10); @@ -1177,6 +1177,6 @@ internal class Vp8Encoder : IDisposable { int total = a + b; return total == 0 ? 255 // that's the default probability. - : ((255 * a) + (int)((uint)total / 2)) / total; // rounded proba + : ((255 * a) + (total >> 1)) / total; // rounded proba } } diff --git a/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs b/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs index 36f3abcd9d..96ed8903a0 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs @@ -731,7 +731,7 @@ internal sealed class WebpLossyDecoder Span dst = buf[dstStartIdx..]; int yEnd = io.MbY + io.MbH; int mbw = io.MbW; - int uvw = (int)(((uint)mbw + 1) / 2); + int uvw = (mbw + 1) >> 1; // >> 1 is bit-hack for / 2 int y = io.MbY; byte[] uvBuffer = new byte[(14 * 32) + 15]; diff --git a/src/ImageSharp/Formats/Webp/WebpEncoderCore.cs b/src/ImageSharp/Formats/Webp/WebpEncoderCore.cs index 33189ba845..49512e03b5 100644 --- a/src/ImageSharp/Formats/Webp/WebpEncoderCore.cs +++ b/src/ImageSharp/Formats/Webp/WebpEncoderCore.cs @@ -27,7 +27,7 @@ internal sealed class WebpEncoderCore : IImageEncoderInternals /// /// Compression quality. Between 0 and 100. /// - private readonly int quality; + private readonly uint quality; /// /// Quality/speed trade-off (0=fast, 6=slower-better). @@ -92,7 +92,7 @@ internal sealed class WebpEncoderCore : IImageEncoderInternals this.memoryAllocator = configuration.MemoryAllocator; this.alphaCompression = encoder.UseAlphaCompression; this.fileFormat = encoder.FileFormat; - this.quality = encoder.Quality; + this.quality = (uint)encoder.Quality; this.method = encoder.Method; this.entropyPasses = encoder.EntropyPasses; this.spatialNoiseShaping = encoder.SpatialNoiseShaping; diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DRowOperation{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DRowOperation{TPixel}.cs index 91fc3a1b1d..2a4a1abf02 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DRowOperation{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DRowOperation{TPixel}.cs @@ -76,7 +76,7 @@ internal readonly struct Convolution2DRowOperation : IRowOperation targetXBuffer = span.Slice(boundsWidth * 2, boundsWidth); var state = new Convolution2DState(in this.kernelMatrixY, in this.kernelMatrixX, this.map); - ref int sampleRowBase = ref state.GetSampleRow(y - this.bounds.Y); + ref int sampleRowBase = ref state.GetSampleRow((uint)(y - this.bounds.Y)); // Clear the target buffers for each row run. targetYBuffer.Clear(); @@ -87,24 +87,24 @@ internal readonly struct Convolution2DRowOperation : IRowOperation sourceRow; - for (int kY = 0; kY < kernelY.Rows; kY++) + for (uint kY = 0; kY < kernelY.Rows; kY++) { // Get the precalculated source sample row for this kernel row and copy to our buffer. - int sampleY = Unsafe.Add(ref sampleRowBase, (uint)kY); + int sampleY = Unsafe.Add(ref sampleRowBase, kY); sourceRow = this.sourcePixels.DangerousGetRowSpan(sampleY).Slice(boundsX, boundsWidth); PixelOperations.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); ref Vector4 sourceBase = ref MemoryMarshal.GetReference(sourceBuffer); - for (int x = 0; x < sourceBuffer.Length; x++) + for (uint x = 0; x < (uint)sourceBuffer.Length; x++) { ref int sampleColumnBase = ref state.GetSampleColumn(x); - ref Vector4 targetY = ref Unsafe.Add(ref targetBaseY, (uint)x); - ref Vector4 targetX = ref Unsafe.Add(ref targetBaseX, (uint)x); + ref Vector4 targetY = ref Unsafe.Add(ref targetBaseY, x); + ref Vector4 targetX = ref Unsafe.Add(ref targetBaseX, x); - for (int kX = 0; kX < kernelY.Columns; kX++) + for (uint kX = 0; kX < kernelY.Columns; kX++) { - int sampleX = Unsafe.Add(ref sampleColumnBase, (uint)kX) - boundsX; + int sampleX = Unsafe.Add(ref sampleColumnBase, kX) - boundsX; Vector4 sample = Unsafe.Add(ref sourceBase, (uint)sampleX); targetY += kernelX[kY, kX] * sample; targetX += kernelY[kY, kX] * sample; @@ -117,14 +117,14 @@ internal readonly struct Convolution2DRowOperation : IRowOperation.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); - for (int x = 0; x < sourceRow.Length; x++) + for (nuint x = 0; x < (uint)sourceRow.Length; x++) { - ref Vector4 target = ref Unsafe.Add(ref targetBaseY, (uint)x); + ref Vector4 target = ref Unsafe.Add(ref targetBaseY, x); Vector4 vectorY = target; - Vector4 vectorX = Unsafe.Add(ref targetBaseX, (uint)x); + Vector4 vectorX = Unsafe.Add(ref targetBaseX, x); target = Vector4.SquareRoot((vectorX * vectorX) + (vectorY * vectorY)); - target.W = Unsafe.Add(ref MemoryMarshal.GetReference(sourceBuffer), (uint)x).W; + target.W = Unsafe.Add(ref MemoryMarshal.GetReference(sourceBuffer), x).W; } Span targetRowSpan = this.targetPixels.DangerousGetRowSpan(y).Slice(boundsX, boundsWidth); @@ -142,7 +142,7 @@ internal readonly struct Convolution2DRowOperation : IRowOperation targetXBuffer = span.Slice(boundsWidth * 2, boundsWidth); var state = new Convolution2DState(in this.kernelMatrixY, in this.kernelMatrixX, this.map); - ref int sampleRowBase = ref state.GetSampleRow(y - this.bounds.Y); + ref int sampleRowBase = ref state.GetSampleRow((uint)(y - this.bounds.Y)); // Clear the target buffers for each row run. targetYBuffer.Clear(); @@ -152,26 +152,26 @@ internal readonly struct Convolution2DRowOperation : IRowOperation sourceRow = this.sourcePixels.DangerousGetRowSpan(sampleY).Slice(boundsX, boundsWidth); PixelOperations.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); Numerics.Premultiply(sourceBuffer); ref Vector4 sourceBase = ref MemoryMarshal.GetReference(sourceBuffer); - for (int x = 0; x < sourceBuffer.Length; x++) + for (uint x = 0; x < (uint)sourceBuffer.Length; x++) { ref int sampleColumnBase = ref state.GetSampleColumn(x); - ref Vector4 targetY = ref Unsafe.Add(ref targetBaseY, (uint)x); - ref Vector4 targetX = ref Unsafe.Add(ref targetBaseX, (uint)x); + ref Vector4 targetY = ref Unsafe.Add(ref targetBaseY, x); + ref Vector4 targetX = ref Unsafe.Add(ref targetBaseX, x); - for (int kX = 0; kX < kernelY.Columns; kX++) + for (uint kX = 0; kX < kernelY.Columns; kX++) { - int sampleX = Unsafe.Add(ref sampleColumnBase, (uint)kX) - boundsX; - Vector4 sample = Unsafe.Add(ref sourceBase, (uint)sampleX); + int sampleX = Unsafe.Add(ref sampleColumnBase, kX) - boundsX; + Vector4 sample = Unsafe.Add(ref sourceBase, sampleX); targetY += kernelX[kY, kX] * sample; targetX += kernelY[kY, kX] * sample; } @@ -179,11 +179,11 @@ internal readonly struct Convolution2DRowOperation : IRowOperation rowOffsetMap; private readonly Span columnOffsetMap; - private readonly int kernelHeight; - private readonly int kernelWidth; + private readonly uint kernelHeight; + private readonly uint kernelWidth; public Convolution2DState( in DenseMatrix kernelY, @@ -24,8 +24,8 @@ internal readonly ref struct Convolution2DState // We check the kernels are the same size upstream. this.KernelY = new ReadOnlyKernel(kernelY); this.KernelX = new ReadOnlyKernel(kernelX); - this.kernelHeight = kernelY.Rows; - this.kernelWidth = kernelY.Columns; + this.kernelHeight = (uint)kernelY.Rows; + this.kernelWidth = (uint)kernelY.Columns; this.rowOffsetMap = map.GetRowOffsetSpan(); this.columnOffsetMap = map.GetColumnOffsetSpan(); } @@ -43,10 +43,10 @@ internal readonly ref struct Convolution2DState } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ref int GetSampleRow(int row) - => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.rowOffsetMap), (uint)(row * this.kernelHeight)); + public readonly ref int GetSampleRow(uint row) + => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.rowOffsetMap), row * this.kernelHeight); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ref int GetSampleColumn(int column) - => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.columnOffsetMap), (uint)(column * this.kernelWidth)); + public readonly ref int GetSampleColumn(uint column) + => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.columnOffsetMap), column * this.kernelWidth); } diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs index 4cbca8d74e..d059ebe030 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs @@ -123,7 +123,7 @@ internal class ConvolutionProcessor : ImageProcessor var state = new ConvolutionState(in this.kernel, this.map); int row = y - this.bounds.Y; - ref int sampleRowBase = ref state.GetSampleRow(row); + ref int sampleRowBase = ref state.GetSampleRow((uint)row); if (this.preserveAlpha) { @@ -132,23 +132,23 @@ internal class ConvolutionProcessor : ImageProcessor ref Vector4 targetBase = ref MemoryMarshal.GetReference(targetBuffer); Span sourceRow; - for (int kY = 0; kY < state.Kernel.Rows; kY++) + for (uint kY = 0; kY < state.Kernel.Rows; kY++) { // Get the precalculated source sample row for this kernel row and copy to our buffer. - int offsetY = Unsafe.Add(ref sampleRowBase, (uint)kY); + int offsetY = Unsafe.Add(ref sampleRowBase, kY); sourceRow = this.sourcePixels.DangerousGetRowSpan(offsetY).Slice(boundsX, boundsWidth); PixelOperations.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); ref Vector4 sourceBase = ref MemoryMarshal.GetReference(sourceBuffer); - for (int x = 0; x < sourceBuffer.Length; x++) + for (uint x = 0; x < (uint)sourceBuffer.Length; x++) { ref int sampleColumnBase = ref state.GetSampleColumn(x); - ref Vector4 target = ref Unsafe.Add(ref targetBase, (uint)x); + ref Vector4 target = ref Unsafe.Add(ref targetBase, x); - for (int kX = 0; kX < state.Kernel.Columns; kX++) + for (uint kX = 0; kX < state.Kernel.Columns; kX++) { - int offsetX = Unsafe.Add(ref sampleColumnBase, (uint)kX) - boundsX; + int offsetX = Unsafe.Add(ref sampleColumnBase, kX) - boundsX; Vector4 sample = Unsafe.Add(ref sourceBase, (uint)offsetX); target += state.Kernel[kY, kX] * sample; } @@ -159,10 +159,10 @@ internal class ConvolutionProcessor : ImageProcessor sourceRow = this.sourcePixels.DangerousGetRowSpan(y).Slice(boundsX, boundsWidth); PixelOperations.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); - for (int x = 0; x < sourceRow.Length; x++) + for (nuint x = 0; x < (uint)sourceRow.Length; x++) { - ref Vector4 target = ref Unsafe.Add(ref targetBase, (uint)x); - target.W = Unsafe.Add(ref MemoryMarshal.GetReference(sourceBuffer), (uint)x).W; + ref Vector4 target = ref Unsafe.Add(ref targetBase, x); + target.W = Unsafe.Add(ref MemoryMarshal.GetReference(sourceBuffer), x).W; } } else @@ -171,24 +171,24 @@ internal class ConvolutionProcessor : ImageProcessor targetBuffer.Clear(); ref Vector4 targetBase = ref MemoryMarshal.GetReference(targetBuffer); - for (int kY = 0; kY < state.Kernel.Rows; kY++) + for (uint kY = 0; kY < state.Kernel.Rows; kY++) { // Get the precalculated source sample row for this kernel row and copy to our buffer. - int offsetY = Unsafe.Add(ref sampleRowBase, (uint)kY); + int offsetY = Unsafe.Add(ref sampleRowBase, kY); Span sourceRow = this.sourcePixels.DangerousGetRowSpan(offsetY).Slice(boundsX, boundsWidth); PixelOperations.Instance.ToVector4(this.configuration, sourceRow, sourceBuffer); Numerics.Premultiply(sourceBuffer); ref Vector4 sourceBase = ref MemoryMarshal.GetReference(sourceBuffer); - for (int x = 0; x < sourceBuffer.Length; x++) + for (uint x = 0; x < (uint)sourceBuffer.Length; x++) { ref int sampleColumnBase = ref state.GetSampleColumn(x); - ref Vector4 target = ref Unsafe.Add(ref targetBase, (uint)x); + ref Vector4 target = ref Unsafe.Add(ref targetBase, x); - for (int kX = 0; kX < state.Kernel.Columns; kX++) + for (uint kX = 0; kX < state.Kernel.Columns; kX++) { - int offsetX = Unsafe.Add(ref sampleColumnBase, (uint)kX) - boundsX; + int offsetX = Unsafe.Add(ref sampleColumnBase, kX) - boundsX; Vector4 sample = Unsafe.Add(ref sourceBase, (uint)offsetX); target += state.Kernel[kY, kX] * sample; } diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionState.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionState.cs index dbf90d0170..6663c45021 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionState.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionState.cs @@ -13,16 +13,16 @@ internal readonly ref struct ConvolutionState { private readonly Span rowOffsetMap; private readonly Span columnOffsetMap; - private readonly int kernelHeight; - private readonly int kernelWidth; + private readonly uint kernelHeight; + private readonly uint kernelWidth; public ConvolutionState( in DenseMatrix kernel, KernelSamplingMap map) { this.Kernel = new ReadOnlyKernel(kernel); - this.kernelHeight = kernel.Rows; - this.kernelWidth = kernel.Columns; + this.kernelHeight = (uint)kernel.Rows; + this.kernelWidth = (uint)kernel.Columns; this.rowOffsetMap = map.GetRowOffsetSpan(); this.columnOffsetMap = map.GetColumnOffsetSpan(); } @@ -34,10 +34,10 @@ internal readonly ref struct ConvolutionState } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ref int GetSampleRow(int row) - => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.rowOffsetMap), (uint)(row * this.kernelHeight)); + public readonly ref int GetSampleRow(uint row) + => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.rowOffsetMap), row * this.kernelHeight); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ref int GetSampleColumn(int column) - => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.columnOffsetMap), (uint)(column * this.kernelWidth)); + public readonly ref int GetSampleColumn(uint column) + => ref Unsafe.Add(ref MemoryMarshal.GetReference(this.columnOffsetMap), column * this.kernelWidth); } diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs index 8de92bee81..cbf893915c 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs @@ -98,8 +98,8 @@ internal class EdgeDetectorCompassProcessor : ImageProcessor { private readonly Buffer2D targetPixels; private readonly Buffer2D passPixels; - private readonly int minX; - private readonly int maxX; + private readonly uint minX; + private readonly uint maxX; [MethodImpl(InliningOptions.ShortMethod)] public RowOperation( @@ -109,8 +109,8 @@ internal class EdgeDetectorCompassProcessor : ImageProcessor { this.targetPixels = targetPixels; this.passPixels = passPixels; - this.minX = bounds.X; - this.maxX = bounds.Right; + this.minX = (uint)bounds.X; + this.maxX = (uint)bounds.Right; } /// @@ -120,11 +120,11 @@ internal class EdgeDetectorCompassProcessor : ImageProcessor ref TPixel passPixelsBase = ref MemoryMarshal.GetReference(this.passPixels.DangerousGetRowSpan(y)); ref TPixel targetPixelsBase = ref MemoryMarshal.GetReference(this.targetPixels.DangerousGetRowSpan(y)); - for (int x = this.minX; x < this.maxX; x++) + for (nuint x = this.minX; x < this.maxX; x++) { // Grab the max components of the two pixels - ref TPixel currentPassPixel = ref Unsafe.Add(ref passPixelsBase, (uint)x); - ref TPixel currentTargetPixel = ref Unsafe.Add(ref targetPixelsBase, (uint)x); + ref TPixel currentPassPixel = ref Unsafe.Add(ref passPixelsBase, x); + ref TPixel currentTargetPixel = ref Unsafe.Add(ref targetPixelsBase, x); var pixelValue = Vector4.Max(currentPassPixel.ToVector4(), currentTargetPixel.ToVector4()); diff --git a/src/ImageSharp/Processing/Processors/Convolution/ReadOnlyKernel.cs b/src/ImageSharp/Processing/Processors/Convolution/ReadOnlyKernel.cs index 46c35c62c7..2a09589bda 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ReadOnlyKernel.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ReadOnlyKernel.cs @@ -17,43 +17,43 @@ internal readonly ref struct ReadOnlyKernel public ReadOnlyKernel(DenseMatrix matrix) { - this.Columns = matrix.Columns; - this.Rows = matrix.Rows; + this.Columns = (uint)matrix.Columns; + this.Rows = (uint)matrix.Rows; this.values = matrix.Span; } - public int Columns + public uint Columns { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } - public int Rows + public uint Rows { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } - public float this[int row, int column] + public float this[uint row, uint column] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { this.CheckCoordinates(row, column); ref float vBase = ref MemoryMarshal.GetReference(this.values); - return Unsafe.Add(ref vBase, (uint)((row * this.Columns) + column)); + return Unsafe.Add(ref vBase, (row * this.Columns) + column); } } [Conditional("DEBUG")] - private void CheckCoordinates(int row, int column) + private void CheckCoordinates(uint row, uint column) { - if (row < 0 || row >= this.Rows) + if (row >= this.Rows) { throw new ArgumentOutOfRangeException(nameof(row), row, $"{row} is outwith the matrix bounds."); } - if (column < 0 || column >= this.Columns) + if (column >= this.Columns) { throw new ArgumentOutOfRangeException(nameof(column), column, $"{column} is outwith the matrix bounds."); } From 65e7761bf9fbec9b30becd676c876a64ee5f4ad2 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Fri, 24 Mar 2023 05:18:37 +0000 Subject: [PATCH 14/86] Update src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Günther Foidl --- src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 2cb205a7d5..dce713a807 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -580,7 +580,7 @@ internal static partial class SimdUtils return AdvSimd.Add(AdvSimd.Multiply(vm0, vm1), va); } - return Avx.Add(Avx.Multiply(vm0, vm1), va); + return Sse.Add(Sse.Multiply(vm0, vm1), va); } /// From 2bbf1cb9b30ec5b529a6af6bab106a481d8d637a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Fri, 24 Mar 2023 11:38:36 +0100 Subject: [PATCH 15/86] Fixed division by vector length --- .../Helpers/SimdUtils.ExtendedIntrinsics.cs | 4 ++-- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 18 +++++++++--------- .../Jpeg/Components/Block8x8F.ScaledCopy.cs | 2 +- .../JpegColorConverter.CmykAvx.cs | 4 ++-- .../JpegColorConverter.CmykVector.cs | 4 ++-- .../JpegColorConverter.GrayScaleAvx.cs | 4 ++-- .../JpegColorConverter.GrayScaleVector.cs | 4 ++-- .../JpegColorConverter.RgbArm.cs | 2 +- .../JpegColorConverter.RgbAvx.cs | 2 +- .../JpegColorConverter.RgbVector.cs | 2 +- .../JpegColorConverter.YCbCrAvx.cs | 4 ++-- .../JpegColorConverter.YCbCrVector.cs | 4 ++-- .../JpegColorConverter.YccKAvx.cs | 4 ++-- .../JpegColorConverter.YccKVector.cs | 4 ++-- .../Components/Encoder/ComponentProcessor.cs | 10 +++++----- .../ImageSharp.Benchmarks/Bulk/FromVector4.cs | 5 ++--- .../Bulk/ToVector4_Rgba32.cs | 4 ++-- .../PixelConversion_PackFromRgbPlanes.cs | 2 +- .../General/Vectorization/UInt32ToSingle.cs | 10 +++++----- .../General/Vectorization/VectorFetching.cs | 6 +++--- .../Vectorization/WidenBytesToUInt32.cs | 2 +- 21 files changed, 50 insertions(+), 51 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs index 43998d0ec9..b9505ba3ef 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs @@ -97,7 +97,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector.Count); - nuint n = (uint)(dest.Length / Vector.Count); + nuint n = (uint)dest.Length / (uint)Vector.Count; ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); @@ -132,7 +132,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector.Count); - nuint n = (uint)(dest.Length / Vector.Count); + nuint n = (uint)dest.Length / (uint)Vector.Count; ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 5f83ccd6be..ce6f335a8f 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -391,7 +391,7 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nuint n = (uint)(source.Length / Vector128.Count); + nuint n = (uint)source.Length / (uint)Vector128.Count; for (nuint i = 0; i < n; i += 3) { @@ -454,7 +454,7 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nuint n = (uint)(source.Length / Vector128.Count); + nuint n = (uint)source.Length / (uint)Vector128.Count; for (nuint i = 0, j = 0; i < n; i += 3, j += 4) { @@ -498,7 +498,7 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nuint n = (uint)(source.Length / Vector128.Count); + nuint n = (uint)source.Length / (uint)Vector128.Count; for (nuint i = 0, j = 0; i < n; i += 4, j += 3) { @@ -650,7 +650,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector256.Count); - nuint n = (uint)(dest.Length / Vector256.Count); + nuint n = (uint)dest.Length / (uint)Vector256.Count; ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); @@ -683,7 +683,7 @@ internal static partial class SimdUtils // Sse VerifySpanInput(source, dest, Vector128.Count); - nuint n = (uint)(dest.Length / Vector128.Count); + nuint n = (uint)dest.Length / (uint)Vector128.Count; ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); @@ -782,7 +782,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector256.Count); - nuint n = (uint)(dest.Length / Vector256.Count); + nuint n = (uint)dest.Length / (uint)Vector256.Count; ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -821,7 +821,7 @@ internal static partial class SimdUtils // Sse VerifySpanInput(source, dest, Vector128.Count); - nuint n = (uint)(dest.Length / Vector128.Count); + nuint n = (uint)dest.Length / (uint)Vector128.Count; ref Vector128 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -864,7 +864,7 @@ internal static partial class SimdUtils ref Vector256 bBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(blueChannel)); ref byte dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(destination)); - nuint count = (uint)(redChannel.Length / Vector256.Count); + nuint count = (uint)redChannel.Length / (uint)Vector256.Count; ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32); Vector256 control1 = Unsafe.As>(ref control1Bytes); @@ -936,7 +936,7 @@ internal static partial class SimdUtils ref Vector256 bBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(blueChannel)); ref Vector256 dBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - nuint count = (uint)(redChannel.Length / Vector256.Count); + nuint count = (uint)redChannel.Length / (uint)Vector256.Count; ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32); Vector256 control1 = Unsafe.As>(ref control1Bytes); var a = Vector256.Create((byte)255); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs index 652c064ad5..efc1dbd729 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs @@ -98,7 +98,7 @@ internal partial struct Block8x8F nuint xx = x * horizontalScale; float value = this[(int)(y8 + x)]; - nuint baseIdx = (uint)((yy * areaStride) + xx); + nuint baseIdx = (yy * areaStride) + xx; for (nuint i = 0; i < verticalScale; i++, baseIdx += areaStride) { diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs index 07ba3648c4..0283e83d0f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs @@ -32,7 +32,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / (this.MaximumValue * this.MaximumValue)); - nuint n = (uint)(values.Component0.Length / Vector256.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; for (nuint i = 0; i < n; i++) { ref Vector256 c = ref Unsafe.Add(ref c0Base, i); @@ -71,7 +71,7 @@ internal abstract partial class JpegColorConverterBase var scale = Vector256.Create(maxValue); - nuint n = (uint)(values.Component0.Length / Vector256.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; for (nuint i = 0; i < n; i++) { Vector256 ctmp = Avx.Subtract(scale, Unsafe.Add(ref srcR, i)); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs index 2e2ff08bf9..4cc8c0665f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs @@ -30,7 +30,7 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / (this.MaximumValue * this.MaximumValue)); - nuint n = (uint)(values.Component0.Length / Vector.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { ref Vector c = ref Unsafe.Add(ref cBase, i); @@ -78,7 +78,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = new Vector(maxValue); - nuint n = (uint)(values.Component0.Length / Vector.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { Vector ctmp = scale - Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs index 80ae6621c4..4efb6f8514 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs @@ -27,7 +27,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / this.MaximumValue); - nuint n = (uint)(values.Component0.Length / Vector256.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; for (nuint i = 0; i < n; i++) { ref Vector256 c0 = ref Unsafe.Add(ref c0Base, i); @@ -53,7 +53,7 @@ internal abstract partial class JpegColorConverterBase var f0587 = Vector256.Create(0.587f); var f0114 = Vector256.Create(0.114f); - nuint n = (uint)(values.Component0.Length / Vector256.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; for (nuint i = 0; i < n; i++) { ref Vector256 r = ref Unsafe.Add(ref srcRed, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs index 018e0ca442..4156a5968b 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs @@ -24,7 +24,7 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / this.MaximumValue); - nuint n = (uint)(values.Component0.Length / Vector.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { ref Vector c0 = ref Unsafe.Add(ref cBase, i); @@ -53,7 +53,7 @@ internal abstract partial class JpegColorConverterBase var gMult = new Vector(0.587f); var bMult = new Vector(0.114f); - nuint n = (uint)(values.Component0.Length / Vector.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { Vector r = Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs index 72d8340a0f..8889223064 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs @@ -30,7 +30,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector128.Create(1 / this.MaximumValue); - nuint n = (uint)(values.Component0.Length / Vector128.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector128.Count; for (nuint i = 0; i < n; i++) { ref Vector128 r = ref Unsafe.Add(ref rBase, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs index 8c095309c7..ae9b943aaf 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs @@ -29,7 +29,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / this.MaximumValue); - nuint n = (uint)(values.Component0.Length / Vector256.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; for (nuint i = 0; i < n; i++) { ref Vector256 r = ref Unsafe.Add(ref rBase, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs index cbba796440..5e3cf9b2b3 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs @@ -28,7 +28,7 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / this.MaximumValue); - nuint n = (uint)(values.Component0.Length / Vector.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { ref Vector r = ref Unsafe.Add(ref rBase, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs index e828ba1179..0a2cfd084c 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs @@ -38,7 +38,7 @@ internal abstract partial class JpegColorConverterBase var bCbMult = Vector256.Create(YCbCrScalar.BCbMult); // Walking 8 elements at one step: - nuint n = (uint)(values.Component0.Length / Vector256.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; for (nuint i = 0; i < n; i++) { // y = yVals[i]; @@ -98,7 +98,7 @@ internal abstract partial class JpegColorConverterBase var fn0081312F = Vector256.Create(-0.081312F); var f05 = Vector256.Create(0.5f); - nuint n = (uint)(values.Component0.Length / Vector256.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; for (nuint i = 0; i < n; i++) { Vector256 r = Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs index e3b4be235f..ca01aed612 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs @@ -35,7 +35,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(-YCbCrScalar.GCrMult); var bCbMult = new Vector(YCbCrScalar.BCbMult); - nuint n = (uint)(values.Component0.Length / Vector.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { // y = yVals[i]; @@ -103,7 +103,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(0.418688f); var bCrMult = new Vector(0.081312f); - nuint n = (uint)(values.Component0.Length / Vector.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { Vector r = Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs index 8ab2dd3d67..337741622a 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs @@ -40,7 +40,7 @@ internal abstract partial class JpegColorConverterBase var bCbMult = Vector256.Create(YCbCrScalar.BCbMult); // Walking 8 elements at one step: - nuint n = (uint)(values.Component0.Length / Vector256.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; for (nuint i = 0; i < n; i++) { // y = yVals[i]; @@ -109,7 +109,7 @@ internal abstract partial class JpegColorConverterBase var fn0081312F = Vector256.Create(-0.081312F); var f05 = Vector256.Create(0.5f); - nuint n = (uint)(values.Component0.Length / Vector256.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; for (nuint i = 0; i < n; i++) { Vector256 r = Avx.Subtract(maxSampleValue, Unsafe.Add(ref srcR, i)); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs index 711b0fe3bb..d67fad3080 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs @@ -36,7 +36,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(-YCbCrScalar.GCrMult); var bCbMult = new Vector(YCbCrScalar.BCbMult); - nuint n = (uint)(values.Component0.Length / Vector.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { // y = yVals[i]; @@ -107,7 +107,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(0.418688f); var bCrMult = new Vector(0.081312f); - nuint n = (uint)(values.Component0.Length / Vector.Count); + nuint n = (uint)values.Component0.Length / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { Vector r = maxSampleValue - Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs index c7d9498b6b..4815baa62f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs @@ -122,7 +122,7 @@ internal class ComponentProcessor : IDisposable ref Vector256 sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed - nuint count = (uint)(source.Length / Vector256.Count); + nuint count = (uint)source.Length / (uint)Vector256.Count; for (nuint i = 0; i < count; i++) { Unsafe.Add(ref targetVectorRef, i) = Avx.Add(Unsafe.Add(ref targetVectorRef, i), Unsafe.Add(ref sourceVectorRef, i)); @@ -133,7 +133,7 @@ internal class ComponentProcessor : IDisposable ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); ref Vector sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); - nuint count = (uint)(source.Length / Vector.Count); + nuint count = (uint)source.Length / (uint)Vector.Count; for (nuint i = 0; i < count; i++) { Unsafe.Add(ref targetVectorRef, i) += Unsafe.Add(ref sourceVectorRef, i); @@ -166,7 +166,7 @@ internal class ComponentProcessor : IDisposable source = source.Slice(touchedCount); target = target.Slice(touchedCount / factor); - nuint length = (uint)(touchedCount / Vector256.Count); + nuint length = (uint)touchedCount / (uint)Vector256.Count; for (uint i = 0; i < haddIterationsCount; i++) { @@ -200,7 +200,7 @@ internal class ComponentProcessor : IDisposable ref Vector256 targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed - nuint count = (uint)(target.Length / Vector256.Count); + nuint count = (uint)target.Length / (uint)Vector256.Count; var multiplierVector = Vector256.Create(multiplier); for (nuint i = 0; i < count; i++) { @@ -211,7 +211,7 @@ internal class ComponentProcessor : IDisposable { ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); - nuint count = (uint)(target.Length / Vector.Count); + nuint count = (uint)target.Length / (uint)Vector.Count; var multiplierVector = new Vector(multiplier); for (nuint i = 0; i < count; i++) { diff --git a/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs b/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs index f0eeb5afb7..7e6cec2018 100644 --- a/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs +++ b/tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs @@ -103,10 +103,9 @@ public class FromVector4Rgba32 : FromVector4 Span src = MemoryMarshal.Cast(this.source.GetSpan()); Span dest = MemoryMarshal.Cast(this.destination.GetSpan()); - nuint n = (uint)(dest.Length / Vector.Count); + nuint n = (uint)dest.Length / (uint)Vector.Count; - ref Vector256 sourceBase = - ref Unsafe.As>(ref MemoryMarshal.GetReference(src)); + ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(src)); ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); ref byte maskBase = ref MemoryMarshal.GetReference(PermuteMaskDeinterleave8x32); diff --git a/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs b/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs index ce3fb70c88..9abf0ed22a 100644 --- a/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs +++ b/tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs @@ -54,7 +54,7 @@ public class ToVector4_Rgba32 : ToVector4 Span sBytes = MemoryMarshal.Cast(this.source.GetSpan()); Span dFloats = MemoryMarshal.Cast(this.destination.GetSpan()); - nuint n = (uint)(dFloats.Length / Vector.Count); + nuint n = (uint)dFloats.Length / (uint)Vector.Count; ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference((ReadOnlySpan)sBytes)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dFloats)); @@ -96,7 +96,7 @@ public class ToVector4_Rgba32 : ToVector4 Span sBytes = MemoryMarshal.Cast(this.source.GetSpan()); Span dFloats = MemoryMarshal.Cast(this.destination.GetSpan()); - nuint n = (uint)(dFloats.Length / Vector.Count); + nuint n = (uint)dFloats.Length / (uint)Vector.Count; ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference((ReadOnlySpan)sBytes)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dFloats)); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs index e3677d238d..ddf192af87 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs @@ -205,7 +205,7 @@ public unsafe class PixelConversion_PackFromRgbPlanes ref Vector256 bBase = ref Unsafe.As>(ref this.bFloat[0]); ref Vector256 resultBase = ref Unsafe.As>(ref this.rgbaFloat[0]); - nuint count = (uint)(this.Count / Vector256.Count); + nuint count = (uint)this.Count / (uint)Vector256.Count; ref byte control = ref MemoryMarshal.GetReference(SimdUtils.HwIntrinsics.PermuteMaskEvenOdd8x32); Vector256 vcontrol = Unsafe.As>(ref control); diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs index 010e1f52b3..fc4dc1fa16 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs @@ -12,7 +12,7 @@ public class UInt32ToSingle { private float[] data; - private const int Count = 32; + private const uint Count = 32; [GlobalSetup] public void Setup() @@ -25,7 +25,7 @@ public class UInt32ToSingle { ref Vector b = ref Unsafe.As>(ref this.data[0]); - nuint n = (uint)(Count / Vector.Count); + nuint n = Count / (uint)Vector.Count; var bVec = new Vector(256.0f / 255.0f); var magicFloat = new Vector(32768.0f); @@ -50,7 +50,7 @@ public class UInt32ToSingle [Benchmark] public void StandardSimd() { - nuint n = (uint)(Count / Vector.Count); + nuint n = Count / (uint)Vector.Count; ref Vector bf = ref Unsafe.As>(ref this.data[0]); ref Vector bu = ref Unsafe.As, Vector>(ref bf); @@ -69,7 +69,7 @@ public class UInt32ToSingle [Benchmark] public void StandardSimdFromInt() { - nuint n = (uint)(Count / Vector.Count); + nuint n = Count / (uint)Vector.Count; ref Vector bf = ref Unsafe.As>(ref this.data[0]); ref Vector bu = ref Unsafe.As, Vector>(ref bf); @@ -88,7 +88,7 @@ public class UInt32ToSingle [Benchmark] public void StandardSimdFromInt_RefCast() { - nuint n = (uint)(Count / Vector.Count); + nuint n = Count / (uint)Vector.Count; ref Vector bf = ref Unsafe.As>(ref this.data[0]); var scale = new Vector(1f / 255f); diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs index 32027729b2..5d20f29d18 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs @@ -63,7 +63,7 @@ public class VectorFetching var v = new Vector(this.testValue); ref Vector start = ref Unsafe.As>(ref this.data[0]); - nuint n = (uint)(this.InputSize / Vector.Count); + nuint n = (uint)this.InputSize / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { @@ -82,7 +82,7 @@ public class VectorFetching var v = new Vector(this.testValue); ref Vector start = ref Unsafe.As>(ref this.data[0]); - nuint n = (uint)(this.InputSize / Vector.Count); + nuint n = (uint)this.InputSize / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { @@ -100,7 +100,7 @@ public class VectorFetching ref Vector start = ref Unsafe.As>(ref MemoryMarshal.GetReference(span)); - nuint n = (uint)(this.InputSize / Vector.Count); + nuint n = (uint)this.InputSize / (uint)Vector.Count; for (nuint i = 0; i < n; i++) { diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs index 6ad7827eb1..f391e42012 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs @@ -42,7 +42,7 @@ public class WidenBytesToUInt32 [Benchmark] public void Simd() { - nuint n = (uint)(Count / Vector.Count); + nuint n = Count / (uint)Vector.Count; ref Vector sBase = ref Unsafe.As>(ref this.source[0]); ref Vector dBase = ref Unsafe.As>(ref this.dest[0]); From f01b69681887414ce67eb38620bd4d09cbe94b34 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 24 Mar 2023 17:53:28 +0100 Subject: [PATCH 16/86] Dont use using statement for encodedAlphaData. It will now be disposed in a try / finally block. --- .../Formats/Webp/Lossy/Vp8Encoder.cs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs index 16b4c827ef..ead636f30c 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs @@ -349,10 +349,11 @@ internal class Vp8Encoder : IDisposable int alphaDataSize = 0; bool alphaCompressionSucceeded = false; Span alphaData = Span.Empty; + IMemoryOwner encodedAlphaData = null; if (hasAlpha) { // TODO: This can potentially run in an separate task. - using IMemoryOwner encodedAlphaData = AlphaEncoder.EncodeAlpha( + encodedAlphaData = AlphaEncoder.EncodeAlpha( image, this.configuration, this.memoryAllocator, @@ -405,16 +406,23 @@ internal class Vp8Encoder : IDisposable ExifProfile exifProfile = this.skipMetadata ? null : metadata.ExifProfile; XmpProfile xmpProfile = this.skipMetadata ? null : metadata.XmpProfile; - this.bitWriter.WriteEncodedImageToStream( - stream, - exifProfile, - xmpProfile, - metadata.IccProfile, - (uint)width, - (uint)height, - hasAlpha, - alphaData[..alphaDataSize], - this.alphaCompression && alphaCompressionSucceeded); + try + { + this.bitWriter.WriteEncodedImageToStream( + stream, + exifProfile, + xmpProfile, + metadata.IccProfile, + (uint)width, + (uint)height, + hasAlpha, + alphaData[..alphaDataSize], + this.alphaCompression && alphaCompressionSucceeded); + } + finally + { + encodedAlphaData?.Dispose(); + } } /// From db3d74862f8d3ab222278adc0da5182f411dc22d Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 24 Mar 2023 18:59:16 +0100 Subject: [PATCH 17/86] Move EncodeAlpha into try catch block --- .../Formats/Webp/Lossy/Vp8Encoder.cs | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs index 6afab41581..eefc4cd0a0 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs @@ -345,30 +345,6 @@ internal class Vp8Encoder : IDisposable int expectedSize = this.Mbw * this.Mbh * averageBytesPerMacroBlock; this.bitWriter = new Vp8BitWriter(expectedSize, this); - // Extract and encode alpha channel data, if present. - int alphaDataSize = 0; - bool alphaCompressionSucceeded = false; - Span alphaData = Span.Empty; - IMemoryOwner encodedAlphaData = null; - if (hasAlpha) - { - // TODO: This can potentially run in an separate task. - encodedAlphaData = AlphaEncoder.EncodeAlpha( - image, - this.configuration, - this.memoryAllocator, - this.skipMetadata, - this.alphaCompression, - out alphaDataSize); - - alphaData = encodedAlphaData.GetSpan(); - if (alphaDataSize < pixelCount) - { - // Only use compressed data, if the compressed data is actually smaller then the uncompressed data. - alphaCompressionSucceeded = true; - } - } - // Stats-collection loop. this.StatLoop(width, height, yStride, uvStride); it.Init(); @@ -406,8 +382,32 @@ internal class Vp8Encoder : IDisposable ExifProfile exifProfile = this.skipMetadata ? null : metadata.ExifProfile; XmpProfile xmpProfile = this.skipMetadata ? null : metadata.XmpProfile; + // Extract and encode alpha channel data, if present. + int alphaDataSize = 0; + bool alphaCompressionSucceeded = false; + Span alphaData = Span.Empty; + IMemoryOwner encodedAlphaData = null; try { + if (hasAlpha) + { + // TODO: This can potentially run in an separate task. + encodedAlphaData = AlphaEncoder.EncodeAlpha( + image, + this.configuration, + this.memoryAllocator, + this.skipMetadata, + this.alphaCompression, + out alphaDataSize); + + alphaData = encodedAlphaData.GetSpan(); + if (alphaDataSize < pixelCount) + { + // Only use compressed data, if the compressed data is actually smaller then the uncompressed data. + alphaCompressionSucceeded = true; + } + } + this.bitWriter.WriteEncodedImageToStream( stream, exifProfile, From b69495666b035c392c553497c95a5355e5a45231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Fri, 24 Mar 2023 20:23:31 +0100 Subject: [PATCH 18/86] Fixed wrong division hack The numerator can be negative, thus the bit-hack yields wrong results. --- src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs index 05b6001c91..8d64a09dfb 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs @@ -1456,7 +1456,7 @@ internal static unsafe class LosslessUtils } [MethodImpl(InliningOptions.ShortMethod)] - private static int AddSubtractComponentHalf(int a, int b) => (int)Clip255((uint)(a + ((a - b) >> 1))); // >> 1 is bit-hack for / 2 + private static int AddSubtractComponentHalf(int a, int b) => (int)Clip255((uint)(a + ((a - b) / 2))); [MethodImpl(InliningOptions.ShortMethod)] private static int AddSubtractComponentFull(int a, int b, int c) => (int)Clip255((uint)(a + b - c)); From b099bda98b5011428899ea6a29f5ec3ca4e51562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sat, 25 Mar 2023 22:35:16 +0100 Subject: [PATCH 19/86] Reduced intermediate allocations: Tiff --- .../BlackIsZero32FloatTiffColor{TPixel}.cs | 11 +++-- .../RgbFloat323232TiffColor{TPixel}.cs | 23 +++++----- .../RgbaFloat32323232TiffColor{TPixel}.cs | 30 ++++++------- .../WhiteIsZero32FloatTiffColor{TPixel}.cs | 9 ++-- .../Formats/Tiff/TiffEncoderCore.cs | 38 ++++++++-------- .../Formats/Tiff/Writers/TiffStreamWriter.cs | 44 +++++++++---------- .../Formats/Tiff/BigTiffMetadataTests.cs | 4 +- .../Formats/Tiff/TiffEncoderHeaderTests.cs | 4 +- .../Formats/Tiff/Utils/TiffWriterTests.cs | 15 ++++--- 9 files changed, 85 insertions(+), 93 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero32FloatTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero32FloatTiffColor{TPixel}.cs index 9007b3f5ab..df37327c35 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero32FloatTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero32FloatTiffColor{TPixel}.cs @@ -24,9 +24,9 @@ internal class BlackIsZero32FloatTiffColor : TiffBaseColorDecoder public override void Decode(ReadOnlySpan data, Buffer2D pixels, int left, int top, int width, int height) { - var color = default(TPixel); + TPixel color = default; color.FromScaledVector4(Vector4.Zero); - byte[] buffer = new byte[4]; + Span buffer = stackalloc byte[4]; int offset = 0; for (int y = top; y < top + height; y++) @@ -37,8 +37,8 @@ internal class BlackIsZero32FloatTiffColor : TiffBaseColorDecoder : TiffBaseColorDecoder : TiffBaseColorDecoder var color = default(TPixel); color.FromScaledVector4(Vector4.Zero); int offset = 0; - byte[] buffer = new byte[4]; + Span buffer = stackalloc byte[4]; for (int y = top; y < top + height; y++) { @@ -38,18 +38,18 @@ internal class RgbFloat323232TiffColor : TiffBaseColorDecoder for (int x = 0; x < pixelRow.Length; x++) { data.Slice(offset, 4).CopyTo(buffer); - Array.Reverse(buffer); - float r = BitConverter.ToSingle(buffer, 0); + buffer.Reverse(); + float r = BitConverter.ToSingle(buffer); offset += 4; data.Slice(offset, 4).CopyTo(buffer); - Array.Reverse(buffer); - float g = BitConverter.ToSingle(buffer, 0); + buffer.Reverse(); + float g = BitConverter.ToSingle(buffer); offset += 4; data.Slice(offset, 4).CopyTo(buffer); - Array.Reverse(buffer); - float b = BitConverter.ToSingle(buffer, 0); + buffer.Reverse(); + float b = BitConverter.ToSingle(buffer); offset += 4; var colorVector = new Vector4(r, g, b, 1.0f); @@ -61,16 +61,13 @@ internal class RgbFloat323232TiffColor : TiffBaseColorDecoder { for (int x = 0; x < pixelRow.Length; x++) { - data.Slice(offset, 4).CopyTo(buffer); - float r = BitConverter.ToSingle(buffer, 0); + float r = BitConverter.ToSingle(data.Slice(offset, 4)); offset += 4; - data.Slice(offset, 4).CopyTo(buffer); - float g = BitConverter.ToSingle(buffer, 0); + float g = BitConverter.ToSingle(data.Slice(offset, 4)); offset += 4; - data.Slice(offset, 4).CopyTo(buffer); - float b = BitConverter.ToSingle(buffer, 0); + float b = BitConverter.ToSingle(data.Slice(offset, 4)); offset += 4; var colorVector = new Vector4(r, g, b, 1.0f); diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbaFloat32323232TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbaFloat32323232TiffColor{TPixel}.cs index 920f9fdc43..743502d56e 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbaFloat32323232TiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/RgbaFloat32323232TiffColor{TPixel}.cs @@ -27,7 +27,7 @@ internal class RgbaFloat32323232TiffColor : TiffBaseColorDecoder var color = default(TPixel); color.FromScaledVector4(Vector4.Zero); int offset = 0; - byte[] buffer = new byte[4]; + Span buffer = stackalloc byte[4]; for (int y = top; y < top + height; y++) { @@ -38,23 +38,23 @@ internal class RgbaFloat32323232TiffColor : TiffBaseColorDecoder for (int x = 0; x < pixelRow.Length; x++) { data.Slice(offset, 4).CopyTo(buffer); - Array.Reverse(buffer); - float r = BitConverter.ToSingle(buffer, 0); + buffer.Reverse(); + float r = BitConverter.ToSingle(buffer); offset += 4; data.Slice(offset, 4).CopyTo(buffer); - Array.Reverse(buffer); - float g = BitConverter.ToSingle(buffer, 0); + buffer.Reverse(); + float g = BitConverter.ToSingle(buffer); offset += 4; data.Slice(offset, 4).CopyTo(buffer); - Array.Reverse(buffer); - float b = BitConverter.ToSingle(buffer, 0); + buffer.Reverse(); + float b = BitConverter.ToSingle(buffer); offset += 4; data.Slice(offset, 4).CopyTo(buffer); - Array.Reverse(buffer); - float a = BitConverter.ToSingle(buffer, 0); + buffer.Reverse(); + float a = BitConverter.ToSingle(buffer); offset += 4; var colorVector = new Vector4(r, g, b, a); @@ -66,20 +66,16 @@ internal class RgbaFloat32323232TiffColor : TiffBaseColorDecoder { for (int x = 0; x < pixelRow.Length; x++) { - data.Slice(offset, 4).CopyTo(buffer); - float r = BitConverter.ToSingle(buffer, 0); + float r = BitConverter.ToSingle(data.Slice(offset, 4)); offset += 4; - data.Slice(offset, 4).CopyTo(buffer); - float g = BitConverter.ToSingle(buffer, 0); + float g = BitConverter.ToSingle(data.Slice(offset, 4)); offset += 4; - data.Slice(offset, 4).CopyTo(buffer); - float b = BitConverter.ToSingle(buffer, 0); + float b = BitConverter.ToSingle(data.Slice(offset, 4)); offset += 4; - data.Slice(offset, 4).CopyTo(buffer); - float a = BitConverter.ToSingle(buffer, 0); + float a = BitConverter.ToSingle(data.Slice(offset, 4)); offset += 4; var colorVector = new Vector4(r, g, b, a); diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero32FloatTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero32FloatTiffColor{TPixel}.cs index 78d557f30b..f3207b2f45 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero32FloatTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero32FloatTiffColor{TPixel}.cs @@ -26,7 +26,7 @@ internal class WhiteIsZero32FloatTiffColor : TiffBaseColorDecoder buffer = stackalloc byte[4]; int offset = 0; for (int y = top; y < top + height; y++) @@ -37,8 +37,8 @@ internal class WhiteIsZero32FloatTiffColor : TiffBaseColorDecoder : TiffBaseColorDecoder private readonly MemoryAllocator memoryAllocator; - /// - /// A scratch buffer to reduce allocations. - /// - private readonly byte[] buffer = new byte[4]; - /// /// The global configuration. /// @@ -157,7 +152,9 @@ internal sealed class TiffEncoderCore : IImageEncoderInternals this.SanitizeAndSetEncoderOptions(bitsPerPixel, image.PixelType.BitsPerPixel, photometricInterpretation, compression, predictor); using TiffStreamWriter writer = new(stream); - long ifdMarker = WriteHeader(writer); + Span buffer = stackalloc byte[4]; + + long ifdMarker = WriteHeader(writer, buffer); Image metadataImage = image; foreach (ImageFrame frame in image.Frames) @@ -171,7 +168,7 @@ internal sealed class TiffEncoderCore : IImageEncoderInternals long currentOffset = writer.BaseStream.Position; foreach ((long, uint) marker in this.frameMarkers) { - writer.WriteMarkerFast(marker.Item1, marker.Item2); + writer.WriteMarkerFast(marker.Item1, marker.Item2, buffer); } writer.BaseStream.Seek(currentOffset, SeekOrigin.Begin); @@ -181,14 +178,15 @@ internal sealed class TiffEncoderCore : IImageEncoderInternals /// Writes the TIFF file header. /// /// The to write data to. + /// Scratch buffer with minimum size of 2. /// /// The marker to write the first IFD offset. /// - public static long WriteHeader(TiffStreamWriter writer) + public static long WriteHeader(TiffStreamWriter writer, Span buffer) { - writer.Write(ByteOrderMarker); - writer.Write(TiffConstants.HeaderMagicNumber); - return writer.PlaceMarker(); + writer.Write(ByteOrderMarker, buffer); + writer.Write(TiffConstants.HeaderMagicNumber, buffer); + return writer.PlaceMarker(buffer); } /// @@ -307,20 +305,22 @@ internal sealed class TiffEncoderCore : IImageEncoderInternals entries.Sort((a, b) => (ushort)a.Tag - (ushort)b.Tag); - writer.Write((ushort)entries.Count); + Span buffer = stackalloc byte[4]; + + writer.Write((ushort)entries.Count, buffer); foreach (IExifValue entry in entries) { - writer.Write((ushort)entry.Tag); - writer.Write((ushort)entry.DataType); - writer.Write(ExifWriter.GetNumberOfComponents(entry)); + writer.Write((ushort)entry.Tag, buffer); + writer.Write((ushort)entry.DataType, buffer); + writer.Write(ExifWriter.GetNumberOfComponents(entry), buffer); uint length = ExifWriter.GetLength(entry); if (length <= 4) { - int sz = ExifWriter.WriteValue(entry, this.buffer, 0); + int sz = ExifWriter.WriteValue(entry, buffer, 0); DebugGuard.IsTrue(sz == length, "Incorrect number of bytes written"); - writer.WritePadded(this.buffer.AsSpan(0, sz)); + writer.WritePadded(buffer.Slice(0, sz)); } else { @@ -328,12 +328,12 @@ internal sealed class TiffEncoderCore : IImageEncoderInternals int sz = ExifWriter.WriteValue(entry, raw, 0); DebugGuard.IsTrue(sz == raw.Length, "Incorrect number of bytes written"); largeDataBlocks.Add(raw); - writer.Write(dataOffset); + writer.Write(dataOffset, buffer); dataOffset += (uint)(raw.Length + (raw.Length % 2)); } } - long nextIfdMarker = writer.PlaceMarker(); + long nextIfdMarker = writer.PlaceMarker(buffer); foreach (byte[] dataBlock in largeDataBlocks) { diff --git a/src/ImageSharp/Formats/Tiff/Writers/TiffStreamWriter.cs b/src/ImageSharp/Formats/Tiff/Writers/TiffStreamWriter.cs index be32ca9ed6..3c2ad60846 100644 --- a/src/ImageSharp/Formats/Tiff/Writers/TiffStreamWriter.cs +++ b/src/ImageSharp/Formats/Tiff/Writers/TiffStreamWriter.cs @@ -10,13 +10,6 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Writers; /// internal sealed class TiffStreamWriter : IDisposable { - private static readonly byte[] PaddingBytes = new byte[4]; - - /// - /// A scratch buffer to reduce allocations. - /// - private readonly byte[] buffer = new byte[4]; - /// /// Initializes a new instance of the class. /// @@ -41,11 +34,12 @@ internal sealed class TiffStreamWriter : IDisposable /// /// Writes an empty four bytes to the stream, returning the offset to be written later. /// + /// Scratch buffer with minimum size of 4. /// The offset to be written later. - public long PlaceMarker() + public long PlaceMarker(Span buffer) { long offset = this.BaseStream.Position; - this.Write(0u); + this.Write(0u, buffer); return offset; } @@ -71,36 +65,38 @@ internal sealed class TiffStreamWriter : IDisposable /// Writes a two-byte unsigned integer to the current stream. /// /// The two-byte unsigned integer to write. - public void Write(ushort value) + /// Scratch buffer with minimum size of 2. + public void Write(ushort value, Span buffer) { if (IsLittleEndian) { - BinaryPrimitives.WriteUInt16LittleEndian(this.buffer, value); + BinaryPrimitives.WriteUInt16LittleEndian(buffer, value); } else { - BinaryPrimitives.WriteUInt16BigEndian(this.buffer, value); + BinaryPrimitives.WriteUInt16BigEndian(buffer, value); } - this.BaseStream.Write(this.buffer.AsSpan(0, 2)); + this.BaseStream.Write(buffer.Slice(0, 2)); } /// /// Writes a four-byte unsigned integer to the current stream. /// /// The four-byte unsigned integer to write. - public void Write(uint value) + /// Scratch buffer with minimum size of 4. + public void Write(uint value, Span buffer) { if (IsLittleEndian) { - BinaryPrimitives.WriteUInt32LittleEndian(this.buffer, value); + BinaryPrimitives.WriteUInt32LittleEndian(buffer, value); } else { - BinaryPrimitives.WriteUInt32BigEndian(this.buffer, value); + BinaryPrimitives.WriteUInt32BigEndian(buffer, value); } - this.BaseStream.Write(this.buffer.AsSpan(0, 4)); + this.BaseStream.Write(buffer.Slice(0, 4)); } /// @@ -113,7 +109,10 @@ internal sealed class TiffStreamWriter : IDisposable if (value.Length % 4 != 0) { - this.BaseStream.Write(PaddingBytes, 0, 4 - (value.Length % 4)); + // No allocation occurs, refers directly to assembly's data segment. + ReadOnlySpan paddingBytes = new byte[4] { 0x00, 0x00, 0x00, 0x00 }; + paddingBytes = paddingBytes[..(4 - (value.Length % 4))]; + this.BaseStream.Write(paddingBytes); } } @@ -122,18 +121,19 @@ internal sealed class TiffStreamWriter : IDisposable /// /// The offset returned when placing the marker /// The four-byte unsigned integer to write. - public void WriteMarker(long offset, uint value) + /// Scratch buffer. + public void WriteMarker(long offset, uint value, Span buffer) { long back = this.BaseStream.Position; this.BaseStream.Seek(offset, SeekOrigin.Begin); - this.Write(value); + this.Write(value, buffer); this.BaseStream.Seek(back, SeekOrigin.Begin); } - public void WriteMarkerFast(long offset, uint value) + public void WriteMarkerFast(long offset, uint value, Span buffer) { this.BaseStream.Seek(offset, SeekOrigin.Begin); - this.Write(value); + this.Write(value, buffer); } /// diff --git a/tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs index 73ce216d8d..4646de7f82 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs @@ -211,8 +211,8 @@ public class BigTiffMetadataTests foreach (IExifValue entry in values) { - writer.Write((ushort)entry.Tag); - writer.Write((ushort)entry.DataType); + writer.Write((ushort)entry.Tag, buffer); + writer.Write((ushort)entry.DataType, buffer); WriteLong8(writer, buffer, ExifWriter.GetNumberOfComponents(entry)); uint length = ExifWriter.GetLength(entry); diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderHeaderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderHeaderTests.cs index 7907597854..8724147301 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderHeaderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderHeaderTests.cs @@ -19,7 +19,7 @@ public class TiffEncoderHeaderTests using (TiffStreamWriter writer = new(stream)) { - long firstIfdMarker = TiffEncoderCore.WriteHeader(writer); + long firstIfdMarker = TiffEncoderCore.WriteHeader(writer, stackalloc byte[4]); } Assert.Equal(new byte[] { 0x49, 0x49, 42, 0, 0x00, 0x00, 0x00, 0x00 }, stream.ToArray()); @@ -32,7 +32,7 @@ public class TiffEncoderHeaderTests TiffEncoderCore encoder = new(Encoder, Configuration.Default.MemoryAllocator); using TiffStreamWriter writer = new(stream); - long firstIfdMarker = TiffEncoderCore.WriteHeader(writer); + long firstIfdMarker = TiffEncoderCore.WriteHeader(writer, stackalloc byte[4]); Assert.Equal(4, firstIfdMarker); } } diff --git a/tests/ImageSharp.Tests/Formats/Tiff/Utils/TiffWriterTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/Utils/TiffWriterTests.cs index f6a1257f47..9b26ab2702 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/Utils/TiffWriterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/Utils/TiffWriterTests.cs @@ -53,7 +53,7 @@ public class TiffWriterTests { using var stream = new MemoryStream(); using var writer = new TiffStreamWriter(stream); - writer.Write(1234); + writer.Write(1234, stackalloc byte[2]); Assert.Equal(new byte[] { 0xD2, 0x04 }, stream.ToArray()); } @@ -63,7 +63,7 @@ public class TiffWriterTests { using var stream = new MemoryStream(); using var writer = new TiffStreamWriter(stream); - writer.Write(12345678U); + writer.Write(12345678U, stackalloc byte[4]); Assert.Equal(new byte[] { 0x4E, 0x61, 0xBC, 0x00 }, stream.ToArray()); } @@ -89,16 +89,17 @@ public class TiffWriterTests public void WriteMarker_WritesToPlacedPosition() { using var stream = new MemoryStream(); + Span buffer = stackalloc byte[4]; using (var writer = new TiffStreamWriter(stream)) { - writer.Write(0x11111111); - long marker = writer.PlaceMarker(); - writer.Write(0x33333333); + writer.Write(0x11111111, buffer); + long marker = writer.PlaceMarker(buffer); + writer.Write(0x33333333, buffer); - writer.WriteMarker(marker, 0x12345678); + writer.WriteMarker(marker, 0x12345678, buffer); - writer.Write(0x44444444); + writer.Write(0x44444444, buffer); } Assert.Equal( From d9e8d79dddbd4619ab34757cd8ff035f58c1647a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sat, 25 Mar 2023 22:35:41 +0100 Subject: [PATCH 20/86] Reduced intermediate allocations: Webp --- .../Formats/Webp/BitReader/Vp8LBitReader.cs | 2 +- .../Formats/Webp/BitWriter/BitWriterBase.cs | 22 ++-- .../Formats/Webp/BitWriter/Vp8LBitWriter.cs | 15 +-- .../Formats/Webp/Lossless/HistogramEncoder.cs | 32 ++++-- .../Formats/Webp/Lossless/HuffmanUtils.cs | 26 ++--- .../Formats/Webp/Lossless/PredictorEncoder.cs | 16 +-- .../Formats/Webp/Lossless/Vp8LEncoder.cs | 57 ++++------ .../Webp/Lossless/WebpLosslessDecoder.cs | 5 +- src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs | 2 +- .../Formats/Webp/Lossy/Vp8EncIterator.cs | 8 +- .../Formats/Webp/Lossy/Vp8Encoder.cs | 20 ++-- .../Formats/Webp/Lossy/Vp8Histogram.cs | 25 ++--- .../Formats/Webp/Lossy/Vp8Residual.cs | 11 +- .../Formats/Webp/Lossy/WebpLossyDecoder.cs | 27 ++--- .../Formats/Webp/WebpAnimationDecoder.cs | 35 +++--- .../Formats/Webp/WebpChunkParsingUtils.cs | 26 +++-- .../Formats/Webp/WebpDecoderCore.cs | 104 ++++++++++-------- 17 files changed, 212 insertions(+), 221 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/BitReader/Vp8LBitReader.cs b/src/ImageSharp/Formats/Webp/BitReader/Vp8LBitReader.cs index 8da717545f..659576cf11 100644 --- a/src/ImageSharp/Formats/Webp/BitReader/Vp8LBitReader.cs +++ b/src/ImageSharp/Formats/Webp/BitReader/Vp8LBitReader.cs @@ -192,7 +192,7 @@ internal class Vp8LBitReader : BitReaderBase [MethodImpl(InliningOptions.ShortMethod)] private void ShiftBytes() { - System.Span dataSpan = this.Data!.Memory.Span; + Span dataSpan = this.Data!.Memory.Span; while (this.bitPos >= 8 && this.pos < this.len) { this.value >>= 8; diff --git a/src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs b/src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs index 02b1d0ab6a..8baf2cc156 100644 --- a/src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs +++ b/src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using System.Buffers.Binary; +using System.Runtime.InteropServices; using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Metadata.Profiles.Xmp; @@ -23,7 +24,7 @@ internal abstract class BitWriterBase /// /// A scratch buffer to reduce allocations. /// - private readonly byte[] scratchBuffer = new byte[4]; + private ScratchBuffer scratchBuffer; // mutable struct, don't make readonly /// /// Initializes a new instance of the class. @@ -90,8 +91,8 @@ internal abstract class BitWriterBase protected void WriteRiffHeader(Stream stream, uint riffSize) { stream.Write(WebpConstants.RiffFourCc); - BinaryPrimitives.WriteUInt32LittleEndian(this.scratchBuffer, riffSize); - stream.Write(this.scratchBuffer.AsSpan(0, 4)); + BinaryPrimitives.WriteUInt32LittleEndian(this.scratchBuffer.Span, riffSize); + stream.Write(this.scratchBuffer.Span.Slice(0, 4)); stream.Write(WebpConstants.WebpHeader); } @@ -128,7 +129,7 @@ internal abstract class BitWriterBase DebugGuard.NotNull(metadataBytes, nameof(metadataBytes)); uint size = (uint)metadataBytes.Length; - Span buf = this.scratchBuffer.AsSpan(0, 4); + Span buf = this.scratchBuffer.Span.Slice(0, 4); BinaryPrimitives.WriteUInt32BigEndian(buf, (uint)chunkType); stream.Write(buf); BinaryPrimitives.WriteUInt32LittleEndian(buf, size); @@ -151,7 +152,7 @@ internal abstract class BitWriterBase protected void WriteAlphaChunk(Stream stream, Span dataBytes, bool alphaDataIsCompressed) { uint size = (uint)dataBytes.Length + 1; - Span buf = this.scratchBuffer.AsSpan(0, 4); + Span buf = this.scratchBuffer.Span.Slice(0, 4); BinaryPrimitives.WriteUInt32BigEndian(buf, (uint)WebpChunkType.Alpha); stream.Write(buf); BinaryPrimitives.WriteUInt32LittleEndian(buf, size); @@ -182,7 +183,7 @@ internal abstract class BitWriterBase { uint size = (uint)iccProfileBytes.Length; - Span buf = this.scratchBuffer.AsSpan(0, 4); + Span buf = this.scratchBuffer.Span.Slice(0, 4); BinaryPrimitives.WriteUInt32BigEndian(buf, (uint)WebpChunkType.Iccp); stream.Write(buf); BinaryPrimitives.WriteUInt32LittleEndian(buf, size); @@ -245,7 +246,7 @@ internal abstract class BitWriterBase flags |= 32; } - Span buf = this.scratchBuffer.AsSpan(0, 4); + Span buf = this.scratchBuffer.Span.Slice(0, 4); stream.Write(WebpConstants.Vp8XMagicBytes); BinaryPrimitives.WriteUInt32LittleEndian(buf, WebpConstants.Vp8XChunkSize); stream.Write(buf); @@ -256,4 +257,11 @@ internal abstract class BitWriterBase BinaryPrimitives.WriteUInt32LittleEndian(buf, height - 1); stream.Write(buf[..3]); } + + private unsafe struct ScratchBuffer + { + private fixed byte scratch[4]; + + public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 4); + } } diff --git a/src/ImageSharp/Formats/Webp/BitWriter/Vp8LBitWriter.cs b/src/ImageSharp/Formats/Webp/BitWriter/Vp8LBitWriter.cs index 22bc195d64..9dc7912392 100644 --- a/src/ImageSharp/Formats/Webp/BitWriter/Vp8LBitWriter.cs +++ b/src/ImageSharp/Formats/Webp/BitWriter/Vp8LBitWriter.cs @@ -14,11 +14,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitWriter; /// internal class Vp8LBitWriter : BitWriterBase { - /// - /// A scratch buffer to reduce allocations. - /// - private readonly byte[] scratchBuffer = new byte[8]; - /// /// This is the minimum amount of size the memory buffer is guaranteed to grow when extra space is needed. /// @@ -194,8 +189,9 @@ internal class Vp8LBitWriter : BitWriterBase stream.Write(WebpConstants.Vp8LMagicBytes); // Write Vp8 Header. - BinaryPrimitives.WriteUInt32LittleEndian(this.scratchBuffer, size); - stream.Write(this.scratchBuffer.AsSpan(0, 4)); + Span scratchBuffer = stackalloc byte[8]; + BinaryPrimitives.WriteUInt32LittleEndian(scratchBuffer, size); + stream.Write(scratchBuffer.Slice(0, 4)); stream.WriteByte(WebpConstants.Vp8LHeaderMagicByte); // Write the encoded bytes of the image to the stream. @@ -228,8 +224,9 @@ internal class Vp8LBitWriter : BitWriterBase this.BitWriterResize(extraSize); } - BinaryPrimitives.WriteUInt64LittleEndian(this.scratchBuffer, this.bits); - this.scratchBuffer.AsSpan(0, 4).CopyTo(this.Buffer.AsSpan(this.cur)); + Span scratchBuffer = stackalloc byte[8]; + BinaryPrimitives.WriteUInt64LittleEndian(scratchBuffer, this.bits); + scratchBuffer.Slice(0, 4).CopyTo(this.Buffer.AsSpan(this.cur)); this.cur += WriterBytes; this.bits >>= WriterBits; diff --git a/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs index 5ac3301519..dd59ed2097 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs @@ -6,7 +6,7 @@ using System.Runtime.CompilerServices; namespace SixLabors.ImageSharp.Formats.Webp.Lossless; -internal class HistogramEncoder +internal static class HistogramEncoder { /// /// Number of partitions for the three dominant (literal, red and blue) symbol costs. @@ -27,7 +27,7 @@ internal class HistogramEncoder private const ushort InvalidHistogramSymbol = ushort.MaxValue; - public static void GetHistoImageSymbols(int xSize, int ySize, Vp8LBackwardRefs refs, uint quality, int histoBits, int cacheBits, List imageHisto, Vp8LHistogram tmpHisto, ushort[] histogramSymbols) + public static void GetHistoImageSymbols(int xSize, int ySize, Vp8LBackwardRefs refs, uint quality, int histoBits, int cacheBits, List imageHisto, Vp8LHistogram tmpHisto, Span histogramSymbols) { int histoXSize = histoBits > 0 ? LosslessUtils.SubSampleSize(xSize, histoBits) : 1; int histoYSize = histoBits > 0 ? LosslessUtils.SubSampleSize(ySize, histoBits) : 1; @@ -148,7 +148,7 @@ internal class HistogramEncoder } } - private static int HistogramCopyAndAnalyze(List origHistograms, List histograms, ushort[] histogramSymbols) + private static int HistogramCopyAndAnalyze(List origHistograms, List histograms, Span histogramSymbols) { var stats = new Vp8LStreaks(); var bitsEntropy = new Vp8LBitEntropy(); @@ -171,20 +171,28 @@ internal class HistogramEncoder } } - int numUsed = histogramSymbols.Count(h => h != InvalidHistogramSymbol); + int numUsed = 0; + foreach (ushort h in histogramSymbols) + { + if (h != InvalidHistogramSymbol) + { + numUsed++; + } + } + return numUsed; } private static void HistogramCombineEntropyBin( List histograms, - ushort[] clusters, + Span clusters, ushort[] clusterMappings, Vp8LHistogram curCombo, ushort[] binMap, int numBins, double combineCostFactor) { - var binInfo = new HistogramBinInfo[BinSize]; + Span binInfo = stackalloc HistogramBinInfo[BinSize]; for (int idx = 0; idx < numBins; idx++) { binInfo[idx].First = -1; @@ -258,7 +266,7 @@ internal class HistogramEncoder /// Given a Histogram set, the mapping of clusters 'clusterMapping' and the /// current assignment of the cells in 'symbols', merge the clusters and assign the smallest possible clusters values. /// - private static void OptimizeHistogramSymbols(ushort[] clusterMappings, int numClusters, ushort[] clusterMappingsTmp, ushort[] symbols) + private static void OptimizeHistogramSymbols(ushort[] clusterMappings, int numClusters, ushort[] clusterMappingsTmp, Span symbols) { bool doContinue = true; @@ -331,7 +339,7 @@ internal class HistogramEncoder int maxSize = 9; // Fill the initial mapping. - int[] mappings = new int[histograms.Count]; + Span mappings = histograms.Count <= 64 ? stackalloc int[histograms.Count] : new int[histograms.Count]; for (int j = 0, iter = 0; iter < histograms.Count; iter++) { if (histograms[iter] == null) @@ -388,9 +396,9 @@ internal class HistogramEncoder int bestIdx1 = histoPriorityList[0].Idx1; int bestIdx2 = histoPriorityList[0].Idx2; - int mappingIndex = Array.IndexOf(mappings, bestIdx2); - Span src = mappings.AsSpan(mappingIndex + 1, numUsed - mappingIndex - 1); - Span dst = mappings.AsSpan(mappingIndex); + int mappingIndex = mappings.IndexOf(bestIdx2); + Span src = mappings.Slice(mappingIndex + 1, numUsed - mappingIndex - 1); + Span dst = mappings.Slice(mappingIndex); src.CopyTo(dst); // Merge the histograms and remove bestIdx2 from the list. @@ -528,7 +536,7 @@ internal class HistogramEncoder } } - private static void HistogramRemap(List input, List output, ushort[] symbols) + private static void HistogramRemap(List input, List output, Span symbols) { int inSize = input.Count; int outSize = output.Count; diff --git a/src/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs index 18104331ce..39ad967e38 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs @@ -25,7 +25,7 @@ internal static class HuffmanUtils 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf }; - public static void CreateHuffmanTree(uint[] histogram, int treeDepthLimit, bool[] bufRle, HuffmanTree[] huffTree, HuffmanTreeCode huffCode) + public static void CreateHuffmanTree(uint[] histogram, int treeDepthLimit, bool[] bufRle, Span huffTree, HuffmanTreeCode huffCode) { int numSymbols = huffCode.NumSymbols; bufRle.AsSpan().Clear(); @@ -159,7 +159,7 @@ internal static class HuffmanUtils /// The size of the histogram. /// The tree depth limit. /// How many bits are used for the symbol. - public static void GenerateOptimalTree(HuffmanTree[] tree, uint[] histogram, int histogramSize, int treeDepthLimit, byte[] bitDepths) + public static void GenerateOptimalTree(Span tree, uint[] histogram, int histogramSize, int treeDepthLimit, byte[] bitDepths) { uint countMin; int treeSizeOrig = 0; @@ -177,7 +177,7 @@ internal static class HuffmanUtils return; } - Span treePool = tree.AsSpan(treeSizeOrig); + Span treePool = tree.Slice(treeSizeOrig); // For block sizes with less than 64k symbols we never need to do a // second iteration of this loop. @@ -202,14 +202,8 @@ internal static class HuffmanUtils } // Build the Huffman tree. -#if NET5_0_OR_GREATER - Span treeSlice = tree.AsSpan(0, treeSize); + Span treeSlice = tree.Slice(0, treeSize); treeSlice.Sort(HuffmanTree.Compare); -#else - HuffmanTree[] treeCopy = tree.AsSpan(0, treeSize).ToArray(); - Array.Sort(treeCopy, HuffmanTree.Compare); - treeCopy.AsSpan().CopyTo(tree); -#endif if (treeSize > 1) { @@ -312,12 +306,12 @@ internal static class HuffmanUtils DebugGuard.MustBeGreaterThan(codeLengthsSize, 0, nameof(codeLengthsSize)); // sorted[codeLengthsSize] is a pre-allocated array for sorting symbols by code length. - int[] sorted = new int[codeLengthsSize]; + Span sorted = codeLengthsSize <= 64 ? stackalloc int[codeLengthsSize] : new int[codeLengthsSize]; int totalSize = 1 << rootBits; // total size root table + 2nd level table. int len; // current code length. int symbol; // symbol index in original or sorted table. - int[] counts = new int[WebpConstants.MaxAllowedCodeLength + 1]; // number of codes of each length. - int[] offsets = new int[WebpConstants.MaxAllowedCodeLength + 1]; // offsets in sorted table for each length. + Span counts = stackalloc int[WebpConstants.MaxAllowedCodeLength + 1]; // number of codes of each length. + Span offsets = stackalloc int[WebpConstants.MaxAllowedCodeLength + 1]; // offsets in sorted table for each length. // Build histogram of code lengths. for (symbol = 0; symbol < codeLengthsSize; ++symbol) @@ -544,8 +538,8 @@ internal static class HuffmanUtils private static void ConvertBitDepthsToSymbols(HuffmanTreeCode tree) { // 0 bit-depth means that the symbol does not exist. - uint[] nextCode = new uint[WebpConstants.MaxAllowedCodeLength + 1]; - int[] depthCount = new int[WebpConstants.MaxAllowedCodeLength + 1]; + Span nextCode = stackalloc uint[WebpConstants.MaxAllowedCodeLength + 1]; + Span depthCount = stackalloc int[WebpConstants.MaxAllowedCodeLength + 1]; int len = tree.NumSymbols; for (int i = 0; i < len; i++) @@ -603,7 +597,7 @@ internal static class HuffmanUtils /// Returns the table width of the next 2nd level table. count is the histogram of bit lengths for the remaining symbols, /// len is the code length of the next processed symbol. /// - private static int NextTableBitSize(int[] count, int len, int rootBits) + private static int NextTableBitSize(ReadOnlySpan count, int len, int rootBits) { int left = 1 << (len - rootBits); while (len < WebpConstants.MaxAllowedCodeLength) diff --git a/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs index 689c63f5b1..2170eb1985 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs @@ -57,11 +57,13 @@ internal static unsafe class PredictorEncoder Span scratch = stackalloc short[8]; // TODO: Can we optimize this? - int[][] histo = new int[4][]; - for (int i = 0; i < 4; i++) + int[][] histo = { - histo[i] = new int[256]; - } + new int[256], + new int[256], + new int[256], + new int[256] + }; if (lowEffort) { @@ -233,7 +235,7 @@ internal static unsafe class PredictorEncoder Span maxDiffs = MemoryMarshal.Cast(currentRow[(width + 1)..]); float bestDiff = MaxDiffCost; int bestMode = 0; - uint[] residuals = new uint[1 << WebpConstants.MaxTransformBits]; + Span residuals = stackalloc uint[1 << WebpConstants.MaxTransformBits]; // 256 bytes for (int i = 0; i < 4; i++) { histoArgb[i].AsSpan().Clear(); @@ -299,9 +301,7 @@ internal static unsafe class PredictorEncoder if (curDiff < bestDiff) { - int[][] tmp = histoArgb; - histoArgb = bestHisto; - bestHisto = tmp; + (bestHisto, histoArgb) = (histoArgb, bestHisto); bestDiff = curDiff; bestMode = mode; } diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs index d678da6028..e3c2797bf3 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs @@ -23,7 +23,7 @@ internal class Vp8LEncoder : IDisposable /// /// Scratch buffer to reduce allocations. /// - private readonly int[] scratch = new int[256]; + private ScratchBuffer scratch; // mutable struct, don't make readonly private readonly int[][] histoArgb = { new int[256], new int[256], new int[256], new int[256] }; @@ -549,12 +549,8 @@ internal class Vp8LEncoder : IDisposable // bgra data with transformations applied. Span bgra = this.EncodedData.GetSpan(); int histogramImageXySize = LosslessUtils.SubSampleSize(width, this.HistoBits) * LosslessUtils.SubSampleSize(height, this.HistoBits); - ushort[] histogramSymbols = new ushort[histogramImageXySize]; - HuffmanTree[] huffTree = new HuffmanTree[3 * WebpConstants.CodeLengthCodes]; - for (int i = 0; i < huffTree.Length; i++) - { - huffTree[i] = default; - } + Span histogramSymbols = histogramImageXySize <= 64 ? stackalloc ushort[histogramImageXySize] : new ushort[histogramImageXySize]; + Span huffTree = stackalloc HuffmanTree[3 * WebpConstants.CodeLengthCodes]; if (useCache) { @@ -607,10 +603,6 @@ internal class Vp8LEncoder : IDisposable int histogramImageSize = histogramImage.Count; int bitArraySize = 5 * histogramImageSize; HuffmanTreeCode[] huffmanCodes = new HuffmanTreeCode[bitArraySize]; - for (int i = 0; i < huffmanCodes.Length; i++) - { - huffmanCodes[i] = default; - } GetHuffBitLengthsAndCodes(histogramImage, huffmanCodes); @@ -702,7 +694,7 @@ internal class Vp8LEncoder : IDisposable /// private void EncodePalette(bool lowEffort) { - Span tmpPalette = new uint[WebpConstants.MaxPaletteSize]; + Span tmpPalette = stackalloc uint[WebpConstants.MaxPaletteSize]; int paletteSize = this.PaletteSize; Span palette = this.Palette.Memory.Span; this.bitWriter.PutBits(WebpConstants.TransformPresent, 1); @@ -763,7 +755,7 @@ internal class Vp8LEncoder : IDisposable int transformWidth = LosslessUtils.SubSampleSize(width, colorTransformBits); int transformHeight = LosslessUtils.SubSampleSize(height, colorTransformBits); - PredictorEncoder.ColorSpaceTransform(width, height, colorTransformBits, this.quality, this.EncodedData.GetSpan(), this.TransformData.GetSpan(), this.scratch); + PredictorEncoder.ColorSpaceTransform(width, height, colorTransformBits, this.quality, this.EncodedData.GetSpan(), this.TransformData.GetSpan(), this.scratch.Span); this.bitWriter.PutBits(WebpConstants.TransformPresent, 1); this.bitWriter.PutBits((uint)Vp8LTransformType.CrossColorTransform, 2); @@ -778,16 +770,7 @@ internal class Vp8LEncoder : IDisposable ushort[] histogramSymbols = new ushort[1]; // Only one tree, one symbol. HuffmanTreeCode[] huffmanCodes = new HuffmanTreeCode[5]; - for (int i = 0; i < huffmanCodes.Length; i++) - { - huffmanCodes[i] = default; - } - - HuffmanTree[] huffTree = new HuffmanTree[3UL * WebpConstants.CodeLengthCodes]; - for (int i = 0; i < huffTree.Length; i++) - { - huffTree[i] = default; - } + Span huffTree = stackalloc HuffmanTree[3 * WebpConstants.CodeLengthCodes]; // Calculate backward references from the image pixels. hashChain.Fill(bgra, quality, width, height, lowEffort); @@ -847,10 +830,10 @@ internal class Vp8LEncoder : IDisposable this.StoreImageToBitMask(width, 0, refs, histogramSymbols, huffmanCodes); } - private void StoreHuffmanCode(HuffmanTree[] huffTree, HuffmanTreeToken[] tokens, HuffmanTreeCode huffmanCode) + private void StoreHuffmanCode(Span huffTree, HuffmanTreeToken[] tokens, HuffmanTreeCode huffmanCode) { int count = 0; - Span symbols = this.scratch.AsSpan(0, 2); + Span symbols = this.scratch.Span.Slice(0, 2); symbols.Clear(); const int maxBits = 8; const int maxSymbol = 1 << maxBits; @@ -901,7 +884,7 @@ internal class Vp8LEncoder : IDisposable } } - private void StoreFullHuffmanCode(HuffmanTree[] huffTree, HuffmanTreeToken[] tokens, HuffmanTreeCode tree) + private void StoreFullHuffmanCode(Span huffTree, HuffmanTreeToken[] tokens, HuffmanTreeCode tree) { int i; byte[] codeLengthBitDepth = new byte[WebpConstants.CodeLengthCodes]; @@ -1013,7 +996,7 @@ internal class Vp8LEncoder : IDisposable } } - private void StoreImageToBitMask(int width, int histoBits, Vp8LBackwardRefs backwardRefs, ushort[] histogramSymbols, HuffmanTreeCode[] huffmanCodes) + private void StoreImageToBitMask(int width, int histoBits, Vp8LBackwardRefs backwardRefs, Span histogramSymbols, HuffmanTreeCode[] huffmanCodes) { int histoXSize = histoBits > 0 ? LosslessUtils.SubSampleSize(width, histoBits) : 1; int tileMask = histoBits == 0 ? 0 : -(1 << histoBits); @@ -1143,8 +1126,8 @@ internal class Vp8LEncoder : IDisposable prevRow = currentRow; } - double[] entropyComp = new double[(int)HistoIx.HistoTotal]; - double[] entropy = new double[(int)EntropyIx.NumEntropyIx]; + Span entropyComp = stackalloc double[(int)HistoIx.HistoTotal]; + Span entropy = stackalloc double[(int)EntropyIx.NumEntropyIx]; int lastModeToAnalyze = usePalette ? (int)EntropyIx.Palette : (int)EntropyIx.SpatialSubGreen; // Let's add one zero to the predicted histograms. The zeros are removed @@ -1647,11 +1630,7 @@ internal class Vp8LEncoder : IDisposable // Create Huffman trees. bool[] bufRle = new bool[maxNumSymbols]; - HuffmanTree[] huffTree = new HuffmanTree[3 * maxNumSymbols]; - for (int i = 0; i < huffTree.Length; i++) - { - huffTree[i] = default; - } + Span huffTree = stackalloc HuffmanTree[3 * maxNumSymbols]; for (int i = 0; i < histogramImage.Count; i++) { @@ -1849,4 +1828,14 @@ internal class Vp8LEncoder : IDisposable this.TransformData.Dispose(); this.HashChain.Dispose(); } + + /// + /// Scratch buffer to reduce allocations. + /// + private unsafe struct ScratchBuffer + { + private fixed int scratch[256]; + + public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 256); + } } diff --git a/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs b/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs index 84ddd4b785..19ea424199 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs @@ -498,10 +498,7 @@ internal sealed class WebpLosslessDecoder private int ReadHuffmanCode(int alphabetSize, int[] codeLengths, Span table) { bool simpleCode = this.bitReader.ReadBit(); - for (int i = 0; i < alphabetSize; i++) - { - codeLengths[i] = 0; - } + codeLengths.AsSpan(0, alphabetSize).Clear(); if (simpleCode) { diff --git a/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs b/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs index 76de2e8f4a..e9eb1110b0 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs @@ -121,7 +121,7 @@ internal static unsafe class QuantEnc var rdi4 = new Vp8ModeScore(); var rdTmp = new Vp8ModeScore(); var res = new Vp8Residual(); - Span tmpLevels = new short[16]; + Span tmpLevels = stackalloc short[16]; do { const int numBlocks = 1; diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs index b33ef57a6b..7211f93766 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs @@ -374,7 +374,7 @@ internal class Vp8EncIterator } else { - byte[] modes = new byte[16]; // DC4 + Span modes = stackalloc byte[16]; // DC4 this.SetIntra4Mode(modes); } @@ -407,7 +407,7 @@ internal class Vp8EncIterator public int MbAnalyzeBestIntra4Mode(int bestAlpha) { - byte[] modes = new byte[16]; + Span modes = stackalloc byte[16]; const int maxMode = MaxIntra4Mode; Vp8Histogram totalHisto = new(); int curHisto = 0; @@ -494,13 +494,13 @@ internal class Vp8EncIterator this.CurrentMacroBlockInfo.MacroBlockType = Vp8MacroBlockType.I16X16; } - public void SetIntra4Mode(byte[] modes) + public void SetIntra4Mode(ReadOnlySpan modes) { int modesIdx = 0; int predIdx = this.PredIdx; for (int y = 4; y > 0; y--) { - modes.AsSpan(modesIdx, 4).CopyTo(this.Preds.AsSpan(predIdx)); + modes.Slice(modesIdx, 4).CopyTo(this.Preds.AsSpan(predIdx)); predIdx += this.predsWidth; modesIdx += 4; } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs index eefc4cd0a0..f17d965e87 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs @@ -329,7 +329,7 @@ internal class Vp8Encoder : IDisposable int uvStride = (yStride + 1) >> 1; Vp8EncIterator it = new(this.YTop, this.UvTop, this.Nz, this.MbInfo, this.Preds, this.TopDerr, this.Mbw, this.Mbh); - int[] alphas = new int[WebpConstants.MaxAlpha + 1]; + Span alphas = stackalloc int[WebpConstants.MaxAlpha + 1]; this.alpha = this.MacroBlockAnalysis(width, height, it, y, u, v, yStride, uvStride, alphas, out this.uvAlpha); int totalMb = this.Mbw * this.Mbw; this.alpha /= totalMb; @@ -625,15 +625,15 @@ internal class Vp8Encoder : IDisposable } // Simplified k-Means, to assign Nb segments based on alpha-histogram. - private void AssignSegments(int[] alphas) + private void AssignSegments(ReadOnlySpan alphas) { int nb = this.SegmentHeader.NumSegments < NumMbSegments ? this.SegmentHeader.NumSegments : NumMbSegments; - int[] centers = new int[NumMbSegments]; + Span centers = stackalloc int[NumMbSegments]; int weightedAverage = 0; - int[] map = new int[WebpConstants.MaxAlpha + 1]; + Span map = stackalloc int[WebpConstants.MaxAlpha + 1]; int n, k; - int[] accum = new int[NumMbSegments]; - int[] distAccum = new int[NumMbSegments]; + Span accum = stackalloc int[NumMbSegments]; + Span distAccum = stackalloc int[NumMbSegments]; // Bracket the input. for (n = 0; n <= WebpConstants.MaxAlpha && alphas[n] == 0; ++n) @@ -719,7 +719,7 @@ internal class Vp8Encoder : IDisposable this.SetSegmentAlphas(centers, weightedAverage); } - private void SetSegmentAlphas(int[] centers, int mid) + private void SetSegmentAlphas(ReadOnlySpan centers, int mid) { int nb = this.SegmentHeader.NumSegments; Vp8SegmentInfo[] dqm = this.SegmentInfos; @@ -840,7 +840,7 @@ internal class Vp8Encoder : IDisposable private void SetSegmentProbas() { - int[] p = new int[NumMbSegments]; + Span p = stackalloc int[NumMbSegments]; int n; for (n = 0; n < this.Mbw * this.Mbh; ++n) @@ -931,7 +931,7 @@ internal class Vp8Encoder : IDisposable } } - private int MacroBlockAnalysis(int width, int height, Vp8EncIterator it, Span y, Span u, Span v, int yStride, int uvStride, int[] alphas, out int uvAlpha) + private int MacroBlockAnalysis(int width, int height, Vp8EncIterator it, Span y, Span u, Span v, int yStride, int uvStride, Span alphas, out int uvAlpha) { int alpha = 0; uvAlpha = 0; @@ -952,7 +952,7 @@ internal class Vp8Encoder : IDisposable return alpha; } - private int MbAnalyze(Vp8EncIterator it, int[] alphas, out int bestUvAlpha) + private int MbAnalyze(Vp8EncIterator it, Span alphas, out int bestUvAlpha) { it.SetIntra16Mode(0); // default: Intra16, DC_PRED it.SetSkip(false); // not skipped. diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Histogram.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Histogram.cs index 4036fb2844..2ace43d2d5 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Histogram.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Histogram.cs @@ -10,12 +10,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal sealed class Vp8Histogram { - private readonly int[] scratch = new int[16]; - - private readonly short[] output = new short[16]; - - private readonly int[] distribution = new int[MaxCoeffThresh + 1]; - /// /// Size of histogram used by CollectHistogram. /// @@ -47,17 +41,20 @@ internal sealed class Vp8Histogram public void CollectHistogram(Span reference, Span pred, int startBlock, int endBlock) { + Span scratch = stackalloc int[16]; + Span output = stackalloc short[16]; + Span distribution = stackalloc int[MaxCoeffThresh + 1]; + int j; - this.distribution.AsSpan().Clear(); for (j = startBlock; j < endBlock; j++) { - Vp8Encoding.FTransform(reference[WebpLookupTables.Vp8DspScan[j]..], pred[WebpLookupTables.Vp8DspScan[j]..], this.output, this.scratch); + Vp8Encoding.FTransform(reference[WebpLookupTables.Vp8DspScan[j]..], pred[WebpLookupTables.Vp8DspScan[j]..], output, scratch); // Convert coefficients to bin. if (Avx2.IsSupported) { // Load. - ref short outputRef = ref MemoryMarshal.GetReference(this.output); + ref short outputRef = ref MemoryMarshal.GetReference(output); Vector256 out0 = Unsafe.As>(ref outputRef); // v = abs(out) >> 3 @@ -73,21 +70,21 @@ internal sealed class Vp8Histogram // Convert coefficients to bin. for (int k = 0; k < 16; ++k) { - ++this.distribution[this.output[k]]; + ++distribution[output[k]]; } } else { for (int k = 0; k < 16; ++k) { - int v = Math.Abs(this.output[k]) >> 3; + int v = Math.Abs(output[k]) >> 3; int clippedValue = ClipMax(v, MaxCoeffThresh); - ++this.distribution[clippedValue]; + ++distribution[clippedValue]; } } } - this.SetHistogramData(this.distribution); + this.SetHistogramData(distribution); } public void Merge(Vp8Histogram other) @@ -103,7 +100,7 @@ internal sealed class Vp8Histogram } } - private void SetHistogramData(int[] distribution) + private void SetHistogramData(ReadOnlySpan distribution) { int maxValue = 0; int lastNonZero = 1; diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs index 7384379dab..1770415062 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs @@ -15,10 +15,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// internal class Vp8Residual { - private readonly byte[] scratch = new byte[32]; - - private readonly ushort[] scratchUShort = new ushort[16]; - public int First { get; set; } public int Last { get; set; } @@ -162,9 +158,10 @@ internal class Vp8Residual if (Avx2.IsSupported) { - Span ctxs = this.scratch.AsSpan(0, 16); - Span levels = this.scratch.AsSpan(16, 16); - Span absLevels = this.scratchUShort.AsSpan(); + Span scratch = stackalloc byte[32]; + Span ctxs = scratch.Slice(0, 16); + Span levels = scratch.Slice(16); + Span absLevels = stackalloc ushort[16]; // Precompute clamped levels and contexts, packed to 8b. ref short outputRef = ref MemoryMarshal.GetReference(this.Coeffs); diff --git a/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs b/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs index 96ed8903a0..cb13825bc2 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs @@ -34,16 +34,6 @@ internal sealed class WebpLossyDecoder /// private readonly Configuration configuration; - /// - /// Scratch buffer to reduce allocations. - /// - private readonly int[] scratch = new int[16]; - - /// - /// Another scratch buffer to reduce allocations. - /// - private readonly byte[] scratchBytes = new byte[4]; - /// /// Initializes a new instance of the class. /// @@ -409,6 +399,9 @@ internal sealed class WebpLossyDecoder topYuv.V.CopyTo(yuv[(vOff - WebpConstants.Bps)..]); } + Span scratch = stackalloc int[16]; + Span scratchBytes = stackalloc byte[4]; + // Predict and add residuals. if (block.IsI4x4) { @@ -448,7 +441,7 @@ internal sealed class WebpLossyDecoder LossyUtils.TM4(dst, yuv, offset); break; case 2: - LossyUtils.VE4(dst, yuv, offset, this.scratchBytes); + LossyUtils.VE4(dst, yuv, offset, scratchBytes); break; case 3: LossyUtils.HE4(dst, yuv, offset); @@ -473,7 +466,7 @@ internal sealed class WebpLossyDecoder break; } - DoTransform(bits, coeffs.AsSpan(n * 16), dst, this.scratch); + DoTransform(bits, coeffs.AsSpan(n * 16), dst, scratch); } } else @@ -508,7 +501,7 @@ internal sealed class WebpLossyDecoder { for (int n = 0; n < 16; ++n, bits <<= 2) { - DoTransform(bits, coeffs.AsSpan(n * 16), yDst[WebpConstants.Scan[n]..], this.scratch); + DoTransform(bits, coeffs.AsSpan(n * 16), yDst[WebpConstants.Scan[n]..], scratch); } } } @@ -547,8 +540,8 @@ internal sealed class WebpLossyDecoder break; } - DoUVTransform(bitsUv, coeffs.AsSpan(16 * 16), uDst, this.scratch); - DoUVTransform(bitsUv >> 8, coeffs.AsSpan(20 * 16), vDst, this.scratch); + DoUVTransform(bitsUv, coeffs.AsSpan(16 * 16), uDst, scratch); + DoUVTransform(bitsUv >> 8, coeffs.AsSpan(20 * 16), vDst, scratch); // Stash away top samples for next block. if (mby < dec.MbHeight - 1) @@ -875,14 +868,14 @@ internal sealed class WebpLossyDecoder else { // Parse DC - short[] dc = new short[16]; + Span dc = stackalloc short[16]; int ctx = (int)(mb.NoneZeroDcCoeffs + leftMb.NoneZeroDcCoeffs); int nz = GetCoeffs(br, bands[1], ctx, q.Y2Mat, 0, dc); mb.NoneZeroDcCoeffs = leftMb.NoneZeroDcCoeffs = (uint)(nz > 0 ? 1 : 0); if (nz > 1) { // More than just the DC -> perform the full transform. - LossyUtils.TransformWht(dc, dst, this.scratch); + LossyUtils.TransformWht(dc, dst, stackalloc int[16]); } else { diff --git a/src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs b/src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs index abaa85ef18..21337ce6c8 100644 --- a/src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs +++ b/src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs @@ -17,11 +17,6 @@ namespace SixLabors.ImageSharp.Formats.Webp; /// internal class WebpAnimationDecoder : IDisposable { - /// - /// Reusable buffer. - /// - private readonly byte[] buffer = new byte[4]; - /// /// Used for allocating memory during the decoding operations. /// @@ -89,11 +84,12 @@ internal class WebpAnimationDecoder : IDisposable this.webpMetadata = this.metadata.GetWebpMetadata(); this.webpMetadata.AnimationLoopCount = features.AnimationLoopCount; + Span buffer = stackalloc byte[4]; uint frameCount = 0; int remainingBytes = (int)completeDataSize; while (remainingBytes > 0) { - WebpChunkType chunkType = WebpChunkParsingUtils.ReadChunkType(stream, this.buffer); + WebpChunkType chunkType = WebpChunkParsingUtils.ReadChunkType(stream, buffer); remainingBytes -= 4; switch (chunkType) { @@ -103,7 +99,7 @@ internal class WebpAnimationDecoder : IDisposable break; case WebpChunkType.Xmp: case WebpChunkType.Exif: - WebpChunkParsingUtils.ParseOptionalChunks(stream, chunkType, image!.Metadata, false, this.buffer); + WebpChunkParsingUtils.ParseOptionalChunks(stream, chunkType, image!.Metadata, false, buffer); break; default: WebpThrowHelper.ThrowImageFormatException("Read unexpected webp chunk data"); @@ -134,15 +130,16 @@ internal class WebpAnimationDecoder : IDisposable { AnimationFrameData frameData = this.ReadFrameHeader(stream); long streamStartPosition = stream.Position; + Span buffer = stackalloc byte[4]; - WebpChunkType chunkType = WebpChunkParsingUtils.ReadChunkType(stream, this.buffer); + WebpChunkType chunkType = WebpChunkParsingUtils.ReadChunkType(stream, buffer); bool hasAlpha = false; byte alphaChunkHeader = 0; if (chunkType is WebpChunkType.Alpha) { alphaChunkHeader = this.ReadAlphaData(stream); hasAlpha = true; - chunkType = WebpChunkParsingUtils.ReadChunkType(stream, this.buffer); + chunkType = WebpChunkParsingUtils.ReadChunkType(stream, buffer); } WebpImageInfo? webpInfo = null; @@ -150,12 +147,12 @@ internal class WebpAnimationDecoder : IDisposable switch (chunkType) { case WebpChunkType.Vp8: - webpInfo = WebpChunkParsingUtils.ReadVp8Header(this.memoryAllocator, stream, this.buffer, features); + webpInfo = WebpChunkParsingUtils.ReadVp8Header(this.memoryAllocator, stream, buffer, features); features.Alpha = hasAlpha; features.AlphaChunkHeader = alphaChunkHeader; break; case WebpChunkType.Vp8L: - webpInfo = WebpChunkParsingUtils.ReadVp8LHeader(this.memoryAllocator, stream, this.buffer, features); + webpInfo = WebpChunkParsingUtils.ReadVp8LHeader(this.memoryAllocator, stream, buffer, features); break; default: WebpThrowHelper.ThrowImageFormatException("Read unexpected chunk type, should be VP8 or VP8L"); @@ -226,7 +223,7 @@ internal class WebpAnimationDecoder : IDisposable { this.alphaData?.Dispose(); - uint alphaChunkSize = WebpChunkParsingUtils.ReadChunkSize(stream, this.buffer); + uint alphaChunkSize = WebpChunkParsingUtils.ReadChunkSize(stream, stackalloc byte[4]); int alphaDataSize = (int)(alphaChunkSize - 1); this.alphaData = this.memoryAllocator.Allocate(alphaDataSize); @@ -353,24 +350,26 @@ internal class WebpAnimationDecoder : IDisposable /// Animation frame data. private AnimationFrameData ReadFrameHeader(BufferedReadStream stream) { + Span buffer = stackalloc byte[4]; + AnimationFrameData data = new() { - DataSize = WebpChunkParsingUtils.ReadChunkSize(stream, this.buffer), + DataSize = WebpChunkParsingUtils.ReadChunkSize(stream, buffer), // 3 bytes for the X coordinate of the upper left corner of the frame. - X = WebpChunkParsingUtils.ReadUnsignedInt24Bit(stream, this.buffer), + X = WebpChunkParsingUtils.ReadUnsignedInt24Bit(stream, buffer), // 3 bytes for the Y coordinate of the upper left corner of the frame. - Y = WebpChunkParsingUtils.ReadUnsignedInt24Bit(stream, this.buffer), + Y = WebpChunkParsingUtils.ReadUnsignedInt24Bit(stream, buffer), // Frame width Minus One. - Width = WebpChunkParsingUtils.ReadUnsignedInt24Bit(stream, this.buffer) + 1, + Width = WebpChunkParsingUtils.ReadUnsignedInt24Bit(stream, buffer) + 1, // Frame height Minus One. - Height = WebpChunkParsingUtils.ReadUnsignedInt24Bit(stream, this.buffer) + 1, + Height = WebpChunkParsingUtils.ReadUnsignedInt24Bit(stream, buffer) + 1, // Frame duration. - Duration = WebpChunkParsingUtils.ReadUnsignedInt24Bit(stream, this.buffer) + Duration = WebpChunkParsingUtils.ReadUnsignedInt24Bit(stream, buffer) }; byte flags = (byte)stream.ReadByte(); diff --git a/src/ImageSharp/Formats/Webp/WebpChunkParsingUtils.cs b/src/ImageSharp/Formats/Webp/WebpChunkParsingUtils.cs index e4acdf311c..a7ae474e46 100644 --- a/src/ImageSharp/Formats/Webp/WebpChunkParsingUtils.cs +++ b/src/ImageSharp/Formats/Webp/WebpChunkParsingUtils.cs @@ -18,7 +18,7 @@ internal static class WebpChunkParsingUtils /// Reads the header of a lossy webp image. /// /// Information about this webp image. - public static WebpImageInfo ReadVp8Header(MemoryAllocator memoryAllocator, BufferedReadStream stream, byte[] buffer, WebpFeatures features) + public static WebpImageInfo ReadVp8Header(MemoryAllocator memoryAllocator, BufferedReadStream stream, Span buffer, WebpFeatures features) { // VP8 data size (not including this 4 bytes). int bytesRead = stream.Read(buffer, 0, 4); @@ -77,7 +77,7 @@ internal static class WebpChunkParsingUtils WebpThrowHelper.ThrowInvalidImageContentException("Not enough data to read the VP8 magic bytes"); } - if (!buffer.AsSpan(0, 3).SequenceEqual(WebpConstants.Vp8HeaderMagicBytes)) + if (!buffer.Slice(0, 3).SequenceEqual(WebpConstants.Vp8HeaderMagicBytes)) { WebpThrowHelper.ThrowImageFormatException("VP8 magic bytes not found"); } @@ -91,7 +91,7 @@ internal static class WebpChunkParsingUtils uint tmp = BinaryPrimitives.ReadUInt16LittleEndian(buffer); uint width = tmp & 0x3fff; sbyte xScale = (sbyte)(tmp >> 6); - tmp = BinaryPrimitives.ReadUInt16LittleEndian(buffer.AsSpan(2)); + tmp = BinaryPrimitives.ReadUInt16LittleEndian(buffer.Slice(2)); uint height = tmp & 0x3fff; sbyte yScale = (sbyte)(tmp >> 6); remaining -= 7; @@ -140,7 +140,7 @@ internal static class WebpChunkParsingUtils /// Reads the header of a lossless webp image. /// /// Information about this image. - public static WebpImageInfo ReadVp8LHeader(MemoryAllocator memoryAllocator, BufferedReadStream stream, byte[] buffer, WebpFeatures features) + public static WebpImageInfo ReadVp8LHeader(MemoryAllocator memoryAllocator, BufferedReadStream stream, Span buffer, WebpFeatures features) { // VP8 data size. uint imageDataSize = ReadChunkSize(stream, buffer); @@ -195,7 +195,7 @@ internal static class WebpChunkParsingUtils /// After the image header, image data will follow. After that optional image metadata chunks (EXIF and XMP) can follow. /// /// Information about this webp image. - public static WebpImageInfo ReadVp8XHeader(BufferedReadStream stream, byte[] buffer, WebpFeatures features) + public static WebpImageInfo ReadVp8XHeader(BufferedReadStream stream, Span buffer, WebpFeatures features) { uint fileSize = ReadChunkSize(stream, buffer); @@ -253,7 +253,7 @@ internal static class WebpChunkParsingUtils /// The stream to read from. /// The buffer to store the read data into. /// A unsigned 24 bit integer. - public static uint ReadUnsignedInt24Bit(BufferedReadStream stream, byte[] buffer) + public static uint ReadUnsignedInt24Bit(BufferedReadStream stream, Span buffer) { if (stream.Read(buffer, 0, 3) == 3) { @@ -271,9 +271,11 @@ internal static class WebpChunkParsingUtils /// The stream to read the data from. /// Buffer to store the data read from the stream. /// The chunk size in bytes. - public static uint ReadChunkSize(BufferedReadStream stream, byte[] buffer) + public static uint ReadChunkSize(BufferedReadStream stream, Span buffer) { - if (stream.Read(buffer, 0, 4) == 4) + DebugGuard.IsTrue(buffer.Length == 4, "buffer has wrong length"); + + if (stream.Read(buffer) == 4) { uint chunkSize = BinaryPrimitives.ReadUInt32LittleEndian(buffer); return (chunkSize % 2 == 0) ? chunkSize : chunkSize + 1; @@ -290,9 +292,11 @@ internal static class WebpChunkParsingUtils /// /// Thrown if the input stream is not valid. /// - public static WebpChunkType ReadChunkType(BufferedReadStream stream, byte[] buffer) + public static WebpChunkType ReadChunkType(BufferedReadStream stream, Span buffer) { - if (stream.Read(buffer, 0, 4) == 4) + DebugGuard.IsTrue(buffer.Length == 4, "buffer has wrong length"); + + if (stream.Read(buffer) == 4) { var chunkType = (WebpChunkType)BinaryPrimitives.ReadUInt32BigEndian(buffer); return chunkType; @@ -306,7 +310,7 @@ internal static class WebpChunkParsingUtils /// If there are more such chunks, readers MAY ignore all except the first one. /// Also, a file may possibly contain both 'EXIF' and 'XMP ' chunks. /// - public static void ParseOptionalChunks(BufferedReadStream stream, WebpChunkType chunkType, ImageMetadata metadata, bool ignoreMetaData, byte[] buffer) + public static void ParseOptionalChunks(BufferedReadStream stream, WebpChunkType chunkType, ImageMetadata metadata, bool ignoreMetaData, Span buffer) { long streamLength = stream.Length; while (stream.Position < streamLength) diff --git a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs b/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs index c158df44d9..0d19dda023 100644 --- a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs +++ b/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs @@ -18,11 +18,6 @@ namespace SixLabors.ImageSharp.Formats.Webp; /// internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable { - /// - /// Reusable buffer. - /// - private readonly byte[] buffer = new byte[4]; - /// /// General configuration options. /// @@ -80,8 +75,9 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable try { ImageMetadata metadata = new(); + Span buffer = stackalloc byte[4]; - uint fileSize = this.ReadImageHeader(stream); + uint fileSize = ReadImageHeader(stream, buffer); using (this.webImageInfo = this.ReadVp8Info(stream, metadata)) { @@ -112,7 +108,7 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable // There can be optional chunks after the image data, like EXIF and XMP. if (this.webImageInfo.Features != null) { - this.ParseOptionalChunks(stream, metadata, this.webImageInfo.Features); + this.ParseOptionalChunks(stream, metadata, this.webImageInfo.Features, buffer); } return image; @@ -128,7 +124,7 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) { - this.ReadImageHeader(stream); + ReadImageHeader(stream, stackalloc byte[4]); ImageMetadata metadata = new(); using (this.webImageInfo = this.ReadVp8Info(stream, metadata, true)) @@ -144,8 +140,9 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// Reads and skips over the image header. /// /// The stream to decode from. + /// Temporary buffer. /// The file size in bytes. - private uint ReadImageHeader(BufferedReadStream stream) + private static uint ReadImageHeader(BufferedReadStream stream, Span buffer) { // Skip FourCC header, we already know its a RIFF file at this point. stream.Skip(4); @@ -153,7 +150,7 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable // Read file size. // The size of the file in bytes starting at offset 8. // The file size in the header is the total size of the chunks that follow plus 4 bytes for the ‘WEBP’ FourCC. - uint fileSize = WebpChunkParsingUtils.ReadChunkSize(stream, this.buffer); + uint fileSize = WebpChunkParsingUtils.ReadChunkSize(stream, buffer); // Skip 'WEBP' from the header. stream.Skip(4); @@ -172,35 +169,36 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable { WebpMetadata webpMetadata = metadata.GetFormatMetadata(WebpFormat.Instance); - WebpChunkType chunkType = WebpChunkParsingUtils.ReadChunkType(stream, this.buffer); + Span buffer = stackalloc byte[4]; + WebpChunkType chunkType = WebpChunkParsingUtils.ReadChunkType(stream, buffer); WebpFeatures features = new(); switch (chunkType) { case WebpChunkType.Vp8: webpMetadata.FileFormat = WebpFileFormatType.Lossy; - return WebpChunkParsingUtils.ReadVp8Header(this.memoryAllocator, stream, this.buffer, features); + return WebpChunkParsingUtils.ReadVp8Header(this.memoryAllocator, stream, buffer, features); case WebpChunkType.Vp8L: webpMetadata.FileFormat = WebpFileFormatType.Lossless; - return WebpChunkParsingUtils.ReadVp8LHeader(this.memoryAllocator, stream, this.buffer, features); + return WebpChunkParsingUtils.ReadVp8LHeader(this.memoryAllocator, stream, buffer, features); case WebpChunkType.Vp8X: - WebpImageInfo webpInfos = WebpChunkParsingUtils.ReadVp8XHeader(stream, this.buffer, features); + WebpImageInfo webpInfos = WebpChunkParsingUtils.ReadVp8XHeader(stream, buffer, features); while (stream.Position < stream.Length) { - chunkType = WebpChunkParsingUtils.ReadChunkType(stream, this.buffer); + chunkType = WebpChunkParsingUtils.ReadChunkType(stream, buffer); if (chunkType == WebpChunkType.Vp8) { webpMetadata.FileFormat = WebpFileFormatType.Lossy; - webpInfos = WebpChunkParsingUtils.ReadVp8Header(this.memoryAllocator, stream, this.buffer, features); + webpInfos = WebpChunkParsingUtils.ReadVp8Header(this.memoryAllocator, stream, buffer, features); } else if (chunkType == WebpChunkType.Vp8L) { webpMetadata.FileFormat = WebpFileFormatType.Lossless; - webpInfos = WebpChunkParsingUtils.ReadVp8LHeader(this.memoryAllocator, stream, this.buffer, features); + webpInfos = WebpChunkParsingUtils.ReadVp8LHeader(this.memoryAllocator, stream, buffer, features); } else if (WebpChunkParsingUtils.IsOptionalVp8XChunk(chunkType)) { - bool isAnimationChunk = this.ParseOptionalExtendedChunks(stream, metadata, chunkType, features, ignoreAlpha); + bool isAnimationChunk = this.ParseOptionalExtendedChunks(stream, metadata, chunkType, features, ignoreAlpha, buffer); if (isAnimationChunk) { return webpInfos; @@ -209,7 +207,7 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable else { // Ignore unknown chunks. - uint chunkSize = this.ReadChunkSize(stream); + uint chunkSize = ReadChunkSize(stream, buffer); stream.Skip((int)chunkSize); } } @@ -230,34 +228,36 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// The chunk type. /// The webp image features. /// For identify, the alpha data should not be read. + /// Temporary buffer. /// true, if its a alpha chunk. private bool ParseOptionalExtendedChunks( BufferedReadStream stream, ImageMetadata metadata, WebpChunkType chunkType, WebpFeatures features, - bool ignoreAlpha) + bool ignoreAlpha, + Span buffer) { switch (chunkType) { case WebpChunkType.Iccp: - this.ReadIccProfile(stream, metadata); + this.ReadIccProfile(stream, metadata, buffer); break; case WebpChunkType.Exif: - this.ReadExifProfile(stream, metadata); + this.ReadExifProfile(stream, metadata, buffer); break; case WebpChunkType.Xmp: - this.ReadXmpProfile(stream, metadata); + this.ReadXmpProfile(stream, metadata, buffer); break; case WebpChunkType.AnimationParameter: - this.ReadAnimationParameters(stream, features); + ReadAnimationParameters(stream, features, buffer); return true; case WebpChunkType.Alpha: - this.ReadAlphaData(stream, features, ignoreAlpha); + this.ReadAlphaData(stream, features, ignoreAlpha, buffer); break; default: WebpThrowHelper.ThrowImageFormatException("Unexpected chunk followed VP8X header"); @@ -273,7 +273,8 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// The stream to decode from. /// The image metadata. /// The webp features. - private void ParseOptionalChunks(BufferedReadStream stream, ImageMetadata metadata, WebpFeatures features) + /// Temporary buffer. + private void ParseOptionalChunks(BufferedReadStream stream, ImageMetadata metadata, WebpFeatures features, Span buffer) { if (this.skipMetadata || (!features.ExifProfile && !features.XmpMetaData)) { @@ -284,19 +285,19 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable while (stream.Position < streamLength) { // Read chunk header. - WebpChunkType chunkType = this.ReadChunkType(stream); + WebpChunkType chunkType = ReadChunkType(stream, buffer); if (chunkType == WebpChunkType.Exif && metadata.ExifProfile == null) { - this.ReadExifProfile(stream, metadata); + this.ReadExifProfile(stream, metadata, buffer); } else if (chunkType == WebpChunkType.Xmp && metadata.XmpProfile == null) { - this.ReadXmpProfile(stream, metadata); + this.ReadXmpProfile(stream, metadata, buffer); } else { // Skip duplicate XMP or EXIF chunk. - uint chunkLength = this.ReadChunkSize(stream); + uint chunkLength = ReadChunkSize(stream, buffer); stream.Skip((int)chunkLength); } } @@ -307,9 +308,10 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// /// The stream to decode from. /// The image metadata. - private void ReadExifProfile(BufferedReadStream stream, ImageMetadata metadata) + /// Temporary buffer. + private void ReadExifProfile(BufferedReadStream stream, ImageMetadata metadata, Span buffer) { - uint exifChunkSize = this.ReadChunkSize(stream); + uint exifChunkSize = ReadChunkSize(stream, buffer); if (this.skipMetadata) { stream.Skip((int)exifChunkSize); @@ -333,9 +335,10 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// /// The stream to decode from. /// The image metadata. - private void ReadXmpProfile(BufferedReadStream stream, ImageMetadata metadata) + /// Temporary buffer. + private void ReadXmpProfile(BufferedReadStream stream, ImageMetadata metadata, Span buffer) { - uint xmpChunkSize = this.ReadChunkSize(stream); + uint xmpChunkSize = ReadChunkSize(stream, buffer); if (this.skipMetadata) { stream.Skip((int)xmpChunkSize); @@ -359,9 +362,10 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// /// The stream to decode from. /// The image metadata. - private void ReadIccProfile(BufferedReadStream stream, ImageMetadata metadata) + /// Temporary buffer. + private void ReadIccProfile(BufferedReadStream stream, ImageMetadata metadata, Span buffer) { - uint iccpChunkSize = this.ReadChunkSize(stream); + uint iccpChunkSize = ReadChunkSize(stream, buffer); if (this.skipMetadata) { stream.Skip((int)iccpChunkSize); @@ -388,22 +392,23 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// /// The stream to decode from. /// The webp features. - private void ReadAnimationParameters(BufferedReadStream stream, WebpFeatures features) + /// Temporary buffer. + private static void ReadAnimationParameters(BufferedReadStream stream, WebpFeatures features, Span buffer) { features.Animation = true; - uint animationChunkSize = WebpChunkParsingUtils.ReadChunkSize(stream, this.buffer); + uint animationChunkSize = WebpChunkParsingUtils.ReadChunkSize(stream, buffer); byte blue = (byte)stream.ReadByte(); byte green = (byte)stream.ReadByte(); byte red = (byte)stream.ReadByte(); byte alpha = (byte)stream.ReadByte(); features.AnimationBackgroundColor = new Color(new Rgba32(red, green, blue, alpha)); - int bytesRead = stream.Read(this.buffer, 0, 2); + int bytesRead = stream.Read(buffer, 0, 2); if (bytesRead != 2) { WebpThrowHelper.ThrowInvalidImageContentException("Not enough data to read the animation loop count"); } - features.AnimationLoopCount = BinaryPrimitives.ReadUInt16LittleEndian(this.buffer); + features.AnimationLoopCount = BinaryPrimitives.ReadUInt16LittleEndian(buffer); } /// @@ -412,9 +417,10 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// The stream to decode from. /// The features. /// if set to true, skips the chunk data. - private void ReadAlphaData(BufferedReadStream stream, WebpFeatures features, bool ignoreAlpha) + /// Temporary buffer. + private void ReadAlphaData(BufferedReadStream stream, WebpFeatures features, bool ignoreAlpha, Span buffer) { - uint alphaChunkSize = WebpChunkParsingUtils.ReadChunkSize(stream, this.buffer); + uint alphaChunkSize = WebpChunkParsingUtils.ReadChunkSize(stream, buffer); if (ignoreAlpha) { stream.Skip((int)alphaChunkSize); @@ -436,14 +442,15 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// Identifies the chunk type from the chunk. /// /// The stream to decode from. + /// Temporary buffer. /// /// Thrown if the input stream is not valid. /// - private WebpChunkType ReadChunkType(BufferedReadStream stream) + private static WebpChunkType ReadChunkType(BufferedReadStream stream, Span buffer) { - if (stream.Read(this.buffer, 0, 4) == 4) + if (stream.Read(buffer, 0, 4) == 4) { - return (WebpChunkType)BinaryPrimitives.ReadUInt32BigEndian(this.buffer); + return (WebpChunkType)BinaryPrimitives.ReadUInt32BigEndian(buffer); } throw new ImageFormatException("Invalid Webp data."); @@ -454,13 +461,14 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// so the chunk size will be increased by 1 in those cases. /// /// The stream to decode from. + /// Temporary buffer. /// The chunk size in bytes. /// Invalid data. - private uint ReadChunkSize(BufferedReadStream stream) + private static uint ReadChunkSize(BufferedReadStream stream, Span buffer) { - if (stream.Read(this.buffer, 0, 4) == 4) + if (stream.Read(buffer, 0, 4) == 4) { - uint chunkSize = BinaryPrimitives.ReadUInt32LittleEndian(this.buffer); + uint chunkSize = BinaryPrimitives.ReadUInt32LittleEndian(buffer); return (chunkSize % 2 == 0) ? chunkSize : chunkSize + 1; } From 31424c0b6477d9451a64ce22578a1732ef64c20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sat, 25 Mar 2023 22:36:00 +0100 Subject: [PATCH 21/86] Reduced intermediate allocations: Png --- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 57 +++++++++++--------- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 50 +++++++++-------- 2 files changed, 59 insertions(+), 48 deletions(-) diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 3ecc363fa4..d1d29dca6b 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -28,11 +28,6 @@ namespace SixLabors.ImageSharp.Formats.Png; /// internal sealed class PngDecoderCore : IImageDecoderInternals { - /// - /// Reusable buffer. - /// - private readonly byte[] buffer = new byte[4]; - /// /// The general decoder options. /// @@ -154,9 +149,11 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.currentStream = stream; this.currentStream.Skip(8); Image image = null; + Span buffer = stackalloc byte[20]; + try { - while (this.TryReadChunk(out PngChunk chunk)) + while (this.TryReadChunk(buffer, out PngChunk chunk)) { try { @@ -252,10 +249,13 @@ internal sealed class PngDecoderCore : IImageDecoderInternals ImageMetadata metadata = new(); PngMetadata pngMetadata = metadata.GetPngMetadata(); this.currentStream = stream; + Span buffer = stackalloc byte[20]; + this.currentStream.Skip(8); + try { - while (this.TryReadChunk(out PngChunk chunk)) + while (this.TryReadChunk(buffer, out PngChunk chunk)) { try { @@ -1401,9 +1401,11 @@ internal sealed class PngDecoderCore : IImageDecoderInternals return 0; } - this.currentStream.Read(this.buffer, 0, 4); + Span buffer = stackalloc byte[20]; + + this.currentStream.Read(buffer, 0, 4); - if (this.TryReadChunk(out PngChunk chunk)) + if (this.TryReadChunk(buffer, out PngChunk chunk)) { if (chunk.Type == PngChunkType.Data) { @@ -1420,11 +1422,12 @@ internal sealed class PngDecoderCore : IImageDecoderInternals /// /// Reads a chunk from the stream. /// + /// Temporary buffer. /// The image format chunk. /// /// The . /// - private bool TryReadChunk(out PngChunk chunk) + private bool TryReadChunk(Span buffer, out PngChunk chunk) { if (this.nextChunk != null) { @@ -1435,7 +1438,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals return true; } - if (!this.TryReadChunkLength(out int length)) + if (!this.TryReadChunkLength(buffer, out int length)) { chunk = default; @@ -1446,7 +1449,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals while (length < 0 || length > (this.currentStream.Length - this.currentStream.Position)) { // Not a valid chunk so try again until we reach a known chunk. - if (!this.TryReadChunkLength(out length)) + if (!this.TryReadChunkLength(buffer, out length)) { chunk = default; @@ -1454,7 +1457,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals } } - PngChunkType type = this.ReadChunkType(); + PngChunkType type = this.ReadChunkType(buffer); // If we're reading color metadata only we're only interested in the IHDR and tRNS chunks. // We can skip all other chunk data in the stream for better performance. @@ -1471,7 +1474,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals type: type, data: this.ReadChunkData(length)); - this.ValidateChunk(chunk); + this.ValidateChunk(chunk, buffer); // Restore the stream position for IDAT chunks, because it will be decoded later and // was only read to verifying the CRC is correct. @@ -1487,9 +1490,10 @@ internal sealed class PngDecoderCore : IImageDecoderInternals /// Validates the png chunk. /// /// The . - private void ValidateChunk(in PngChunk chunk) + /// Temporary buffer. + private void ValidateChunk(in PngChunk chunk, Span buffer) { - uint inputCrc = this.ReadChunkCrc(); + uint inputCrc = this.ReadChunkCrc(buffer); if (chunk.IsCritical) { @@ -1513,13 +1517,14 @@ internal sealed class PngDecoderCore : IImageDecoderInternals /// /// Reads the cycle redundancy chunk from the data. /// + /// Temporary buffer. [MethodImpl(InliningOptions.ShortMethod)] - private uint ReadChunkCrc() + private uint ReadChunkCrc(Span buffer) { uint crc = 0; - if (this.currentStream.Read(this.buffer, 0, 4) == 4) + if (this.currentStream.Read(buffer, 0, 4) == 4) { - crc = BinaryPrimitives.ReadUInt32BigEndian(this.buffer); + crc = BinaryPrimitives.ReadUInt32BigEndian(buffer); } return crc; @@ -1554,15 +1559,16 @@ internal sealed class PngDecoderCore : IImageDecoderInternals /// /// Identifies the chunk type from the chunk. /// + /// Temporary buffer. /// /// Thrown if the input stream is not valid. /// [MethodImpl(InliningOptions.ShortMethod)] - private PngChunkType ReadChunkType() + private PngChunkType ReadChunkType(Span buffer) { - if (this.currentStream.Read(this.buffer, 0, 4) == 4) + if (this.currentStream.Read(buffer, 0, 4) == 4) { - return (PngChunkType)BinaryPrimitives.ReadUInt32BigEndian(this.buffer); + return (PngChunkType)BinaryPrimitives.ReadUInt32BigEndian(buffer); } PngThrowHelper.ThrowInvalidChunkType(); @@ -1574,16 +1580,17 @@ internal sealed class PngDecoderCore : IImageDecoderInternals /// /// Attempts to read the length of the next chunk. /// + /// Temporary buffer. /// The result length. If the return type is this parameter is passed uninitialized. /// /// Whether the length was read. /// [MethodImpl(InliningOptions.ShortMethod)] - private bool TryReadChunkLength(out int result) + private bool TryReadChunkLength(Span buffer, out int result) { - if (this.currentStream.Read(this.buffer, 0, 4) == 4) + if (this.currentStream.Read(buffer, 0, 4) == 4) { - result = BinaryPrimitives.ReadInt32BigEndian(this.buffer); + result = BinaryPrimitives.ReadInt32BigEndian(buffer); return true; } diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 5794da3d56..a2edbc4c3f 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -38,15 +38,10 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable /// private readonly Configuration configuration; - /// - /// Reusable buffer for writing general data. - /// - private readonly byte[] buffer = new byte[8]; - /// /// Reusable buffer for writing chunk data. /// - private readonly byte[] chunkDataBuffer = new byte[16]; + private ScratchBuffer chunkDataBuffer; // mutable struct, don't make readonly /// /// The encoder with options @@ -576,9 +571,9 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable filterMethod: 0, interlaceMethod: this.interlaceMode); - header.WriteTo(this.chunkDataBuffer); + header.WriteTo(this.chunkDataBuffer.Span); - this.WriteChunk(stream, PngChunkType.Header, this.chunkDataBuffer, 0, PngHeader.Size); + this.WriteChunk(stream, PngChunkType.Header, this.chunkDataBuffer.Span, 0, PngHeader.Size); } /// @@ -652,9 +647,9 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable return; } - PhysicalChunkData.FromMetadata(meta).WriteTo(this.chunkDataBuffer); + PhysicalChunkData.FromMetadata(meta).WriteTo(this.chunkDataBuffer.Span); - this.WriteChunk(stream, PngChunkType.Physical, this.chunkDataBuffer, 0, PhysicalChunkData.Size); + this.WriteChunk(stream, PngChunkType.Physical, this.chunkDataBuffer.Span, 0, PhysicalChunkData.Size); } /// @@ -880,9 +875,9 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable // 4-byte unsigned integer of gamma * 100,000. uint gammaValue = (uint)(this.gamma * 100_000F); - BinaryPrimitives.WriteUInt32BigEndian(this.chunkDataBuffer.AsSpan(0, 4), gammaValue); + BinaryPrimitives.WriteUInt32BigEndian(this.chunkDataBuffer.Span.Slice(0, 4), gammaValue); - this.WriteChunk(stream, PngChunkType.Gamma, this.chunkDataBuffer, 0, 4); + this.WriteChunk(stream, PngChunkType.Gamma, this.chunkDataBuffer.Span, 0, 4); } } @@ -899,7 +894,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable return; } - Span alpha = this.chunkDataBuffer.AsSpan(); + Span alpha = this.chunkDataBuffer.Span; if (pngMetadata.ColorType == PngColorType.Rgb) { if (pngMetadata.TransparentRgb48.HasValue && this.use16Bit) @@ -909,7 +904,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable BinaryPrimitives.WriteUInt16LittleEndian(alpha.Slice(2, 2), rgb.G); BinaryPrimitives.WriteUInt16LittleEndian(alpha.Slice(4, 2), rgb.B); - this.WriteChunk(stream, PngChunkType.Transparency, this.chunkDataBuffer, 0, 6); + this.WriteChunk(stream, PngChunkType.Transparency, this.chunkDataBuffer.Span, 0, 6); } else if (pngMetadata.TransparentRgb24.HasValue) { @@ -918,7 +913,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable alpha[1] = rgb.R; alpha[3] = rgb.G; alpha[5] = rgb.B; - this.WriteChunk(stream, PngChunkType.Transparency, this.chunkDataBuffer, 0, 6); + this.WriteChunk(stream, PngChunkType.Transparency, this.chunkDataBuffer.Span, 0, 6); } } else if (pngMetadata.ColorType == PngColorType.Grayscale) @@ -926,13 +921,13 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable if (pngMetadata.TransparentL16.HasValue && this.use16Bit) { BinaryPrimitives.WriteUInt16LittleEndian(alpha, pngMetadata.TransparentL16.Value.PackedValue); - this.WriteChunk(stream, PngChunkType.Transparency, this.chunkDataBuffer, 0, 2); + this.WriteChunk(stream, PngChunkType.Transparency, this.chunkDataBuffer.Span, 0, 2); } else if (pngMetadata.TransparentL8.HasValue) { alpha.Clear(); alpha[1] = pngMetadata.TransparentL8.Value.PackedValue; - this.WriteChunk(stream, PngChunkType.Transparency, this.chunkDataBuffer, 0, 2); + this.WriteChunk(stream, PngChunkType.Transparency, this.chunkDataBuffer.Span, 0, 2); } } } @@ -1173,12 +1168,14 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable /// The of the data to write. private void WriteChunk(Stream stream, PngChunkType type, Span data, int offset, int length) { - BinaryPrimitives.WriteInt32BigEndian(this.buffer, length); - BinaryPrimitives.WriteUInt32BigEndian(this.buffer.AsSpan(4, 4), (uint)type); + Span buffer = stackalloc byte[8]; + + BinaryPrimitives.WriteInt32BigEndian(buffer, length); + BinaryPrimitives.WriteUInt32BigEndian(buffer.Slice(4, 4), (uint)type); - stream.Write(this.buffer, 0, 8); + stream.Write(buffer); - uint crc = Crc32.Calculate(this.buffer.AsSpan(4, 4)); // Write the type buffer + uint crc = Crc32.Calculate(buffer.Slice(4)); // Write the type buffer if (data.Length > 0 && length > 0) { @@ -1187,9 +1184,9 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable crc = Crc32.Calculate(crc, data.Slice(offset, length)); } - BinaryPrimitives.WriteUInt32BigEndian(this.buffer, crc); + BinaryPrimitives.WriteUInt32BigEndian(buffer, crc); - stream.Write(this.buffer, 0, 4); // write the crc + stream.Write(buffer, 0, 4); // write the crc } /// @@ -1412,4 +1409,11 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable Type t when t == typeof(RgbaVector) => PngBitDepth.Bit16, _ => PngBitDepth.Bit8 }; + + private unsafe struct ScratchBuffer + { + private fixed byte scratch[16]; + + public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 16); + } } From 858a8485b741dd5b2cb790be2e7f37881011e17a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sat, 25 Mar 2023 22:36:15 +0100 Subject: [PATCH 22/86] Reduced intermediate allocations: Jpeg --- .../Jpeg/Components/Decoder/AdobeMarker.cs | 2 +- .../Jpeg/Components/Decoder/JFifMarker.cs | 2 +- .../Formats/Jpeg/JpegDecoderCore.cs | 146 ++++----- .../Formats/Jpeg/JpegEncoderCore.cs | 289 +++++++++--------- 4 files changed, 231 insertions(+), 208 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs index c9ee55cd77..cf2369b2cb 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs @@ -62,7 +62,7 @@ internal readonly struct AdobeMarker : IEquatable /// /// The byte array containing metadata to parse. /// The marker to return. - public static bool TryParse(byte[] bytes, out AdobeMarker marker) + public static bool TryParse(ReadOnlySpan bytes, out AdobeMarker marker) { if (ProfileResolver.IsProfile(bytes, ProfileResolver.AdobeMarker)) { diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs index e13b26f9a9..153dc8a03e 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs @@ -69,7 +69,7 @@ internal readonly struct JFifMarker : IEquatable /// /// The byte array containing metadata to parse. /// The marker to return. - public static bool TryParse(byte[] bytes, out JFifMarker marker) + public static bool TryParse(ReadOnlySpan bytes, out JFifMarker marker) { if (ProfileResolver.IsProfile(bytes, ProfileResolver.JFifMarker)) { diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 45029f9459..3c383e7766 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -27,21 +27,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg; /// internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals { - /// - /// The only supported precision - /// - private readonly byte[] supportedPrecisions = { 8, 12 }; - - /// - /// The buffer used to temporarily store bytes read from the stream. - /// - private readonly byte[] temp = new byte[2 * 16 * 4]; - - /// - /// The buffer used to read markers from the stream. - /// - private readonly byte[] markerBuffer = new byte[2]; - /// /// Whether the image has an EXIF marker. /// @@ -139,6 +124,12 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals this.skipMetadata = options.GeneralOptions.SkipMetadata; } + /// + /// The only supported precision + /// + // Refers to assembly's static data segment, no allocation occurs. + private static ReadOnlySpan SupportedPrecisions => new byte[] { 8, 12 }; + /// public DecoderOptions Options { get; } @@ -257,24 +248,26 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals using MemoryStream ms = new(tableBytes); using BufferedReadStream stream = new(this.configuration, ms); + Span markerBuffer = stackalloc byte[2]; + // Check for the Start Of Image marker. - int bytesRead = stream.Read(this.markerBuffer, 0, 2); - JpegFileMarker fileMarker = new(this.markerBuffer[1], 0); + int bytesRead = stream.Read(markerBuffer); + JpegFileMarker fileMarker = new(markerBuffer[1], 0); if (fileMarker.Marker != JpegConstants.Markers.SOI) { JpegThrowHelper.ThrowInvalidImageContentException("Missing SOI marker."); } // Read next marker. - bytesRead = stream.Read(this.markerBuffer, 0, 2); - fileMarker = new JpegFileMarker(this.markerBuffer[1], (int)stream.Position - 2); + bytesRead = stream.Read(markerBuffer); + fileMarker = new JpegFileMarker(markerBuffer[1], (int)stream.Position - 2); while (fileMarker.Marker != JpegConstants.Markers.EOI || (fileMarker.Marker == JpegConstants.Markers.EOI && fileMarker.Invalid)) { if (!fileMarker.Invalid) { // Get the marker length. - int markerContentByteSize = this.ReadUint16(stream) - 2; + int markerContentByteSize = ReadUint16(stream, markerBuffer) - 2; // Check whether the stream actually has enough bytes to read // markerContentByteSize is always positive so we cast @@ -297,7 +290,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals this.ProcessDefineQuantizationTablesMarker(stream, markerContentByteSize); break; case JpegConstants.Markers.DRI: - this.ProcessDefineRestartIntervalMarker(stream, markerContentByteSize); + this.ProcessDefineRestartIntervalMarker(stream, markerContentByteSize, markerBuffer); break; case JpegConstants.Markers.EOI: return; @@ -305,13 +298,13 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals } // Read next marker. - bytesRead = stream.Read(this.markerBuffer, 0, 2); + bytesRead = stream.Read(markerBuffer); if (bytesRead != 2) { JpegThrowHelper.ThrowInvalidImageContentException("Not enough data to read marker"); } - fileMarker = new JpegFileMarker(this.markerBuffer[1], 0); + fileMarker = new JpegFileMarker(markerBuffer[1], 0); } } @@ -329,9 +322,11 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals this.Metadata = new ImageMetadata(); + Span markerBuffer = stackalloc byte[2]; + // Check for the Start Of Image marker. - stream.Read(this.markerBuffer, 0, 2); - JpegFileMarker fileMarker = new(this.markerBuffer[1], 0); + stream.Read(markerBuffer); + JpegFileMarker fileMarker = new(markerBuffer[1], 0); if (fileMarker.Marker != JpegConstants.Markers.SOI) { JpegThrowHelper.ThrowInvalidImageContentException("Missing SOI marker."); @@ -349,7 +344,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals if (!fileMarker.Invalid) { // Get the marker length. - int markerContentByteSize = this.ReadUint16(stream) - 2; + int markerContentByteSize = ReadUint16(stream, markerBuffer) - 2; // Check whether stream actually has enough bytes to read // markerContentByteSize is always positive so we cast @@ -446,7 +441,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals } else { - this.ProcessDefineRestartIntervalMarker(stream, markerContentByteSize); + this.ProcessDefineRestartIntervalMarker(stream, markerContentByteSize, markerBuffer); } break; @@ -755,8 +750,10 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals return; } - stream.Read(this.temp, 0, JFifMarker.Length); - if (!JFifMarker.TryParse(this.temp, out this.jFif)) + Span temp = stackalloc byte[2 * 16 * 4]; + + stream.Read(temp, 0, JFifMarker.Length); + if (!JFifMarker.TryParse(temp, out this.jFif)) { JpegThrowHelper.ThrowNotSupportedException("Unknown App0 Marker - Expected JFIF."); } @@ -796,11 +793,13 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals JpegThrowHelper.ThrowInvalidImageContentException("Bad App1 Marker length."); } + Span temp = stackalloc byte[2 * 16 * 4]; + // XMP marker is the longer then the EXIF marker, so first try read the EXIF marker bytes. - stream.Read(this.temp, 0, exifMarkerLength); + stream.Read(temp, 0, exifMarkerLength); remaining -= exifMarkerLength; - if (ProfileResolver.IsProfile(this.temp, ProfileResolver.ExifMarker)) + if (ProfileResolver.IsProfile(temp, ProfileResolver.ExifMarker)) { this.hasExif = true; byte[] profile = new byte[remaining]; @@ -819,7 +818,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals remaining = 0; } - if (ProfileResolver.IsProfile(this.temp, ProfileResolver.XmpMarker[..exifMarkerLength])) + if (ProfileResolver.IsProfile(temp, ProfileResolver.XmpMarker[..exifMarkerLength])) { const int remainingXmpMarkerBytes = xmpMarkerLength - exifMarkerLength; if (remaining < remainingXmpMarkerBytes || this.skipMetadata) @@ -829,9 +828,9 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals return; } - stream.Read(this.temp, exifMarkerLength, remainingXmpMarkerBytes); + stream.Read(temp, exifMarkerLength, remainingXmpMarkerBytes); remaining -= remainingXmpMarkerBytes; - if (ProfileResolver.IsProfile(this.temp, ProfileResolver.XmpMarker)) + if (ProfileResolver.IsProfile(temp, ProfileResolver.XmpMarker)) { this.hasXmp = true; byte[] profile = new byte[remaining]; @@ -870,8 +869,8 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals return; } - byte[] identifier = new byte[icclength]; - stream.Read(identifier, 0, icclength); + Span identifier = stackalloc byte[icclength]; + stream.Read(identifier); remaining -= icclength; // We have read it by this point if (ProfileResolver.IsProfile(identifier, ProfileResolver.IccMarker)) @@ -911,13 +910,13 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals return; } - stream.Read(this.temp, 0, ProfileResolver.AdobePhotoshopApp13Marker.Length); + Span temp = stackalloc byte[2 * 16 * 4]; + stream.Read(temp, 0, ProfileResolver.AdobePhotoshopApp13Marker.Length); remaining -= ProfileResolver.AdobePhotoshopApp13Marker.Length; - if (ProfileResolver.IsProfile(this.temp, ProfileResolver.AdobePhotoshopApp13Marker)) + if (ProfileResolver.IsProfile(temp, ProfileResolver.AdobePhotoshopApp13Marker)) { - byte[] resourceBlockData = new byte[remaining]; - stream.Read(resourceBlockData, 0, remaining); - Span blockDataSpan = resourceBlockData.AsSpan(); + Span blockDataSpan = remaining <= 128 ? stackalloc byte[remaining] : new byte[remaining]; + stream.Read(blockDataSpan); while (blockDataSpan.Length > 12) { @@ -1047,10 +1046,12 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals return; } - stream.Read(this.temp, 0, markerLength); + Span temp = stackalloc byte[2 * 16 * 4]; + + stream.Read(temp, 0, markerLength); remaining -= markerLength; - if (AdobeMarker.TryParse(this.temp, out this.adobe)) + if (AdobeMarker.TryParse(temp, out this.adobe)) { this.hasAdobeMarker = true; } @@ -1072,6 +1073,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals private void ProcessDefineQuantizationTablesMarker(BufferedReadStream stream, int remaining) { JpegMetadata jpegMetadata = this.Metadata.GetFormatMetadata(JpegFormat.Instance); + Span temp = stackalloc byte[2 * 16 * 4]; while (remaining > 0) { @@ -1102,13 +1104,13 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals JpegThrowHelper.ThrowBadMarker(nameof(JpegConstants.Markers.DQT), remaining); } - stream.Read(this.temp, 0, 64); + stream.Read(temp, 0, 64); remaining -= 64; // Parsing quantization table & saving it in natural order for (int j = 0; j < 64; j++) { - table[ZigZag.ZigZagOrder[j]] = this.temp[j]; + table[ZigZag.ZigZagOrder[j]] = temp[j]; } break; @@ -1121,13 +1123,13 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals JpegThrowHelper.ThrowBadMarker(nameof(JpegConstants.Markers.DQT), remaining); } - stream.Read(this.temp, 0, 128); + stream.Read(temp, 0, 128); remaining -= 128; // Parsing quantization table & saving it in natural order for (int j = 0; j < 64; j++) { - table[ZigZag.ZigZagOrder[j]] = (this.temp[2 * j] << 8) | this.temp[(2 * j) + 1]; + table[ZigZag.ZigZagOrder[j]] = (temp[2 * j] << 8) | temp[(2 * j) + 1]; } break; @@ -1174,28 +1176,30 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals JpegThrowHelper.ThrowInvalidImageContentException("Multiple SOF markers. Only single frame jpegs supported."); } + Span temp = stackalloc byte[2 * 16 * 4]; + // Read initial marker definitions. const int length = 6; - int bytesRead = stream.Read(this.temp, 0, length); + int bytesRead = stream.Read(temp, 0, length); if (bytesRead != length) { JpegThrowHelper.ThrowInvalidImageContentException("SOF marker does not contain enough data."); } // 1 byte: Bits/sample precision. - byte precision = this.temp[0]; + byte precision = temp[0]; // Validate: only 8-bit and 12-bit precisions are supported. - if (Array.IndexOf(this.supportedPrecisions, precision) == -1) + if (SupportedPrecisions.IndexOf(precision) < 0) { JpegThrowHelper.ThrowInvalidImageContentException("Only 8-Bit and 12-Bit precision is supported."); } // 2 byte: Height - int frameHeight = (this.temp[1] << 8) | this.temp[2]; + int frameHeight = (temp[1] << 8) | temp[2]; // 2 byte: Width - int frameWidth = (this.temp[3] << 8) | this.temp[4]; + int frameWidth = (temp[3] << 8) | temp[4]; // Validate: width/height > 0 (they are upper-bounded by 2 byte max value so no need to check that). if (frameHeight == 0 || frameWidth == 0) @@ -1204,7 +1208,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals } // 1 byte: Number of components. - byte componentCount = this.temp[5]; + byte componentCount = temp[5]; // Validate: componentCount more than 4 can lead to a buffer overflow during stream // reading so we must limit it to 4. @@ -1227,7 +1231,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals } // components*3 bytes: component data - stream.Read(this.temp, 0, remaining); + stream.Read(temp, 0, remaining); // No need to pool this. They max out at 4 this.Frame.ComponentIds = new byte[componentCount]; @@ -1240,10 +1244,10 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals for (int i = 0; i < this.Frame.Components.Length; i++) { // 1 byte: component identifier - byte componentId = this.temp[index]; + byte componentId = temp[index]; // 1 byte: component sampling factors - byte hv = this.temp[index + 1]; + byte hv = temp[index + 1]; int h = (hv >> 4) & 15; int v = hv & 15; @@ -1270,7 +1274,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals } // 1 byte: quantization table destination selector - byte quantTableIndex = this.temp[index + 2]; + byte quantTableIndex = temp[index + 2]; // Validate: 0-3 range if (quantTableIndex > 3) @@ -1379,7 +1383,8 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals /// /// The input stream. /// The remaining bytes in the segment block. - private void ProcessDefineRestartIntervalMarker(BufferedReadStream stream, int remaining) + /// Scratch buffer. + private void ProcessDefineRestartIntervalMarker(BufferedReadStream stream, int remaining, Span markerBuffer) { if (remaining != 2) { @@ -1388,7 +1393,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals // Save the reset interval, because it can come before or after the SOF marker. // If the reset interval comes after the SOF marker, the scanDecoder has not been created. - this.resetInterval = this.ReadUint16(stream); + this.resetInterval = ReadUint16(stream, markerBuffer); if (this.scanDecoder != null) { @@ -1425,14 +1430,16 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals JpegThrowHelper.ThrowBadMarker(nameof(JpegConstants.Markers.SOS), remaining); } + Span temp = stackalloc byte[2 * 16 * 4]; + // selectorsCount*2 bytes: component index + huffman tables indices - stream.Read(this.temp, 0, selectorsBytes); + stream.Read(temp, 0, selectorsBytes); this.Frame.Interleaved = this.Frame.ComponentCount == selectorsCount; for (int i = 0; i < selectorsBytes; i += 2) { // 1 byte: Component id - int componentSelectorId = this.temp[i]; + int componentSelectorId = temp[i]; int componentIndex = -1; for (int j = 0; j < this.Frame.ComponentIds.Length; j++) @@ -1459,7 +1466,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals // 1 byte: Huffman table selectors. // 4 bits - dc // 4 bits - ac - int tableSpec = this.temp[i + 1]; + int tableSpec = temp[i + 1]; int dcTableIndex = tableSpec >> 4; int acTableIndex = tableSpec & 15; @@ -1475,17 +1482,17 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals } // 3 bytes: Progressive scan decoding data. - int bytesRead = stream.Read(this.temp, 0, 3); + int bytesRead = stream.Read(temp, 0, 3); if (bytesRead != 3) { JpegThrowHelper.ThrowInvalidImageContentException("Not enough data to read progressive scan decoding data"); } - this.scanDecoder.SpectralStart = this.temp[0]; + this.scanDecoder.SpectralStart = temp[0]; - this.scanDecoder.SpectralEnd = this.temp[1]; + this.scanDecoder.SpectralEnd = temp[1]; - int successiveApproximation = this.temp[2]; + int successiveApproximation = temp[2]; this.scanDecoder.SuccessiveHigh = successiveApproximation >> 4; this.scanDecoder.SuccessiveLow = successiveApproximation & 15; @@ -1501,16 +1508,17 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals /// Reads a from the stream advancing it by two bytes. /// /// The input stream. + /// The scratch buffer used for reading from the stream. /// The [MethodImpl(InliningOptions.ShortMethod)] - private ushort ReadUint16(BufferedReadStream stream) + private static ushort ReadUint16(BufferedReadStream stream, Span markerBuffer) { - int bytesRead = stream.Read(this.markerBuffer, 0, 2); + int bytesRead = stream.Read(markerBuffer, 0, 2); if (bytesRead != 2) { JpegThrowHelper.ThrowInvalidImageContentException("jpeg stream does not contain enough data, could not read ushort."); } - return BinaryPrimitives.ReadUInt16BigEndian(this.markerBuffer); + return BinaryPrimitives.ReadUInt16BigEndian(markerBuffer); } } diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index 1d06333e30..95f7fde32c 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -25,11 +25,6 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// private static readonly JpegFrameConfig[] FrameConfigs = CreateFrameConfigs(); - /// - /// A scratch buffer to reduce allocations. - /// - private readonly byte[] buffer = new byte[20]; - private readonly JpegEncoder encoder; /// @@ -67,6 +62,7 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals cancellationToken.ThrowIfCancellationRequested(); this.outputStream = stream; + Span buffer = stackalloc byte[20]; ImageMetadata metadata = image.Metadata; JpegMetadata jpegMetadata = metadata.GetJpegMetadata(); @@ -76,39 +72,39 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals using JpegFrame frame = new(image, frameConfig, interleaved); // Write the Start Of Image marker. - this.WriteStartOfImage(); + this.WriteStartOfImage(buffer); // Write APP0 marker if (frameConfig.AdobeColorTransformMarkerFlag is null) { - this.WriteJfifApplicationHeader(metadata); + this.WriteJfifApplicationHeader(metadata, buffer); } // Write APP14 marker with adobe color extension else { - this.WriteApp14Marker(frameConfig.AdobeColorTransformMarkerFlag.Value); + this.WriteApp14Marker(frameConfig.AdobeColorTransformMarkerFlag.Value, buffer); } // Write Exif, XMP, ICC and IPTC profiles - this.WriteProfiles(metadata); + this.WriteProfiles(metadata, buffer); // Write the image dimensions. - this.WriteStartOfFrame(image.Width, image.Height, frameConfig); + this.WriteStartOfFrame(image.Width, image.Height, frameConfig, buffer); // Write the Huffman tables. HuffmanScanEncoder scanEncoder = new(frame.BlocksPerMcu, stream); - this.WriteDefineHuffmanTables(frameConfig.HuffmanTables, scanEncoder); + this.WriteDefineHuffmanTables(frameConfig.HuffmanTables, scanEncoder, buffer); // Write the quantization tables. - this.WriteDefineQuantizationTables(frameConfig.QuantizationTables, this.encoder.Quality, jpegMetadata); + this.WriteDefineQuantizationTables(frameConfig.QuantizationTables, this.encoder.Quality, jpegMetadata, buffer); // Write scans with actual pixel data using SpectralConverter spectralConverter = new(frame, image, this.QuantizationTables); - this.WriteHuffmanScans(frame, frameConfig, spectralConverter, scanEncoder, cancellationToken); + this.WriteHuffmanScans(frame, frameConfig, spectralConverter, scanEncoder, buffer, cancellationToken); // Write the End Of Image marker. - this.WriteEndOfImageMarker(); + this.WriteEndOfImageMarker(buffer); stream.Flush(); } @@ -116,58 +112,59 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// /// Write the start of image marker. /// - private void WriteStartOfImage() + private void WriteStartOfImage(Span buffer) { // Markers are always prefixed with 0xff. - this.buffer[0] = JpegConstants.Markers.XFF; - this.buffer[1] = JpegConstants.Markers.SOI; + buffer[1] = JpegConstants.Markers.SOI; + buffer[0] = JpegConstants.Markers.XFF; - this.outputStream.Write(this.buffer, 0, 2); + this.outputStream.Write(buffer, 0, 2); } /// /// Writes the application header containing the JFIF identifier plus extra data. /// /// The image metadata. - private void WriteJfifApplicationHeader(ImageMetadata meta) + /// Temporary buffer. + private void WriteJfifApplicationHeader(ImageMetadata meta, Span buffer) { - // Write the JFIF headers - this.buffer[0] = JpegConstants.Markers.XFF; - this.buffer[1] = JpegConstants.Markers.APP0; // Application Marker - this.buffer[2] = 0x00; - this.buffer[3] = 0x10; - this.buffer[4] = 0x4a; // J - this.buffer[5] = 0x46; // F - this.buffer[6] = 0x49; // I - this.buffer[7] = 0x46; // F - this.buffer[8] = 0x00; // = "JFIF",'\0' - this.buffer[9] = 0x01; // versionhi - this.buffer[10] = 0x01; // versionlo + // Write the JFIF headers (highest index first to avoid additional bound checks) + buffer[10] = 0x01; // versionlo + buffer[0] = JpegConstants.Markers.XFF; + buffer[1] = JpegConstants.Markers.APP0; // Application Marker + buffer[2] = 0x00; + buffer[3] = 0x10; + buffer[4] = 0x4a; // J + buffer[5] = 0x46; // F + buffer[6] = 0x49; // I + buffer[7] = 0x46; // F + buffer[8] = 0x00; // = "JFIF",'\0' + buffer[9] = 0x01; // versionhi // Resolution. Big Endian - Span hResolution = this.buffer.AsSpan(12, 2); - Span vResolution = this.buffer.AsSpan(14, 2); + Span hResolution = buffer.Slice(12, 2); + Span vResolution = buffer.Slice(14, 2); if (meta.ResolutionUnits == PixelResolutionUnit.PixelsPerMeter) { // Scale down to PPI - this.buffer[11] = (byte)PixelResolutionUnit.PixelsPerInch; // xyunits + buffer[11] = (byte)PixelResolutionUnit.PixelsPerInch; // xyunits BinaryPrimitives.WriteInt16BigEndian(hResolution, (short)Math.Round(UnitConverter.MeterToInch(meta.HorizontalResolution))); BinaryPrimitives.WriteInt16BigEndian(vResolution, (short)Math.Round(UnitConverter.MeterToInch(meta.VerticalResolution))); } else { // We can simply pass the value. - this.buffer[11] = (byte)meta.ResolutionUnits; // xyunits + buffer[11] = (byte)meta.ResolutionUnits; // xyunits BinaryPrimitives.WriteInt16BigEndian(hResolution, (short)Math.Round(meta.HorizontalResolution)); BinaryPrimitives.WriteInt16BigEndian(vResolution, (short)Math.Round(meta.VerticalResolution)); } // No thumbnail - this.buffer[16] = 0x00; // Thumbnail width - this.buffer[17] = 0x00; // Thumbnail height + buffer[17] = 0x00; // Thumbnail height + buffer[16] = 0x00; // Thumbnail width - this.outputStream.Write(this.buffer, 0, 18); + this.outputStream.Write(buffer, 0, 18); } /// @@ -175,8 +172,9 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// /// The table configuration. /// The scan encoder. + /// Temporary buffer. /// is . - private void WriteDefineHuffmanTables(JpegHuffmanTableConfig[] tableConfigs, HuffmanScanEncoder scanEncoder) + private void WriteDefineHuffmanTables(JpegHuffmanTableConfig[] tableConfigs, HuffmanScanEncoder scanEncoder, Span buffer) { if (tableConfigs is null) { @@ -190,7 +188,7 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals markerlen += 1 + 16 + tableConfigs[i].Table.Values.Length; } - this.WriteMarkerHeader(JpegConstants.Markers.DHT, markerlen); + this.WriteMarkerHeader(JpegConstants.Markers.DHT, markerlen, buffer); for (int i = 0; i < tableConfigs.Length; i++) { JpegHuffmanTableConfig tableConfig = tableConfigs[i]; @@ -208,37 +206,39 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// Writes the APP14 marker to indicate the image is in RGB color space. /// /// The color transform byte. - private void WriteApp14Marker(byte colorTransform) + /// Temporary buffer. + private void WriteApp14Marker(byte colorTransform, Span buffer) { - this.WriteMarkerHeader(JpegConstants.Markers.APP14, 2 + Components.Decoder.AdobeMarker.Length); + this.WriteMarkerHeader(JpegConstants.Markers.APP14, 2 + Components.Decoder.AdobeMarker.Length, buffer); - // Identifier: ASCII "Adobe". - this.buffer[0] = 0x41; - this.buffer[1] = 0x64; - this.buffer[2] = 0x6F; - this.buffer[3] = 0x62; - this.buffer[4] = 0x65; + // Identifier: ASCII "Adobe" (highest index first to avoid additional bound checks). + buffer[4] = 0x65; + buffer[0] = 0x41; + buffer[1] = 0x64; + buffer[2] = 0x6F; + buffer[3] = 0x62; // Version, currently 100. - BinaryPrimitives.WriteInt16BigEndian(this.buffer.AsSpan(5, 2), 100); + BinaryPrimitives.WriteInt16BigEndian(buffer.Slice(5, 2), 100); // Flags0 - BinaryPrimitives.WriteInt16BigEndian(this.buffer.AsSpan(7, 2), 0); + BinaryPrimitives.WriteInt16BigEndian(buffer.Slice(7, 2), 0); // Flags1 - BinaryPrimitives.WriteInt16BigEndian(this.buffer.AsSpan(9, 2), 0); + BinaryPrimitives.WriteInt16BigEndian(buffer.Slice(9, 2), 0); // Color transform byte - this.buffer[11] = colorTransform; + buffer[11] = colorTransform; - this.outputStream.Write(this.buffer.AsSpan(0, 12)); + this.outputStream.Write(buffer.Slice(0, 12)); } /// /// Writes the EXIF profile. /// /// The exif profile. - private void WriteExifProfile(ExifProfile exifProfile) + /// Temporary buffer. + private void WriteExifProfile(ExifProfile exifProfile, Span buffer) { if (exifProfile is null || exifProfile.Values.Count == 0) { @@ -262,7 +262,7 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals int app1Length = bytesToWrite + 2; // Write the app marker, EXIF marker, and data - this.WriteApp1Header(app1Length); + this.WriteApp1Header(app1Length, buffer); this.outputStream.Write(Components.Decoder.ProfileResolver.ExifMarker); this.outputStream.Write(data, 0, bytesToWrite - exifMarkerLength); remaining -= bytesToWrite; @@ -273,7 +273,7 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals bytesToWrite = remaining > maxBytesWithExifId ? maxBytesWithExifId : remaining; app1Length = bytesToWrite + 2 + exifMarkerLength; - this.WriteApp1Header(app1Length); + this.WriteApp1Header(app1Length, buffer); // Write Exif00 marker this.outputStream.Write(Components.Decoder.ProfileResolver.ExifMarker); @@ -289,10 +289,11 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// Writes the IPTC metadata. /// /// The iptc metadata to write. + /// Temporary buffer. /// /// Thrown if the IPTC profile size exceeds the limit of 65533 bytes. /// - private void WriteIptcProfile(IptcProfile iptcProfile) + private void WriteIptcProfile(IptcProfile iptcProfile, Span buffer) { const int maxBytes = 65533; if (iptcProfile is null || !iptcProfile.Values.Any()) @@ -316,14 +317,14 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals Components.Decoder.ProfileResolver.AdobeImageResourceBlockMarker.Length + Components.Decoder.ProfileResolver.AdobeIptcMarker.Length + 2 + 4 + data.Length; - this.WriteAppHeader(app13Length, JpegConstants.Markers.APP13); + this.WriteAppHeader(app13Length, JpegConstants.Markers.APP13, buffer); this.outputStream.Write(Components.Decoder.ProfileResolver.AdobePhotoshopApp13Marker); this.outputStream.Write(Components.Decoder.ProfileResolver.AdobeImageResourceBlockMarker); this.outputStream.Write(Components.Decoder.ProfileResolver.AdobeIptcMarker); this.outputStream.WriteByte(0); // a empty pascal string (padded to make size even) this.outputStream.WriteByte(0); - BinaryPrimitives.WriteInt32BigEndian(this.buffer, data.Length); - this.outputStream.Write(this.buffer, 0, 4); + BinaryPrimitives.WriteInt32BigEndian(buffer, data.Length); + this.outputStream.Write(buffer, 0, 4); this.outputStream.Write(data, 0, data.Length); } @@ -331,10 +332,11 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// Writes the XMP metadata. /// /// The XMP metadata to write. + /// Temporary buffer. /// /// Thrown if the XMP profile size exceeds the limit of 65533 bytes. /// - private void WriteXmpProfile(XmpProfile xmpProfile) + private void WriteXmpProfile(XmpProfile xmpProfile, Span buffer) { if (xmpProfile is null) { @@ -367,7 +369,7 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals dataLength -= length; int app1Length = 2 + Components.Decoder.ProfileResolver.XmpMarker.Length + length; - this.WriteApp1Header(app1Length); + this.WriteApp1Header(app1Length, buffer); this.outputStream.Write(Components.Decoder.ProfileResolver.XmpMarker); this.outputStream.Write(data, offset, length); @@ -379,32 +381,35 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// Writes the App1 header. /// /// The length of the data the app1 marker contains. - private void WriteApp1Header(int app1Length) - => this.WriteAppHeader(app1Length, JpegConstants.Markers.APP1); + /// Temporary buffer. + private void WriteApp1Header(int app1Length, Span buffer) + => this.WriteAppHeader(app1Length, JpegConstants.Markers.APP1, buffer); /// /// Writes a AppX header. /// /// The length of the data the app marker contains. /// The app marker to write. - private void WriteAppHeader(int length, byte appMarker) + /// Temporary buffer. + private void WriteAppHeader(int length, byte appMarker, Span buffer) { - this.buffer[0] = JpegConstants.Markers.XFF; - this.buffer[1] = appMarker; - this.buffer[2] = (byte)((length >> 8) & 0xFF); - this.buffer[3] = (byte)(length & 0xFF); + buffer[0] = JpegConstants.Markers.XFF; + buffer[1] = appMarker; + buffer[2] = (byte)((length >> 8) & 0xFF); + buffer[3] = (byte)(length & 0xFF); - this.outputStream.Write(this.buffer, 0, 4); + this.outputStream.Write(buffer, 0, 4); } /// /// Writes the ICC profile. /// /// The ICC profile to write. + /// Temporary buffer. /// /// Thrown if any of the ICC profiles size exceeds the limit. /// - private void WriteIccProfile(IccProfile iccProfile) + private void WriteIccProfile(IccProfile iccProfile, Span buffer) { if (iccProfile is null) { @@ -446,30 +451,31 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals dataLength -= length; - this.buffer[0] = JpegConstants.Markers.XFF; - this.buffer[1] = JpegConstants.Markers.APP2; // Application Marker + buffer[0] = JpegConstants.Markers.XFF; + buffer[1] = JpegConstants.Markers.APP2; // Application Marker int markerLength = length + 16; - this.buffer[2] = (byte)((markerLength >> 8) & 0xFF); - this.buffer[3] = (byte)(markerLength & 0xFF); - - this.outputStream.Write(this.buffer, 0, 4); - - this.buffer[0] = (byte)'I'; - this.buffer[1] = (byte)'C'; - this.buffer[2] = (byte)'C'; - this.buffer[3] = (byte)'_'; - this.buffer[4] = (byte)'P'; - this.buffer[5] = (byte)'R'; - this.buffer[6] = (byte)'O'; - this.buffer[7] = (byte)'F'; - this.buffer[8] = (byte)'I'; - this.buffer[9] = (byte)'L'; - this.buffer[10] = (byte)'E'; - this.buffer[11] = 0x00; - this.buffer[12] = (byte)current; // The position within the collection. - this.buffer[13] = (byte)count; // The total number of profiles. - - this.outputStream.Write(this.buffer, 0, iccOverheadLength); + buffer[2] = (byte)((markerLength >> 8) & 0xFF); + buffer[3] = (byte)(markerLength & 0xFF); + + this.outputStream.Write(buffer, 0, 4); + + // We write the highest index first, to have only one bound check. + buffer[13] = (byte)count; // The total number of profiles. + buffer[12] = (byte)current; // The position within the collection. + buffer[11] = 0x00; + buffer[0] = (byte)'I'; + buffer[1] = (byte)'C'; + buffer[2] = (byte)'C'; + buffer[3] = (byte)'_'; + buffer[4] = (byte)'P'; + buffer[5] = (byte)'R'; + buffer[6] = (byte)'O'; + buffer[7] = (byte)'F'; + buffer[8] = (byte)'I'; + buffer[9] = (byte)'L'; + buffer[10] = (byte)'E'; + + this.outputStream.Write(buffer, 0, iccOverheadLength); this.outputStream.Write(data, offset, length); current++; @@ -481,7 +487,8 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// Writes the metadata profiles to the image. /// /// The image metadata. - private void WriteProfiles(ImageMetadata metadata) + /// Temporary buffer. + private void WriteProfiles(ImageMetadata metadata, Span buffer) { if (metadata is null) { @@ -494,10 +501,10 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals // - APP2 ICC // - APP13 IPTC metadata.SyncProfiles(); - this.WriteExifProfile(metadata.ExifProfile); - this.WriteXmpProfile(metadata.XmpProfile); - this.WriteIccProfile(metadata.IccProfile); - this.WriteIptcProfile(metadata.IptcProfile); + this.WriteExifProfile(metadata.ExifProfile, buffer); + this.WriteXmpProfile(metadata.XmpProfile, buffer); + this.WriteIccProfile(metadata.IccProfile, buffer); + this.WriteIptcProfile(metadata.IptcProfile, buffer); } /// @@ -506,25 +513,26 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// The frame width. /// The frame height. /// The frame configuration. - private void WriteStartOfFrame(int width, int height, JpegFrameConfig frame) + /// Temporary buffer. + private void WriteStartOfFrame(int width, int height, JpegFrameConfig frame, Span buffer) { JpegComponentConfig[] components = frame.Components; // Length (high byte, low byte), 8 + components * 3. int markerlen = 8 + (3 * components.Length); - this.WriteMarkerHeader(JpegConstants.Markers.SOF0, markerlen); - this.buffer[0] = 8; // Data Precision. 8 for now, 12 and 16 bit jpegs not supported - this.buffer[1] = (byte)(height >> 8); - this.buffer[2] = (byte)(height & 0xff); // (2 bytes, Hi-Lo), must be > 0 if DNL not supported - this.buffer[3] = (byte)(width >> 8); - this.buffer[4] = (byte)(width & 0xff); // (2 bytes, Hi-Lo), must be > 0 if DNL not supported - this.buffer[5] = (byte)components.Length; + this.WriteMarkerHeader(JpegConstants.Markers.SOF0, markerlen, buffer); + buffer[5] = (byte)components.Length; + buffer[0] = 8; // Data Precision. 8 for now, 12 and 16 bit jpegs not supported + buffer[1] = (byte)(height >> 8); + buffer[2] = (byte)(height & 0xff); // (2 bytes, Hi-Lo), must be > 0 if DNL not supported + buffer[3] = (byte)(width >> 8); + buffer[4] = (byte)(width & 0xff); // (2 bytes, Hi-Lo), must be > 0 if DNL not supported // Components data for (int i = 0; i < components.Length; i++) { int i3 = 3 * i; - Span bufferSpan = this.buffer.AsSpan(i3 + 6, 3); + Span bufferSpan = buffer.Slice(i3 + 6, 3); // Quantization table selector bufferSpan[2] = (byte)components[i].QuantizatioTableIndex; @@ -538,14 +546,15 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals bufferSpan[0] = components[i].Id; } - this.outputStream.Write(this.buffer, 0, (3 * (components.Length - 1)) + 9); + this.outputStream.Write(buffer, 0, (3 * (components.Length - 1)) + 9); } /// /// Writes the StartOfScan marker. /// /// The collecction of component configuration items. - private void WriteStartOfScan(Span components) + /// Temporary buffer. + private void WriteStartOfScan(Span components, Span buffer) { // Write the SOS (Start Of Scan) marker "\xff\xda" followed by 12 bytes: // - the marker length "\x00\x0c", @@ -556,14 +565,14 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals // - the bytes "\x00\x3f\x00". Section B.2.3 of the spec says that for // sequential DCTs, those bytes (8-bit Ss, 8-bit Se, 4-bit Ah, 4-bit Al) // should be 0x00, 0x3f, 0x00<<4 | 0x00. - this.buffer[0] = JpegConstants.Markers.XFF; - this.buffer[1] = JpegConstants.Markers.SOS; + buffer[1] = JpegConstants.Markers.SOS; + buffer[0] = JpegConstants.Markers.XFF; // Length (high byte, low byte), must be 6 + 2 * (number of components in scan) int sosSize = 6 + (2 * components.Length); - this.buffer[2] = 0x00; - this.buffer[3] = (byte)sosSize; - this.buffer[4] = (byte)components.Length; // Number of components in a scan + buffer[4] = (byte)components.Length; // Number of components in a scan + buffer[3] = (byte)sosSize; + buffer[2] = 0x00; // Components data for (int i = 0; i < components.Length; i++) @@ -571,27 +580,28 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals int i2 = 2 * i; // Id - this.buffer[i2 + 5] = components[i].Id; + buffer[i2 + 5] = components[i].Id; // Table selectors int tableSelectors = (components[i].DcTableSelector << 4) | components[i].AcTableSelector; - this.buffer[i2 + 6] = (byte)tableSelectors; + buffer[i2 + 6] = (byte)tableSelectors; } - this.buffer[sosSize - 1] = 0x00; // Ss - Start of spectral selection. - this.buffer[sosSize] = 0x3f; // Se - End of spectral selection. - this.buffer[sosSize + 1] = 0x00; // Ah + Ah (Successive approximation bit position high + low) - this.outputStream.Write(this.buffer, 0, sosSize + 2); + buffer[sosSize - 1] = 0x00; // Ss - Start of spectral selection. + buffer[sosSize] = 0x3f; // Se - End of spectral selection. + buffer[sosSize + 1] = 0x00; // Ah + Ah (Successive approximation bit position high + low) + this.outputStream.Write(buffer, 0, sosSize + 2); } /// /// Writes the EndOfImage marker. /// - private void WriteEndOfImageMarker() + /// Temporary buffer. + private void WriteEndOfImageMarker(Span buffer) { - this.buffer[0] = JpegConstants.Markers.XFF; - this.buffer[1] = JpegConstants.Markers.EOI; - this.outputStream.Write(this.buffer, 0, 2); + buffer[1] = JpegConstants.Markers.EOI; + buffer[0] = JpegConstants.Markers.XFF; + this.outputStream.Write(buffer, 0, 2); } /// @@ -602,12 +612,14 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// The frame configuration. /// The spectral converter. /// The scan encoder. + /// Temporary buffer. /// The cancellation token. private void WriteHuffmanScans( JpegFrame frame, JpegFrameConfig frameConfig, SpectralConverter spectralConverter, HuffmanScanEncoder encoder, + Span buffer, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { @@ -615,14 +627,14 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals { frame.AllocateComponents(fullScan: false); - this.WriteStartOfScan(frameConfig.Components); + this.WriteStartOfScan(frameConfig.Components, buffer); encoder.EncodeScanBaselineSingleComponent(frame.Components[0], spectralConverter, cancellationToken); } else if (frame.Interleaved) { frame.AllocateComponents(fullScan: false); - this.WriteStartOfScan(frameConfig.Components); + this.WriteStartOfScan(frameConfig.Components, buffer); encoder.EncodeScanBaselineInterleaved(frameConfig.EncodingColor, frame, spectralConverter, cancellationToken); } else @@ -633,7 +645,7 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals Span components = frameConfig.Components; for (int i = 0; i < frame.Components.Length; i++) { - this.WriteStartOfScan(components.Slice(i, 1)); + this.WriteStartOfScan(components.Slice(i, 1), buffer); encoder.EncodeScanBaseline(frame.Components[i], cancellationToken); } } @@ -644,14 +656,16 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// /// The marker to write. /// The marker length. - private void WriteMarkerHeader(byte marker, int length) + /// Temporary buffer. + private void WriteMarkerHeader(byte marker, int length, Span buffer) { // Markers are always prefixed with 0xff. - this.buffer[0] = JpegConstants.Markers.XFF; - this.buffer[1] = marker; - this.buffer[2] = (byte)(length >> 8); - this.buffer[3] = (byte)(length & 0xff); - this.outputStream.Write(this.buffer, 0, 4); + buffer[3] = (byte)(length & 0xff); + buffer[2] = (byte)(length >> 8); + buffer[1] = marker; + buffer[0] = JpegConstants.Markers.XFF; + + this.outputStream.Write(buffer, 0, 4); } /// @@ -668,15 +682,16 @@ internal sealed unsafe partial class JpegEncoderCore : IImageEncoderInternals /// Quantization tables configs. /// Optional quality value from the options. /// Jpeg metadata instance. - private void WriteDefineQuantizationTables(JpegQuantizationTableConfig[] configs, int? optionsQuality, JpegMetadata metadata) + /// Temporary buffer. + private void WriteDefineQuantizationTables(JpegQuantizationTableConfig[] configs, int? optionsQuality, JpegMetadata metadata, Span tmpBuffer) { int dataLen = configs.Length * (1 + Block8x8.Size); // Marker + quantization table lengths. int markerlen = 2 + dataLen; - this.WriteMarkerHeader(JpegConstants.Markers.DQT, markerlen); + this.WriteMarkerHeader(JpegConstants.Markers.DQT, markerlen, tmpBuffer); - byte[] buffer = new byte[dataLen]; + Span buffer = dataLen <= 256 ? stackalloc byte[dataLen] : new byte[dataLen]; int offset = 0; Block8x8F workspaceBlock = default; From 1d3ae0ed9dc3ad0a20efb6e2650e2d08b24624bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sat, 25 Mar 2023 22:36:30 +0100 Subject: [PATCH 23/86] Reduced intermediate allocations: Gif --- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 29 +++++++++++------- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 32 ++++++++++---------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 6ff2723ddd..efde4e9aa8 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -22,7 +22,7 @@ internal sealed class GifDecoderCore : IImageDecoderInternals /// /// The temp buffer used to reduce allocations. /// - private readonly byte[] buffer = new byte[16]; + private ScratchBuffer buffer; // mutable struct, don't make readonly /// /// The global color table. @@ -249,13 +249,13 @@ internal sealed class GifDecoderCore : IImageDecoderInternals /// The containing image data. private void ReadGraphicalControlExtension(BufferedReadStream stream) { - int bytesRead = stream.Read(this.buffer, 0, 6); + int bytesRead = stream.Read(this.buffer.Span, 0, 6); if (bytesRead != 6) { GifThrowHelper.ThrowInvalidImageContentException("Not enough data to read the graphic control extension"); } - this.graphicsControlExtension = GifGraphicControlExtension.Parse(this.buffer); + this.graphicsControlExtension = GifGraphicControlExtension.Parse(this.buffer.Span); } /// @@ -264,13 +264,13 @@ internal sealed class GifDecoderCore : IImageDecoderInternals /// The containing image data. private void ReadImageDescriptor(BufferedReadStream stream) { - int bytesRead = stream.Read(this.buffer, 0, 9); + int bytesRead = stream.Read(this.buffer.Span, 0, 9); if (bytesRead != 9) { GifThrowHelper.ThrowInvalidImageContentException("Not enough data to read the image descriptor"); } - this.imageDescriptor = GifImageDescriptor.Parse(this.buffer); + this.imageDescriptor = GifImageDescriptor.Parse(this.buffer.Span); if (this.imageDescriptor.Height == 0 || this.imageDescriptor.Width == 0) { GifThrowHelper.ThrowInvalidImageContentException("Width or height should not be 0"); @@ -283,13 +283,13 @@ internal sealed class GifDecoderCore : IImageDecoderInternals /// The containing image data. private void ReadLogicalScreenDescriptor(BufferedReadStream stream) { - int bytesRead = stream.Read(this.buffer, 0, 7); + int bytesRead = stream.Read(this.buffer.Span, 0, 7); if (bytesRead != 7) { GifThrowHelper.ThrowInvalidImageContentException("Not enough data to read the logical screen descriptor"); } - this.logicalScreenDescriptor = GifLogicalScreenDescriptor.Parse(this.buffer); + this.logicalScreenDescriptor = GifLogicalScreenDescriptor.Parse(this.buffer.Span); } /// @@ -306,8 +306,8 @@ internal sealed class GifDecoderCore : IImageDecoderInternals long position = stream.Position; if (appLength == GifConstants.ApplicationBlockSize) { - stream.Read(this.buffer, 0, GifConstants.ApplicationBlockSize); - bool isXmp = this.buffer.AsSpan().StartsWith(GifConstants.XmpApplicationIdentificationBytes); + stream.Read(this.buffer.Span, 0, GifConstants.ApplicationBlockSize); + bool isXmp = this.buffer.Span.StartsWith(GifConstants.XmpApplicationIdentificationBytes); if (isXmp && !this.skipMetadata) { GifXmpApplicationExtension extension = GifXmpApplicationExtension.Read(stream, this.memoryAllocator); @@ -331,8 +331,8 @@ internal sealed class GifDecoderCore : IImageDecoderInternals // http://www.vurdalakov.net/misc/gif/netscape-buffering-application-extension if (subBlockSize == GifConstants.NetscapeLoopingSubBlockSize) { - stream.Read(this.buffer, 0, GifConstants.NetscapeLoopingSubBlockSize); - this.gifMetadata!.RepeatCount = GifNetscapeLoopingApplicationExtension.Parse(this.buffer.AsSpan(1)).RepeatCount; + stream.Read(this.buffer.Span, 0, GifConstants.NetscapeLoopingSubBlockSize); + this.gifMetadata!.RepeatCount = GifNetscapeLoopingApplicationExtension.Parse(this.buffer.Span.Slice(1)).RepeatCount; stream.Skip(1); // Skip the terminator. return; } @@ -762,4 +762,11 @@ internal sealed class GifDecoderCore : IImageDecoderInternals } } } + + private unsafe struct ScratchBuffer + { + private fixed byte scratch[16]; + + public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 16); + } } diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index f736da78dd..c01cc78ef0 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -28,11 +28,6 @@ internal sealed class GifEncoderCore : IImageEncoderInternals /// private readonly Configuration configuration; - /// - /// A reusable buffer used to reduce allocations. - /// - private readonly byte[] buffer = new byte[20]; - /// /// Whether to skip metadata during encode. /// @@ -324,9 +319,10 @@ internal sealed class GifEncoderCore : IImageEncoderInternals backgroundColorIndex: unchecked((byte)transparencyIndex), ratio); - descriptor.WriteTo(this.buffer); + Span buffer = stackalloc byte[20]; + descriptor.WriteTo(buffer); - stream.Write(this.buffer, 0, GifLogicalScreenDescriptor.Size); + stream.Write(buffer, 0, GifLogicalScreenDescriptor.Size); } /// @@ -365,12 +361,14 @@ internal sealed class GifEncoderCore : IImageEncoderInternals return; } + Span buffer = stackalloc byte[2]; + for (int i = 0; i < metadata.Comments.Count; i++) { string comment = metadata.Comments[i]; - this.buffer[0] = GifConstants.ExtensionIntroducer; - this.buffer[1] = GifConstants.CommentLabel; - stream.Write(this.buffer, 0, 2); + buffer[1] = GifConstants.CommentLabel; + buffer[0] = GifConstants.ExtensionIntroducer; + stream.Write(buffer); // Comment will be stored in chunks of 255 bytes, if it exceeds this size. ReadOnlySpan commentSpan = comment.AsSpan(); @@ -437,22 +435,23 @@ internal sealed class GifEncoderCore : IImageEncoderInternals private void WriteExtension(TGifExtension extension, Stream stream) where TGifExtension : struct, IGifExtension { - IMemoryOwner? owner = null; - Span extensionBuffer; int extensionSize = extension.ContentLength; if (extensionSize == 0) { return; } - else if (extensionSize > this.buffer.Length - 3) + + IMemoryOwner? owner = null; + Span extensionBuffer = stackalloc byte[0]; // workaround compiler limitation + if (extensionSize > 128) { owner = this.memoryAllocator.Allocate(extensionSize + 3); extensionBuffer = owner.GetSpan(); } else { - extensionBuffer = this.buffer; + extensionBuffer = stackalloc byte[extensionSize + 3]; } extensionBuffer[0] = GifConstants.ExtensionIntroducer; @@ -489,9 +488,10 @@ internal sealed class GifEncoderCore : IImageEncoderInternals height: (ushort)image.Height, packed: packedValue); - descriptor.WriteTo(this.buffer); + Span buffer = stackalloc byte[20]; + descriptor.WriteTo(buffer); - stream.Write(this.buffer, 0, GifImageDescriptor.Size); + stream.Write(buffer, 0, GifImageDescriptor.Size); } /// From 3c3479ee1218f8acc2ce4a468fb9159fbeace1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sat, 25 Mar 2023 22:36:43 +0100 Subject: [PATCH 24/86] Reduced intermediate allocations: Tga --- src/ImageSharp/Formats/Tga/TgaDecoderCore.cs | 43 ++++++++++---------- src/ImageSharp/Formats/Tga/TgaEncoderCore.cs | 12 ++---- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs index e7dca00f79..26e057bff9 100644 --- a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs @@ -17,11 +17,6 @@ namespace SixLabors.ImageSharp.Formats.Tga; /// internal sealed class TgaDecoderCore : IImageDecoderInternals { - /// - /// A scratch buffer to reduce allocations. - /// - private readonly byte[] scratchBuffer = new byte[4]; - /// /// General configuration options. /// @@ -407,6 +402,7 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals bool invertX = InvertX(origin); using IMemoryOwner row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 2, 0); Span rowSpan = row.GetSpan(); + Span scratchBuffer = stackalloc byte[2]; for (int y = 0; y < height; y++) { @@ -417,7 +413,7 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals { for (int x = width - 1; x >= 0; x--) { - int bytesRead = stream.Read(this.scratchBuffer, 0, 2); + int bytesRead = stream.Read(scratchBuffer); if (bytesRead != 2) { TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a pixel row"); @@ -425,16 +421,16 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals if (!this.hasAlpha) { - this.scratchBuffer[1] |= 1 << 7; + scratchBuffer[1] |= 1 << 7; } if (this.fileHeader.ImageType == TgaImageType.BlackAndWhite) { - color.FromLa16(Unsafe.As(ref MemoryMarshal.GetArrayDataReference(this.scratchBuffer))); + color.FromLa16(Unsafe.As(ref MemoryMarshal.GetReference(scratchBuffer))); } else { - color.FromBgra5551(Unsafe.As(ref MemoryMarshal.GetArrayDataReference(this.scratchBuffer))); + color.FromBgra5551(Unsafe.As(ref MemoryMarshal.GetReference(scratchBuffer))); } pixelSpan[x] = color; @@ -484,6 +480,7 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals bool invertX = InvertX(origin); if (invertX) { + Span scratchBuffer = stackalloc byte[4]; TPixel color = default; for (int y = 0; y < height; y++) { @@ -491,7 +488,7 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals Span pixelSpan = pixels.DangerousGetRowSpan(newY); for (int x = width - 1; x >= 0; x--) { - this.ReadBgr24Pixel(stream, color, x, pixelSpan); + ReadBgr24Pixel(stream, color, x, pixelSpan, scratchBuffer); } } @@ -558,6 +555,8 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals return; } + Span scratchBuffer = stackalloc byte[4]; + for (int y = 0; y < height; y++) { int newY = InvertY(y, height, origin); @@ -566,14 +565,14 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals { for (int x = width - 1; x >= 0; x--) { - this.ReadBgra32Pixel(stream, x, color, pixelRow); + this.ReadBgra32Pixel(stream, x, color, pixelRow, scratchBuffer); } } else { for (int x = 0; x < width; x++) { - this.ReadBgra32Pixel(stream, x, color, pixelRow); + this.ReadBgra32Pixel(stream, x, color, pixelRow, scratchBuffer); } } } @@ -687,16 +686,16 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ReadBgr24Pixel(BufferedReadStream stream, TPixel color, int x, Span pixelSpan) + private static void ReadBgr24Pixel(BufferedReadStream stream, TPixel color, int x, Span pixelSpan, Span scratchBuffer) where TPixel : unmanaged, IPixel { - int bytesRead = stream.Read(this.scratchBuffer, 0, 3); + int bytesRead = stream.Read(scratchBuffer, 0, 3); if (bytesRead != 3) { TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a bgr pixel"); } - color.FromBgr24(Unsafe.As(ref MemoryMarshal.GetArrayDataReference(this.scratchBuffer))); + color.FromBgr24(Unsafe.As(ref MemoryMarshal.GetReference(scratchBuffer))); pixelSpan[x] = color; } @@ -715,10 +714,10 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ReadBgra32Pixel(BufferedReadStream stream, int x, TPixel color, Span pixelRow) + private void ReadBgra32Pixel(BufferedReadStream stream, int x, TPixel color, Span pixelRow, Span scratchBuffer) where TPixel : unmanaged, IPixel { - int bytesRead = stream.Read(this.scratchBuffer, 0, 4); + int bytesRead = stream.Read(scratchBuffer, 0, 4); if (bytesRead != 4) { TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a bgra pixel"); @@ -726,8 +725,8 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals Guard.NotNull(this.tgaMetadata); - byte alpha = this.tgaMetadata.AlphaChannelBits == 0 ? byte.MaxValue : this.scratchBuffer[3]; - color.FromBgra32(new Bgra32(this.scratchBuffer[2], this.scratchBuffer[1], this.scratchBuffer[0], alpha)); + byte alpha = this.tgaMetadata.AlphaChannelBits == 0 ? byte.MaxValue : scratchBuffer[3]; + color.FromBgra32(new Bgra32(scratchBuffer[2], scratchBuffer[1], scratchBuffer[0], alpha)); pixelRow[x] = color; } @@ -814,7 +813,7 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals private void UncompressRle(BufferedReadStream stream, int width, int height, Span buffer, int bytesPerPixel) { int uncompressedPixels = 0; - Span pixel = this.scratchBuffer.AsSpan(0, bytesPerPixel); + Span pixel = stackalloc byte[bytesPerPixel]; int totalPixels = width * height; while (uncompressedPixels < totalPixels) { @@ -825,7 +824,7 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals if (highBit == 1) { int runLength = runLengthByte & 127; - int bytesRead = stream.Read(pixel, 0, bytesPerPixel); + int bytesRead = stream.Read(pixel); if (bytesRead != bytesPerPixel) { TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a pixel from the stream"); @@ -845,7 +844,7 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals int bufferIdx = uncompressedPixels * bytesPerPixel; for (int i = 0; i < runLength + 1; i++, uncompressedPixels++) { - int bytesRead = stream.Read(pixel, 0, bytesPerPixel); + int bytesRead = stream.Read(pixel); if (bytesRead != bytesPerPixel) { TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a pixel from the stream"); diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs index f468ab9ae7..ad63bd356d 100644 --- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs @@ -22,11 +22,6 @@ internal sealed class TgaEncoderCore : IImageEncoderInternals /// private readonly MemoryAllocator memoryAllocator; - /// - /// Reusable buffer for writing data. - /// - private readonly byte[] buffer = new byte[2]; - /// /// The color depth, in number of bits per pixel. /// @@ -221,9 +216,10 @@ internal sealed class TgaEncoderCore : IImageEncoderInternals case TgaBitsPerPixel.Pixel16: Bgra5551 bgra5551 = new(color.ToVector4()); - BinaryPrimitives.WriteInt16LittleEndian(this.buffer, (short)bgra5551.PackedValue); - stream.WriteByte(this.buffer[0]); - stream.WriteByte(this.buffer[1]); + Span buffer = stackalloc byte[2]; + BinaryPrimitives.WriteInt16LittleEndian(buffer, (short)bgra5551.PackedValue); + stream.WriteByte(buffer[0]); + stream.WriteByte(buffer[1]); break; From b9b6f72008689a98cf13ce4bfb89fe9a3de2a3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sat, 25 Mar 2023 22:36:55 +0100 Subject: [PATCH 25/86] Reduced intermediate allocations: Bmp --- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 38 +++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 0c1b273f77..863fed359c 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -453,6 +453,7 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals /// Keeps track of rows, which have undefined pixels. private void UncompressRle4(BufferedReadStream stream, int w, Span buffer, Span undefinedPixels, Span rowsWithUndefinedPixels) { + Span scratchBuffer = stackalloc byte[128]; Span cmd = stackalloc byte[2]; int count = 0; @@ -491,9 +492,9 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals int max = cmd[1]; int bytesToRead = (int)(((uint)max + 1) / 2); - byte[] run = new byte[bytesToRead]; + Span run = bytesToRead <= 128 ? scratchBuffer.Slice(0, bytesToRead) : new byte[bytesToRead]; - stream.Read(run, 0, run.Length); + stream.Read(run); int idx = 0; for (int i = 0; i < max; i++) @@ -559,6 +560,7 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals /// Keeps track of rows, which have undefined pixels. private void UncompressRle8(BufferedReadStream stream, int w, Span buffer, Span undefinedPixels, Span rowsWithUndefinedPixels) { + Span scratchBuffer = stackalloc byte[128]; Span cmd = stackalloc byte[2]; int count = 0; @@ -596,13 +598,13 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals // Take this number of bytes from the stream as uncompressed data. int length = cmd[1]; - byte[] run = new byte[length]; + Span run = length <= 128 ? scratchBuffer.Slice(0, length) : new byte[length]; - stream.Read(run, 0, run.Length); + stream.Read(run); - run.AsSpan().CopyTo(buffer[count..]); + run.CopyTo(buffer[count..]); - count += run.Length; + count += length; // Absolute mode data is aligned to two-byte word-boundary. int padding = length & 1; @@ -639,6 +641,7 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals /// Keeps track of rows, which have undefined pixels. private void UncompressRle24(BufferedReadStream stream, int w, Span buffer, Span undefinedPixels, Span rowsWithUndefinedPixels) { + Span scratchBuffer = stackalloc byte[128]; Span cmd = stackalloc byte[2]; int uncompressedPixels = 0; @@ -675,17 +678,18 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals // If the second byte > 2, we are in 'absolute mode'. // Take this number of bytes from the stream as uncompressed data. int length = cmd[1]; + int length3 = length * 3; - byte[] run = new byte[length * 3]; + Span run = length3 <= 128 ? scratchBuffer.Slice(0, length3) : new byte[length3]; - stream.Read(run, 0, run.Length); + stream.Read(run); - run.AsSpan().CopyTo(buffer[(uncompressedPixels * 3)..]); + run.CopyTo(buffer[(uncompressedPixels * 3)..]); uncompressedPixels += length; // Absolute mode data is aligned to two-byte word-boundary. - int padding = run.Length & 1; + int padding = length3 & 1; stream.Skip(padding); @@ -1286,18 +1290,18 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals // color masks for each color channel follow the info header. if (this.infoHeader.Compression == BmpCompression.BitFields) { - byte[] bitfieldsBuffer = new byte[12]; - stream.Read(bitfieldsBuffer, 0, 12); - Span data = bitfieldsBuffer.AsSpan(); + Span bitfieldsBuffer = stackalloc byte[12]; + stream.Read(bitfieldsBuffer); + Span data = bitfieldsBuffer; this.infoHeader.RedMask = BinaryPrimitives.ReadInt32LittleEndian(data[..4]); this.infoHeader.GreenMask = BinaryPrimitives.ReadInt32LittleEndian(data.Slice(4, 4)); this.infoHeader.BlueMask = BinaryPrimitives.ReadInt32LittleEndian(data.Slice(8, 4)); } else if (this.infoHeader.Compression == BmpCompression.BI_ALPHABITFIELDS) { - byte[] bitfieldsBuffer = new byte[16]; - stream.Read(bitfieldsBuffer, 0, 16); - Span data = bitfieldsBuffer.AsSpan(); + Span bitfieldsBuffer = stackalloc byte[16]; + stream.Read(bitfieldsBuffer); + Span data = bitfieldsBuffer; this.infoHeader.RedMask = BinaryPrimitives.ReadInt32LittleEndian(data[..4]); this.infoHeader.GreenMask = BinaryPrimitives.ReadInt32LittleEndian(data.Slice(4, 4)); this.infoHeader.BlueMask = BinaryPrimitives.ReadInt32LittleEndian(data.Slice(8, 4)); @@ -1470,7 +1474,7 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals { // Usually the color palette is 1024 byte (256 colors * 4), but the documentation does not mention a size limit. // Make sure, that we will not read pass the bitmap offset (starting position of image data). - if ((stream.Position + colorMapSizeBytes) > this.fileHeader.Offset) + if (stream.Position > this.fileHeader.Offset - colorMapSizeBytes) { BmpThrowHelper.ThrowInvalidImageContentException( $"Reading the color map would read beyond the bitmap offset. Either the color map size of '{colorMapSizeBytes}' is invalid or the bitmap offset."); From 5d65ef0afdef0fd59f41af60ecc07bfe0a57c696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sat, 25 Mar 2023 22:37:07 +0100 Subject: [PATCH 26/86] Reduced intermediate allocations: Profiles --- .../Metadata/Profiles/Exif/ExifReader.cs | 33 ++++++++++++------- .../Profiles/Exif/Values/ExifByteArray.cs | 4 +-- .../Metadata/Profiles/ICC/IccProfile.cs | 14 ++++---- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs index 885db3a5e9..953ef74afb 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs @@ -86,10 +86,6 @@ internal class ExifReader : BaseExifReader /// internal abstract class BaseExifReader { - private readonly byte[] buf8 = new byte[8]; - private readonly byte[] buf4 = new byte[4]; - private readonly byte[] buf2 = new byte[2]; - private readonly MemoryAllocator? allocator; private readonly Stream data; private List? invalidTags; @@ -528,20 +524,33 @@ internal abstract class BaseExifReader return read == length; } - protected ulong ReadUInt64() => - this.TryReadSpan(this.buf8) - ? this.ConvertToUInt64(this.buf8) + protected ulong ReadUInt64() + { + Span buffer = stackalloc byte[8]; + + return this.TryReadSpan(buffer) + ? this.ConvertToUInt64(buffer) : default; + } // Known as Long in Exif Specification. - protected uint ReadUInt32() => - this.TryReadSpan(this.buf4) - ? this.ConvertToUInt32(this.buf4) + protected uint ReadUInt32() + { + Span buffer = stackalloc byte[4]; + + return this.TryReadSpan(buffer) + ? this.ConvertToUInt32(buffer) : default; + } - protected ushort ReadUInt16() => this.TryReadSpan(this.buf2) - ? this.ConvertToShort(this.buf2) + protected ushort ReadUInt16() + { + Span buffer = stackalloc byte[2]; + + return this.TryReadSpan(buffer) + ? this.ConvertToShort(buffer) : default; + } private long ConvertToInt64(ReadOnlySpan buffer) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs index 4320cb5e82..6811fc6f9c 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs @@ -45,12 +45,12 @@ internal sealed class ExifByteArray : ExifArrayValue private bool TrySetSignedIntArray(int[] intArrayValue) { - if (Array.FindIndex(intArrayValue, x => x < byte.MinValue || x > byte.MaxValue) > -1) + if (Array.FindIndex(intArrayValue, x => (uint)x > byte.MaxValue) >= 0) { return false; } - var value = new byte[intArrayValue.Length]; + byte[] value = new byte[intArrayValue.Length]; for (int i = 0; i < intArrayValue.Length; i++) { int s = intArrayValue[i]; diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs index 5699f9bf36..3b5e438299 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs @@ -108,10 +108,10 @@ public sealed class IccProfile : IDeepCloneable const int profileIdPos = 84; // need to copy some values because they need to be zero for the hashing - byte[] temp = new byte[24]; - Buffer.BlockCopy(data, profileFlagPos, temp, 0, 4); - Buffer.BlockCopy(data, renderingIntentPos, temp, 4, 4); - Buffer.BlockCopy(data, profileIdPos, temp, 8, 16); + Span temp = stackalloc byte[24]; + data.AsSpan(profileFlagPos, 4).CopyTo(temp); + data.AsSpan(renderingIntentPos, 4).CopyTo(temp.Slice(4)); + data.AsSpan(profileIdPos, 16).CopyTo(temp.Slice(8)); try { @@ -131,9 +131,9 @@ public sealed class IccProfile : IDeepCloneable } finally { - Buffer.BlockCopy(temp, 0, data, profileFlagPos, 4); - Buffer.BlockCopy(temp, 4, data, renderingIntentPos, 4); - Buffer.BlockCopy(temp, 8, data, profileIdPos, 16); + temp.Slice(0, 4).CopyTo(data.AsSpan(profileFlagPos)); + temp.Slice(4, 4).CopyTo(data.AsSpan(renderingIntentPos)); + temp.Slice(8, 16).CopyTo(data.AsSpan(profileIdPos)); } } From 57d0793130a3a71dd896df6bd8e2696fefa9a190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sat, 25 Mar 2023 23:04:02 +0100 Subject: [PATCH 27/86] Fixed build warnings / errors --- src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs | 2 +- src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs | 6 +++--- src/ImageSharp/Formats/Webp/WebpDecoderCore.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 3c383e7766..83a828caaf 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -125,7 +125,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals } /// - /// The only supported precision + /// Gets the only supported precisions /// // Refers to assembly's static data segment, no allocation occurs. private static ReadOnlySpan SupportedPrecisions => new byte[] { 8, 12 }; diff --git a/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs b/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs index cb13825bc2..7952b15b44 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs @@ -361,6 +361,9 @@ internal sealed class WebpLossyDecoder } } + Span scratch = stackalloc int[16]; + Span scratchBytes = stackalloc byte[4]; + // Reconstruct one row. for (int mbx = 0; mbx < dec.MbWidth; mbx++) { @@ -399,9 +402,6 @@ internal sealed class WebpLossyDecoder topYuv.V.CopyTo(yuv[(vOff - WebpConstants.Bps)..]); } - Span scratch = stackalloc int[16]; - Span scratchBytes = stackalloc byte[4]; - // Predict and add residuals. if (block.IsI4x4) { diff --git a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs b/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs index 0d19dda023..223e15a0e7 100644 --- a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs +++ b/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs @@ -228,7 +228,7 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable /// The chunk type. /// The webp image features. /// For identify, the alpha data should not be read. - /// Temporary buffer. + /// Temporary buffer. /// true, if its a alpha chunk. private bool ParseOptionalExtendedChunks( BufferedReadStream stream, From 8199e0611b0ba09c1f15a751dc579daba0de48d4 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 26 Mar 2023 11:17:54 +0200 Subject: [PATCH 28/86] Fix RgbScalar --- .../Jpeg/Components/ColorConverters/JpegColorConverterBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs index 58b0b9b1b2..a0850c304e 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs @@ -229,7 +229,7 @@ internal abstract partial class JpegColorConverterBase return new RgbScalar(precision); } - return new GrayscaleScalar(precision); + return new RgbScalar(precision); } /// From b9e54a16a3cf7a9bfdcc61f77fbcc84ed77af73d Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 26 Mar 2023 11:21:31 +0200 Subject: [PATCH 29/86] Return Vector not Scalar --- .../Jpeg/Components/ColorConverters/JpegColorConverterBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs index a0850c304e..5171c4986e 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs @@ -226,7 +226,7 @@ internal abstract partial class JpegColorConverterBase if (JpegColorConverterVector.IsSupported) { - return new RgbScalar(precision); + return new RgbVector(precision); } return new RgbScalar(precision); From 7b2923d7efe82188f35fd86bb61fbd450160c547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sun, 26 Mar 2023 13:44:25 +0200 Subject: [PATCH 30/86] Use constant to specify the size of the buffer It's only one value for the fixed buffer size and the creation of the span -- so less error prone once the value needs to be updated. --- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 5 +++-- .../Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs | 1 + src/ImageSharp/Formats/Png/PngEncoderCore.cs | 5 +++-- src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs | 5 +++-- src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs | 5 +++-- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index efde4e9aa8..55ad2c4585 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -765,8 +765,9 @@ internal sealed class GifDecoderCore : IImageDecoderInternals private unsafe struct ScratchBuffer { - private fixed byte scratch[16]; + private const int Size = 16; + private fixed byte scratch[Size]; - public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 16); + public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size); } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs index 5ecf779615..02a346ff07 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs @@ -53,6 +53,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder private ArithmeticDecodingTable[] acDecodingTables; + // Don't make this a ReadOnlySpan, as the values need to get updated. private readonly byte[] fixedBin = { 113, 0, 0, 0 }; private readonly CancellationToken cancellationToken; diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index a2edbc4c3f..fb1d33277a 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -1412,8 +1412,9 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable private unsafe struct ScratchBuffer { - private fixed byte scratch[16]; + private const int Size = 16; + private fixed byte scratch[Size]; - public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 16); + public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size); } } diff --git a/src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs b/src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs index 8baf2cc156..ab78d18604 100644 --- a/src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs +++ b/src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs @@ -260,8 +260,9 @@ internal abstract class BitWriterBase private unsafe struct ScratchBuffer { - private fixed byte scratch[4]; + private const int Size = 4; + private fixed byte scratch[Size]; - public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 4); + public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size); } } diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs index e3c2797bf3..1f7c7586eb 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs @@ -1834,8 +1834,9 @@ internal class Vp8LEncoder : IDisposable /// private unsafe struct ScratchBuffer { - private fixed int scratch[256]; + private const int Size = 256; + private fixed int scratch[Size]; - public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 256); + public Span Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size); } } From 809ba98186f40729d2c7cbcac57af3524a8c7e90 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 26 Mar 2023 14:36:38 +0200 Subject: [PATCH 31/86] Added the arm converter to GetGrayScaleConverter --- .../Components/ColorConverters/JpegColorConverterBase.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs index 58b0b9b1b2..44b4ed4ec3 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs @@ -200,6 +200,11 @@ internal abstract partial class JpegColorConverterBase return new GrayscaleAvx(precision); } + if (JpegColorConverterArm.IsSupported) + { + return new GrayscaleArm(precision); + } + if (JpegColorConverterVector.IsSupported) { return new GrayScaleVector(precision); From 9dddb8caad7b87ce07eb25c13a6833ea1f3d2cab Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Wed, 22 Mar 2023 20:22:09 +0100 Subject: [PATCH 32/86] Port YCbCr ColorConverter to ARM --- .../JpegColorConverter.YCbCrArm.cs | 122 ++++++++++++++++++ .../ColorConverters/JpegColorConverterBase.cs | 5 + .../Formats/Jpg/JpegColorConverterTests.cs | 17 +++ 3 files changed, 144 insertions(+) create mode 100644 src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrArm.cs diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrArm.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrArm.cs new file mode 100644 index 0000000000..4f7cf1ed65 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrArm.cs @@ -0,0 +1,122 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.Arm; +using System.Runtime.Intrinsics.X86; +using static SixLabors.ImageSharp.SimdUtils; + +// ReSharper disable ImpureMethodCallOnReadonlyValueField +namespace SixLabors.ImageSharp.Formats.Jpeg.Components; + +internal abstract partial class JpegColorConverterBase +{ + internal sealed class YCbCrArm : JpegColorConverterArm + { + public YCbCrArm(int precision) + : base(JpegColorSpace.YCbCr, precision) + { + } + + /// + public override void ConvertToRgbInplace(in ComponentValues values) + { + ref Vector128 c0Base = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component0)); + ref Vector128 c1Base = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component1)); + ref Vector128 c2Base = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component2)); + + // Used for the color conversion + var chromaOffset = Vector128.Create(-this.HalfValue); + var scale = Vector128.Create(1 / this.MaximumValue); + var rCrMult = Vector128.Create(YCbCrScalar.RCrMult); + var gCbMult = Vector128.Create(-YCbCrScalar.GCbMult); + var gCrMult = Vector128.Create(-YCbCrScalar.GCrMult); + var bCbMult = Vector128.Create(YCbCrScalar.BCbMult); + + // Walking 8 elements at one step: + nuint n = (uint)values.Component0.Length / (uint)Vector128.Count; + for (nuint i = 0; i < n; i++) + { + // y = yVals[i]; + // cb = cbVals[i] - 128F; + // cr = crVals[i] - 128F; + ref Vector128 c0 = ref Unsafe.Add(ref c0Base, i); + ref Vector128 c1 = ref Unsafe.Add(ref c1Base, i); + ref Vector128 c2 = ref Unsafe.Add(ref c2Base, i); + + Vector128 y = c0; + Vector128 cb = AdvSimd.Add(c1, chromaOffset); + Vector128 cr = AdvSimd.Add(c2, chromaOffset); + + // r = y + (1.402F * cr); + // g = y - (0.344136F * cb) - (0.714136F * cr); + // b = y + (1.772F * cb); + Vector128 r = HwIntrinsics.MultiplyAdd(y, cr, rCrMult); + Vector128 g = HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(y, cb, gCbMult), cr, gCrMult); + Vector128 b = HwIntrinsics.MultiplyAdd(y, cb, bCbMult); + + r = AdvSimd.Multiply(AdvSimd.RoundToNearest(r), scale); + g = AdvSimd.Multiply(AdvSimd.RoundToNearest(g), scale); + b = AdvSimd.Multiply(AdvSimd.RoundToNearest(b), scale); + + c0 = r; + c1 = g; + c2 = b; + } + } + + /// + public override void ConvertFromRgb(in ComponentValues values, Span rLane, Span gLane, Span bLane) + { + ref Vector128 destY = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component0)); + ref Vector128 destCb = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component1)); + ref Vector128 destCr = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component2)); + + ref Vector128 srcR = + ref Unsafe.As>(ref MemoryMarshal.GetReference(rLane)); + ref Vector128 srcG = + ref Unsafe.As>(ref MemoryMarshal.GetReference(gLane)); + ref Vector128 srcB = + ref Unsafe.As>(ref MemoryMarshal.GetReference(bLane)); + + // Used for the color conversion + var chromaOffset = Vector128.Create(this.HalfValue); + + var f0299 = Vector128.Create(0.299f); + var f0587 = Vector128.Create(0.587f); + var f0114 = Vector128.Create(0.114f); + var fn0168736 = Vector128.Create(-0.168736f); + var fn0331264 = Vector128.Create(-0.331264f); + var fn0418688 = Vector128.Create(-0.418688f); + var fn0081312F = Vector128.Create(-0.081312F); + var f05 = Vector128.Create(0.5f); + + nuint n = (uint)values.Component0.Length / (uint)Vector128.Count; + for (nuint i = 0; i < n; i++) + { + Vector128 r = Unsafe.Add(ref srcR, i); + Vector128 g = Unsafe.Add(ref srcG, i); + Vector128 b = Unsafe.Add(ref srcB, i); + + // y = 0 + (0.299 * r) + (0.587 * g) + (0.114 * b) + // cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b) + // cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b) + Vector128 y = HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(f0114, b), f0587, g), f0299, r); + Vector128 cb = AdvSimd.Add(chromaOffset, HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(f05, b), fn0331264, g), fn0168736, r)); + Vector128 cr = AdvSimd.Add(chromaOffset, HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(fn0081312F, b), fn0418688, g), f05, r)); + + Unsafe.Add(ref destY, i) = y; + Unsafe.Add(ref destCb, i) = cb; + Unsafe.Add(ref destCr, i) = cr; + } + } + } +} diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs index 44b4ed4ec3..10d80ddb23 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs @@ -138,6 +138,11 @@ internal abstract partial class JpegColorConverterBase return new YCbCrAvx(precision); } + if (JpegColorConverterArm.IsSupported) + { + return new YCbCrArm(precision); + } + if (JpegColorConverterVector.IsSupported) { return new YCbCrVector(precision); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index c71c70c336..fac08ee3d3 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -256,6 +256,23 @@ public class JpegColorConverterTests new JpegColorConverterBase.YCbCrScalar(8), precísion: 2); + [Theory] + [MemberData(nameof(Seeds))] + public void FromYCbCrArm(int seed) => + this.TestConversionToRgb(new JpegColorConverterBase.YCbCrArm(8), + 3, + seed, + new JpegColorConverterBase.YCbCrScalar(8)); + + [Theory] + [MemberData(nameof(Seeds))] + public void FromRgbToYCbCrArm(int seed) => + this.TestConversionFromRgb(new JpegColorConverterBase.YCbCrArm(8), + 3, + seed, + new JpegColorConverterBase.YCbCrScalar(8), + precísion: 2); + [Theory] [MemberData(nameof(Seeds))] public void FromCmykAvx2(int seed) => From a4ad7b09fc8dda2f0efa9e0f7abcf4e6f0a4ac67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sun, 26 Mar 2023 14:20:24 +0200 Subject: [PATCH 33/86] Avoid length-check in pinning spans Only where it seems profitable. E.g. not when a UnmanagedMemoryStream is constructed of that pointer. --- .../ColorSpaces/Companding/SRgbCompanding.cs | 4 ++-- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 2 +- src/ImageSharp/Compression/Zlib/Adler32.cs | 2 +- src/ImageSharp/Compression/Zlib/Crc32.cs | 6 +++--- src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs | 9 ++++----- .../Formats/Webp/Lossless/PredictorEncoder.cs | 10 +++++----- src/ImageSharp/Formats/Webp/WebpCommonUtils.cs | 4 ++-- src/ImageSharp/Memory/Buffer2DExtensions.cs | 2 +- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs b/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs index 2a6fcb0832..4c3923c888 100644 --- a/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs +++ b/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs @@ -167,7 +167,7 @@ public static class SRgbCompanding [MethodImpl(MethodImplOptions.AggressiveInlining)] private static unsafe void CompandAvx2(Span vectors, float[] table) { - fixed (float* tablePointer = &table[0]) + fixed (float* tablePointer = &MemoryMarshal.GetArrayDataReference(table)) { var scale = Vector256.Create((float)Scale); Vector256 zero = Vector256.Zero; @@ -199,7 +199,7 @@ public static class SRgbCompanding [MethodImpl(MethodImplOptions.AggressiveInlining)] private static unsafe void CompandScalar(Span vectors, float[] table) { - fixed (float* tablePointer = &table[0]) + fixed (float* tablePointer = &MemoryMarshal.GetArrayDataReference(table)) { Vector4 zero = Vector4.Zero; var scale = new Vector4(Scale); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index ce6f335a8f..7871eee6ba 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -644,7 +644,7 @@ internal static partial class SimdUtils ReadOnlySpan source, Span dest) { - fixed (byte* sourceBase = source) + fixed (byte* sourceBase = &MemoryMarshal.GetReference(source)) { if (Avx2.IsSupported) { diff --git a/src/ImageSharp/Compression/Zlib/Adler32.cs b/src/ImageSharp/Compression/Zlib/Adler32.cs index dd8217541a..3ecdf81539 100644 --- a/src/ImageSharp/Compression/Zlib/Adler32.cs +++ b/src/ImageSharp/Compression/Zlib/Adler32.cs @@ -387,7 +387,7 @@ internal static class Adler32 uint s1 = adler & 0xFFFF; uint s2 = (adler >> 16) & 0xFFFF; - fixed (byte* bufferPtr = buffer) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) { byte* localBufferPtr = bufferPtr; uint length = (uint)buffer.Length; diff --git a/src/ImageSharp/Compression/Zlib/Crc32.cs b/src/ImageSharp/Compression/Zlib/Crc32.cs index 2d0a09bd4c..e21621ab74 100644 --- a/src/ImageSharp/Compression/Zlib/Crc32.cs +++ b/src/ImageSharp/Compression/Zlib/Crc32.cs @@ -81,7 +81,7 @@ internal static partial class Crc32 int chunksize = buffer.Length & ~ChunksizeMask; int length = chunksize; - fixed (byte* bufferPtr = buffer) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) { fixed (ulong* k05PolyPtr = K05Poly) { @@ -201,7 +201,7 @@ internal static partial class Crc32 [MethodImpl(InliningOptions.HotPath | InliningOptions.ShortMethod)] private static unsafe uint CalculateArm(uint crc, ReadOnlySpan buffer) { - fixed (byte* bufferPtr = buffer) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) { byte* localBufferPtr = bufferPtr; int len = buffer.Length; @@ -248,7 +248,7 @@ internal static partial class Crc32 [MethodImpl(InliningOptions.HotPath | InliningOptions.ShortMethod)] private static unsafe uint CalculateArm64(uint crc, ReadOnlySpan buffer) { - fixed (byte* bufferPtr = buffer) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) { byte* localBufferPtr = bufferPtr; int len = buffer.Length; diff --git a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs index 8d64a09dfb..ab6e4cfccf 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs @@ -569,7 +569,7 @@ internal static unsafe class LosslessUtils Span pixelData, Span outputSpan) { - fixed (uint* inputFixed = pixelData) + fixed (uint* inputFixed = &MemoryMarshal.GetReference(pixelData)) { fixed (uint* outputFixed = outputSpan) { @@ -1474,8 +1474,7 @@ internal static unsafe class LosslessUtils { if (Sse2.IsSupported) { - Span output = scratch; - fixed (short* p = output) + fixed (short* ptr = &MemoryMarshal.GetReference(scratch)) { Vector128 a0 = Sse2.ConvertScalarToVector128UInt32(a).AsByte(); Vector128 b0 = Sse2.ConvertScalarToVector128UInt32(b).AsByte(); @@ -1489,8 +1488,8 @@ internal static unsafe class LosslessUtils Vector128 pa = Sse2.UnpackLow(ac, Vector128.Zero); // |a - c| Vector128 pb = Sse2.UnpackLow(bc, Vector128.Zero); // |b - c| Vector128 diff = Sse2.Subtract(pb.AsUInt16(), pa.AsUInt16()); - Sse2.Store((ushort*)p, diff); - int paMinusPb = output[3] + output[2] + output[1] + output[0]; + Sse2.Store((ushort*)ptr, diff); + int paMinusPb = ptr[3] + ptr[2] + ptr[1] + ptr[0]; return (paMinusPb <= 0) ? a : b; } } diff --git a/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs index 689c63f5b1..4113579637 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs @@ -353,8 +353,8 @@ internal static unsafe class PredictorEncoder else { #pragma warning disable SA1503 // Braces should not be omitted - fixed (uint* currentRow = currentRowSpan) - fixed (uint* upperRow = upperRowSpan) + fixed (uint* currentRow = &MemoryMarshal.GetReference(currentRowSpan)) + fixed (uint* upperRow = &MemoryMarshal.GetReference(upperRowSpan)) { for (int x = xStart; x < xEnd; x++) { @@ -664,9 +664,9 @@ internal static unsafe class PredictorEncoder Span scratch) { #pragma warning disable SA1503 // Braces should not be omitted - fixed (uint* current = currentSpan) - fixed (uint* upper = upperSpan) - fixed (uint* outputFixed = outputSpan) + fixed (uint* current = &MemoryMarshal.GetReference(currentSpan)) + fixed (uint* upper = &MemoryMarshal.GetReference(upperSpan)) + fixed (uint* outputFixed = &MemoryMarshal.GetReference(outputSpan)) { uint* output = outputFixed; if (xStart == 0) diff --git a/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs b/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs index 1a8fcbafc9..735d0bf557 100644 --- a/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs +++ b/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs @@ -25,7 +25,7 @@ internal static class WebpCommonUtils ReadOnlySpan rowBytes = MemoryMarshal.AsBytes(row); int i = 0; int length = (row.Length * 4) - 3; - fixed (byte* src = rowBytes) + fixed (byte* src = &MemoryMarshal.GetReference(rowBytes)) { var alphaMaskVector256 = Vector256.Create(0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255); Vector256 all0x80Vector256 = Vector256.Create((byte)0x80).AsByte(); @@ -81,7 +81,7 @@ internal static class WebpCommonUtils ReadOnlySpan rowBytes = MemoryMarshal.AsBytes(row); int i = 0; int length = (row.Length * 4) - 3; - fixed (byte* src = rowBytes) + fixed (byte* src = &MemoryMarshal.GetReference(rowBytes)) { for (; i + 64 <= length; i += 64) { diff --git a/src/ImageSharp/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs index 2eb05ea935..31617c163b 100644 --- a/src/ImageSharp/Memory/Buffer2DExtensions.cs +++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs @@ -50,7 +50,7 @@ public static class Buffer2DExtensions Span span = MemoryMarshal.AsBytes(buffer.DangerousGetSingleMemory().Span); - fixed (byte* ptr = span) + fixed (byte* ptr = &MemoryMarshal.GetReference(span)) { byte* basePtr = ptr; for (int y = 0; y < buffer.Height; y++) From 45321948c837b675b6339dafaf7ac8d7fc5e9421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sun, 26 Mar 2023 14:19:26 +0200 Subject: [PATCH 34/86] Block8x8 set explicit size instead of (unused) fixed sized buffer field --- .../Formats/Jpeg/Components/Block8x8.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs index d119a18c8b..b417a8c814 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs @@ -15,25 +15,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components; /// 8x8 matrix of coefficients. /// // ReSharper disable once InconsistentNaming -[StructLayout(LayoutKind.Explicit)] -internal unsafe partial struct Block8x8 +[StructLayout(LayoutKind.Explicit, Size = 2 * Size)] +internal partial struct Block8x8 { /// /// A number of scalar coefficients in a /// public const int Size = 64; -#pragma warning disable IDE0051 // Remove unused private member - /// - /// A placeholder buffer so the actual struct occupies exactly 64 * 2 bytes. - /// - /// - /// This is not used directly in the code. - /// - [FieldOffset(0)] - private fixed short data[Size]; -#pragma warning restore IDE0051 - /// /// Gets or sets a value at the given index /// From a534328dc482683834c6901d93da61cf0d053724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sun, 26 Mar 2023 14:34:07 +0200 Subject: [PATCH 35/86] Optimized Block8x8F --- .../Formats/Jpeg/Components/Block8x8F.cs | 25 +++++++------------ .../Block8x8F_MultiplyInPlaceBlock.cs | 4 +-- .../Formats/Jpg/Block8x8FTests.cs | 12 +++------ .../ImageSharp.Tests/Formats/Jpg/DCTTests.cs | 15 ++++------- ...ferenceImplementationsTests.AccurateDCT.cs | 3 +-- ...plementationsTests.FastFloatingPointDCT.cs | 3 +-- ...ceImplementations.LLM_FloatingPoint_DCT.cs | 6 ++--- 7 files changed, 23 insertions(+), 45 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs index 21971a8c7d..d432e82d24 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs @@ -101,24 +101,17 @@ internal partial struct Block8x8F : IEquatable set => this[((uint)y * 8) + (uint)x] = value; } - public static Block8x8F Load(Span data) - { - Block8x8F result = default; - result.LoadFrom(data); - return result; - } - /// /// Load raw 32bit floating point data from source. /// - /// Source + /// Source [MethodImpl(InliningOptions.ShortMethod)] - public void LoadFrom(Span source) + public static Block8x8F Load(Span data) { - ref byte s = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); - ref byte d = ref Unsafe.As(ref this); + DebugGuard.MustBeGreaterThanOrEqualTo(data.Length, Size, "data is too small"); - Unsafe.CopyBlock(ref d, ref s, Size * sizeof(float)); + ref byte src = ref Unsafe.As(ref MemoryMarshal.GetReference(data)); + return Unsafe.ReadUnaligned(ref src); } /// @@ -144,10 +137,10 @@ internal partial struct Block8x8F : IEquatable [MethodImpl(InliningOptions.ShortMethod)] public unsafe void ScaledCopyTo(float[] dest) { - fixed (void* ptr = &this.V0L) - { - Marshal.Copy((IntPtr)ptr, dest, 0, Size); - } + DebugGuard.MustBeGreaterThanOrEqualTo(dest.Length, Size, "dest is too small"); + + ref byte destRef = ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(dest)); + Unsafe.WriteUnaligned(ref destRef, this); } public float[] ToArray() diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_MultiplyInPlaceBlock.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_MultiplyInPlaceBlock.cs index a5abeb3b66..722b095870 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_MultiplyInPlaceBlock.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_MultiplyInPlaceBlock.cs @@ -29,8 +29,6 @@ public class Block8x8F_MultiplyInPlaceBlock } } - var source = default(Block8x8F); - source.LoadFrom(result); - return source; + return Block8x8F.Load(result); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs index 3e4bcae6b7..cde9e776b2 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs @@ -99,8 +99,7 @@ public partial class Block8x8FTests : JpegFixture Times, () => { - var b = default(Block8x8F); - b.LoadFrom(data); + Block8x8F b = Block8x8F.Load(data); b.ScaledCopyTo(mirror); }); @@ -117,8 +116,7 @@ public partial class Block8x8FTests : JpegFixture float[] expected = Create8x8FloatData(); ReferenceImplementations.Transpose8x8(expected); - var block8x8 = default(Block8x8F); - block8x8.LoadFrom(Create8x8FloatData()); + Block8x8F block8x8 = Block8x8F.Load(Create8x8FloatData()); block8x8.TransposeInplace(); @@ -153,9 +151,8 @@ public partial class Block8x8FTests : JpegFixture [Fact] public void NormalizeColors() { - var block = default(Block8x8F); float[] input = Create8x8ColorCropTestData(); - block.LoadFrom(input); + Block8x8F block = Block8x8F.Load(input); this.Output.WriteLine("Input:"); this.PrintLinearData(input); @@ -242,8 +239,7 @@ public partial class Block8x8FTests : JpegFixture { float[] data = Create8x8RandomFloatData(-1000, 1000); - var source = default(Block8x8F); - source.LoadFrom(data); + Block8x8F source = Block8x8F.Load(data); var dest = default(Block8x8); source.RoundInto(ref dest); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs index 5853ff37a5..5a1488c411 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs @@ -114,8 +114,7 @@ public static class DCTTests int seed = FeatureTestRunner.Deserialize(serialized); Span src = Create8x8RandomFloatData(MinInputValue, MaxInputValue, seed); - var srcBlock = default(Block8x8F); - srcBlock.LoadFrom(src); + Block8x8F srcBlock = Block8x8F.Load(src); float[] expectedDest = new float[64]; float[] temp = new float[64]; @@ -162,8 +161,7 @@ public static class DCTTests public void TranformIDCT_4x4(int seed) { Span src = Create8x8RandomFloatData(MinInputValue, MaxInputValue, seed, 4, 4); - var srcBlock = default(Block8x8F); - srcBlock.LoadFrom(src); + Block8x8F srcBlock = Block8x8F.Load(src); float[] expectedDest = new float[64]; float[] temp = new float[64]; @@ -224,8 +222,7 @@ public static class DCTTests public void TranformIDCT_2x2(int seed) { Span src = Create8x8RandomFloatData(MinInputValue, MaxInputValue, seed, 2, 2); - var srcBlock = default(Block8x8F); - srcBlock.LoadFrom(src); + Block8x8F srcBlock = Block8x8F.Load(src); float[] expectedDest = new float[64]; float[] temp = new float[64]; @@ -286,8 +283,7 @@ public static class DCTTests public void TranformIDCT_1x1(int seed) { Span src = Create8x8RandomFloatData(MinInputValue, MaxInputValue, seed, 1, 1); - var srcBlock = default(Block8x8F); - srcBlock.LoadFrom(src); + Block8x8F srcBlock = Block8x8F.Load(src); float[] expectedDest = new float[64]; float[] temp = new float[64]; @@ -330,8 +326,7 @@ public static class DCTTests int seed = FeatureTestRunner.Deserialize(serialized); Span src = Create8x8RandomFloatData(MinInputValue, MaxInputValue, seed); - var block = default(Block8x8F); - block.LoadFrom(src); + Block8x8F block = Block8x8F.Load(src); float[] expectedDest = new float[64]; float[] temp1 = new float[64]; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs index cd93adefd8..c593a029ab 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs @@ -25,8 +25,7 @@ public partial class ReferenceImplementationsTests { float[] data = Create8x8RandomFloatData(-1000, 1000, seed); - var b0 = default(Block8x8F); - b0.LoadFrom(data); + Block8x8F b0 = Block8x8F.Load(data); Block8x8F b1 = ReferenceImplementations.AccurateDCT.TransformFDCT(ref b0); Block8x8F b2 = ReferenceImplementations.AccurateDCT.TransformIDCT(ref b1); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs index 46c6ee2da6..f5d7c159ba 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs @@ -70,8 +70,7 @@ public partial class ReferenceImplementationsTests { float[] floatData = Create8x8RandomFloatData(-1000, 1000); - Block8x8F source = default; - source.LoadFrom(floatData); + Block8x8F source = Block8x8F.Load(floatData); Block8x8F expected = ReferenceImplementations.AccurateDCT.TransformFDCT(ref source); Block8x8F actual = ReferenceImplementations.LLM_FloatingPoint_DCT.TransformFDCT_UpscaleBy8(ref source); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs index 9e0c62d139..0d5f3114d1 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs @@ -36,8 +36,7 @@ internal static partial class ReferenceImplementations float[] temp = new float[64]; IDCT2D_llm(s, d, temp); - Block8x8F result = default; - result.LoadFrom(d); + Block8x8F result = Block8x8F.Load(d); return result; } @@ -49,8 +48,7 @@ internal static partial class ReferenceImplementations float[] temp = new float[64]; FDCT2D_llm(s, d, temp); - Block8x8F result = default; - result.LoadFrom(d); + Block8x8F result = Block8x8F.Load(d); return result; } From 77ffeeabd623b6331e1fafc3142a8a3132e8ce6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sun, 26 Mar 2023 17:03:29 +0200 Subject: [PATCH 36/86] Create vector constants inline and not via ROS --- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 113 +++++++++--------- .../PixelConversion_PackFromRgbPlanes.cs | 3 +- 2 files changed, 56 insertions(+), 60 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index ce6f335a8f..8eebf7fb9e 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -13,33 +13,38 @@ internal static partial class SimdUtils { public static class HwIntrinsics { - public static ReadOnlySpan PermuteMaskDeinterleave8x32 => new byte[] { 0, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 3, 0, 0, 0, 7, 0, 0, 0 }; + [MethodImpl(MethodImplOptions.AggressiveInlining)] // too much IL for JIT to inline, so give a hint + public static Vector256 PermuteMaskDeinterleave8x32() => Vector256.Create(0, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 3, 0, 0, 0, 7, 0, 0, 0).AsInt32(); - public static ReadOnlySpan PermuteMaskEvenOdd8x32 => new byte[] { 0, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 5, 0, 0, 0, 7, 0, 0, 0 }; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Vector256 PermuteMaskEvenOdd8x32() => Vector256.Create(0, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 5, 0, 0, 0, 7, 0, 0, 0).AsUInt32(); - public static ReadOnlySpan PermuteMaskSwitchInnerDWords8x32 => new byte[] { 0, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0 }; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Vector256 PermuteMaskSwitchInnerDWords8x32() => Vector256.Create(0, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0).AsUInt32(); - private static ReadOnlySpan MoveFirst24BytesToSeparateLanes => new byte[] { 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 7, 0, 0, 0 }; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Vector256 MoveFirst24BytesToSeparateLanes() => Vector256.Create(0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 7, 0, 0, 0).AsUInt32(); - internal static ReadOnlySpan ExtractRgb => new byte[] { 0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11, 0xFF, 0xFF, 0xFF, 0xFF, 0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11, 0xFF, 0xFF, 0xFF, 0xFF }; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static Vector256 ExtractRgb() => Vector256.Create(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11, 0xFF, 0xFF, 0xFF, 0xFF, 0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11, 0xFF, 0xFF, 0xFF, 0xFF); - private static ReadOnlySpan ShuffleMaskPad4Nx16 => new byte[] { 0, 1, 2, 0x80, 3, 4, 5, 0x80, 6, 7, 8, 0x80, 9, 10, 11, 0x80 }; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Vector128 ShuffleMaskPad4Nx16() => Vector128.Create(0, 1, 2, 0x80, 3, 4, 5, 0x80, 6, 7, 8, 0x80, 9, 10, 11, 0x80); - private static ReadOnlySpan ShuffleMaskSlice4Nx16 => new byte[] { 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 0x80, 0x80, 0x80, 0x80 }; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Vector128 ShuffleMaskSlice4Nx16() => Vector128.Create(0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 0x80, 0x80, 0x80, 0x80); - private static ReadOnlySpan ShuffleMaskShiftAlpha => - new byte[] - { - 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 3, 7, 11, 15, - 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 3, 7, 11, 15 - }; +#pragma warning disable SA1003, SA1116, SA1117 // Parameters should be on same line or separate lines + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Vector256 ShuffleMaskShiftAlpha() => Vector256.Create((byte) + 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 3, 7, 11, 15, + 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 3, 7, 11, 15); - public static ReadOnlySpan PermuteMaskShiftAlpha8x32 => - new byte[] - { - 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, - 5, 0, 0, 0, 6, 0, 0, 0, 3, 0, 0, 0, 7, 0, 0, 0 - }; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Vector256 PermuteMaskShiftAlpha8x32() => Vector256.Create( + 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, + 5, 0, 0, 0, 6, 0, 0, 0, 3, 0, 0, 0, 7, 0, 0, 0).AsUInt32(); +#pragma warning restore SA1003, SA1116, SA1117 // Parameters should be on same line or separate lines /// /// Shuffle single-precision (32-bit) floating-point elements in @@ -189,7 +194,7 @@ internal static partial class SimdUtils { if (Ssse3.IsSupported) { - int remainder = source.Length % (Vector128.Count * 4); + int remainder = source.Length & (Vector128.Count * 4 - 1); // bit-hack for modulo int sourceCount = source.Length - remainder; int destCount = (int)((uint)sourceCount * 3 / 4); @@ -221,7 +226,7 @@ internal static partial class SimdUtils ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)(uint)(dest.Length / Vector256.Count); + nint n = (nint)((uint)dest.Length / (uint)Vector256.Count); nint m = Numerics.Modulo4(n); nint u = n - m; @@ -253,7 +258,7 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)(uint)dest.Length / Vector128.Count; + nint n = (nint)((uint)dest.Length / (uint)Vector128.Count); nint m = Numerics.Modulo4(n); nint u = n - m; @@ -306,7 +311,7 @@ internal static partial class SimdUtils ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)(uint)dest.Length / Vector256.Count; + nint n = (nint)((uint)dest.Length / (uint)Vector256.Count); nint m = Numerics.Modulo4(n); nint u = n - m; @@ -342,7 +347,7 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)(uint)dest.Length / Vector128.Count; + nint n = (nint)((uint)dest.Length / (uint)Vector128.Count); nint m = Numerics.Modulo4(n); nint u = n - m; @@ -375,10 +380,8 @@ internal static partial class SimdUtils { if (Ssse3.IsSupported) { - ref byte vmaskBase = ref MemoryMarshal.GetReference(ShuffleMaskPad4Nx16); - Vector128 vmask = Unsafe.As>(ref vmaskBase); - ref byte vmaskoBase = ref MemoryMarshal.GetReference(ShuffleMaskSlice4Nx16); - Vector128 vmasko = Unsafe.As>(ref vmaskoBase); + Vector128 vmask = ShuffleMaskPad4Nx16(); + Vector128 vmasko = ShuffleMaskSlice4Nx16(); Vector128 vmaske = Ssse3.AlignRight(vmasko, vmasko, 12); Span bytes = stackalloc byte[Vector128.Count]; @@ -440,8 +443,7 @@ internal static partial class SimdUtils { if (Ssse3.IsSupported) { - ref byte vmaskBase = ref MemoryMarshal.GetReference(ShuffleMaskPad4Nx16); - Vector128 vmask = Unsafe.As>(ref vmaskBase); + Vector128 vmask = ShuffleMaskPad4Nx16(); Vector128 vfill = Vector128.Create(0xff000000ff000000ul).AsByte(); Span bytes = stackalloc byte[Vector128.Count]; @@ -484,8 +486,7 @@ internal static partial class SimdUtils { if (Ssse3.IsSupported) { - ref byte vmaskoBase = ref MemoryMarshal.GetReference(ShuffleMaskSlice4Nx16); - Vector128 vmasko = Unsafe.As>(ref vmaskoBase); + Vector128 vmasko = ShuffleMaskSlice4Nx16(); Vector128 vmaske = Ssse3.AlignRight(vmasko, vmasko, 12); Span bytes = stackalloc byte[Vector128.Count]; @@ -542,9 +543,9 @@ internal static partial class SimdUtils /// The . [MethodImpl(InliningOptions.AlwaysInline)] public static Vector256 MultiplyAdd( - in Vector256 va, - in Vector256 vm0, - in Vector256 vm1) + Vector256 va, + Vector256 vm0, + Vector256 vm1) { if (Fma.IsSupported) { @@ -565,9 +566,9 @@ internal static partial class SimdUtils /// The . [MethodImpl(InliningOptions.ShortMethod)] public static Vector256 MultiplySubtract( - in Vector256 vs, - in Vector256 vm0, - in Vector256 vm1) + Vector256 vs, + Vector256 vm0, + Vector256 vm1) { if (Fma.IsSupported) { @@ -587,9 +588,9 @@ internal static partial class SimdUtils /// The . [MethodImpl(InliningOptions.ShortMethod)] public static Vector256 MultiplyAddNegated( - in Vector256 a, - in Vector256 b, - in Vector256 c) + Vector256 a, + Vector256 b, + Vector256 c) { if (Fma.IsSupported) { @@ -655,7 +656,7 @@ internal static partial class SimdUtils ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - var scale = Vector256.Create(1 / (float)byte.MaxValue); + Vector256 scale = Vector256.Create(1 / (float)byte.MaxValue); for (nuint i = 0; i < n; i++) { @@ -688,7 +689,7 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - var scale = Vector128.Create(1 / (float)byte.MaxValue); + Vector128 scale = Vector128.Create(1 / (float)byte.MaxValue); Vector128 zero = Vector128.Zero; for (nuint i = 0; i < n; i++) @@ -790,9 +791,8 @@ internal static partial class SimdUtils ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - var scale = Vector256.Create((float)byte.MaxValue); - ref byte maskBase = ref MemoryMarshal.GetReference(PermuteMaskDeinterleave8x32); - Vector256 mask = Unsafe.As>(ref maskBase); + Vector256 scale = Vector256.Create((float)byte.MaxValue); + Vector256 mask = PermuteMaskDeinterleave8x32(); for (nuint i = 0; i < n; i++) { @@ -829,7 +829,7 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - var scale = Vector128.Create((float)byte.MaxValue); + Vector128 scale = Vector128.Create((float)byte.MaxValue); for (nuint i = 0; i < n; i++) { @@ -866,14 +866,12 @@ internal static partial class SimdUtils nuint count = (uint)redChannel.Length / (uint)Vector256.Count; - ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32); - Vector256 control1 = Unsafe.As>(ref control1Bytes); + Vector256 control1 = PermuteMaskEvenOdd8x32(); - ref byte control2Bytes = ref MemoryMarshal.GetReference(PermuteMaskShiftAlpha8x32); - Vector256 control2 = Unsafe.As>(ref control2Bytes); - var a = Vector256.Create((byte)255); + Vector256 control2 = PermuteMaskShiftAlpha8x32(); + Vector256 a = Vector256.Create((byte)255); - Vector256 shuffleAlpha = Unsafe.As>(ref MemoryMarshal.GetReference(ShuffleMaskShiftAlpha)); + Vector256 shuffleAlpha = ShuffleMaskShiftAlpha(); for (nuint i = 0; i < count; i++) { @@ -937,9 +935,8 @@ internal static partial class SimdUtils ref Vector256 dBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); nuint count = (uint)redChannel.Length / (uint)Vector256.Count; - ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32); - Vector256 control1 = Unsafe.As>(ref control1Bytes); - var a = Vector256.Create((byte)255); + Vector256 control1 = PermuteMaskEvenOdd8x32(); + Vector256 a = Vector256.Create((byte)255); for (nuint i = 0; i < count; i++) { @@ -988,8 +985,8 @@ internal static partial class SimdUtils ref Vector256 destGRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(greenChannel)); ref Vector256 destBRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(blueChannel)); - Vector256 extractToLanesMask = Unsafe.As>(ref MemoryMarshal.GetReference(MoveFirst24BytesToSeparateLanes)); - Vector256 extractRgbMask = Unsafe.As>(ref MemoryMarshal.GetReference(ExtractRgb)); + Vector256 extractToLanesMask = MoveFirst24BytesToSeparateLanes(); + Vector256 extractRgbMask = ExtractRgb(); Vector256 rgb, rg, bx; Vector256 r, g, b; diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs index ddf192af87..a42c6c253c 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs @@ -207,8 +207,7 @@ public unsafe class PixelConversion_PackFromRgbPlanes nuint count = (uint)this.Count / (uint)Vector256.Count; - ref byte control = ref MemoryMarshal.GetReference(SimdUtils.HwIntrinsics.PermuteMaskEvenOdd8x32); - Vector256 vcontrol = Unsafe.As>(ref control); + Vector256 vcontrol = SimdUtils.HwIntrinsics.PermuteMaskEvenOdd8x32().AsInt32(); var va = Vector256.Create(1F); From cdf6eed33b7392e1abccea2da277b22df8498945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sun, 26 Mar 2023 17:19:17 +0200 Subject: [PATCH 37/86] Fixed build --- src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 8eebf7fb9e..d4705fed74 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -194,7 +194,7 @@ internal static partial class SimdUtils { if (Ssse3.IsSupported) { - int remainder = source.Length & (Vector128.Count * 4 - 1); // bit-hack for modulo + int remainder = source.Length & ((Vector128.Count * 4) - 1); // bit-hack for modulo int sourceCount = source.Length - remainder; int destCount = (int)((uint)sourceCount * 3 / 4); From 09b4dd751d9383156ea7e7671e90ab59c3ea618f Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 26 Mar 2023 19:47:27 +0200 Subject: [PATCH 38/86] Add test for GetConverter with rgb color space which uses FeatureTestRunner to disable specific hw features --- .../Formats/Jpg/JpegColorConverterTests.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index 44675aaea2..eb7179b89b 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Runtime.Intrinsics.Arm; +using System.Runtime.Intrinsics.X86; using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces.Conversion; using SixLabors.ImageSharp.Formats.Jpeg.Components; @@ -69,6 +71,39 @@ public class JpegColorConverterTests Assert.Equal(precision, converter.Precision); } + [Fact] + public void GetConverterReturnsValidConverterWithRgbColorSpace() + { + FeatureTestRunner.RunWithHwIntrinsicsFeature( + RunTest, + HwIntrinsics.AllowAll | HwIntrinsics.DisableAVX2 | HwIntrinsics.DisableSSE2 | HwIntrinsics.DisableHWIntrinsic); + + static void RunTest(string arg) + { + // arrange + Type expectedType = typeof(JpegColorConverterBase.RgbScalar); + if (Avx.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.RgbAvx); + } + else if (Sse2.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.RgbVector); + } + else if (AdvSimd.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.RgbArm); + } + + // act + JpegColorConverterBase converter = JpegColorConverterBase.GetConverter(JpegColorSpace.RGB, 8); + Type actualType = converter.GetType(); + + // assert + Assert.Equal(expectedType, actualType); + } + } + [Theory] [InlineData(JpegColorSpace.Grayscale, 1)] [InlineData(JpegColorSpace.Ycck, 4)] From e62b62f5be39e631385eb55749112c4cda752480 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 26 Mar 2023 19:50:25 +0200 Subject: [PATCH 39/86] Fix formatting warnings --- .../Formats/Jpg/JpegColorConverterTests.cs | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index eb7179b89b..93c246e7cf 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -277,7 +277,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromYCbCrAvx2(int seed) => - this.TestConversionToRgb(new JpegColorConverterBase.YCbCrAvx(8), + this.TestConversionToRgb( + new JpegColorConverterBase.YCbCrAvx(8), 3, seed, new JpegColorConverterBase.YCbCrScalar(8)); @@ -285,7 +286,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromRgbToYCbCrAvx2(int seed) => - this.TestConversionFromRgb(new JpegColorConverterBase.YCbCrAvx(8), + this.TestConversionFromRgb( + new JpegColorConverterBase.YCbCrAvx(8), 3, seed, new JpegColorConverterBase.YCbCrScalar(8), @@ -294,7 +296,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromCmykAvx2(int seed) => - this.TestConversionToRgb(new JpegColorConverterBase.CmykAvx(8), + this.TestConversionToRgb( + new JpegColorConverterBase.CmykAvx(8), 4, seed, new JpegColorConverterBase.CmykScalar(8)); @@ -302,7 +305,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromRgbToCmykAvx2(int seed) => - this.TestConversionFromRgb(new JpegColorConverterBase.CmykAvx(8), + this.TestConversionFromRgb( + new JpegColorConverterBase.CmykAvx(8), 4, seed, new JpegColorConverterBase.CmykScalar(8), @@ -311,7 +315,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromCmykArm(int seed) => - this.TestConversionToRgb( new JpegColorConverterBase.CmykArm64(8), + this.TestConversionToRgb( + new JpegColorConverterBase.CmykArm64(8), 4, seed, new JpegColorConverterBase.CmykScalar(8)); @@ -319,7 +324,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromRgbToCmykArm(int seed) => - this.TestConversionFromRgb(new JpegColorConverterBase.CmykArm64(8), + this.TestConversionFromRgb( + new JpegColorConverterBase.CmykArm64(8), 4, seed, new JpegColorConverterBase.CmykScalar(8), @@ -328,7 +334,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromGrayscaleAvx2(int seed) => - this.TestConversionToRgb(new JpegColorConverterBase.GrayscaleAvx(8), + this.TestConversionToRgb( + new JpegColorConverterBase.GrayscaleAvx(8), 1, seed, new JpegColorConverterBase.GrayscaleScalar(8)); @@ -336,7 +343,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromRgbToGrayscaleAvx2(int seed) => - this.TestConversionFromRgb(new JpegColorConverterBase.GrayscaleAvx(8), + this.TestConversionFromRgb( + new JpegColorConverterBase.GrayscaleAvx(8), 1, seed, new JpegColorConverterBase.GrayscaleScalar(8), @@ -345,7 +353,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromRgbAvx2(int seed) => - this.TestConversionToRgb(new JpegColorConverterBase.RgbAvx(8), + this.TestConversionToRgb( + new JpegColorConverterBase.RgbAvx(8), 3, seed, new JpegColorConverterBase.RgbScalar(8)); @@ -353,7 +362,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromRgbArm(int seed) => - this.TestConversionToRgb(new JpegColorConverterBase.RgbArm(8), + this.TestConversionToRgb( + new JpegColorConverterBase.RgbArm(8), 3, seed, new JpegColorConverterBase.RgbScalar(8)); @@ -361,7 +371,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromYccKAvx2(int seed) => - this.TestConversionToRgb( new JpegColorConverterBase.YccKAvx(8), + this.TestConversionToRgb( + new JpegColorConverterBase.YccKAvx(8), 4, seed, new JpegColorConverterBase.YccKScalar(8)); @@ -369,7 +380,8 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromRgbToYccKAvx2(int seed) => - this.TestConversionFromRgb(new JpegColorConverterBase.YccKAvx(8), + this.TestConversionFromRgb( + new JpegColorConverterBase.YccKAvx(8), 4, seed, new JpegColorConverterBase.YccKScalar(8), @@ -515,7 +527,7 @@ public class JpegColorConverterTests JpegColorConverterBase baseLineConverter, int precision = 4) { - // arrange + // arrange JpegColorConverterBase.ComponentValues actual = CreateRandomValues(TestBufferLength, componentCount, seed); JpegColorConverterBase.ComponentValues expected = CreateRandomValues(TestBufferLength, componentCount, seed); Random rnd = new(seed); From 2c534ea6027be4eeafcea38b22873c7c80fb4ee6 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 26 Mar 2023 23:10:41 +0200 Subject: [PATCH 40/86] Add arm benchmark --- .../Codecs/Jpeg/ColorConversion/YCbCrColorConversion.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/YCbCrColorConversion.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/YCbCrColorConversion.cs index 800190d2d7..87e1bf5aa9 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/YCbCrColorConversion.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/YCbCrColorConversion.cs @@ -37,4 +37,12 @@ public class YCbCrColorConversion : ColorConversionBenchmark new JpegColorConverterBase.YCbCrAvx(8).ConvertToRgbInplace(values); } + + [Benchmark] + public void SimdVectorArm() + { + var values = new JpegColorConverterBase.ComponentValues(this.Input, 0); + + new JpegColorConverterBase.YCbCrArm(8).ConvertToRgbInplace(values); + } } From 60c39bbd9ffaccb2c118458b87b9bf1e5eda7772 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 26 Mar 2023 14:35:26 +0200 Subject: [PATCH 41/86] Port YCCK to arm --- .../JpegColorConverter.YccKArm64.cs | 133 ++++++++++++++++++ .../ColorConverters/JpegColorConverterBase.cs | 5 + .../ColorConversion/YccKColorConverter.cs | 8 ++ .../Formats/Jpg/JpegColorConverterTests.cs | 17 +++ 4 files changed, 163 insertions(+) create mode 100644 src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKArm64.cs diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKArm64.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKArm64.cs new file mode 100644 index 0000000000..285ba62cfd --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKArm64.cs @@ -0,0 +1,133 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.Arm; +using System.Runtime.Intrinsics.X86; +using static SixLabors.ImageSharp.SimdUtils; + +namespace SixLabors.ImageSharp.Formats.Jpeg.Components; + +internal abstract partial class JpegColorConverterBase +{ + internal sealed class YccKArm64 : JpegColorConverterArm64 + { + public YccKArm64(int precision) + : base(JpegColorSpace.Ycck, precision) + { + } + + /// + public override void ConvertToRgbInplace(in ComponentValues values) + { + ref Vector128 c0Base = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component0)); + ref Vector128 c1Base = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component1)); + ref Vector128 c2Base = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component2)); + ref Vector128 kBase = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component3)); + + // Used for the color conversion + var chromaOffset = Vector128.Create(-this.HalfValue); + var scale = Vector128.Create(1 / (this.MaximumValue * this.MaximumValue)); + var max = Vector128.Create(this.MaximumValue); + var rCrMult = Vector128.Create(YCbCrScalar.RCrMult); + var gCbMult = Vector128.Create(-YCbCrScalar.GCbMult); + var gCrMult = Vector128.Create(-YCbCrScalar.GCrMult); + var bCbMult = Vector128.Create(YCbCrScalar.BCbMult); + + // Walking 8 elements at one step: + nuint n = (uint)values.Component0.Length / (uint)Vector128.Count; + for (nuint i = 0; i < n; i++) + { + // y = yVals[i]; + // cb = cbVals[i] - 128F; + // cr = crVals[i] - 128F; + // k = kVals[i] / 256F; + ref Vector128 c0 = ref Unsafe.Add(ref c0Base, i); + ref Vector128 c1 = ref Unsafe.Add(ref c1Base, i); + ref Vector128 c2 = ref Unsafe.Add(ref c2Base, i); + Vector128 y = c0; + Vector128 cb = AdvSimd.Add(c1, chromaOffset); + Vector128 cr = AdvSimd.Add(c2, chromaOffset); + Vector128 scaledK = AdvSimd.Multiply(Unsafe.Add(ref kBase, i), scale); + + // r = y + (1.402F * cr); + // g = y - (0.344136F * cb) - (0.714136F * cr); + // b = y + (1.772F * cb); + Vector128 r = HwIntrinsics.MultiplyAdd(y, cr, rCrMult); + Vector128 g = + HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(y, cb, gCbMult), cr, gCrMult); + Vector128 b = HwIntrinsics.MultiplyAdd(y, cb, bCbMult); + + r = AdvSimd.Subtract(max, AdvSimd.RoundToNearest(r)); + g = AdvSimd.Subtract(max, AdvSimd.RoundToNearest(g)); + b = AdvSimd.Subtract(max, AdvSimd.RoundToNearest(b)); + + r = AdvSimd.Multiply(r, scaledK); + g = AdvSimd.Multiply(g, scaledK); + b = AdvSimd.Multiply(b, scaledK); + + c0 = r; + c1 = g; + c2 = b; + } + } + + /// + public override void ConvertFromRgb(in ComponentValues values, Span rLane, Span gLane, Span bLane) + { + // rgb -> cmyk + CmykArm64.ConvertFromRgb(in values, this.MaximumValue, rLane, gLane, bLane); + + // cmyk -> ycck + ref Vector128 destY = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component0)); + ref Vector128 destCb = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component1)); + ref Vector128 destCr = + ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component2)); + + ref Vector128 srcR = ref destY; + ref Vector128 srcG = ref destCb; + ref Vector128 srcB = ref destCr; + + // Used for the color conversion + var maxSampleValue = Vector128.Create(this.MaximumValue); + + var chromaOffset = Vector128.Create(this.HalfValue); + + var f0299 = Vector128.Create(0.299f); + var f0587 = Vector128.Create(0.587f); + var f0114 = Vector128.Create(0.114f); + var fn0168736 = Vector128.Create(-0.168736f); + var fn0331264 = Vector128.Create(-0.331264f); + var fn0418688 = Vector128.Create(-0.418688f); + var fn0081312F = Vector128.Create(-0.081312F); + var f05 = Vector128.Create(0.5f); + + nuint n = (uint)values.Component0.Length / (uint)Vector128.Count; + for (nuint i = 0; i < n; i++) + { + Vector128 r = AdvSimd.Subtract(maxSampleValue, Unsafe.Add(ref srcR, i)); + Vector128 g = AdvSimd.Subtract(maxSampleValue, Unsafe.Add(ref srcG, i)); + Vector128 b = AdvSimd.Subtract(maxSampleValue, Unsafe.Add(ref srcB, i)); + + // y = 0 + (0.299 * r) + (0.587 * g) + (0.114 * b) + // cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b) + // cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b) + Vector128 y = HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(f0114, b), f0587, g), f0299, r); + Vector128 cb = AdvSimd.Add(chromaOffset, HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(f05, b), fn0331264, g), fn0168736, r)); + Vector128 cr = AdvSimd.Add(chromaOffset, HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(fn0081312F, b), fn0418688, g), f05, r)); + + Unsafe.Add(ref destY, i) = y; + Unsafe.Add(ref destCb, i) = cb; + Unsafe.Add(ref destCr, i) = cr; + } + } + } +} diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs index 10d80ddb23..90b55eb87d 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs @@ -167,6 +167,11 @@ internal abstract partial class JpegColorConverterBase return new YccKVector(precision); } + if (JpegColorConverterArm64.IsSupported) + { + return new YccKArm64(precision); + } + return new YccKScalar(precision); } diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/YccKColorConverter.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/YccKColorConverter.cs index 991d3b0d02..136182936f 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/YccKColorConverter.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/ColorConversion/YccKColorConverter.cs @@ -37,4 +37,12 @@ public class YccKColorConverter : ColorConversionBenchmark new JpegColorConverterBase.YccKAvx(8).ConvertToRgbInplace(values); } + + [Benchmark] + public void SimdVectorArm64() + { + var values = new JpegColorConverterBase.ComponentValues(this.Input, 0); + + new JpegColorConverterBase.YccKArm64(8).ConvertToRgbInplace(values); + } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index fac08ee3d3..b2db5b4bcd 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -374,6 +374,23 @@ public class JpegColorConverterTests new JpegColorConverterBase.YccKScalar(8), precísion: 4); + [Theory] + [MemberData(nameof(Seeds))] + public void FromYccKArm64(int seed) => + this.TestConversionToRgb( new JpegColorConverterBase.YccKArm64(8), + 4, + seed, + new JpegColorConverterBase.YccKScalar(8)); + + [Theory] + [MemberData(nameof(Seeds))] + public void FromRgbToYccKArm64(int seed) => + this.TestConversionFromRgb(new JpegColorConverterBase.YccKArm64(8), + 4, + seed, + new JpegColorConverterBase.YccKScalar(8), + precísion: 4); + private void TestConversionToRgb( JpegColorConverterBase converter, int componentCount, From f4727d1d3480d2b01d0619051ec5ada0959dbb71 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 27 Mar 2023 18:13:52 +0200 Subject: [PATCH 42/86] Add test for GetConverter with cmyk color space which uses FeatureTestRunner to disable specific hw features --- .../Formats/Jpg/JpegColorConverterTests.cs | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index 93c246e7cf..bb6a67403e 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -72,7 +72,7 @@ public class JpegColorConverterTests } [Fact] - public void GetConverterReturnsValidConverterWithRgbColorSpace() + public void GetConverterReturnsCorrectConverterWithRgbColorSpace() { FeatureTestRunner.RunWithHwIntrinsicsFeature( RunTest, @@ -104,6 +104,39 @@ public class JpegColorConverterTests } } + [Fact] + public void GetConverterReturnsCorrectConverterWithCmykColorSpace() + { + FeatureTestRunner.RunWithHwIntrinsicsFeature( + RunTest, + HwIntrinsics.AllowAll | HwIntrinsics.DisableAVX2 | HwIntrinsics.DisableSSE2 | HwIntrinsics.DisableHWIntrinsic); + + static void RunTest(string arg) + { + // arrange + Type expectedType = typeof(JpegColorConverterBase.CmykScalar); + if (Avx.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.CmykAvx); + } + else if (Sse2.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.CmykVector); + } + else if (AdvSimd.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.CmykArm64); + } + + // act + JpegColorConverterBase converter = JpegColorConverterBase.GetConverter(JpegColorSpace.Cmyk, 8); + Type actualType = converter.GetType(); + + // assert + Assert.Equal(expectedType, actualType); + } + } + [Theory] [InlineData(JpegColorSpace.Grayscale, 1)] [InlineData(JpegColorSpace.Ycck, 4)] From ecb6c0f823d0cd27281c1bf84c63022744123f6a Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 27 Mar 2023 18:18:19 +0200 Subject: [PATCH 43/86] Add test for GetConverter with ycbcr color space which uses FeatureTestRunner to disable specific hw features --- .../Formats/Jpg/JpegColorConverterTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index bb6a67403e..dcb56e5714 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -137,6 +137,35 @@ public class JpegColorConverterTests } } + [Fact] + public void GetConverterReturnsCorrectConverterWithYCbCrColorSpace() + { + FeatureTestRunner.RunWithHwIntrinsicsFeature( + RunTest, + HwIntrinsics.AllowAll | HwIntrinsics.DisableAVX2 | HwIntrinsics.DisableSSE2 | HwIntrinsics.DisableHWIntrinsic); + + static void RunTest(string arg) + { + // arrange + Type expectedType = typeof(JpegColorConverterBase.YCbCrScalar); + if (Avx.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.YCbCrAvx); + } + else if (Sse2.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.YCbCrVector); + } + + // act + JpegColorConverterBase converter = JpegColorConverterBase.GetConverter(JpegColorSpace.YCbCr, 8); + Type actualType = converter.GetType(); + + // assert + Assert.Equal(expectedType, actualType); + } + } + [Theory] [InlineData(JpegColorSpace.Grayscale, 1)] [InlineData(JpegColorSpace.Ycck, 4)] From f0530bf56a404bbe3be6a20b4748793b078d543c Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 27 Mar 2023 18:22:00 +0200 Subject: [PATCH 44/86] Add test for GetConverter with ycck color space which uses FeatureTestRunner to disable specific hw features --- .../Formats/Jpg/JpegColorConverterTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index dcb56e5714..8ede71a5c7 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -166,6 +166,35 @@ public class JpegColorConverterTests } } + [Fact] + public void GetConverterReturnsCorrectConverterWithYcckColorSpace() + { + FeatureTestRunner.RunWithHwIntrinsicsFeature( + RunTest, + HwIntrinsics.AllowAll | HwIntrinsics.DisableAVX2 | HwIntrinsics.DisableSSE2 | HwIntrinsics.DisableHWIntrinsic); + + static void RunTest(string arg) + { + // arrange + Type expectedType = typeof(JpegColorConverterBase.YccKScalar); + if (Avx.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.YccKAvx); + } + else if (Sse2.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.YccKVector); + } + + // act + JpegColorConverterBase converter = JpegColorConverterBase.GetConverter(JpegColorSpace.Ycck, 8); + Type actualType = converter.GetType(); + + // assert + Assert.Equal(expectedType, actualType); + } + } + [Theory] [InlineData(JpegColorSpace.Grayscale, 1)] [InlineData(JpegColorSpace.Ycck, 4)] From 42918ed6158305e75e8cf14646abefed844aa9f8 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 27 Mar 2023 18:25:27 +0200 Subject: [PATCH 45/86] Add test for GetConverter with grayscale color space which uses FeatureTestRunner to disable specific hw features --- .../Formats/Jpg/JpegColorConverterTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index 8ede71a5c7..2eb988e751 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -104,6 +104,35 @@ public class JpegColorConverterTests } } + [Fact] + public void GetConverterReturnsCorrectConverterWithGrayScaleColorSpace() + { + FeatureTestRunner.RunWithHwIntrinsicsFeature( + RunTest, + HwIntrinsics.AllowAll | HwIntrinsics.DisableAVX2 | HwIntrinsics.DisableSSE2 | HwIntrinsics.DisableHWIntrinsic); + + static void RunTest(string arg) + { + // arrange + Type expectedType = typeof(JpegColorConverterBase.GrayscaleScalar); + if (Avx.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.GrayscaleAvx); + } + else if (Sse2.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.GrayScaleVector); + } + + // act + JpegColorConverterBase converter = JpegColorConverterBase.GetConverter(JpegColorSpace.Grayscale, 8); + Type actualType = converter.GetType(); + + // assert + Assert.Equal(expectedType, actualType); + } + } + [Fact] public void GetConverterReturnsCorrectConverterWithCmykColorSpace() { From 2f6edd76fa672a8c259c2da89d74169b94b0e319 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 27 Mar 2023 18:27:32 +0200 Subject: [PATCH 46/86] Add GrayscaleArm case --- tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index 72f89394d8..41623ebf64 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -123,6 +123,10 @@ public class JpegColorConverterTests { expectedType = typeof(JpegColorConverterBase.GrayScaleVector); } + else if (AdvSimd.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.GrayscaleArm); + } // act JpegColorConverterBase converter = JpegColorConverterBase.GetConverter(JpegColorSpace.Grayscale, 8); From f348d704efac5bcb001cd8ba40b12d1cc7329d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 27 Mar 2023 18:34:02 +0200 Subject: [PATCH 47/86] Block8x8 Load and CopyTo simplified Similar to a534328dc482683834c6901d93da61cf0d053724 --- .../Formats/Jpeg/Components/Block8x8.cs | 27 ++++++------------- .../Formats/Jpg/Block8x8Tests.cs | 3 +-- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs index b417a8c814..01d112bd6f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs @@ -63,9 +63,10 @@ internal partial struct Block8x8 public static Block8x8 Load(Span data) { - Unsafe.SkipInit(out Block8x8 result); - result.LoadFrom(data); - return result; + DebugGuard.MustBeGreaterThanOrEqualTo(data.Length, Size, "data is too small"); + + ref byte src = ref Unsafe.As(ref MemoryMarshal.GetReference(data)); + return Unsafe.ReadUnaligned(ref src); } /// @@ -93,9 +94,10 @@ internal partial struct Block8x8 /// public void CopyTo(Span destination) { - ref byte selfRef = ref Unsafe.As(ref this); - ref byte destRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(destination)); - Unsafe.CopyBlockUnaligned(ref destRef, ref selfRef, Size * sizeof(short)); + DebugGuard.MustBeGreaterThanOrEqualTo(destination.Length, Size, "destination is too small"); + + ref byte destRef = ref Unsafe.As(ref MemoryMarshal.GetReference(destination)); + Unsafe.WriteUnaligned(ref destRef, this); } /// @@ -124,19 +126,6 @@ internal partial struct Block8x8 } } - /// - /// Load raw 16bit integers from source. - /// - /// Source - [MethodImpl(InliningOptions.ShortMethod)] - public void LoadFrom(Span source) - { - ref byte sourceRef = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); - ref byte destRef = ref Unsafe.As(ref this); - - Unsafe.CopyBlockUnaligned(ref destRef, ref sourceRef, Size * sizeof(short)); - } - /// /// Cast and copy -s from the beginning of 'source' span. /// diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs index 798ea30407..b5d364dd38 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs @@ -269,8 +269,7 @@ public class Block8x8Tests : JpegFixture short[] expected = Create8x8ShortData(); ReferenceImplementations.Transpose8x8(expected); - var block8x8 = default(Block8x8); - block8x8.LoadFrom(Create8x8ShortData()); + Block8x8 block8x8 = Block8x8.Load(Create8x8ShortData()); block8x8.TransposeInplace(); From dae030d8b85a275ee75762493b59194ad1320462 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 27 Mar 2023 18:49:59 +0200 Subject: [PATCH 48/86] Expect YCbCrVector on ARM --- tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index 41623ebf64..67602295c0 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -189,6 +189,10 @@ public class JpegColorConverterTests { expectedType = typeof(JpegColorConverterBase.YCbCrVector); } + else if (AdvSimd.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.YCbCrVector); + } // act JpegColorConverterBase converter = JpegColorConverterBase.GetConverter(JpegColorSpace.YCbCr, 8); From 4b84aecb94d37e934051273e2487ebe798424c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 27 Mar 2023 19:09:25 +0200 Subject: [PATCH 49/86] Reverted some pinning changes to have less verbose C# code --- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 2 +- src/ImageSharp/Compression/Zlib/Adler32.cs | 2 +- src/ImageSharp/Compression/Zlib/Crc32.cs | 6 +++--- src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs | 2 +- .../Formats/Webp/Lossless/PredictorEncoder.cs | 10 +++++----- src/ImageSharp/Formats/Webp/WebpCommonUtils.cs | 2 +- src/ImageSharp/Memory/Buffer2DExtensions.cs | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index fd8a61350f..8ba1b09125 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -673,7 +673,7 @@ internal static partial class SimdUtils ReadOnlySpan source, Span dest) { - fixed (byte* sourceBase = &MemoryMarshal.GetReference(source)) + fixed (byte* sourceBase = source) { if (Avx2.IsSupported) { diff --git a/src/ImageSharp/Compression/Zlib/Adler32.cs b/src/ImageSharp/Compression/Zlib/Adler32.cs index 3ecdf81539..dd8217541a 100644 --- a/src/ImageSharp/Compression/Zlib/Adler32.cs +++ b/src/ImageSharp/Compression/Zlib/Adler32.cs @@ -387,7 +387,7 @@ internal static class Adler32 uint s1 = adler & 0xFFFF; uint s2 = (adler >> 16) & 0xFFFF; - fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) + fixed (byte* bufferPtr = buffer) { byte* localBufferPtr = bufferPtr; uint length = (uint)buffer.Length; diff --git a/src/ImageSharp/Compression/Zlib/Crc32.cs b/src/ImageSharp/Compression/Zlib/Crc32.cs index e21621ab74..2d0a09bd4c 100644 --- a/src/ImageSharp/Compression/Zlib/Crc32.cs +++ b/src/ImageSharp/Compression/Zlib/Crc32.cs @@ -81,7 +81,7 @@ internal static partial class Crc32 int chunksize = buffer.Length & ~ChunksizeMask; int length = chunksize; - fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) + fixed (byte* bufferPtr = buffer) { fixed (ulong* k05PolyPtr = K05Poly) { @@ -201,7 +201,7 @@ internal static partial class Crc32 [MethodImpl(InliningOptions.HotPath | InliningOptions.ShortMethod)] private static unsafe uint CalculateArm(uint crc, ReadOnlySpan buffer) { - fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) + fixed (byte* bufferPtr = buffer) { byte* localBufferPtr = bufferPtr; int len = buffer.Length; @@ -248,7 +248,7 @@ internal static partial class Crc32 [MethodImpl(InliningOptions.HotPath | InliningOptions.ShortMethod)] private static unsafe uint CalculateArm64(uint crc, ReadOnlySpan buffer) { - fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) + fixed (byte* bufferPtr = buffer) { byte* localBufferPtr = bufferPtr; int len = buffer.Length; diff --git a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs index ab6e4cfccf..024adb7c23 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs @@ -569,7 +569,7 @@ internal static unsafe class LosslessUtils Span pixelData, Span outputSpan) { - fixed (uint* inputFixed = &MemoryMarshal.GetReference(pixelData)) + fixed (uint* inputFixed = pixelData) { fixed (uint* outputFixed = outputSpan) { diff --git a/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs index 4113579637..689c63f5b1 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs @@ -353,8 +353,8 @@ internal static unsafe class PredictorEncoder else { #pragma warning disable SA1503 // Braces should not be omitted - fixed (uint* currentRow = &MemoryMarshal.GetReference(currentRowSpan)) - fixed (uint* upperRow = &MemoryMarshal.GetReference(upperRowSpan)) + fixed (uint* currentRow = currentRowSpan) + fixed (uint* upperRow = upperRowSpan) { for (int x = xStart; x < xEnd; x++) { @@ -664,9 +664,9 @@ internal static unsafe class PredictorEncoder Span scratch) { #pragma warning disable SA1503 // Braces should not be omitted - fixed (uint* current = &MemoryMarshal.GetReference(currentSpan)) - fixed (uint* upper = &MemoryMarshal.GetReference(upperSpan)) - fixed (uint* outputFixed = &MemoryMarshal.GetReference(outputSpan)) + fixed (uint* current = currentSpan) + fixed (uint* upper = upperSpan) + fixed (uint* outputFixed = outputSpan) { uint* output = outputFixed; if (xStart == 0) diff --git a/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs b/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs index 735d0bf557..4a7dc74ca7 100644 --- a/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs +++ b/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs @@ -81,7 +81,7 @@ internal static class WebpCommonUtils ReadOnlySpan rowBytes = MemoryMarshal.AsBytes(row); int i = 0; int length = (row.Length * 4) - 3; - fixed (byte* src = &MemoryMarshal.GetReference(rowBytes)) + fixed (byte* src = rowBytes) { for (; i + 64 <= length; i += 64) { diff --git a/src/ImageSharp/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs index 31617c163b..2eb05ea935 100644 --- a/src/ImageSharp/Memory/Buffer2DExtensions.cs +++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs @@ -50,7 +50,7 @@ public static class Buffer2DExtensions Span span = MemoryMarshal.AsBytes(buffer.DangerousGetSingleMemory().Span); - fixed (byte* ptr = &MemoryMarshal.GetReference(span)) + fixed (byte* ptr = span) { byte* basePtr = ptr; for (int y = 0; y < buffer.Height; y++) From 66b2f327bed811d7abce65921148d797ee4fdbd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Mon, 27 Mar 2023 19:19:02 +0200 Subject: [PATCH 50/86] Reverted Webp/WebpCommonUtils fixed-verbosity --- src/ImageSharp/Formats/Webp/WebpCommonUtils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs b/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs index 4a7dc74ca7..1a8fcbafc9 100644 --- a/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs +++ b/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs @@ -25,7 +25,7 @@ internal static class WebpCommonUtils ReadOnlySpan rowBytes = MemoryMarshal.AsBytes(row); int i = 0; int length = (row.Length * 4) - 3; - fixed (byte* src = &MemoryMarshal.GetReference(rowBytes)) + fixed (byte* src = rowBytes) { var alphaMaskVector256 = Vector256.Create(0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255); Vector256 all0x80Vector256 = Vector256.Create((byte)0x80).AsByte(); From 52861d87d0c571652d6e8c008d6d783f1ce94660 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 27 Mar 2023 19:27:24 +0200 Subject: [PATCH 51/86] Another case for arm where YccKVector should be expected --- tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index 67602295c0..bdb175f6f1 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -222,6 +222,10 @@ public class JpegColorConverterTests { expectedType = typeof(JpegColorConverterBase.YccKVector); } + else if (AdvSimd.IsSupported) + { + expectedType = typeof(JpegColorConverterBase.YccKVector); + } // act JpegColorConverterBase converter = JpegColorConverterBase.GetConverter(JpegColorSpace.Ycck, 8); From 7b13ae21ad80cef72fea0ae8f2df8cead08f44e6 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Tue, 28 Mar 2023 06:38:15 +0200 Subject: [PATCH 52/86] Adapt testchanges --- tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index 1dbbc58e65..8eb2e383fc 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -191,7 +191,7 @@ public class JpegColorConverterTests } else if (AdvSimd.IsSupported) { - expectedType = typeof(JpegColorConverterBase.YCbCrVector); + expectedType = typeof(JpegColorConverterBase.YCbCrArm); } // act @@ -224,7 +224,7 @@ public class JpegColorConverterTests } else if (AdvSimd.IsSupported) { - expectedType = typeof(JpegColorConverterBase.YccKVector); + expectedType = typeof(JpegColorConverterBase.YccKArm64); } // act From 33fe244a242bdb5f09231c5fcecf8ba979ca9537 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Tue, 28 Mar 2023 07:15:05 +0200 Subject: [PATCH 53/86] Arm needs to come before vector --- .../Components/ColorConverters/JpegColorConverterBase.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs index f8d60b972c..041f6b0578 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs @@ -162,14 +162,14 @@ internal abstract partial class JpegColorConverterBase return new YccKAvx(precision); } - if (JpegColorConverterVector.IsSupported) + if (JpegColorConverterArm64.IsSupported) { - return new YccKVector(precision); + return new YccKArm64(precision); } - if (JpegColorConverterArm64.IsSupported) + if (JpegColorConverterVector.IsSupported) { - return new YccKArm64(precision); + return new YccKVector(precision); } return new YccKScalar(precision); From 996f7675b98005c31d2186b18653e8c547409dec Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Tue, 28 Mar 2023 13:22:41 +0200 Subject: [PATCH 54/86] Change test, only expect it for ARM64 --- tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index 8eb2e383fc..d71fa31e1e 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -156,7 +156,7 @@ public class JpegColorConverterTests { expectedType = typeof(JpegColorConverterBase.CmykVector); } - else if (AdvSimd.IsSupported) + else if (AdvSimd.Arm64.IsSupported) { expectedType = typeof(JpegColorConverterBase.CmykArm64); } @@ -222,7 +222,7 @@ public class JpegColorConverterTests { expectedType = typeof(JpegColorConverterBase.YccKVector); } - else if (AdvSimd.IsSupported) + else if (AdvSimd.Arm64.IsSupported) { expectedType = typeof(JpegColorConverterBase.YccKArm64); } From b2dc1e5704928009c57c7a6e1f9836153885951b Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Tue, 28 Mar 2023 16:37:34 +0000 Subject: [PATCH 55/86] Update tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs Co-authored-by: Anton Firszov --- tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index d71fa31e1e..ef9f48a890 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -556,7 +556,7 @@ public class JpegColorConverterTests [Theory] [MemberData(nameof(Seeds))] public void FromYccKArm64(int seed) => - this.TestConversionToRgb( new JpegColorConverterBase.YccKArm64(8), + this.TestConversionToRgb(new JpegColorConverterBase.YccKArm64(8), 4, seed, new JpegColorConverterBase.YccKScalar(8)); From 0b140a4ad9f7be71f172eac4d10997bc0936844d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Wed, 29 Mar 2023 10:29:55 +0200 Subject: [PATCH 56/86] Added and used Numerics.Vector{128|256}Count extension --- src/ImageSharp/Common/Helpers/Numerics.cs | 90 +++++++++++++++++++ .../Helpers/SimdUtils.ExtendedIntrinsics.cs | 4 +- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 20 ++--- .../JpegColorConverter.CmykAvx.cs | 4 +- .../JpegColorConverter.CmykVector.cs | 4 +- .../JpegColorConverter.GrayScaleArm.cs | 4 +- .../JpegColorConverter.GrayScaleAvx.cs | 4 +- .../JpegColorConverter.GrayScaleVector.cs | 4 +- .../JpegColorConverter.RgbArm.cs | 2 +- .../JpegColorConverter.RgbAvx.cs | 2 +- .../JpegColorConverter.RgbVector.cs | 2 +- .../JpegColorConverter.YCbCrAvx.cs | 4 +- .../JpegColorConverter.YCbCrVector.cs | 4 +- .../JpegColorConverter.YccKAvx.cs | 4 +- .../JpegColorConverter.YccKVector.cs | 4 +- .../Components/Encoder/ComponentProcessor.cs | 10 +-- .../FeatureTesting/FeatureTestRunner.cs | 2 +- 17 files changed, 129 insertions(+), 39 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index 876f6e1fe6..5af5db3cda 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -949,4 +949,94 @@ internal static class Numerics [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOutOfRange(int value, int min, int max) => (uint)(value - min) > (uint)(max - min); + + /// + /// Gets the count of vectors that safely fit into the given span. + /// + /// The type of the vector. + /// The given span. + /// Count of vectors that safely fit into the span. + public static nuint VectorCount(this Span span) + where TVector : struct + => (uint)span.Length / (uint)Vector.Count; + + /// + /// Gets the count of vectors that safely fit into the given span. + /// + /// The type of the vector. + /// The given span. + /// Count of vectors that safely fit into the span. + public static nuint Vector128Count(this Span span) + where TVector : struct + => (uint)span.Length / (uint)Vector128.Count; + + /// + /// Gets the count of vectors that safely fit into the given span. + /// + /// The type of the vector. + /// The given span. + /// Count of vectors that safely fit into the span. + public static nuint Vector128Count(this ReadOnlySpan span) + where TVector : struct + => (uint)span.Length / (uint)Vector128.Count; + + /// + /// Gets the count of vectors that safely fit into the given span. + /// + /// The type of the vector. + /// The given span. + /// Count of vectors that safely fit into the span. + public static nuint Vector256Count(this Span span) + where TVector : struct + => (uint)span.Length / (uint)Vector256.Count; + + /// + /// Gets the count of vectors that safely fit into the given span. + /// + /// The type of the vector. + /// The given span. + /// Count of vectors that safely fit into the span. + public static nuint Vector256Count(this ReadOnlySpan span) + where TVector : struct + => (uint)span.Length / (uint)Vector256.Count; + + /// + /// Gets the count of vectors that safely fit into the given span. + /// + /// The type of the vector. + /// The given span. + /// Count of vectors that safely fit into the span. + public static nuint VectorCount(this Span span) + where TVector : struct + => (uint)span.Length / (uint)Vector.Count; + + /// + /// Gets the count of vectors that safely fit into the given span. + /// + /// The type of the vector. + /// The given span. + /// Count of vectors that safely fit into the span. + public static nuint Vector128Count(this Span span) + where TVector : struct + => (uint)span.Length / (uint)Vector128.Count; + + /// + /// Gets the count of vectors that safely fit into the given span. + /// + /// The type of the vector. + /// The given span. + /// Count of vectors that safely fit into the span. + public static nuint Vector256Count(this Span span) + where TVector : struct + => (uint)span.Length / (uint)Vector256.Count; + + /// + /// Gets the count of vectors that safely fit into length. + /// + /// The type of the vector. + /// The given length. + /// Count of vectors that safely fit into the length. + public static nuint Vector256Count(int length) + where TVector : struct + => (uint)length / (uint)Vector256.Count; } diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs index b9505ba3ef..ac122fc7d4 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs @@ -97,7 +97,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector.Count); - nuint n = (uint)dest.Length / (uint)Vector.Count; + nuint n = dest.VectorCount(); ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); @@ -132,7 +132,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector.Count); - nuint n = (uint)dest.Length / (uint)Vector.Count; + nuint n = dest.VectorCount(); ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 8ba1b09125..5b5a3493de 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -222,7 +222,7 @@ internal static partial class SimdUtils ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)(uint)(dest.Length / Vector256.Count); + nint n = (nint)dest.Vector256Count(); nint m = Numerics.Modulo4(n); nint u = n - m; @@ -392,7 +392,7 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nuint n = (uint)source.Length / (uint)Vector128.Count; + nuint n = source.Vector128Count(); for (nuint i = 0; i < n; i += 3) { @@ -455,7 +455,7 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nuint n = (uint)source.Length / (uint)Vector128.Count; + nuint n = source.Vector128Count(); for (nuint i = 0, j = 0; i < n; i += 3, j += 4) { @@ -499,7 +499,7 @@ internal static partial class SimdUtils ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); - nuint n = (uint)source.Length / (uint)Vector128.Count; + nuint n = source.Vector128Count(); for (nuint i = 0, j = 0; i < n; i += 4, j += 3) { @@ -679,7 +679,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector256.Count); - nuint n = (uint)dest.Length / (uint)Vector256.Count; + nuint n = dest.Vector256Count(); ref Vector256 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); @@ -712,7 +712,7 @@ internal static partial class SimdUtils // Sse VerifySpanInput(source, dest, Vector128.Count); - nuint n = (uint)dest.Length / (uint)Vector128.Count; + nuint n = dest.Vector128Count(); ref Vector128 destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest)); @@ -811,7 +811,7 @@ internal static partial class SimdUtils { VerifySpanInput(source, dest, Vector256.Count); - nuint n = (uint)dest.Length / (uint)Vector256.Count; + nuint n = dest.Vector256Count(); ref Vector256 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -850,7 +850,7 @@ internal static partial class SimdUtils // Sse VerifySpanInput(source, dest, Vector128.Count); - nuint n = (uint)dest.Length / (uint)Vector128.Count; + nuint n = dest.Vector128Count(); ref Vector128 sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); @@ -893,7 +893,7 @@ internal static partial class SimdUtils ref Vector256 bBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(blueChannel)); ref byte dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(destination)); - nuint count = (uint)redChannel.Length / (uint)Vector256.Count; + nuint count = redChannel.Vector256Count(); ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32); Vector256 control1 = Unsafe.As>(ref control1Bytes); @@ -965,7 +965,7 @@ internal static partial class SimdUtils ref Vector256 bBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(blueChannel)); ref Vector256 dBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination)); - nuint count = (uint)redChannel.Length / (uint)Vector256.Count; + nuint count = redChannel.Vector256Count(); ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32); Vector256 control1 = Unsafe.As>(ref control1Bytes); var a = Vector256.Create((byte)255); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs index 0283e83d0f..76d188f457 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs @@ -32,7 +32,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / (this.MaximumValue * this.MaximumValue)); - nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; + nuint n = values.Component0.Vector256Count(); for (nuint i = 0; i < n; i++) { ref Vector256 c = ref Unsafe.Add(ref c0Base, i); @@ -71,7 +71,7 @@ internal abstract partial class JpegColorConverterBase var scale = Vector256.Create(maxValue); - nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; + nuint n = values.Component0.Vector256Count(); for (nuint i = 0; i < n; i++) { Vector256 ctmp = Avx.Subtract(scale, Unsafe.Add(ref srcR, i)); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs index 4cc8c0665f..a59be009b7 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs @@ -30,7 +30,7 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / (this.MaximumValue * this.MaximumValue)); - nuint n = (uint)values.Component0.Length / (uint)Vector.Count; + nuint n = values.Component0.VectorCount(); for (nuint i = 0; i < n; i++) { ref Vector c = ref Unsafe.Add(ref cBase, i); @@ -78,7 +78,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = new Vector(maxValue); - nuint n = (uint)values.Component0.Length / (uint)Vector.Count; + nuint n = values.Component0.VectorCount(); for (nuint i = 0; i < n; i++) { Vector ctmp = scale - Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs index a8d5f49c24..6bb8fd7aa3 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs @@ -27,7 +27,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector128.Create(1 / this.MaximumValue); - nuint n = (uint)values.Component0.Length / (uint)Vector128.Count; + nuint n = values.Component0.Vector128Count(); for (nuint i = 0; i < n; i++) { ref Vector128 c0 = ref Unsafe.Add(ref c0Base, i); @@ -53,7 +53,7 @@ internal abstract partial class JpegColorConverterBase var f0587 = Vector128.Create(0.587f); var f0114 = Vector128.Create(0.114f); - nuint n = (uint)values.Component0.Length / (uint)Vector128.Count; + nuint n = values.Component0.Vector128Count(); for (nuint i = 0; i < n; i++) { ref Vector128 r = ref Unsafe.Add(ref srcRed, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs index 4efb6f8514..a9e1c5d130 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs @@ -27,7 +27,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / this.MaximumValue); - nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; + nuint n = values.Component0.Vector256Count(); for (nuint i = 0; i < n; i++) { ref Vector256 c0 = ref Unsafe.Add(ref c0Base, i); @@ -53,7 +53,7 @@ internal abstract partial class JpegColorConverterBase var f0587 = Vector256.Create(0.587f); var f0114 = Vector256.Create(0.114f); - nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; + nuint n = values.Component0.Vector256Count(); for (nuint i = 0; i < n; i++) { ref Vector256 r = ref Unsafe.Add(ref srcRed, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs index 4156a5968b..cac10636f5 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs @@ -24,7 +24,7 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / this.MaximumValue); - nuint n = (uint)values.Component0.Length / (uint)Vector.Count; + nuint n = values.Component0.VectorCount(); for (nuint i = 0; i < n; i++) { ref Vector c0 = ref Unsafe.Add(ref cBase, i); @@ -53,7 +53,7 @@ internal abstract partial class JpegColorConverterBase var gMult = new Vector(0.587f); var bMult = new Vector(0.114f); - nuint n = (uint)values.Component0.Length / (uint)Vector.Count; + nuint n = values.Component0.VectorCount(); for (nuint i = 0; i < n; i++) { Vector r = Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs index 8889223064..75eeb17dd3 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs @@ -30,7 +30,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector128.Create(1 / this.MaximumValue); - nuint n = (uint)values.Component0.Length / (uint)Vector128.Count; + nuint n = values.Component0.Vector128Count(); for (nuint i = 0; i < n; i++) { ref Vector128 r = ref Unsafe.Add(ref rBase, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs index ae9b943aaf..b56728fa71 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs @@ -29,7 +29,7 @@ internal abstract partial class JpegColorConverterBase // Used for the color conversion var scale = Vector256.Create(1 / this.MaximumValue); - nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; + nuint n = values.Component0.Vector256Count(); for (nuint i = 0; i < n; i++) { ref Vector256 r = ref Unsafe.Add(ref rBase, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs index 5e3cf9b2b3..bd3142fa13 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs @@ -28,7 +28,7 @@ internal abstract partial class JpegColorConverterBase var scale = new Vector(1 / this.MaximumValue); - nuint n = (uint)values.Component0.Length / (uint)Vector.Count; + nuint n = values.Component0.VectorCount(); for (nuint i = 0; i < n; i++) { ref Vector r = ref Unsafe.Add(ref rBase, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs index 0a2cfd084c..c5fa786e2c 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs @@ -38,7 +38,7 @@ internal abstract partial class JpegColorConverterBase var bCbMult = Vector256.Create(YCbCrScalar.BCbMult); // Walking 8 elements at one step: - nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; + nuint n = values.Component0.Vector256Count(); for (nuint i = 0; i < n; i++) { // y = yVals[i]; @@ -98,7 +98,7 @@ internal abstract partial class JpegColorConverterBase var fn0081312F = Vector256.Create(-0.081312F); var f05 = Vector256.Create(0.5f); - nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; + nuint n = values.Component0.Vector256Count(); for (nuint i = 0; i < n; i++) { Vector256 r = Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs index ca01aed612..a5d0c889e3 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs @@ -35,7 +35,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(-YCbCrScalar.GCrMult); var bCbMult = new Vector(YCbCrScalar.BCbMult); - nuint n = (uint)values.Component0.Length / (uint)Vector.Count; + nuint n = values.Component0.VectorCount(); for (nuint i = 0; i < n; i++) { // y = yVals[i]; @@ -103,7 +103,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(0.418688f); var bCrMult = new Vector(0.081312f); - nuint n = (uint)values.Component0.Length / (uint)Vector.Count; + nuint n = values.Component0.VectorCount(); for (nuint i = 0; i < n; i++) { Vector r = Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs index 337741622a..efe40ba085 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs @@ -40,7 +40,7 @@ internal abstract partial class JpegColorConverterBase var bCbMult = Vector256.Create(YCbCrScalar.BCbMult); // Walking 8 elements at one step: - nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; + nuint n = values.Component0.Vector256Count(); for (nuint i = 0; i < n; i++) { // y = yVals[i]; @@ -109,7 +109,7 @@ internal abstract partial class JpegColorConverterBase var fn0081312F = Vector256.Create(-0.081312F); var f05 = Vector256.Create(0.5f); - nuint n = (uint)values.Component0.Length / (uint)Vector256.Count; + nuint n = values.Component0.Vector256Count(); for (nuint i = 0; i < n; i++) { Vector256 r = Avx.Subtract(maxSampleValue, Unsafe.Add(ref srcR, i)); diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs index d67fad3080..570a401adf 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs @@ -36,7 +36,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(-YCbCrScalar.GCrMult); var bCbMult = new Vector(YCbCrScalar.BCbMult); - nuint n = (uint)values.Component0.Length / (uint)Vector.Count; + nuint n = values.Component0.VectorCount(); for (nuint i = 0; i < n; i++) { // y = yVals[i]; @@ -107,7 +107,7 @@ internal abstract partial class JpegColorConverterBase var gCrMult = new Vector(0.418688f); var bCrMult = new Vector(0.081312f); - nuint n = (uint)values.Component0.Length / (uint)Vector.Count; + nuint n = values.Component0.VectorCount(); for (nuint i = 0; i < n; i++) { Vector r = maxSampleValue - Unsafe.Add(ref srcR, i); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs index 4815baa62f..be27385cd0 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs @@ -122,7 +122,7 @@ internal class ComponentProcessor : IDisposable ref Vector256 sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed - nuint count = (uint)source.Length / (uint)Vector256.Count; + nuint count = source.Vector256Count(); for (nuint i = 0; i < count; i++) { Unsafe.Add(ref targetVectorRef, i) = Avx.Add(Unsafe.Add(ref targetVectorRef, i), Unsafe.Add(ref sourceVectorRef, i)); @@ -133,7 +133,7 @@ internal class ComponentProcessor : IDisposable ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); ref Vector sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); - nuint count = (uint)source.Length / (uint)Vector.Count; + nuint count = source.VectorCount(); for (nuint i = 0; i < count; i++) { Unsafe.Add(ref targetVectorRef, i) += Unsafe.Add(ref sourceVectorRef, i); @@ -166,7 +166,7 @@ internal class ComponentProcessor : IDisposable source = source.Slice(touchedCount); target = target.Slice(touchedCount / factor); - nuint length = (uint)touchedCount / (uint)Vector256.Count; + nuint length = Numerics.Vector256Count(touchedCount); for (uint i = 0; i < haddIterationsCount; i++) { @@ -200,7 +200,7 @@ internal class ComponentProcessor : IDisposable ref Vector256 targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed - nuint count = (uint)target.Length / (uint)Vector256.Count; + nuint count = target.Vector256Count(); var multiplierVector = Vector256.Create(multiplier); for (nuint i = 0; i < count; i++) { @@ -211,7 +211,7 @@ internal class ComponentProcessor : IDisposable { ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); - nuint count = (uint)target.Length / (uint)Vector.Count; + nuint count = target.VectorCount(); var multiplierVector = new Vector(multiplier); for (nuint i = 0; i < count; i++) { diff --git a/tests/ImageSharp.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs b/tests/ImageSharp.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs index f68bfdbe6e..5a9a72f967 100644 --- a/tests/ImageSharp.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs +++ b/tests/ImageSharp.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs @@ -62,7 +62,7 @@ public static class FeatureTestRunner ProcessStartInfo processStartInfo = new(); if (intrinsic.Key != HwIntrinsics.AllowAll) { - processStartInfo.Environment[$"COMPlus_{intrinsic.Value}"] = "0"; + processStartInfo.Environment[$"DOTNET_{intrinsic.Value}"] = "0"; RemoteExecutor.Invoke( action, From 404342916e6808b4ac8641145d91b63074411d97 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Wed, 29 Mar 2023 18:25:09 +0200 Subject: [PATCH 57/86] Add test case for: Fixed wrong division hack #2413 --- .../Formats/WebP/LosslessUtilsTests.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs b/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs index 73c034a6be..75ecc43eb2 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs @@ -186,21 +186,32 @@ public class LosslessUtilsTests private static void RunPredictor13Test() { // arrange - uint[] topData = { 4278193922, 4278193666 }; - const uint left = 4278193410; - const uint expectedResult = 4278193154; + uint[] topData0 = { 4278193922, 4278193666 }; + const uint left0 = 4278193410; + const uint expectedResult0 = 4278193154; + uint[] topData1 = { 4294933015, 4278219803 }; + const uint left1 = 4278236686; + const uint expectedResult1 = 4278231571; + uint actual0 = 0; + uint actual1 = 0; // act unsafe { - fixed (uint* top = &topData[1]) + fixed (uint* top = &topData0[1]) { - uint actual = LosslessUtils.Predictor13(left, top); + actual0 = LosslessUtils.Predictor13(left0, top); + } - // assert - Assert.Equal(expectedResult, actual); + fixed (uint* top = &topData1[1]) + { + actual1 = LosslessUtils.Predictor13(left1, top); } } + + // assert + Assert.Equal(expectedResult0, actual0); + Assert.Equal(expectedResult1, actual1); } [Fact] From b0d9cb8b4b2bb205ccf3965e9000a71114521485 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Wed, 29 Mar 2023 19:51:35 +0200 Subject: [PATCH 58/86] Add BundleColorMap tests --- .../Formats/WebP/LosslessUtilsTests.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs b/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs index 75ecc43eb2..203cf57495 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs @@ -214,6 +214,62 @@ public class LosslessUtilsTests Assert.Equal(expectedResult1, actual1); } + [Fact] + public void BundleColorMap_WithXbitsZero_Works() + { + // arrange + byte[] row = { 238, 238, 238, 238, 238, 238, 240, 237, 240, 235, 223, 223, 218, 220, 226, 219, 220, 204, 218, 211, 218, 221, 254, 255 }; + int xBits = 0; + uint[] actual = new uint[row.Length]; + uint[] expected = + { + 4278251008, 4278251008, 4278251008, 4278251008, 4278251008, + 4278251008, 4278251520, 4278250752, 4278251520, 4278250240, + 4278247168, 4278247168, 4278245888, 4278246400, 4278247936, + 4278246144, 4278246400, 4278242304, 4278245888, 4278244096, + 4278245888, 4278246656, 4278255104, 4278255360 + }; + + // act + LosslessUtils.BundleColorMap(row, actual.Length, xBits, actual); + + // assert + Assert.True(actual.SequenceEqual(expected)); + } + + [Fact] + public void BundleColorMap_WithXbitsNoneZero_Works() + { + // arrange + byte[] row = + { + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 + }; + int xBits = 2; + uint[] actual = new uint[row.Length]; + uint[] expected = + { + 4278233600, 4278233600, 4278233600, 4278233600, 4278255360, 4278255360, 4278255360, 4278255360, 4278233600, 4278233600, 4278233600, 4278233600, + 4278255360, 4278255360, 4278255360, 4278255360, 4278211840, 4278211840, 4278211840, 4278211840, 4278255360, 4278255360, 4278255360, 4278255360, + 4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278206208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + + // act + LosslessUtils.BundleColorMap(row, actual.Length, xBits, actual); + + // assert + Assert.True(actual.SequenceEqual(expected)); + } + [Fact] public void CombinedShannonEntropy_Works() => RunCombinedShannonEntropyTest(); From 73e1306973486d1047402dbeaae7c9e98ef805b3 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Wed, 29 Mar 2023 19:55:50 +0200 Subject: [PATCH 59/86] Add SubtractGreen Scalar test --- .../ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs b/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs index 203cf57495..4551e3e23e 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs @@ -282,9 +282,6 @@ public class LosslessUtilsTests [Fact] public void Predictor13_Works() => RunPredictor13Test(); - [Fact] - public void SubtractGreen_Works() => RunSubtractGreenTest(); - [Fact] public void AddGreenToBlueAndRed_Works() => RunAddGreenToBlueAndRedTest(); @@ -318,12 +315,18 @@ public class LosslessUtilsTests [Fact] public void Predictor13_WithoutSSE2_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunPredictor13Test, HwIntrinsics.DisableSSE2); + [Fact] + public void SubtractGreen_Works() => RunSubtractGreenTest(); + [Fact] public void SubtractGreen_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubtractGreenTest, HwIntrinsics.AllowAll); [Fact] public void SubtractGreen_WithoutAVX2_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubtractGreenTest, HwIntrinsics.DisableAVX2); + [Fact] + public void SubtractGreen_Scalar_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubtractGreenTest, HwIntrinsics.DisableHWIntrinsic); + [Fact] public void SubtractGreen_WithoutAvxOrSSSE3_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubtractGreenTest, HwIntrinsics.DisableAVX2 | HwIntrinsics.DisableSSSE3); From 764452a6aa334a87686ea0ed6e9faad33b3383e9 Mon Sep 17 00:00:00 2001 From: red Date: Sat, 1 Apr 2023 09:57:09 +0300 Subject: [PATCH 60/86] Fix incorrect comments --- src/ImageSharp/Image.FromFile.cs | 2 +- src/ImageSharp/Image.FromStream.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index 24a737493c..884acf7a40 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -81,7 +81,7 @@ public abstract partial class Image /// A return value indicates whether the operation succeeded. /// /// The image file to open and to read the header from. - /// if the information can be read; otherwise, + /// The . /// The path is null. /// The file stream is not readable or the image format is not supported. /// The encoded image contains invalid content. diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs index 1748ca00e0..63f9e64f6c 100644 --- a/src/ImageSharp/Image.FromStream.cs +++ b/src/ImageSharp/Image.FromStream.cs @@ -29,7 +29,7 @@ public abstract partial class Image /// /// The general decoder options. /// The image stream to read the header from. - /// if a match is found; otherwise, + /// The . /// The options are null. /// The stream is null. /// The stream is not readable or the image format is not supported. @@ -79,7 +79,7 @@ public abstract partial class Image /// Reads the raw image information from the specified stream without fully decoding it. /// /// The image stream to read the header from. - /// if the information can be read; otherwise, + /// The . /// The stream is null. /// The stream is not readable or the image format is not supported. /// The encoded image contains invalid content. From c19095153eb392c5dbfd7ccfb6d612d4dde097cd Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 2 Apr 2023 17:24:15 +0200 Subject: [PATCH 61/86] Add Arm for MultiplyToAverage --- .../Jpeg/Components/Encoder/ComponentProcessor.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs index be27385cd0..31c1e27cb3 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs @@ -5,6 +5,7 @@ using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.X86; using SixLabors.ImageSharp.Memory; @@ -201,12 +202,24 @@ internal class ComponentProcessor : IDisposable // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed nuint count = target.Vector256Count(); - var multiplierVector = Vector256.Create(multiplier); + Vector256 multiplierVector = Vector256.Create(multiplier); for (nuint i = 0; i < count; i++) { Unsafe.Add(ref targetVectorRef, i) = Avx.Multiply(Unsafe.Add(ref targetVectorRef, i), multiplierVector); } } + else if (AdvSimd.IsSupported) + { + ref Vector128 targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); + + // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed + nuint count = target.Vector128Count(); + Vector128 multiplierVector = Vector128.Create(multiplier); + for (nuint i = 0; i < count; i++) + { + Unsafe.Add(ref targetVectorRef, i) = AdvSimd.Multiply(Unsafe.Add(ref targetVectorRef, i), multiplierVector); + } + } else { ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); From 32859b87fdee440f10e5978a78e731a9f142482d Mon Sep 17 00:00:00 2001 From: br3aker Date: Sun, 2 Apr 2023 19:20:09 +0300 Subject: [PATCH 62/86] Fixed invalid jpeg buffer width compliment for scalar color converters --- .../Decoder/SpectralConverter{TPixel}.cs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs index d6250127f5..5add4c6f06 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs @@ -184,34 +184,39 @@ internal class SpectralConverter : SpectralConverter, IDisposable MemoryAllocator allocator = this.Configuration.MemoryAllocator; - // color converter from RGB to TPixel + // Color converter from RGB to TPixel JpegColorConverterBase converter = this.GetColorConverter(this.frame, this.jpegData); this.colorConverter = converter; - // resulting image size + // Resulting image size Size pixelSize = CalculateResultingImageSize(this.frame.PixelSize, this.targetSize, out int blockPixelSize); - // iteration data + // Iteration data int majorBlockWidth = this.frame.Components.Max((component) => component.SizeInBlocks.Width); int majorVerticalSamplingFactor = this.frame.Components.Max((component) => component.SamplingFactors.Height); this.pixelRowsPerStep = majorVerticalSamplingFactor * blockPixelSize; - // pixel buffer for resulting image + // Pixel buffer for resulting image this.pixelBuffer = allocator.Allocate2D( pixelSize.Width, pixelSize.Height, this.Configuration.PreferContiguousImageBuffers); this.paddedProxyPixelRow = allocator.Allocate(pixelSize.Width + 3); - // component processors from spectral to RGB + // Component processors from spectral to RGB int bufferWidth = majorBlockWidth * blockPixelSize; - int batchSize = converter.ElementsPerBatch; - int batchRemainder = bufferWidth & (batchSize - 1); - Size postProcessorBufferSize = new(bufferWidth + (batchSize - batchRemainder), this.pixelRowsPerStep); + + // Converters process pixels in batches and require target buffer size to be divisible by a batch size + // Corner case: image size including jpeg padding is already divisible by a batch size or remainder == 0 + int elementsPerBatch = converter.ElementsPerBatch; + int batchRemainder = bufferWidth & (elementsPerBatch - 1); + int widthComplementaryValue = batchRemainder == 0 ? 0 : elementsPerBatch - batchRemainder; + + Size postProcessorBufferSize = new(bufferWidth + widthComplementaryValue, this.pixelRowsPerStep); this.componentProcessors = this.CreateComponentProcessors(this.frame, this.jpegData, blockPixelSize, postProcessorBufferSize); - // single 'stride' rgba32 buffer for conversion between spectral and TPixel + // Single 'stride' rgba32 buffer for conversion between spectral and TPixel this.rgbBuffer = allocator.Allocate(pixelSize.Width * 3); } From 03a988be3d3d7f3e68349c69198393175b34766a Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 2 Apr 2023 22:48:40 +0200 Subject: [PATCH 63/86] Add Arm for SumVertical --- .../Jpeg/Components/Encoder/ComponentProcessor.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs index 31c1e27cb3..7d4f7ee842 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs @@ -129,6 +129,18 @@ internal class ComponentProcessor : IDisposable Unsafe.Add(ref targetVectorRef, i) = Avx.Add(Unsafe.Add(ref targetVectorRef, i), Unsafe.Add(ref sourceVectorRef, i)); } } + else if (AdvSimd.IsSupported) + { + ref Vector128 targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); + ref Vector128 sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); + + // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed + nuint count = source.Vector128Count(); + for (nuint i = 0; i < count; i++) + { + Unsafe.Add(ref targetVectorRef, i) = AdvSimd.Add(Unsafe.Add(ref targetVectorRef, i), Unsafe.Add(ref sourceVectorRef, i)); + } + } else { ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); From 4571325fe2041d5b5c4489cfe01a0d99c32fbb26 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Mon, 3 Apr 2023 18:11:34 +0200 Subject: [PATCH 64/86] add DebugGuard to check for multiple of 8 --- .../Formats/Jpeg/Components/Encoder/ComponentProcessor.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs index 7d4f7ee842..c33a8a1968 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs @@ -123,6 +123,7 @@ internal class ComponentProcessor : IDisposable ref Vector256 sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed + DebugGuard.IsTrue(source.Length % 8 == 0, "source must be multiple of 8"); nuint count = source.Vector256Count(); for (nuint i = 0; i < count; i++) { @@ -135,6 +136,7 @@ internal class ComponentProcessor : IDisposable ref Vector128 sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed + DebugGuard.IsTrue(source.Length % 8 == 0, "source must be multiple of 8"); nuint count = source.Vector128Count(); for (nuint i = 0; i < count; i++) { @@ -213,6 +215,7 @@ internal class ComponentProcessor : IDisposable ref Vector256 targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed + DebugGuard.IsTrue(target.Length % 8 == 0, "target must be multiple of 8"); nuint count = target.Vector256Count(); Vector256 multiplierVector = Vector256.Create(multiplier); for (nuint i = 0; i < count; i++) @@ -225,6 +228,7 @@ internal class ComponentProcessor : IDisposable ref Vector128 targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed + DebugGuard.IsTrue(target.Length % 8 == 0, "target must be multiple of 8"); nuint count = target.Vector128Count(); Vector128 multiplierVector = Vector128.Create(multiplier); for (nuint i = 0; i < count; i++) From fad143d5f8ff7d9ed2e4fda48924cf0be5fe71f3 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 3 Apr 2023 19:39:32 +0200 Subject: [PATCH 65/86] Switch back to Sse2 version of residual costs, since avx version is not the same as scalar version --- .../Formats/Webp/Lossy/Vp8Residual.cs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs index 1770415062..68bf09f948 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs @@ -156,7 +156,7 @@ internal class Vp8Residual return LossyUtils.Vp8BitCost(0, (byte)p0); } - if (Avx2.IsSupported) + if (Sse2.IsSupported) { Span scratch = stackalloc byte[32]; Span ctxs = scratch.Slice(0, 16); @@ -165,19 +165,23 @@ internal class Vp8Residual // Precompute clamped levels and contexts, packed to 8b. ref short outputRef = ref MemoryMarshal.GetReference(this.Coeffs); - Vector256 c0 = Unsafe.As>(ref outputRef).AsInt16(); - Vector256 d0 = Avx2.Subtract(Vector256.Zero, c0); - Vector256 e0 = Avx2.Max(c0, d0); // abs(v), 16b - Vector256 f = Avx2.PackSignedSaturate(e0, e0); - Vector256 g = Avx2.Min(f.AsByte(), Vector256.Create((byte)2)); - Vector256 h = Avx2.Min(f.AsByte(), Vector256.Create((byte)67)); // clampLevel in [0..67] + Vector128 c0 = Unsafe.As>(ref outputRef).AsInt16(); + Vector128 c1 = Unsafe.As>(ref Unsafe.Add(ref outputRef, 8)).AsInt16(); + Vector128 d0 = Sse2.Subtract(Vector128.Zero, c0); + Vector128 d1 = Sse2.Subtract(Vector128.Zero, c1); + Vector128 e0 = Sse2.Max(c0, d0); // abs(v), 16b + Vector128 e1 = Sse2.Max(c1, d1); + Vector128 f = Sse2.PackSignedSaturate(e0, e1); + Vector128 g = Sse2.Min(f.AsByte(), Vector128.Create((byte)2)); // context = 0, 1, 2 + Vector128 h = Sse2.Min(f.AsByte(), Vector128.Create((byte)67)); // clampLevel in [0..67] ref byte ctxsRef = ref MemoryMarshal.GetReference(ctxs); ref byte levelsRef = ref MemoryMarshal.GetReference(levels); ref ushort absLevelsRef = ref MemoryMarshal.GetReference(absLevels); - Unsafe.As>(ref ctxsRef) = g.GetLower(); - Unsafe.As>(ref levelsRef) = h.GetLower(); - Unsafe.As>(ref absLevelsRef) = e0.AsUInt16(); + Unsafe.As>(ref ctxsRef) = g; + Unsafe.As>(ref levelsRef) = h; + Unsafe.As>(ref absLevelsRef) = e0.AsUInt16(); + Unsafe.As>(ref Unsafe.Add(ref absLevelsRef, 8)) = e1.AsUInt16(); int level; int flevel; From 0d6e50f29fb5388f87d6be67f489c072ef4204a6 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 7 Apr 2023 19:21:23 +0200 Subject: [PATCH 66/86] Add Vp8Residual Serialization test --- .../Formats/WebP/Vp8ResidualTests.cs | 107 +++++++++++++++++- 1 file changed, 101 insertions(+), 6 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs index 1f9136e9ab..e9f0f31d75 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json; +using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Formats.Webp.Lossy; using SixLabors.ImageSharp.Tests.TestUtilities; @@ -9,10 +11,106 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp; [Trait("Format", "Webp")] public class Vp8ResidualTests { + [Fact] + public void Serialization_Works() + { + // arrange + Vp8Residual expected = new(); + Vp8EncProba encProb = new(); + Random rand = new(439); + CreateRandomProbas(encProb, rand); + CreateCosts(encProb, rand); + expected.Init(1, 0, encProb); + for (int i = 0; i < expected.Coeffs.Length; i++) + { + expected.Coeffs[i] = (byte)rand.Next(255); + } + + // act + string jsonString = JsonSerializer.Serialize(expected); + Vp8Residual actual = JsonSerializer.Deserialize(jsonString); + + // assert + Assert.Equal(expected.CoeffType, actual.CoeffType); + Assert.Equal(expected.Coeffs, actual.Coeffs); + Assert.Equal(expected.Costs.Length, actual.Costs.Length); + Assert.Equal(expected.First, actual.First); + Assert.Equal(expected.Last, actual.Last); + Assert.Equal(expected.Stats.Length, actual.Stats.Length); + for (int i = 0; i < expected.Stats.Length; i++) + { + Vp8StatsArray[] expectedStats = expected.Stats[i].Stats; + Vp8StatsArray[] actualStats = actual.Stats[i].Stats; + Assert.Equal(expectedStats.Length, actualStats.Length); + for (int j = 0; j < expectedStats.Length; j++) + { + Assert.Equal(expectedStats[j].Stats, actualStats[j].Stats); + } + } + + Assert.Equal(expected.Prob.Length, actual.Prob.Length); + for (int i = 0; i < expected.Prob.Length; i++) + { + Vp8ProbaArray[] expectedProbabilities = expected.Prob[i].Probabilities; + Vp8ProbaArray[] actualProbabilities = actual.Prob[i].Probabilities; + Assert.Equal(expectedProbabilities.Length, actualProbabilities.Length); + for (int j = 0; j < expectedProbabilities.Length; j++) + { + Assert.Equal(expectedProbabilities[j].Probabilities, actualProbabilities[j].Probabilities); + } + } + + for (int i = 0; i < expected.Costs.Length; i++) + { + Vp8CostArray[] expectedCosts = expected.Costs[i].Costs; + Vp8CostArray[] actualCosts = actual.Costs[i].Costs; + Assert.Equal(expectedCosts.Length, actualCosts.Length); + for (int j = 0; j < expectedCosts.Length; j++) + { + Assert.Equal(expectedCosts[j].Costs, actualCosts[j].Costs); + } + } + } + + private static void CreateRandomProbas(Vp8EncProba probas, Random rand) + { + for (int t = 0; t < WebpConstants.NumTypes; ++t) + { + for (int b = 0; b < WebpConstants.NumBands; ++b) + { + for (int c = 0; c < WebpConstants.NumCtx; ++c) + { + for (int p = 0; p < WebpConstants.NumProbas; ++p) + { + probas.Coeffs[t][b].Probabilities[c].Probabilities[p] = (byte)rand.Next(255); + } + } + } + } + } + + private static void CreateCosts(Vp8EncProba probas, Random rand) + { + for (int i = 0; i < probas.RemappedCosts.Length; i++) + { + for (int j = 0; j < probas.RemappedCosts[i].Length; j++) + { + for (int k = 0; k < probas.RemappedCosts[i][j].Costs.Length; k++) + { + ushort[] costs = probas.RemappedCosts[i][j].Costs[k].Costs; + for (int m = 0; m < costs.Length; m++) + { + costs[m] = (byte)rand.Next(255); + } + } + } + } + } + private static void RunSetCoeffsTest() { // arrange - var residual = new Vp8Residual(); + Vp8Residual residual = new(); short[] coeffs = { 110, 0, -2, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0 }; // act @@ -23,11 +121,8 @@ public class Vp8ResidualTests } [Fact] - public void RunSetCoeffsTest_Works() => RunSetCoeffsTest(); - - [Fact] - public void RunSetCoeffsTest_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSetCoeffsTest, HwIntrinsics.AllowAll); + public void SetCoeffsTest_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSetCoeffsTest, HwIntrinsics.AllowAll); [Fact] - public void RunSetCoeffsTest_WithoutHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSetCoeffsTest, HwIntrinsics.DisableHWIntrinsic); + public void SetCoeffsTest_WithoutSSE2_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSetCoeffsTest, HwIntrinsics.DisableSSE2); } From c8d580cbe050244a464ce97de6acb6cd4ef858d2 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 7 Apr 2023 19:29:07 +0200 Subject: [PATCH 67/86] Add JsonConstructors --- .../Formats/Webp/Lossy/Vp8BandProbas.cs | 9 +++ .../Formats/Webp/Lossy/Vp8CostArray.cs | 9 +++ src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs | 9 +++ .../Formats/Webp/Lossy/Vp8ProbaArray.cs | 9 +++ .../Formats/Webp/Lossy/Vp8Residual.cs | 66 +++++++++++++++++++ src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs | 9 +++ .../Formats/Webp/Lossy/Vp8StatsArray.cs | 9 +++ 7 files changed, 120 insertions(+) diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs index 90506efb81..86304d4bd8 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// @@ -20,6 +22,13 @@ internal class Vp8BandProbas } } + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8BandProbas(Vp8ProbaArray[] probabilities) => this.Probabilities = probabilities; + /// /// Gets the Probabilities. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs index 2c8d723d74..8268e1c02c 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8CostArray @@ -10,5 +12,12 @@ internal class Vp8CostArray /// public Vp8CostArray() => this.Costs = new ushort[67 + 1]; + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8CostArray(ushort[] costs) => this.Costs = costs; + public ushort[] Costs { get; } } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs index eee22159e1..2441436fb2 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8Costs @@ -17,6 +19,13 @@ internal class Vp8Costs } } + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8Costs(Vp8CostArray[] costs) => this.Costs = costs; + /// /// Gets the Costs. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs index 3375275424..a19f9742f3 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// @@ -13,6 +15,13 @@ internal class Vp8ProbaArray /// public Vp8ProbaArray() => this.Probabilities = new byte[WebpConstants.NumProbas]; + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8ProbaArray(byte[] probabilities) => this.Probabilities = probabilities; + /// /// Gets the probabilities. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs index 68bf09f948..c00d7dbdd4 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs @@ -7,6 +7,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; +using System.Text.Json.Serialization; namespace SixLabors.ImageSharp.Formats.Webp.Lossy; @@ -15,6 +16,22 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// internal class Vp8Residual { + public Vp8Residual() + { + } + + [JsonConstructor] + public Vp8Residual(int first, int last, int coeffType, short[] coeffs, Vp8BandProbas[] prob, Vp8Stats[] stats, Vp8Costs[] costs) + { + this.First = first; + this.Last = last; + this.CoeffType = coeffType; + this.Coeffs = coeffs; + this.Prob = prob; + this.Stats = stats; + this.Costs = costs; + } + public int First { get; set; } public int Last { get; set; } @@ -156,6 +173,55 @@ internal class Vp8Residual return LossyUtils.Vp8BitCost(0, (byte)p0); } + if (false) + { + Span scratch = stackalloc byte[32]; + Span ctxs = scratch.Slice(0, 16); + Span levels = scratch.Slice(16); + Span absLevels = stackalloc ushort[16]; + + // Precompute clamped levels and contexts, packed to 8b. + ref short outputRef = ref MemoryMarshal.GetReference(this.Coeffs); + Vector256 c0 = Unsafe.As>(ref outputRef).AsInt16(); + Vector256 d0 = Avx2.Subtract(Vector256.Zero, c0); + Vector256 e0 = Avx2.Max(c0, d0); // abs(v), 16b + Vector256 f = Avx2.PackSignedSaturate(e0, e0); + Vector256 g = Avx2.Min(f.AsByte(), Vector256.Create((byte)2)); + Vector256 h = Avx2.Min(f.AsByte(), Vector256.Create((byte)67)); // clampLevel in [0..67] + + ref byte ctxsRef = ref MemoryMarshal.GetReference(ctxs); + ref byte levelsRef = ref MemoryMarshal.GetReference(levels); + ref ushort absLevelsRef = ref MemoryMarshal.GetReference(absLevels); + Unsafe.As>(ref ctxsRef) = g.GetLower(); + Unsafe.As>(ref levelsRef) = h.GetLower(); + Unsafe.As>(ref absLevelsRef) = e0.AsUInt16(); + + int level; + int flevel; + for (; n < this.Last; ++n) + { + int ctx = ctxs[n]; + level = levels[n]; + flevel = absLevels[n]; + cost += WebpLookupTables.Vp8LevelFixedCosts[flevel] + t.Costs[level]; + t = costs[n + 1].Costs[ctx]; + } + + // Last coefficient is always non-zero. + level = levels[n]; + flevel = absLevels[n]; + cost += WebpLookupTables.Vp8LevelFixedCosts[flevel] + t.Costs[level]; + if (n < 15) + { + int b = WebpConstants.Vp8EncBands[n + 1]; + int ctx = ctxs[n]; + int lastP0 = this.Prob[b].Probabilities[ctx].Probabilities[0]; + cost += LossyUtils.Vp8BitCost(0, (byte)lastP0); + } + + return cost; + } + if (Sse2.IsSupported) { Span scratch = stackalloc byte[32]; diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs index dda921a7c7..b6c05f2d4c 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8Stats @@ -17,5 +19,12 @@ internal class Vp8Stats } } + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8Stats(Vp8StatsArray[] stats) => this.Stats = stats; + public Vp8StatsArray[] Stats { get; } } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs index 2fbba6996d..864248dd8f 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8StatsArray @@ -10,5 +12,12 @@ internal class Vp8StatsArray /// public Vp8StatsArray() => this.Stats = new uint[WebpConstants.NumProbas]; + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8StatsArray(uint[] stats) => this.Stats = stats; + public uint[] Stats { get; } } From 79bc8ebef68fe106ae8f67791b5dbc33e60ddfbc Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 7 Apr 2023 19:40:06 +0200 Subject: [PATCH 68/86] Add test for calculating residual costs --- .../Formats/Webp/Lossy/Vp8Residual.cs | 49 ------------------- .../Formats/WebP/Vp8ResidualTests.cs | 16 ++++++ .../ImageSharp.Tests/ImageSharp.Tests.csproj | 3 ++ .../TestDataWebp/Vp8Residual.json | 1 + 4 files changed, 20 insertions(+), 49 deletions(-) create mode 100644 tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.json diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs index c00d7dbdd4..6e0937d86b 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs @@ -173,55 +173,6 @@ internal class Vp8Residual return LossyUtils.Vp8BitCost(0, (byte)p0); } - if (false) - { - Span scratch = stackalloc byte[32]; - Span ctxs = scratch.Slice(0, 16); - Span levels = scratch.Slice(16); - Span absLevels = stackalloc ushort[16]; - - // Precompute clamped levels and contexts, packed to 8b. - ref short outputRef = ref MemoryMarshal.GetReference(this.Coeffs); - Vector256 c0 = Unsafe.As>(ref outputRef).AsInt16(); - Vector256 d0 = Avx2.Subtract(Vector256.Zero, c0); - Vector256 e0 = Avx2.Max(c0, d0); // abs(v), 16b - Vector256 f = Avx2.PackSignedSaturate(e0, e0); - Vector256 g = Avx2.Min(f.AsByte(), Vector256.Create((byte)2)); - Vector256 h = Avx2.Min(f.AsByte(), Vector256.Create((byte)67)); // clampLevel in [0..67] - - ref byte ctxsRef = ref MemoryMarshal.GetReference(ctxs); - ref byte levelsRef = ref MemoryMarshal.GetReference(levels); - ref ushort absLevelsRef = ref MemoryMarshal.GetReference(absLevels); - Unsafe.As>(ref ctxsRef) = g.GetLower(); - Unsafe.As>(ref levelsRef) = h.GetLower(); - Unsafe.As>(ref absLevelsRef) = e0.AsUInt16(); - - int level; - int flevel; - for (; n < this.Last; ++n) - { - int ctx = ctxs[n]; - level = levels[n]; - flevel = absLevels[n]; - cost += WebpLookupTables.Vp8LevelFixedCosts[flevel] + t.Costs[level]; - t = costs[n + 1].Costs[ctx]; - } - - // Last coefficient is always non-zero. - level = levels[n]; - flevel = absLevels[n]; - cost += WebpLookupTables.Vp8LevelFixedCosts[flevel] + t.Costs[level]; - if (n < 15) - { - int b = WebpConstants.Vp8EncBands[n + 1]; - int ctx = ctxs[n]; - int lastP0 = this.Prob[b].Probabilities[ctx].Probabilities[0]; - cost += LossyUtils.Vp8BitCost(0, (byte)lastP0); - } - - return cost; - } - if (Sse2.IsSupported) { Span scratch = stackalloc byte[32]; diff --git a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs index e9f0f31d75..2ced8e8cae 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs @@ -11,6 +11,22 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp; [Trait("Format", "Webp")] public class Vp8ResidualTests { + [Fact] + public void GetResidualCost_Works() + { + // arrange + int ctx0 = 0; + int expected = 20911; + string jsonString = File.ReadAllText(@"TestDataWebp\Vp8Residual.json"); + Vp8Residual residual = JsonSerializer.Deserialize(jsonString); + + // act + int actual = residual.GetResidualCost(ctx0); + + // assert + Assert.Equal(expected, actual); + } + [Fact] public void Serialization_Works() { diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index a6197b6009..270a02c0c9 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -56,6 +56,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.json b/tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.json new file mode 100644 index 0000000000..41a524b893 --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.json @@ -0,0 +1 @@ +{"First":1,"Last":15,"CoeffType":0,"Coeffs":[0,-3,-5,1,1,0,0,1,2,0,-1,-1,0,-1,-1,2],"Prob":[{"Probabilities":[{"Probabilities":"gICAgICAgICAgIA="},{"Probabilities":"gICAgICAgICAgIA="},{"Probabilities":"gICAgICAgICAgIA="}]},{"Probabilities":[{"Probabilities":"/Yj+/+TbgICAgIA="},{"Probabilities":"vYHy/+PV/9uAgIA="},{"Probabilities":"an7j/NbR//+AgIA="}]},{"Probabilities":[{"Probabilities":"AWL4/+zi//+AgIA="},{"Probabilities":"tYXu/t3q/5qAgIA="},{"Probabilities":"TobK98a0/9uAgIA="}]},{"Probabilities":[{"Probabilities":"Abn5//P/gICAgIA="},{"Probabilities":"uJb3/+zggICAgIA="},{"Probabilities":"TW7Y/+zmgICAgIA="}]},{"Probabilities":[{"Probabilities":"AWX7//H/gICAgIA="},{"Probabilities":"qovx/OzR//+AgIA="},{"Probabilities":"JXTE8+T///+AgIA="}]},{"Probabilities":[{"Probabilities":"Acz+//X/gICAgIA="},{"Probabilities":"z6D6/+6AgICAgIA="},{"Probabilities":"Zmfn/9OrgICAgIA="}]},{"Probabilities":[{"Probabilities":"AZj8//D/gICAgIA="},{"Probabilities":"sYfz/+rhgICAgIA="},{"Probabilities":"UIHT/8LggICAgIA="}]},{"Probabilities":[{"Probabilities":"AQH/gICAgICAgIA="},{"Probabilities":"9gH/gICAgICAgIA="},{"Probabilities":"/4CAgICAgICAgIA="}]}],"Stats":[{"Stats":[{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]}]},{"Stats":[{"Stats":[3145728,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]}]},{"Stats":[{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]}]},{"Stats":[{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]}]},{"Stats":[{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]}]},{"Stats":[{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]}]},{"Stats":[{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]}]},{"Stats":[{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]},{"Stats":[0,0,0,0,0,0,0,0,0,0,0]}]}],"Costs":[{"Costs":[{"Costs":[256,512,1024,1280,1280,1280,1280,1280,1280,1280,1280,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536,1536]},{"Costs":[512,768,1280,1536,1536,1536,1536,1536,1536,1536,1536,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792]},{"Costs":[512,768,1280,1536,1536,1536,1536,1536,1536,1536,1536,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792,1792]}]},{"Costs":[{"Costs":[234,287,2122,2957,3618,4379,4379,4379,4379,4379,4379,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635,4635]},{"Costs":[756,784,1887,2721,3318,3692,3692,4353,4353,4353,4353,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934,5934]},{"Costs":[463,503,1342,2023,2578,2810,2810,4599,4599,4599,4599,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108,5108]}]},{"Costs":[{"Costs":[355,194,1496,2462,3209,3259,3259,5048,5048,5048,5048,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557,5557]},{"Costs":[700,761,1783,2503,3379,3707,3707,3861,3861,3861,3861,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820,5820]},{"Costs":[378,504,1102,1692,2013,2333,2333,2994,2994,2994,2994,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575,4575]}]},{"Costs":[{"Costs":[121,489,1867,2959,4748,4147,4147,4147,4147,4147,4147,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403,4403]},{"Costs":[671,818,2118,3088,3805,4387,4387,4387,4387,4387,4387,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643,4643]},{"Costs":[447,410,1071,2031,2844,3340,3340,3340,3340,3340,3340,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596,3596]}]},{"Costs":[{"Costs":[192,343,1900,2902,4691,4176,4176,4176,4176,4176,4176,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432]},{"Costs":[675,739,1866,2791,3528,4132,4132,4132,4132,4132,4132,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388]},{"Costs":[398,477,1157,1633,2350,3355,3355,3355,3355,3355,3355,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611]}]},{"Costs":[{"Costs":[342,197,1751,2791,4580,4028,4028,4028,4028,4028,4028,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284,4284]},{"Costs":[632,723,1799,2794,3349,3302,3302,5091,5091,5091,5091,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600,5600]},{"Costs":[354,387,893,1672,3461,1944,1944,3733,3733,3733,3733,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242,4242]}]},{"Costs":[{"Costs":[86,596,2405,3568,5357,4688,4688,4688,4688,4688,4688,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944,4944]},{"Costs":[790,991,2421,3640,3640,4693,4693,4693,4693,4693,4693,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949,4949]},{"Costs":[527,423,1330,2054,2314,3558,3558,3558,3558,3558,3558,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814,3814]}]},{"Costs":[{"Costs":[192,343,1900,2902,4691,4176,4176,4176,4176,4176,4176,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432]},{"Costs":[675,739,1866,2791,3528,4132,4132,4132,4132,4132,4132,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388]},{"Costs":[398,477,1157,1633,2350,3355,3355,3355,3355,3355,3355,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611]}]},{"Costs":[{"Costs":[192,343,1900,2902,4691,4176,4176,4176,4176,4176,4176,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432]},{"Costs":[675,739,1866,2791,3528,4132,4132,4132,4132,4132,4132,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388]},{"Costs":[398,477,1157,1633,2350,3355,3355,3355,3355,3355,3355,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611]}]},{"Costs":[{"Costs":[192,343,1900,2902,4691,4176,4176,4176,4176,4176,4176,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432]},{"Costs":[675,739,1866,2791,3528,4132,4132,4132,4132,4132,4132,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388]},{"Costs":[398,477,1157,1633,2350,3355,3355,3355,3355,3355,3355,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611]}]},{"Costs":[{"Costs":[192,343,1900,2902,4691,4176,4176,4176,4176,4176,4176,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432]},{"Costs":[675,739,1866,2791,3528,4132,4132,4132,4132,4132,4132,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388]},{"Costs":[398,477,1157,1633,2350,3355,3355,3355,3355,3355,3355,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611]}]},{"Costs":[{"Costs":[192,343,1900,2902,4691,4176,4176,4176,4176,4176,4176,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432]},{"Costs":[675,739,1866,2791,3528,4132,4132,4132,4132,4132,4132,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388]},{"Costs":[398,477,1157,1633,2350,3355,3355,3355,3355,3355,3355,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611]}]},{"Costs":[{"Costs":[192,343,1900,2902,4691,4176,4176,4176,4176,4176,4176,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432]},{"Costs":[675,739,1866,2791,3528,4132,4132,4132,4132,4132,4132,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388]},{"Costs":[398,477,1157,1633,2350,3355,3355,3355,3355,3355,3355,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611]}]},{"Costs":[{"Costs":[192,343,1900,2902,4691,4176,4176,4176,4176,4176,4176,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432]},{"Costs":[675,739,1866,2791,3528,4132,4132,4132,4132,4132,4132,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388]},{"Costs":[398,477,1157,1633,2350,3355,3355,3355,3355,3355,3355,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611]}]},{"Costs":[{"Costs":[192,343,1900,2902,4691,4176,4176,4176,4176,4176,4176,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432,4432]},{"Costs":[675,739,1866,2791,3528,4132,4132,4132,4132,4132,4132,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388,4388]},{"Costs":[398,477,1157,1633,2350,3355,3355,3355,3355,3355,3355,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611,3611]}]},{"Costs":[{"Costs":[1792,7,2308,2564,2564,2564,2564,2564,2564,2564,2564,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820,2820]},{"Costs":[3008,1223,3524,3780,3780,3780,3780,3780,3780,3780,3780,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036,4036]},{"Costs":[2048,2304,2816,3072,3072,3072,3072,3072,3072,3072,3072,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328,3328]}]}]} \ No newline at end of file From 4432937bd83a767a3129c82b728350ce10650a2a Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 7 Apr 2023 19:52:46 +0200 Subject: [PATCH 69/86] Skip serialization tests when SSE2 is not available --- .../Formats/WebP/Vp8ResidualTests.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs index 2ced8e8cae..f7a8482d9f 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Runtime.Intrinsics.X86; using System.Text.Json; using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Formats.Webp.Lossy; @@ -14,6 +15,12 @@ public class Vp8ResidualTests [Fact] public void GetResidualCost_Works() { + if (!Sse2.IsSupported) + { + // JsonSerializer without SSE2 does not seem to work, skip test then. + return; + } + // arrange int ctx0 = 0; int expected = 20911; @@ -30,6 +37,12 @@ public class Vp8ResidualTests [Fact] public void Serialization_Works() { + if (!Sse2.IsSupported) + { + // JsonSerializer without SSE2 does not seem to work, skip test then. + return; + } + // arrange Vp8Residual expected = new(); Vp8EncProba encProb = new(); From ba7b1df56289c84da4c9dedb1caf8477fa684119 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 7 Apr 2023 20:14:05 +0200 Subject: [PATCH 70/86] Fix path to test data --- tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs index f7a8482d9f..cadf92973c 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs @@ -24,7 +24,7 @@ public class Vp8ResidualTests // arrange int ctx0 = 0; int expected = 20911; - string jsonString = File.ReadAllText(@"TestDataWebp\Vp8Residual.json"); + string jsonString = File.ReadAllText(Path.Combine("TestDataWebp", "Vp8Residual.json")); Vp8Residual residual = JsonSerializer.Deserialize(jsonString); // act From fd57eac1d41fc263808c39129cb0792664d22c73 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 7 Apr 2023 21:34:19 +0200 Subject: [PATCH 71/86] Add mention to tools wikipdage --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 09262eb572..6a0b6dee33 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,8 @@ git submodule update --init --recursive Please... Spread the word, contribute algorithms, submit performance improvements, unit tests, no input is too little. Make sure to read our [Contribution Guide](https://github.com/SixLabors/ImageSharp/blob/main/.github/CONTRIBUTING.md) before opening a PR. +Useful tools for development and links to specifications can be found in our wikipage: [Useful-tools-and-links](https://github.com/SixLabors/ImageSharp/wiki/Useful-tools-and-links). + ## The ImageSharp Team - [James Jackson-South](https://github.com/jimbobsquarepants) From c65955da844601530ba0781e49a42553deee71c9 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 7 Apr 2023 21:41:23 +0200 Subject: [PATCH 72/86] Add a little thanks to jetbrains in the readme for supporting ImageSharp --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 6a0b6dee33..9a52b91d80 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,5 @@ Useful tools for development and links to specifications can be found in our wik - [Scott Williams](https://github.com/tocsoft) - [Brian Popow](https://github.com/brianpopow) - - +Thanks to [jetbrains](https://www.jetbrains.com) for supporting the ImageSharp team via the [Open Source Development Program](www.jetbrains.com/community/opensource/), so we can use the jetbrains tools for developing ImageSharp! From 4a17bc53ef504d1c9b571cee0d39a8000c2d2de7 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 8 Apr 2023 21:17:35 +0200 Subject: [PATCH 73/86] Add jetbrains logo, change jetbrains mention text --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a52b91d80..fa51d57cdf 100644 --- a/README.md +++ b/README.md @@ -111,5 +111,11 @@ Useful tools for development and links to specifications can be found in our wik - [Scott Williams](https://github.com/tocsoft) - [Brian Popow](https://github.com/brianpopow) -Thanks to [jetbrains](https://www.jetbrains.com) for supporting the ImageSharp team via the [Open Source Development Program](www.jetbrains.com/community/opensource/), so we can use the jetbrains tools for developing ImageSharp! +--- +
+ JetBrains +
+ + Special thanks to [JetBrains](https://www.jetbrains.com/?from=ImageSharp) for supporting us with open-source licenses for their IDEs. +
From 79448ec9590c93f1d1e7d4823ed39992f4204869 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 9 Apr 2023 14:04:11 +0200 Subject: [PATCH 74/86] Revert adding JsonConstructor attributes --- .../Formats/Webp/Lossy/Vp8BandProbas.cs | 9 --------- .../Formats/Webp/Lossy/Vp8CostArray.cs | 9 --------- src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs | 9 --------- .../Formats/Webp/Lossy/Vp8ProbaArray.cs | 9 --------- .../Formats/Webp/Lossy/Vp8Residual.cs | 17 ----------------- src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs | 9 --------- .../Formats/Webp/Lossy/Vp8StatsArray.cs | 9 --------- 7 files changed, 71 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs index 86304d4bd8..90506efb81 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// @@ -22,13 +20,6 @@ internal class Vp8BandProbas } } - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8BandProbas(Vp8ProbaArray[] probabilities) => this.Probabilities = probabilities; - /// /// Gets the Probabilities. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs index 8268e1c02c..2c8d723d74 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8CostArray @@ -12,12 +10,5 @@ internal class Vp8CostArray /// public Vp8CostArray() => this.Costs = new ushort[67 + 1]; - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8CostArray(ushort[] costs) => this.Costs = costs; - public ushort[] Costs { get; } } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs index 2441436fb2..eee22159e1 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8Costs @@ -19,13 +17,6 @@ internal class Vp8Costs } } - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8Costs(Vp8CostArray[] costs) => this.Costs = costs; - /// /// Gets the Costs. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs index a19f9742f3..3375275424 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// @@ -15,13 +13,6 @@ internal class Vp8ProbaArray /// public Vp8ProbaArray() => this.Probabilities = new byte[WebpConstants.NumProbas]; - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8ProbaArray(byte[] probabilities) => this.Probabilities = probabilities; - /// /// Gets the probabilities. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs index 6e0937d86b..68bf09f948 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs @@ -7,7 +7,6 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; -using System.Text.Json.Serialization; namespace SixLabors.ImageSharp.Formats.Webp.Lossy; @@ -16,22 +15,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// internal class Vp8Residual { - public Vp8Residual() - { - } - - [JsonConstructor] - public Vp8Residual(int first, int last, int coeffType, short[] coeffs, Vp8BandProbas[] prob, Vp8Stats[] stats, Vp8Costs[] costs) - { - this.First = first; - this.Last = last; - this.CoeffType = coeffType; - this.Coeffs = coeffs; - this.Prob = prob; - this.Stats = stats; - this.Costs = costs; - } - public int First { get; set; } public int Last { get; set; } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs index b6c05f2d4c..dda921a7c7 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8Stats @@ -19,12 +17,5 @@ internal class Vp8Stats } } - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8Stats(Vp8StatsArray[] stats) => this.Stats = stats; - public Vp8StatsArray[] Stats { get; } } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs index 864248dd8f..2fbba6996d 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8StatsArray @@ -12,12 +10,5 @@ internal class Vp8StatsArray /// public Vp8StatsArray() => this.Stats = new uint[WebpConstants.NumProbas]; - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8StatsArray(uint[] stats) => this.Stats = stats; - public uint[] Stats { get; } } From 4dcf8569a72dc9f1e6e61fafd0d0a4c245006585 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 9 Apr 2023 14:06:21 +0200 Subject: [PATCH 75/86] Add Vp8CostArray Serialization test, add stub for Vp8CostArray JsonConverter --- .../Vp8CostArrayJsonConverter.cs | 15 ++++++ .../Formats/WebP/Vp8ResidualTests.cs | 51 ++++++++++++++----- 2 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 tests/ImageSharp.Tests/Formats/WebP/Serialization/Vp8CostArrayJsonConverter.cs diff --git a/tests/ImageSharp.Tests/Formats/WebP/Serialization/Vp8CostArrayJsonConverter.cs b/tests/ImageSharp.Tests/Formats/WebP/Serialization/Vp8CostArrayJsonConverter.cs new file mode 100644 index 0000000000..b3cfd03401 --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/WebP/Serialization/Vp8CostArrayJsonConverter.cs @@ -0,0 +1,15 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Text.Json; +using System.Text.Json.Serialization; +using SixLabors.ImageSharp.Formats.Webp.Lossy; + +namespace SixLabors.ImageSharp.Tests.Formats.WebP.Serialization; + +internal class Vp8CostArrayJsonConverter : JsonConverter +{ + public override Vp8CostArray Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => throw new NotImplementedException(); + + public override void Write(Utf8JsonWriter writer, Vp8CostArray value, JsonSerializerOptions options) => throw new NotImplementedException(); +} diff --git a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs index cadf92973c..457f3576fe 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs @@ -5,7 +5,9 @@ using System.Runtime.Intrinsics.X86; using System.Text.Json; using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Formats.Webp.Lossy; +using SixLabors.ImageSharp.Tests.Formats.WebP.Serialization; using SixLabors.ImageSharp.Tests.TestUtilities; +using JsonSerializer = System.Text.Json.JsonSerializer; namespace SixLabors.ImageSharp.Tests.Formats.Webp; @@ -13,29 +15,30 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp; public class Vp8ResidualTests { [Fact] - public void GetResidualCost_Works() + public void Vp8CostArray_Serialization_Works() { - if (!Sse2.IsSupported) + // arrange + Vp8CostArray expected = new(); + for (ushort i = 0; i < expected.Costs.Length; i++) { - // JsonSerializer without SSE2 does not seem to work, skip test then. - return; + expected.Costs[i] = i; } - // arrange - int ctx0 = 0; - int expected = 20911; - string jsonString = File.ReadAllText(Path.Combine("TestDataWebp", "Vp8Residual.json")); - Vp8Residual residual = JsonSerializer.Deserialize(jsonString); + JsonSerializerOptions options = new() + { + Converters = { new Vp8CostArrayJsonConverter() } + }; // act - int actual = residual.GetResidualCost(ctx0); + string jsonString = JsonSerializer.Serialize(expected); + Vp8CostArray actual = JsonSerializer.Deserialize(jsonString, options); // assert - Assert.Equal(expected, actual); + Assert.Equal(expected.Costs, actual.Costs); } [Fact] - public void Serialization_Works() + public void Vp8Residual_Serialization_Works() { if (!Sse2.IsSupported) { @@ -101,6 +104,30 @@ public class Vp8ResidualTests } } + [Fact] + public void GetResidualCost_Works() + { + if (!Sse2.IsSupported) + { + // JsonSerializer without SSE2 does not seem to work, skip test then. + return; + } + + // arrange + int ctx0 = 0; + int expected = 20911; + string jsonString = File.ReadAllText(Path.Combine("TestDataWebp", "Vp8Residual.json")); + Vp8Residual residual = JsonSerializer.Deserialize(jsonString); + + // act + int actual = residual.GetResidualCost(ctx0); + + // assert + Assert.Equal(expected, actual); + } + + + private static void CreateRandomProbas(Vp8EncProba probas, Random rand) { for (int t = 0; t < WebpConstants.NumTypes; ++t) From 46e1f3578aa84782ecbb1aa22f5cc2bc2aa4674b Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 12 Apr 2023 22:12:33 +1000 Subject: [PATCH 76/86] Remove commercial template for v3 --- .github/CONTRIBUTING.md | 2 - .../ISSUE_TEMPLATE/commercial-bug-report.yml | 56 ------------------- .github/ISSUE_TEMPLATE/oss-bug-report.yml | 2 +- ImageSharp.sln | 1 - 4 files changed, 1 insertion(+), 60 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/commercial-bug-report.yml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index ffacf51e4a..543506197b 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -29,7 +29,6 @@ #### **Running tests and Debugging** * Expected test output is pulled in as a submodule from the [ImageSharp.Tests.Images repository](https://github.com/SixLabors/Imagesharp.Tests.Images/tree/main/ReferenceOutput). To succesfully run tests, make sure that you have updated the submodules! -* Debugging (running tests in Debug mode) is only supported on .NET Core 2.1+, because of JIT Code Generation bugs like [dotnet/coreclr#16443](https://github.com/dotnet/coreclr/issues/16443) or [dotnet/coreclr#20657](https://github.com/dotnet/coreclr/issues/20657) #### **Do you have questions about consuming the library or the source code?** @@ -37,7 +36,6 @@ #### Code of Conduct This project has adopted the code of conduct defined by the [Contributor Covenant](https://contributor-covenant.org/) to clarify expected behavior in our community. -For more information, see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct). And please remember. SixLabors.ImageSharp is the work of a very, very, small number of developers who struggle balancing time to contribute to the project with family time and work commitments. We encourage you to pitch in and help make our vision of simple accessible image processing available to all. Open Source can only exist with your help. diff --git a/.github/ISSUE_TEMPLATE/commercial-bug-report.yml b/.github/ISSUE_TEMPLATE/commercial-bug-report.yml deleted file mode 100644 index 6b4d914d7e..0000000000 --- a/.github/ISSUE_TEMPLATE/commercial-bug-report.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: "Commercial License : Bug Report" -description: | - Create a report to help us improve the project. For Commercial License holders only. - Please contact help@sixlabors.com for issues requiring private support. -labels: ["commercial", "needs triage"] -body: -- type: checkboxes - attributes: - label: Prerequisites - options: - - label: I have bought a Commercial License - required: true - - label: I have written a descriptive issue title - required: true - - label: I have verified that I am running the latest version of ImageSharp - required: true - - label: I have verified if the problem exist in both `DEBUG` and `RELEASE` mode - required: true - - label: I have searched [open](https://github.com/SixLabors/ImageSharp/issues) and [closed](https://github.com/SixLabors/ImageSharp/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported - required: true -- type: input - attributes: - label: ImageSharp version - validations: - required: true -- type: input - attributes: - label: Other ImageSharp packages and versions - validations: - required: true -- type: input - attributes: - label: Environment (Operating system, version and so on) - validations: - required: true -- type: input - attributes: - label: .NET Framework version - validations: - required: true -- type: textarea - attributes: - label: Description - description: A description of the bug - validations: - required: true -- type: textarea - attributes: - label: Steps to Reproduce - description: List of steps, sample code, failing test or link to a project that reproduces the behavior. Make sure you place a stack trace inside a code (```) block to avoid linking unrelated issues. - validations: - required: true -- type: textarea - attributes: - label: Images - description: Please upload images that can be used to reproduce issues in the area below. If the file type is not supported the file can be zipped and then uploaded instead. diff --git a/.github/ISSUE_TEMPLATE/oss-bug-report.yml b/.github/ISSUE_TEMPLATE/oss-bug-report.yml index a4e5619d46..67fccbf3c6 100644 --- a/.github/ISSUE_TEMPLATE/oss-bug-report.yml +++ b/.github/ISSUE_TEMPLATE/oss-bug-report.yml @@ -1,5 +1,5 @@ name: "OSS : Bug Report" -description: Create a report to help us improve the project. OSS Issues are not guaranteed to be triaged. +description: Create a report to help us improve the project. Issues are not guaranteed to be triaged. labels: ["needs triage"] body: - type: checkboxes diff --git a/ImageSharp.sln b/ImageSharp.sln index 3ea3160a79..6eab8da752 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -28,7 +28,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{1799 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ISSUE_TEMPLATE", "ISSUE_TEMPLATE", "{FBE8C1AD-5AEC-4514-9B64-091D8E145865}" ProjectSection(SolutionItems) = preProject - .github\ISSUE_TEMPLATE\commercial-bug-report.yml = .github\ISSUE_TEMPLATE\commercial-bug-report.yml .github\ISSUE_TEMPLATE\config.yml = .github\ISSUE_TEMPLATE\config.yml .github\ISSUE_TEMPLATE\oss-bug-report.yml = .github\ISSUE_TEMPLATE\oss-bug-report.yml EndProjectSection From 661f28158c7b396e42a69d8e74ef6caefadc8996 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 12 Apr 2023 22:13:34 +1000 Subject: [PATCH 77/86] Update oss-bug-report.yml --- .github/ISSUE_TEMPLATE/oss-bug-report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/oss-bug-report.yml b/.github/ISSUE_TEMPLATE/oss-bug-report.yml index 67fccbf3c6..87cd1a7a17 100644 --- a/.github/ISSUE_TEMPLATE/oss-bug-report.yml +++ b/.github/ISSUE_TEMPLATE/oss-bug-report.yml @@ -1,4 +1,4 @@ -name: "OSS : Bug Report" +name: "Bug Report" description: Create a report to help us improve the project. Issues are not guaranteed to be triaged. labels: ["needs triage"] body: From ed71d7e1dd04ad4c5b062bcb3f59c5204a7f5fa4 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Wed, 12 Apr 2023 19:36:19 +0200 Subject: [PATCH 78/86] Add additional constructors for json serialization and add JsonConstructor attributes --- .../Formats/Webp/Lossy/Vp8BandProbas.cs | 9 +++++++ .../Formats/Webp/Lossy/Vp8CostArray.cs | 9 +++++++ src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs | 9 +++++++ .../Formats/Webp/Lossy/Vp8ProbaArray.cs | 9 +++++++ .../Formats/Webp/Lossy/Vp8Residual.cs | 17 +++++++++++++ src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs | 9 +++++++ .../Formats/Webp/Lossy/Vp8StatsArray.cs | 9 +++++++ .../Vp8CostArrayJsonConverter.cs | 15 ----------- .../Formats/WebP/Vp8ResidualTests.cs | 25 ------------------- 9 files changed, 71 insertions(+), 40 deletions(-) delete mode 100644 tests/ImageSharp.Tests/Formats/WebP/Serialization/Vp8CostArrayJsonConverter.cs diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs index 90506efb81..86304d4bd8 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// @@ -20,6 +22,13 @@ internal class Vp8BandProbas } } + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8BandProbas(Vp8ProbaArray[] probabilities) => this.Probabilities = probabilities; + /// /// Gets the Probabilities. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs index 2c8d723d74..8268e1c02c 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8CostArray @@ -10,5 +12,12 @@ internal class Vp8CostArray /// public Vp8CostArray() => this.Costs = new ushort[67 + 1]; + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8CostArray(ushort[] costs) => this.Costs = costs; + public ushort[] Costs { get; } } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs index eee22159e1..2441436fb2 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8Costs @@ -17,6 +19,13 @@ internal class Vp8Costs } } + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8Costs(Vp8CostArray[] costs) => this.Costs = costs; + /// /// Gets the Costs. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs index 3375275424..a19f9742f3 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// @@ -13,6 +15,13 @@ internal class Vp8ProbaArray /// public Vp8ProbaArray() => this.Probabilities = new byte[WebpConstants.NumProbas]; + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8ProbaArray(byte[] probabilities) => this.Probabilities = probabilities; + /// /// Gets the probabilities. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs index 68bf09f948..6e0937d86b 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs @@ -7,6 +7,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; +using System.Text.Json.Serialization; namespace SixLabors.ImageSharp.Formats.Webp.Lossy; @@ -15,6 +16,22 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// internal class Vp8Residual { + public Vp8Residual() + { + } + + [JsonConstructor] + public Vp8Residual(int first, int last, int coeffType, short[] coeffs, Vp8BandProbas[] prob, Vp8Stats[] stats, Vp8Costs[] costs) + { + this.First = first; + this.Last = last; + this.CoeffType = coeffType; + this.Coeffs = coeffs; + this.Prob = prob; + this.Stats = stats; + this.Costs = costs; + } + public int First { get; set; } public int Last { get; set; } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs index dda921a7c7..b6c05f2d4c 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8Stats @@ -17,5 +19,12 @@ internal class Vp8Stats } } + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8Stats(Vp8StatsArray[] stats) => this.Stats = stats; + public Vp8StatsArray[] Stats { get; } } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs index 2fbba6996d..864248dd8f 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Text.Json.Serialization; + namespace SixLabors.ImageSharp.Formats.Webp.Lossy; internal class Vp8StatsArray @@ -10,5 +12,12 @@ internal class Vp8StatsArray /// public Vp8StatsArray() => this.Stats = new uint[WebpConstants.NumProbas]; + /// + /// Initializes a new instance of the class. + /// Only used for unit tests. + /// + [JsonConstructor] + public Vp8StatsArray(uint[] stats) => this.Stats = stats; + public uint[] Stats { get; } } diff --git a/tests/ImageSharp.Tests/Formats/WebP/Serialization/Vp8CostArrayJsonConverter.cs b/tests/ImageSharp.Tests/Formats/WebP/Serialization/Vp8CostArrayJsonConverter.cs deleted file mode 100644 index b3cfd03401..0000000000 --- a/tests/ImageSharp.Tests/Formats/WebP/Serialization/Vp8CostArrayJsonConverter.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Six Labors Split License. - -using System.Text.Json; -using System.Text.Json.Serialization; -using SixLabors.ImageSharp.Formats.Webp.Lossy; - -namespace SixLabors.ImageSharp.Tests.Formats.WebP.Serialization; - -internal class Vp8CostArrayJsonConverter : JsonConverter -{ - public override Vp8CostArray Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => throw new NotImplementedException(); - - public override void Write(Utf8JsonWriter writer, Vp8CostArray value, JsonSerializerOptions options) => throw new NotImplementedException(); -} diff --git a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs index 457f3576fe..20a161371d 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs @@ -2,10 +2,8 @@ // Licensed under the Six Labors Split License. using System.Runtime.Intrinsics.X86; -using System.Text.Json; using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Formats.Webp.Lossy; -using SixLabors.ImageSharp.Tests.Formats.WebP.Serialization; using SixLabors.ImageSharp.Tests.TestUtilities; using JsonSerializer = System.Text.Json.JsonSerializer; @@ -14,29 +12,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp; [Trait("Format", "Webp")] public class Vp8ResidualTests { - [Fact] - public void Vp8CostArray_Serialization_Works() - { - // arrange - Vp8CostArray expected = new(); - for (ushort i = 0; i < expected.Costs.Length; i++) - { - expected.Costs[i] = i; - } - - JsonSerializerOptions options = new() - { - Converters = { new Vp8CostArrayJsonConverter() } - }; - - // act - string jsonString = JsonSerializer.Serialize(expected); - Vp8CostArray actual = JsonSerializer.Deserialize(jsonString, options); - - // assert - Assert.Equal(expected.Costs, actual.Costs); - } - [Fact] public void Vp8Residual_Serialization_Works() { From 8756c32a741d4d8e129ea0e494d814b5bcd7dc72 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 13 Apr 2023 18:50:04 +0200 Subject: [PATCH 79/86] Fix retrieving wrong tile height, fixes #2435 --- src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs index 45bbed12d5..aed6d4ec66 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs @@ -344,7 +344,7 @@ internal class TiffDecoderCore : IImageDecoderInternals ArgumentNullException.ThrowIfNull(valueWidth); } - if (!tags.TryGetValue(ExifTag.TileWidth, out IExifValue valueLength)) + if (!tags.TryGetValue(ExifTag.TileLength, out IExifValue valueLength)) { ArgumentNullException.ThrowIfNull(valueLength); } From 93790ba9a60e8800f550b252fe2069c06fcaeb0d Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 13 Apr 2023 19:31:21 +0200 Subject: [PATCH 80/86] Add test for #2435 --- .../Formats/Tiff/TiffDecoderTests.cs | 48 +++++-------------- tests/ImageSharp.Tests/TestImages.cs | 1 + tests/Images/Input/Tiff/Issues/Issue2435.tiff | 3 ++ 3 files changed, 17 insertions(+), 35 deletions(-) create mode 100644 tests/Images/Input/Tiff/Issues/Issue2435.tiff diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs index 72b87bcf02..1f664cf646 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs @@ -200,11 +200,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester [Theory] [WithFile(Rgba3BitAssociatedAlpha, PixelTypes.Rgba32)] public void TiffDecoder_CanDecode_12Bit_WithAssociatedAlpha(TestImageProvider provider) - where TPixel : unmanaged, IPixel - { - - TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.264F); - } + where TPixel : unmanaged, IPixel => TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.264F); [Theory] [WithFile(Flower14BitGray, PixelTypes.Rgba32)] @@ -249,11 +245,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester [WithFile(Rgba5BitAssociatedAlpha, PixelTypes.Rgba32)] public void TiffDecoder_CanDecode_20Bit_WithAssociatedAlpha(TestImageProvider provider) - where TPixel : unmanaged, IPixel - { - - TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.376F); - } + where TPixel : unmanaged, IPixel => TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.376F); [Theory] [WithFile(FlowerRgb888Contiguous, PixelTypes.Rgba32)] @@ -268,11 +260,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester [Theory] [WithFile(Rgba6BitAssociatedAlpha, PixelTypes.Rgba32)] public void TiffDecoder_CanDecode_24Bit_WithAssociatedAlpha(TestImageProvider provider) - where TPixel : unmanaged, IPixel - { - - TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.405F); - } + where TPixel : unmanaged, IPixel => TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.405F); [Theory] [WithFile(Flower24BitGray, PixelTypes.Rgba32)] @@ -362,12 +350,8 @@ public class TiffDecoderTests : TiffDecoderBaseTester [Theory] [WithFile(Rgba8BitAssociatedAlpha, PixelTypes.Rgba32)] public void TiffDecoder_CanDecode_32Bit_WithAssociatedAlpha(TestImageProvider provider) - where TPixel : unmanaged, IPixel - { - // Note: Using tolerant comparer here, because there is a small difference to the reference decoder probably due to floating point rounding issues. - TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.004F); - } + where TPixel : unmanaged, IPixel => TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.004F); [Theory] [WithFile(Flower32BitGrayPredictorBigEndian, PixelTypes.Rgba32)] @@ -395,11 +379,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester [WithFile(Rgba10BitAssociatedAlphaBigEndian, PixelTypes.Rgba32)] [WithFile(Rgba10BitAssociatedAlphaLittleEndian, PixelTypes.Rgba32)] public void TiffDecoder_CanDecode_40Bit_WithAssociatedAlpha(TestImageProvider provider) - where TPixel : unmanaged, IPixel - { - - TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.247F); - } + where TPixel : unmanaged, IPixel => TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.247F); [Theory] [WithFile(FlowerRgb141414Contiguous, PixelTypes.Rgba32)] @@ -426,11 +406,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester [WithFile(Rgba12BitAssociatedAlphaBigEndian, PixelTypes.Rgba32)] [WithFile(Rgba12BitAssociatedAlphaLittleEndian, PixelTypes.Rgba32)] public void TiffDecoder_CanDecode_48Bit_WithAssociatedAlpha(TestImageProvider provider) - where TPixel : unmanaged, IPixel - { - - TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.118F); - } + where TPixel : unmanaged, IPixel => TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.118F); [Theory] [WithFile(FlowerRgb161616PredictorBigEndian, PixelTypes.Rgba32)] @@ -448,11 +424,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester [WithFile(Rgba14BitAssociatedAlphaBigEndian, PixelTypes.Rgba32)] [WithFile(Rgba14BitAssociatedAlphaLittleEndian, PixelTypes.Rgba32)] public void TiffDecoder_CanDecode_56Bit_WithAssociatedAlpha(TestImageProvider provider) - where TPixel : unmanaged, IPixel - { - - TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.075F); - } + where TPixel : unmanaged, IPixel => TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.075F); [Theory] [WithFile(FlowerRgb242424Contiguous, PixelTypes.Rgba32)] @@ -686,6 +658,12 @@ public class TiffDecoderTests : TiffDecoderBaseTester public void TiffDecoder_CanDecode_Fax4CompressedWithStrips(TestImageProvider provider) where TPixel : unmanaged, IPixel => TestTiffDecoder(provider); + // https://github.com/SixLabors/ImageSharp/issues/2435 + [Theory] + [WithFile(Issues2435, PixelTypes.Rgba32)] + public void TiffDecoder_CanDecode_TiledWithNonEqualWidthAndHeight(TestImageProvider provider) + where TPixel : unmanaged, IPixel => TestTiffDecoder(provider); + [Theory] [WithFileCollection(nameof(MultiframeTestImages), PixelTypes.Rgba32)] public void DecodeMultiframe(TestImageProvider provider) diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 589168f009..409378b179 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -964,6 +964,7 @@ public static class TestImages public const string Issues2123 = "Tiff/Issues/Issue2123.tiff"; public const string Issues2149 = "Tiff/Issues/Group4CompressionWithStrips.tiff"; public const string Issues2255 = "Tiff/Issues/Issue2255.png"; + public const string Issues2435 = "Tiff/Issues/Issue2435.tiff"; public const string SmallRgbDeflate = "Tiff/rgb_small_deflate.tiff"; public const string SmallRgbLzw = "Tiff/rgb_small_lzw.tiff"; diff --git a/tests/Images/Input/Tiff/Issues/Issue2435.tiff b/tests/Images/Input/Tiff/Issues/Issue2435.tiff new file mode 100644 index 0000000000..2afc20a558 --- /dev/null +++ b/tests/Images/Input/Tiff/Issues/Issue2435.tiff @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e5c90d6d90f1cf090562d7d70df858b83513e5d7d78fb7b7c4d7992cb620030e +size 258540 From 39f8c776debeabba977055c2ac1007c437eeba01 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 14 Apr 2023 19:50:09 +0200 Subject: [PATCH 81/86] Using Binary serialization for Vp8Residual --- .../Formats/Webp/Lossy/Vp8BandProbas.cs | 8 +---- .../Formats/Webp/Lossy/Vp8CostArray.cs | 10 +----- src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs | 10 +----- .../Formats/Webp/Lossy/Vp8ProbaArray.cs | 10 +----- .../Formats/Webp/Lossy/Vp8Residual.cs | 13 +------ src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs | 10 +----- .../Formats/Webp/Lossy/Vp8StatsArray.cs | 10 +----- .../Formats/WebP/Vp8ResidualTests.cs | 32 +++++++----------- .../ImageSharp.Tests/ImageSharp.Tests.csproj | 2 +- .../TestDataWebp/Vp8Residual.bin | Bin 0 -> 15043 bytes 10 files changed, 20 insertions(+), 85 deletions(-) create mode 100644 tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.bin diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs index 86304d4bd8..5db842ba33 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs @@ -8,6 +8,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// /// All the probabilities associated to one band. /// +[Serializable] internal class Vp8BandProbas { /// @@ -22,13 +23,6 @@ internal class Vp8BandProbas } } - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8BandProbas(Vp8ProbaArray[] probabilities) => this.Probabilities = probabilities; - /// /// Gets the Probabilities. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs index 8268e1c02c..ba1b498816 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; +[Serializable] internal class Vp8CostArray { /// @@ -12,12 +11,5 @@ internal class Vp8CostArray /// public Vp8CostArray() => this.Costs = new ushort[67 + 1]; - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8CostArray(ushort[] costs) => this.Costs = costs; - public ushort[] Costs { get; } } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs index 2441436fb2..6768748205 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; +[Serializable] internal class Vp8Costs { /// @@ -19,13 +18,6 @@ internal class Vp8Costs } } - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8Costs(Vp8CostArray[] costs) => this.Costs = costs; - /// /// Gets the Costs. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs index a19f9742f3..ddc1c9d61a 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs @@ -1,13 +1,12 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// /// Probabilities associated to one of the contexts. /// +[Serializable] internal class Vp8ProbaArray { /// @@ -15,13 +14,6 @@ internal class Vp8ProbaArray /// public Vp8ProbaArray() => this.Probabilities = new byte[WebpConstants.NumProbas]; - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8ProbaArray(byte[] probabilities) => this.Probabilities = probabilities; - /// /// Gets the probabilities. /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs index 6e0937d86b..58fba10a7f 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs @@ -14,24 +14,13 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// /// On-the-fly info about the current set of residuals. /// +[Serializable] internal class Vp8Residual { public Vp8Residual() { } - [JsonConstructor] - public Vp8Residual(int first, int last, int coeffType, short[] coeffs, Vp8BandProbas[] prob, Vp8Stats[] stats, Vp8Costs[] costs) - { - this.First = first; - this.Last = last; - this.CoeffType = coeffType; - this.Coeffs = coeffs; - this.Prob = prob; - this.Stats = stats; - this.Costs = costs; - } - public int First { get; set; } public int Last { get; set; } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs index b6c05f2d4c..23d63f322d 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; +[Serializable] internal class Vp8Stats { /// @@ -19,12 +18,5 @@ internal class Vp8Stats } } - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8Stats(Vp8StatsArray[] stats) => this.Stats = stats; - public Vp8StatsArray[] Stats { get; } } diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs index 864248dd8f..2ab0702ebd 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; +[Serializable] internal class Vp8StatsArray { /// @@ -12,12 +11,5 @@ internal class Vp8StatsArray /// public Vp8StatsArray() => this.Stats = new uint[WebpConstants.NumProbas]; - /// - /// Initializes a new instance of the class. - /// Only used for unit tests. - /// - [JsonConstructor] - public Vp8StatsArray(uint[] stats) => this.Stats = stats; - public uint[] Stats { get; } } diff --git a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs index 20a161371d..2371a179ea 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs @@ -1,11 +1,10 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Runtime.Intrinsics.X86; +using System.Runtime.Serialization.Formatters.Binary; using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Formats.Webp.Lossy; using SixLabors.ImageSharp.Tests.TestUtilities; -using JsonSerializer = System.Text.Json.JsonSerializer; namespace SixLabors.ImageSharp.Tests.Formats.Webp; @@ -15,12 +14,6 @@ public class Vp8ResidualTests [Fact] public void Vp8Residual_Serialization_Works() { - if (!Sse2.IsSupported) - { - // JsonSerializer without SSE2 does not seem to work, skip test then. - return; - } - // arrange Vp8Residual expected = new(); Vp8EncProba encProb = new(); @@ -34,8 +27,12 @@ public class Vp8ResidualTests } // act - string jsonString = JsonSerializer.Serialize(expected); - Vp8Residual actual = JsonSerializer.Deserialize(jsonString); + BinaryFormatter formatter = new(); + using MemoryStream ms = new(); + formatter.Serialize(ms, expected); + ms.Position = 0; + object obj = formatter.Deserialize(ms); + Vp8Residual actual = (Vp8Residual)obj; // assert Assert.Equal(expected.CoeffType, actual.CoeffType); @@ -82,17 +79,14 @@ public class Vp8ResidualTests [Fact] public void GetResidualCost_Works() { - if (!Sse2.IsSupported) - { - // JsonSerializer without SSE2 does not seem to work, skip test then. - return; - } - // arrange int ctx0 = 0; int expected = 20911; - string jsonString = File.ReadAllText(Path.Combine("TestDataWebp", "Vp8Residual.json")); - Vp8Residual residual = JsonSerializer.Deserialize(jsonString); + byte[] data = File.ReadAllBytes(Path.Combine("TestDataWebp", "Vp8Residual.bin")); + BinaryFormatter formatter = new(); + using Stream stream = new MemoryStream(data); + object obj = formatter.Deserialize(stream); + Vp8Residual residual = (Vp8Residual)obj; // act int actual = residual.GetResidualCost(ctx0); @@ -101,8 +95,6 @@ public class Vp8ResidualTests Assert.Equal(expected, actual); } - - private static void CreateRandomProbas(Vp8EncProba probas, Random rand) { for (int t = 0; t < WebpConstants.NumTypes; ++t) diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 270a02c0c9..d17cffc4ff 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -56,7 +56,7 @@ PreserveNewest - + PreserveNewest diff --git a/tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.bin b/tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.bin new file mode 100644 index 0000000000000000000000000000000000000000..d96a3c093a7e4e97708b276341d17cbad0047afc GIT binary patch literal 15043 zcmd6t3wRXO6~}irySbS>cJeUTiYQgAeb5jd3bcVLSXvQnDhO?@#SJVNi3!c4B_aqa zFTocIB0j*kf^S7pqauyst3^u{TT4Zup(3J)5|qb!e`mPOegVHa`R3bi_I&wge`n{O zdw0&gGiPQtWQ9VZq<-3- zl$Mm1^eidu-gR(8ReeKkVnB7Gp}sa=)xB$ZLq%2Pn9~xCBWfljst1hi-@jiX5${{k zv(K1#MbF+*dg*g(Za4vJTgrSo{*+2^qTdwFOp!}H!uhVM3` zM-t=cKVEhQ5<#L!rWOZZzW&ph*q7X+r;9sbtPri4K(2=M_ty^jG)w=FoZ#WBwCx6h z+9cg3h;1X;NDh*V}*#$@;QiL3a6eFFqDE5W)#kLVI zeaQ}&z7E$-?QbF9Mvg!_BS#`#kfV^Jk*>&hkYkWzk#5Lw$al3w*-stY&E)VXnfCFD z%Bsrx%EUnvJ>q2^%N#zrwl?0_HnZ&Gbte{Slze^o7ZiQW%lq6_th znDIhChM4+7KY>^SLS+z(L1+NPst_6ou{?x+3U$>Ybdr8!v0#KwhFCd5gCLfW&|rwQ zBywJ27pFLBEW`77j1EsFK-OWfgv9D$srMRDZtCGJQXhNQg#I-06Y`(;;AmkWitQN%~(wDdi zLXJbmYf&6*eTjP>AuEydwI~kTzQmnC$SULlEs7I>FLA30S%XZ}qBxcK688^;tVQay zC{9Yg#H}Y}1M){Ls;`!|xP3Zul9K8BCn8Ql8nr0SPkw~Gkcg9!i?k?Cbbf@LLd2=a z#aa|+Oh3X-(_!rC$R%17r(Qq8UP{EvkQrJO=Wsv5&LrY2WVRMXG2lnoIYhi1nX5%n zRrnEh9ucoVuGFF^Py7gb6%nsSuF;}S(&9(h`8te!EpnX}MZx4p*abvfh+MBl4btLA z*hNIV0a>g?QNsBV_C_M!gxst}Q49JJ_7);8L6&M!6qSC2y;X;?Z$oa^qNq;&2zv(+ z??mp>5~WP_a#`6{g&u&YTZJBks5^xof+#?R9)_qyg&u*ZB!wP@C@F;=gQzWqRzTE-LXSff zi9%06REt6@A*wy0Cn3r{p{F3~KcS}~>NlY#h(b>28HkEb=vnWa!q94n`c1a{GejXL)C?sIy#P^>$!9M@;|;BWD6QnP zmmq2^p_d_wEumK+iY1{}p(;bKL6lGO*aAECcOHHOwg6h!jb>ktKv&>IkyjnLm9 zN*tke5G9Jx-yv!hp*JCl7NNKFnJ7tmruUqUw;+5_EWXfJfLp?%OThW0~C z3?-qZhB$Lrw;Hmb+YE)F+YMzvcNmI5cN*f(zIB(OOij++nsW4Ccv{=bx#v*Mdk^JY zW}N$G?@w-iM`Ae3jq{o5pC&iGnZ)hfXPoCx-L&_uHpmClt^Oe>YA9G_qWSrKMUnF-DQE&OMajsn0n%uV0bv|O8r&qt7+}7ec zA2m)Zu_w9XK=a3pbJ^S-d$%1J=L+LIuD*HaW_=%>jvhBo>$UyK&krwE5&Pa9|X^mWPA8(n9Uaaxw! zR=b^NjB{6t^I7Bk-*$S-=MFd>{r?-koK<>LW{bC0&v&TR>b6#;`t3J+Ih@eEkFdEz ztzPI*D^8@|N5~1+dn-=N-dnxgp;nyez4!HMhgwlMc<+k>!+R?V5$~F{G$U#ZePErYuF9EL*gHSP3VNs6ocGL#mV|p{49UvR-4HvrAjJxgO|v;% zN=w$Bvld%DA|IZ1vZ~a`oZ*G#`6*UVo@R44n-Sd}-V`3H zwq(DQ*DXKA3c97)9BymKKDyG{V9kicGfV8wc_|j_oMv;lwIU-LX}u6ypSdM_b3v1n zV);#JHiz3gGNMW0bz!BpW*6tRG!YQDCyhE$Con zjoaYC${M%gWki9=8jk~ll{Fqo1S@Mi7713?cr+8Ntnqj#SXtu{Rj{(gW3pgnjYoCC z${LRggOxQNSq3X>JT?th)_8OqtgP|)I9OTZ5q7Y$#$)tgWsOJq!O9vxCkR&7_(_9| zD5O*0g8kXD6@wgc literal 0 HcmV?d00001 From 461224485d948009c593add446c0d427a45ffa1a Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 15 Apr 2023 21:01:37 +0200 Subject: [PATCH 82/86] Use BinaryWriter/BinaryReader to serialize Vp8Residual --- .../Formats/WebP/Vp8ResidualTests.cs | 129 ++++++++++++++++-- .../TestDataWebp/Vp8Residual.bin | Bin 15043 -> 7892 bytes 2 files changed, 117 insertions(+), 12 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs index 2371a179ea..4982929c2c 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Runtime.Serialization.Formatters.Binary; +using System.Text; using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Formats.Webp.Lossy; using SixLabors.ImageSharp.Tests.TestUtilities; @@ -11,6 +11,117 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp; [Trait("Format", "Webp")] public class Vp8ResidualTests { + private static void WriteVp8Residual(string filename, Vp8Residual residual) + { + using FileStream stream = File.Open(filename, FileMode.Create); + using BinaryWriter writer = new(stream, Encoding.UTF8, false); + + writer.Write(residual.First); + writer.Write(residual.Last); + writer.Write(residual.CoeffType); + + for (int i = 0; i < residual.Coeffs.Length; i++) + { + writer.Write(residual.Coeffs[i]); + } + + for (int i = 0; i < residual.Prob.Length; i++) + { + for (int j = 0; j < residual.Prob[i].Probabilities.Length; j++) + { + writer.Write(residual.Prob[i].Probabilities[j].Probabilities); + } + } + + for (int i = 0; i < residual.Costs.Length; i++) + { + Vp8Costs costs = residual.Costs[i]; + Vp8CostArray[] costsArray = costs.Costs; + for (int j = 0; j < costsArray.Length; j++) + { + for (int k = 0; k < costsArray[j].Costs.Length; k++) + { + writer.Write(costsArray[j].Costs[k]); + } + } + } + + for (int i = 0; i < residual.Stats.Length; i++) + { + for (int j = 0; j < residual.Stats[i].Stats.Length; j++) + { + for (int k = 0; k < residual.Stats[i].Stats[j].Stats.Length; k++) + { + writer.Write(residual.Stats[i].Stats[j].Stats[k]); + } + } + } + + writer.Flush(); + } + + private static Vp8Residual ReadVp8Residual(string fileName) + { + using FileStream stream = File.Open(fileName, FileMode.Open); + using BinaryReader reader = new(stream, Encoding.UTF8, false); + + Vp8Residual residual = new() + { + First = reader.ReadInt32(), + Last = reader.ReadInt32(), + CoeffType = reader.ReadInt32() + }; + + for (int i = 0; i < residual.Coeffs.Length; i++) + { + residual.Coeffs[i] = reader.ReadInt16(); + } + + Vp8BandProbas[] bandProbas = new Vp8BandProbas[8]; + for (int i = 0; i < bandProbas.Length; i++) + { + bandProbas[i] = new Vp8BandProbas(); + for (int j = 0; j < bandProbas[i].Probabilities.Length; j++) + { + for (int k = 0; k < 11; k++) + { + bandProbas[i].Probabilities[j].Probabilities[k] = reader.ReadByte(); + } + } + } + + residual.Prob = bandProbas; + + residual.Costs = new Vp8Costs[16]; + for (int i = 0; i < residual.Costs.Length; i++) + { + residual.Costs[i] = new Vp8Costs(); + Vp8CostArray[] costsArray = residual.Costs[i].Costs; + for (int j = 0; j < costsArray.Length; j++) + { + for (int k = 0; k < costsArray[j].Costs.Length; k++) + { + costsArray[j].Costs[k] = reader.ReadUInt16(); + } + } + } + + residual.Stats = new Vp8Stats[8]; + for (int i = 0; i < residual.Stats.Length; i++) + { + residual.Stats[i] = new Vp8Stats(); + for (int j = 0; j < residual.Stats[i].Stats.Length; j++) + { + for (int k = 0; k < residual.Stats[i].Stats[j].Stats.Length; k++) + { + residual.Stats[i].Stats[j].Stats[k] = reader.ReadUInt32(); + } + } + } + + return residual; + } + [Fact] public void Vp8Residual_Serialization_Works() { @@ -27,12 +138,10 @@ public class Vp8ResidualTests } // act - BinaryFormatter formatter = new(); - using MemoryStream ms = new(); - formatter.Serialize(ms, expected); - ms.Position = 0; - object obj = formatter.Deserialize(ms); - Vp8Residual actual = (Vp8Residual)obj; + string fileName = "Vp8SerializationTest.bin"; + WriteVp8Residual(fileName, expected); + Vp8Residual actual = ReadVp8Residual(fileName); + File.Delete(fileName); // assert Assert.Equal(expected.CoeffType, actual.CoeffType); @@ -82,11 +191,7 @@ public class Vp8ResidualTests // arrange int ctx0 = 0; int expected = 20911; - byte[] data = File.ReadAllBytes(Path.Combine("TestDataWebp", "Vp8Residual.bin")); - BinaryFormatter formatter = new(); - using Stream stream = new MemoryStream(data); - object obj = formatter.Deserialize(stream); - Vp8Residual residual = (Vp8Residual)obj; + Vp8Residual residual = ReadVp8Residual(Path.Combine("TestDataWebp", "Vp8Residual.bin")); // act int actual = residual.GetResidualCost(ctx0); diff --git a/tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.bin b/tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.bin index d96a3c093a7e4e97708b276341d17cbad0047afc..1fbb39277626b5f71603c8170ab24aee76bd1262 100644 GIT binary patch delta 661 zcmX?Hdd0S$k%57MABZ8~@BiQb85uxg3_y|zNd5-`2+73IKnVQp`1k+GZLq4nji3HM zzWN`;$*Oz&=i0^p|A9=#q#ys^JOVSfw!Zs!_f`G>SwLaGwo~7aZ2>E0-1+nWXOPl{ zh8@$s|9|rU%=FE>@&C;;Fq1L$_y3O&1*^J0{&@p2SheKH=O;j?0+leH`S<@TM8Ww5 zzy7}i>uN|#fBygSYKRFl{`~&{QLxdh{qz4<55d9#jhFu)dH_+u2$2SIz9E=!v4)1p zIr1HoCn!L$l48f?EkNw1)G_%65N9cOO#TDJeJUN36;wMWZvx^=dL5H57cJeUTiYQgAeb5jd3bcVLSXvQnDhO?@#SJVNi3!c4B_aqa zFTocIB0j*kf^S7pqauyst3^u{TT4Zup(3J)5|qb!e`mPOegVHa`R3bi_I&wge`n{O zdw0&gGiPQtWQ9VZq<-3- zl$Mm1^eidu-gR(8ReeKkVnB7Gp}sa=)xB$ZLq%2Pn9~xCBWfljst1hi-@jiX5${{k zv(K1#MbF+*dg*g(Za4vJTgrSo{*+2^qTdwFOp!}H!uhVM3` zM-t=cKVEhQ5<#L!rWOZZzW&ph*q7X+r;9sbtPri4K(2=M_ty^jG)w=FoZ#WBwCx6h z+9cg3h;1X;NDh*V}*#$@;QiL3a6eFFqDE5W)#kLVI zeaQ}&z7E$-?QbF9Mvg!_BS#`#kfV^Jk*>&hkYkWzk#5Lw$al3w*-stY&E)VXnfCFD z%Bsrx%EUnvJ>q2^%N#zrwl?0_HnZ&Gbte{Slze^o7ZiQW%lq6_th znDIhChM4+7KY>^SLS+z(L1+NPst_6ou{?x+3U$>Ybdr8!v0#KwhFCd5gCLfW&|rwQ zBywJ27pFLBEW`77j1EsFK-OWfgv9D$srMRDZtCGJQXhNQg#I-06Y`(;;AmkWitQN%~(wDdi zLXJbmYf&6*eTjP>AuEydwI~kTzQmnC$SULlEs7I>FLA30S%XZ}qBxcK688^;tVQay zC{9Yg#H}Y}1M){Ls;`!|xP3Zul9K8BCn8Ql8nr0SPkw~Gkcg9!i?k?Cbbf@LLd2=a z#aa|+Oh3X-(_!rC$R%17r(Qq8UP{EvkQrJO=Wsv5&LrY2WVRMXG2lnoIYhi1nX5%n zRrnEh9ucoVuGFF^Py7gb6%nsSuF;}S(&9(h`8te!EpnX}MZx4p*abvfh+MBl4btLA z*hNIV0a>g?QNsBV_C_M!gxst}Q49JJ_7);8L6&M!6qSC2y;X;?Z$oa^qNq;&2zv(+ z??mp>5~WP_a#`6{g&u&YTZJBks5^xof+#?R9)_qyg&u*ZB!wP@C@F;=gQzWqRzTE-LXSff zi9%06REt6@A*wy0Cn3r{p{F3~KcS}~>NlY#h(b>28HkEb=vnWa!q94n`c1a{GejXL)C?sIy#P^>$!9M@;|;BWD6QnP zmmq2^p_d_wEumK+iY1{}p(;bKL6lGO*aAECcOHHOwg6h!jb>ktKv&>IkyjnLm9 zN*tke5G9Jx-yv!hp*JCl7NNKFnJ7tmruUqUw;+5_EWXfJfLp?%OThW0~C z3?-qZhB$Lrw;Hmb+YE)F+YMzvcNmI5cN*f(zIB(OOij++nsW4Ccv{=bx#v*Mdk^JY zW}N$G?@w-iM`Ae3jq{o5pC&iGnZ)hfXPoCx-L&_uHpmClt^Oe>YA9G_qWSrKMUnF-DQE&OMajsn0n%uV0bv|O8r&qt7+}7ec zA2m)Zu_w9XK=a3pbJ^S-d$%1J=L+LIuD*HaW_=%>jvhBo>$UyK&krwE5&Pa9|X^mWPA8(n9Uaaxw! zR=b^NjB{6t^I7Bk-*$S-=MFd>{r?-koK<>LW{bC0&v&TR>b6#;`t3J+Ih@eEkFdEz ztzPI*D^8@|N5~1+dn-=N-dnxgp;nyez4!HMhgwlMc<+k>!+R?V5$~F{G$U#ZePErYuF9EL*gHSP3VNs6ocGL#mV|p{49UvR-4HvrAjJxgO|v;% zN=w$Bvld%DA|IZ1vZ~a`oZ*G#`6*UVo@R44n-Sd}-V`3H zwq(DQ*DXKA3c97)9BymKKDyG{V9kicGfV8wc_|j_oMv;lwIU-LX}u6ypSdM_b3v1n zV);#JHiz3gGNMW0bz!BpW*6tRG!YQDCyhE$Con zjoaYC${M%gWki9=8jk~ll{Fqo1S@Mi7713?cr+8Ntnqj#SXtu{Rj{(gW3pgnjYoCC z${LRggOxQNSq3X>JT?th)_8OqtgP|)I9OTZ5q7Y$#$)tgWsOJq!O9vxCkR&7_(_9| zD5O*0g8kXD6@wgc From c49cb7df5ddda913118fa59176602bc79695007f Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 15 Apr 2023 21:03:06 +0200 Subject: [PATCH 83/86] Remove [Serializable] attributes --- src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs | 1 - src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs | 1 - src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs | 1 - src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs | 1 - src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs | 1 - 5 files changed, 5 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs index ba1b498816..2c8d723d74 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs @@ -3,7 +3,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; -[Serializable] internal class Vp8CostArray { /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs index 6768748205..eee22159e1 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs @@ -3,7 +3,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; -[Serializable] internal class Vp8Costs { /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs index ddc1c9d61a..3375275424 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs @@ -6,7 +6,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// /// Probabilities associated to one of the contexts. /// -[Serializable] internal class Vp8ProbaArray { /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs index 23d63f322d..dda921a7c7 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs @@ -3,7 +3,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; -[Serializable] internal class Vp8Stats { /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs index 2ab0702ebd..2fbba6996d 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs @@ -3,7 +3,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy; -[Serializable] internal class Vp8StatsArray { /// From 81d47f4d50ed5652e79e7b21d6f807c625d3f182 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 15 Apr 2023 21:07:47 +0200 Subject: [PATCH 84/86] Remove some missed Serializable attributes --- src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs | 3 --- src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs | 6 ------ 2 files changed, 9 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs index 5db842ba33..90506efb81 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs @@ -1,14 +1,11 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Text.Json.Serialization; - namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// /// All the probabilities associated to one band. /// -[Serializable] internal class Vp8BandProbas { /// diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs index 58fba10a7f..68bf09f948 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs @@ -7,20 +7,14 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; -using System.Text.Json.Serialization; namespace SixLabors.ImageSharp.Formats.Webp.Lossy; /// /// On-the-fly info about the current set of residuals. /// -[Serializable] internal class Vp8Residual { - public Vp8Residual() - { - } - public int First { get; set; } public int Last { get; set; } From 3541a4e08b692669b4c6a79487ef889dbc69b1e3 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 16 Apr 2023 18:09:47 +0200 Subject: [PATCH 85/86] Use less tolerant comparer when Fma.IsSupported for resize tests --- tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs | 7 ++++--- tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs | 7 ++++--- tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs | 6 ++++-- tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs | 6 ++++-- tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs | 6 ++++-- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs index b4facfa3fe..376bb4a06f 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.X86; using Microsoft.DotNet.RemoteExecutor; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Gif; @@ -51,10 +51,11 @@ public class GifDecoderTests image.DebugSave(provider, testOutputDetails: details, appendPixelTypeToFileName: false); - // Floating point differences result in minor pixel differences. + // Floating point differences in FMA used in the ResizeKernel result in minor pixel differences. // Output have been manually verified. + // For more details see discussion: https://github.com/SixLabors/ImageSharp/pull/1513#issuecomment-763643594 image.CompareToReferenceOutput( - ImageComparer.TolerantPercentage(TestEnvironment.OSArchitecture == Architecture.Arm64 ? 0.0002F : 0.0001F), + ImageComparer.TolerantPercentage(Fma.IsSupported ? 0.0001F : 0.0002F), provider, testOutputDetails: details, appendPixelTypeToFileName: false); diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index afd33608ce..ef1ccbed58 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.X86; using Microsoft.DotNet.RemoteExecutor; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Png; @@ -122,10 +122,11 @@ public partial class PngDecoderTests image.DebugSave(provider, testOutputDetails: details, appendPixelTypeToFileName: false); - // Floating point differences result in minor pixel differences. + // Floating point differences in FMA used in the ResizeKernel result in minor pixel differences. // Output have been manually verified. + // For more details see discussion: https://github.com/SixLabors/ImageSharp/pull/1513#issuecomment-763643594 image.CompareToReferenceOutput( - ImageComparer.TolerantPercentage(TestEnvironment.OSArchitecture == Architecture.Arm64 ? 0.0005F : 0.0003F), + ImageComparer.TolerantPercentage(Fma.IsSupported ? 0.0003F : 0.0005F), provider, testOutputDetails: details, appendPixelTypeToFileName: false); diff --git a/tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs index 0bbe1984f0..da5de8e898 100644 --- a/tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.X86; using Microsoft.DotNet.RemoteExecutor; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Tga; @@ -760,10 +761,11 @@ public class TgaDecoderTests image.DebugSave(provider, testOutputDetails: details, appendPixelTypeToFileName: false); - // Floating point differences result in minor pixel differences. + // Floating point differences in FMA used in the ResizeKernel result in minor pixel differences. // Output have been manually verified. + // For more details see discussion: https://github.com/SixLabors/ImageSharp/pull/1513#issuecomment-763643594 image.CompareToReferenceOutput( - ImageComparer.TolerantPercentage(TestEnvironment.OSArchitecture == Architecture.Arm64 ? 0.0016F : 0.0001F), + ImageComparer.TolerantPercentage(Fma.IsSupported ? 0.0001F : 0.0016F), provider, testOutputDetails: details, appendPixelTypeToFileName: false); diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs index 1f664cf646..a9e2b75c02 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs @@ -3,6 +3,7 @@ // ReSharper disable InconsistentNaming using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.X86; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Tiff; using SixLabors.ImageSharp.Metadata; @@ -695,10 +696,11 @@ public class TiffDecoderTests : TiffDecoderBaseTester image.DebugSave(provider, testOutputDetails: details, appendPixelTypeToFileName: false); - // Floating point differences result in minor pixel differences. + // Floating point differences in FMA used in the ResizeKernel result in minor pixel differences. // Output have been manually verified. + // For more details see discussion: https://github.com/SixLabors/ImageSharp/pull/1513#issuecomment-763643594 image.CompareToReferenceOutput( - TestEnvironment.OSArchitecture == Architecture.Arm64 ? ImageComparer.TolerantPercentage(0.0006F) : ImageComparer.Exact, + Fma.IsSupported ? ImageComparer.Exact : ImageComparer.TolerantPercentage(0.0006F), provider, testOutputDetails: details, appendPixelTypeToFileName: false); diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs index 010af3fbbe..f95b003d0a 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.X86; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.PixelFormats; @@ -367,10 +368,11 @@ public class WebpDecoderTests image.DebugSave(provider, testOutputDetails: details, appendPixelTypeToFileName: false); - // Floating point differences result in minor pixel differences. + // Floating point differences in FMA used in the ResizeKernel result in minor pixel differences. // Output have been manually verified. + // For more details see discussion: https://github.com/SixLabors/ImageSharp/pull/1513#issuecomment-763643594 image.CompareToReferenceOutput( - ImageComparer.TolerantPercentage(TestEnvironment.OSArchitecture == Architecture.Arm64 ? 0.0156F : 0.0007F), + ImageComparer.TolerantPercentage(Fma.IsSupported ? 0.0007F : 0.0156F), provider, testOutputDetails: details, appendPixelTypeToFileName: false); From 78ef6de9b72a06ef940f51e17c619132bdadf8ff Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 22 Apr 2023 15:47:05 +0200 Subject: [PATCH 86/86] Add scalar version of PngDecoder_Decode_Resize test --- .../Formats/Png/PngDecoderTests.cs | 36 +++++++++++++++++++ ...size_ScalarResizeKernel_splash_150_150.png | 3 ++ 2 files changed, 39 insertions(+) create mode 100644 tests/Images/External/ReferenceOutput/PngDecoderTests/PngDecoder_Decode_Resize_ScalarResizeKernel_splash_150_150.png diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index ef1ccbed58..97d7b02bea 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -132,6 +132,42 @@ public partial class PngDecoderTests appendPixelTypeToFileName: false); } + [Theory] + [WithFile(TestImages.Png.Splash, PixelTypes.Rgba32)] + public void PngDecoder_Decode_Resize_ScalarResizeKernel(TestImageProvider provider) + { + HwIntrinsics intrinsicsFilter = HwIntrinsics.DisableHWIntrinsic; + + FeatureTestRunner.RunWithHwIntrinsicsFeature( + RunTest, + intrinsicsFilter, + provider, + string.Empty); + + static void RunTest(string arg1, string notUsed) + { + TestImageProvider provider = + FeatureTestRunner.DeserializeForXunit>(arg1); + + DecoderOptions options = new() + { + TargetSize = new() { Width = 150, Height = 150 } + }; + + using Image image = provider.GetImage(PngDecoder.Instance, options); + + FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}"; + + image.DebugSave(provider, testOutputDetails: details, appendPixelTypeToFileName: false); + + image.CompareToReferenceOutput( + ImageComparer.TolerantPercentage(0.0005F), + provider, + testOutputDetails: details, + appendPixelTypeToFileName: false); + } + } + [Theory] [WithFile(TestImages.Png.AverageFilter3BytesPerPixel, PixelTypes.Rgba32)] [WithFile(TestImages.Png.AverageFilter4BytesPerPixel, PixelTypes.Rgba32)] diff --git a/tests/Images/External/ReferenceOutput/PngDecoderTests/PngDecoder_Decode_Resize_ScalarResizeKernel_splash_150_150.png b/tests/Images/External/ReferenceOutput/PngDecoderTests/PngDecoder_Decode_Resize_ScalarResizeKernel_splash_150_150.png new file mode 100644 index 0000000000..62251f931b --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngDecoderTests/PngDecoder_Decode_Resize_ScalarResizeKernel_splash_150_150.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11e8aa44e32ae133914c91cc32a58ecdba1a107d36a0ca252e0e088053e57be1 +size 28129