Merge pull request #844 from elyoh/elyoh-file-format-from-extension-fix

Addresses limitations of detecting ImageFormat / ContainerFormat from the file extension
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2024-08-28 09:57:05 -07:00
コミット af9a4ddf1e
2ファイル変更
+17 -2

検索条件に一致するファイルはありません

+14 -2
ファイルの表示
@@ -111,16 +111,28 @@ internal static class WICFormatHelper
/// <exception cref="ArgumentException">Thrown when the input filename doesn't have a valid file extension.</exception>
public static Guid GetForFilename(ReadOnlySpan<char> filename)
{
return Path.GetExtension(filename) switch
Span<char> 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
".bmp" => GUID.GUID_ContainerFormatBmp,
".png" => GUID.GUID_ContainerFormatPng,
".jpe" or
".jfif" or
".exif" or
".jpg" or
".jpeg" => GUID.GUID_ContainerFormatJpeg,
".jxr" or
".hdp" or
".wdp" or
".wmp" => GUID.GUID_ContainerFormatWmp,
".tif" or
".tiff" => GUID.GUID_ContainerFormatTiff,
".dds" => GUID.GUID_ContainerFormatDds,
_ => default(ArgumentException).Throw<Guid>(nameof(filename))
@@ -146,4 +158,4 @@ internal static class WICFormatHelper
_ => default(ArgumentException).Throw<Guid>(nameof(format))
};
}
}
}
+3
ファイルの表示
@@ -358,6 +358,7 @@ internal sealed unsafe class WICHelper
where T : unmanaged
{
using ComPtr<IWICBitmapEncoder> 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<IWICBitmapEncoder> 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<IWICBitmapEncoder> wicBitmapEncoder = default;
Guid containerGuid = WICFormatHelper.GetForFormat(format);
// Create the image encoder