diff --git a/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs b/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs index c8f6d5d1..3934af2b 100644 --- a/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs @@ -111,7 +111,13 @@ internal static class WICFormatHelper /// Thrown when the input filename doesn't have a valid file extension. public static Guid GetForFilename(ReadOnlySpan filename) { - return Path.GetExtension(filename).ToString().ToLowerInvariant() switch + Span extension = stackalloc char[4]; + + int length = Path.GetExtension(filename).ToLowerInvariant(extension); + + default(ArgumentException).ThrowIf(length == -1, nameof(filename)); + + return extension[..length] switch { ".dib" or ".rle" or diff --git a/src/ComputeSharp/Graphics/Helpers/WICHelper.cs b/src/ComputeSharp/Graphics/Helpers/WICHelper.cs index e7c63cd4..0b725b8d 100644 --- a/src/ComputeSharp/Graphics/Helpers/WICHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/WICHelper.cs @@ -358,6 +358,7 @@ internal sealed unsafe class WICHelper where T : unmanaged { using ComPtr wicBitmapEncoder = default; + Guid containerGuid = WICFormatHelper.GetForFilename(filename); // Create the image encoder @@ -397,6 +398,7 @@ internal sealed unsafe class WICHelper where T : unmanaged { using ComPtr wicBitmapEncoder = default; + Guid containerGuid = WICFormatHelper.GetForFormat(format); // Create the image encoder @@ -431,6 +433,7 @@ internal sealed unsafe class WICHelper where T : unmanaged { using ComPtr wicBitmapEncoder = default; + Guid containerGuid = WICFormatHelper.GetForFormat(format); // Create the image encoder