Repository: SixLabors/ImageSharp

Issue:
PlatformNotSupportedException from Image.Load on server
### Prerequisites

- [X] I have written a descriptive issue title
- [X] I have verified that I am running the latest version of ImageSharp
- [X] I have verified if the problem exist in both `DEBUG` and `RELEASE` mode
- [X] 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

### ImageSharp version

3.1.1 and 3.1.0

### Other ImageSharp packages and versions

None

### Environment (Operating system, version and so on)

Windows Server 2016 Datacenter, Intel Xeon Gold 6134, 64-bit

### .NET Framework version

.NET 8

### Description

When loading data using `Image.Load` on a server with ImageSharp >= 3.1.0, I get the exception below. It works fine in my local computer, and it works fine on the server with ImageSharp 3.0.2. Only from 3.1.0 and above does it fail on the server.

```
Unhandled exception. System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Runtime.Intrinsics.X86.Ssse3.Abs(Vector128`1 value)
   at SixLabors.ImageSharp.Formats.Png.PngDecoderCore.DecodePixelData[TPixel](FrameControl frameControl, DeflateStream compressedStream, ImageFrame`1 imageFrame, PngMetadata pngMetadata, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Png.PngDecoderCore.ReadScanlines[TPixel](Int32 chunkLength, ImageFrame`1 image, PngMetadata pngMetadata, Func`1 getData, FrameControl& frameControl, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Png.PngDecoderCore.Decode[TPixel](BufferedReadStream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.ImageDecoderUtilities.Decode[TPixel](IImageDecoderInternals decoder, Configuration configuration, Stream stream, Func`3 largeImageExceptionFactory, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.ImageDecoderUtilities.Decode[TPixel](IImageDecoderInternals decoder, Configuration configuration, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Png.PngDecoder.Decode[TPixel](PngDecoderOptions options, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Png.PngDecoder.Decode(PngDecoderOptions options, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.SpecializedImageDecoder`1.Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.ImageDecoder.<>c__DisplayClass1_0.<Decode>b__0(Stream s)
   at SixLabors.ImageSharp.Formats.ImageDecoder.<WithSeekableStream>g__PeformActionAndResetPosition|11_0[T](Stream s, Int64 position, <>c__DisplayClass11_0`1&)
   at SixLabors.ImageSharp.Formats.ImageDecoder.WithSeekableStream[T](DecoderOptions options, Stream stream, Func`2 action)
   at SixLabors.ImageSharp.Formats.ImageDecoder.Decode(DecoderOptions options, Stream stream)
   at SixLabors.ImageSharp.Image.Decode(DecoderOptions options, Stream stream)
   at SixLabors.ImageSharp.Image.<>c__DisplayClass80_0.<Load>b__0(Stream s)
   at SixLabors.ImageSharp.Image.WithSeekableStream[T](DecoderOptions options, Stream stream, Func`2 action)
   at SixLabors.ImageSharp.Image.Load(DecoderOptions options, Stream stream)
   at SixLabors.ImageSharp.Image.Load(DecoderOptions options, ReadOnlySpan`1 buffer)
   at SixLabors.ImageSharp.Image.Load(ReadOnlySpan`1 buffer)
   at <StartupCode$ImageSharpTest>.$Foo.main@() in C:\Users\cmeer\Source\Repos\ImageSharpTest\ImageSharpTest\Program.fs:line 7
```

### Steps to Reproduce

Please see the attached repro solution. I am publishing it using this command:

```
dotnet publish ImageSharpTest -c Release -r win-x64 --self-contained -o out
```

[ImageSharpTest.zip](https://github.com/SixLabors/ImageSharp/files/13645770/ImageSharpTest.zip)

For reference, the repro solution contains a trivial/minimal project file and this `Program.fs` file:

```f#
open System
open SixLabors.ImageSharp

let data = "..." // 56665 characters omitted here
data |> Convert.FromBase64String |> Image.Load |> ignore<Image>
printfn "OK"

```

### Images

_No response_


Hints:
I don’t think this is a regression. There have been no changes to the scan line decoding code across those versions.
As mentioned, using the trivial repro, it works when referencing 3.0.2 and does not work when referencing 3.1.0 or 3.1.1. Isn't that the definition of a regression?
Actually, you're correct. I broke it 7 months ago.

https://github.com/SixLabors/ImageSharp/blob/12da625cbb95a7005dbc78a82b9602f3a90022de/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs

Patch:
diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
index b8324a0809..59c903c1dd 100644
--- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
@@ -35,9 +35,9 @@ public static void Decode(Span<byte> scanline, Span<byte> previousScanline, int
         // row:  a d
         // The Paeth function predicts d to be whichever of a, b, or c is nearest to
         // p = a + b - c.
-        if (Sse2.IsSupported && bytesPerPixel is 4)
+        if (Ssse3.IsSupported && bytesPerPixel is 4)
         {
-            DecodeSse3(scanline, previousScanline);
+            DecodeSsse3(scanline, previousScanline);
         }
         else if (AdvSimd.Arm64.IsSupported && bytesPerPixel is 4)
         {
@@ -50,7 +50,7 @@ public static void Decode(Span<byte> scanline, Span<byte> previousScanline, int
     }
 
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
-    private static void DecodeSse3(Span<byte> scanline, Span<byte> previousScanline)
+    private static void DecodeSsse3(Span<byte> scanline, Span<byte> previousScanline)
     {
         ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
         ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);


Test patch:
diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderFilterTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderFilterTests.cs
index ec6de0dfab..f5c42c734b 100644
--- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderFilterTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderFilterTests.cs
@@ -170,6 +170,9 @@ private static void RunPaethFilterTest()
     [Fact]
     public void PaethFilter_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunPaethFilterTest, HwIntrinsics.AllowAll);
 
+    [Fact]
+    public void PaethFilter_WithoutSsse3_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunPaethFilterTest, HwIntrinsics.DisableSSSE3);
+
     [Fact]
     public void PaethFilter_WithoutHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunPaethFilterTest, HwIntrinsics.DisableHWIntrinsic);
 }