diff --git a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs index febca037b5..19a71c3e56 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs @@ -28,14 +28,16 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy if (Sse2.IsSupported) { // Load values. - Vector128 a0 = Unsafe.As>(ref MemoryMarshal.GetReference(a)); - Vector128 a1 = Unsafe.As>(ref MemoryMarshal.GetReference(a.Slice(WebpConstants.Bps, 8))); - Vector128 a2 = Unsafe.As>(ref MemoryMarshal.GetReference(a.Slice(WebpConstants.Bps * 2, 8))); - Vector128 a3 = Unsafe.As>(ref MemoryMarshal.GetReference(a.Slice(WebpConstants.Bps * 3, 8))); - Vector128 b0 = Unsafe.As>(ref MemoryMarshal.GetReference(b)); - Vector128 b1 = Unsafe.As>(ref MemoryMarshal.GetReference(b.Slice(WebpConstants.Bps, 8))); - Vector128 b2 = Unsafe.As>(ref MemoryMarshal.GetReference(b.Slice(WebpConstants.Bps * 2, 8))); - Vector128 b3 = Unsafe.As>(ref MemoryMarshal.GetReference(b.Slice(WebpConstants.Bps * 3, 8))); + ref byte aRef = ref MemoryMarshal.GetReference(a); + Vector128 a0 = Unsafe.As>(ref aRef); + Vector128 a1 = Unsafe.As>(ref Unsafe.Add(ref aRef, WebpConstants.Bps)); + Vector128 a2 = Unsafe.As>(ref Unsafe.Add(ref aRef, WebpConstants.Bps * 2)); + Vector128 a3 = Unsafe.As>(ref Unsafe.Add(ref aRef, WebpConstants.Bps * 3)); + ref byte bRef = ref MemoryMarshal.GetReference(b); + Vector128 b0 = Unsafe.As>(ref bRef); + Vector128 b1 = Unsafe.As>(ref Unsafe.Add(ref bRef, WebpConstants.Bps)); + Vector128 b2 = Unsafe.As>(ref Unsafe.Add(ref bRef, WebpConstants.Bps * 2)); + Vector128 b3 = Unsafe.As>(ref Unsafe.Add(ref bRef, WebpConstants.Bps * 3)); // Combine pair of lines. Vector128 a01 = Sse2.UnpackLow(a0.AsInt32(), a1.AsInt32());