From a66597546003a9b5a76306a7f2ffdf1d1411c93f Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Mon, 13 Jan 2025 12:05:10 +0000 Subject: [PATCH] [AdvancedPaste]Add all BitmapDecoder supported image filetypes to ImageToText (#35600) Adds support to ImageToText for all image filetypes supported by BitmapDecoder. --- .../AdvancedPaste/Helpers/DataPackageHelpers.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/DataPackageHelpers.cs b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/DataPackageHelpers.cs index 37ddf5e56e..4aacd0c115 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/DataPackageHelpers.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/DataPackageHelpers.cs @@ -18,7 +18,7 @@ namespace AdvancedPaste.Helpers; internal static class DataPackageHelpers { - private static readonly HashSet ImageFileTypes = new(StringComparer.InvariantCultureIgnoreCase) { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico", ".svg" }; + private static readonly Lazy> ImageFileTypes = new(GetImageFileTypes()); private static readonly (string DataFormat, ClipboardFormat ClipboardFormat)[] DataFormats = [ @@ -57,7 +57,7 @@ internal static class DataPackageHelpers { availableFormats |= ClipboardFormat.File; - if (ImageFileTypes.Contains(file.FileType)) + if (ImageFileTypes.Value.Contains(file.FileType)) { availableFormats |= ClipboardFormat.Image; } @@ -148,4 +148,9 @@ internal static class DataPackageHelpers return null; } + + private static HashSet GetImageFileTypes() => + BitmapDecoder.GetDecoderInformationEnumerator() + .SelectMany(di => di.FileExtensions) + .ToHashSet(StringComparer.InvariantCultureIgnoreCase); }