diff --git a/src/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs b/src/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs index ca758378627..389223c06e1 100644 --- a/src/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs +++ b/src/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs @@ -35,3 +35,13 @@ public Matrix(System.Numerics.Matrix3x2 matrix) { } public System.Numerics.Matrix3x2 MatrixElements { get { throw null; } set { } } } } +namespace System.Drawing.Imaging +{ + public sealed partial class ImageFormat + { + [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows10.0.17763.0")] + public static ImageFormat Heif { get { throw null; } } + [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows10.0.17763.0")] + public static ImageFormat Webp { get { throw null; } } + } +} diff --git a/src/System.Drawing.Common/src/System/Drawing/ImageFormatConverter.cs b/src/System.Drawing.Common/src/System/Drawing/ImageFormatConverter.cs index 1ab594ed93d..9bbb729a629 100644 --- a/src/System.Drawing.Common/src/System/Drawing/ImageFormatConverter.cs +++ b/src/System.Drawing.Common/src/System/Drawing/ImageFormatConverter.cs @@ -10,6 +10,8 @@ namespace System.Drawing { + [SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "Heif and Webp are referenced here for " + + "design-time support, the user is responsible to ensure that they are used on a supported version of Windows.")] public class ImageFormatConverter : TypeConverter { public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) @@ -63,6 +65,10 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen( return ImageFormat.Tiff; else if (strFormat.Equals("Wmf", StringComparison.OrdinalIgnoreCase)) return ImageFormat.Wmf; + else if (strFormat.Equals("Heif", StringComparison.OrdinalIgnoreCase)) + return ImageFormat.Heif; + else if (strFormat.Equals("Webp", StringComparison.OrdinalIgnoreCase)) + return ImageFormat.Webp; throw new FormatException(SR.Format(SR.ConvertInvalidPrimitive, strFormat, nameof(ImageFormat))); } @@ -128,7 +134,9 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex ImageFormat.Png, ImageFormat.Tiff, ImageFormat.Exif, - ImageFormat.Icon + ImageFormat.Icon, + ImageFormat.Heif, + ImageFormat.Webp }); } diff --git a/src/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs b/src/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs index ca4e867fcba..1a37c8b2db5 100644 --- a/src/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs +++ b/src/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; +using System.Runtime.Versioning; namespace System.Drawing.Imaging { @@ -24,6 +25,8 @@ public sealed class ImageFormat private static readonly ImageFormat s_tiff = new ImageFormat(new Guid("{b96b3cb1-0728-11d3-9d7b-0000f81ef32e}")); private static readonly ImageFormat s_exif = new ImageFormat(new Guid("{b96b3cb2-0728-11d3-9d7b-0000f81ef32e}")); private static readonly ImageFormat s_icon = new ImageFormat(new Guid("{b96b3cb5-0728-11d3-9d7b-0000f81ef32e}")); + private static readonly ImageFormat s_heif = new ImageFormat(new Guid("{b96b3cb6-0728-11d3-9d7b-0000f81ef32e}")); + private static readonly ImageFormat s_webp = new ImageFormat(new Guid("{b96b3cb7-0728-11d3-9d7b-0000f81ef32e}")); private Guid _guid; @@ -123,6 +126,30 @@ public static ImageFormat Icon get { return s_icon; } } + /// + /// Specifies the High Efficiency Image Format (HEIF). + /// + /// + /// This format is supported since Windows 10 1809. + /// + [SupportedOSPlatform("windows10.0.17763.0")] + public static ImageFormat Heif + { + get { return s_heif; } + } + + /// + /// Specifies the WebP image format. + /// + /// + /// This format is supported since Windows 10 1809. + /// + [SupportedOSPlatform("windows10.0.17763.0")] + public static ImageFormat Webp + { + get { return s_webp; } + } + /// /// Returns a value indicating whether the specified object is an equivalent to this /// . @@ -170,6 +197,8 @@ public override string ToString() if (this.Guid == s_tiff.Guid) return "Tiff"; if (this.Guid == s_exif.Guid) return "Exif"; if (this.Guid == s_icon.Guid) return "Icon"; + if (this.Guid == s_heif.Guid) return "Heif"; + if (this.Guid == s_webp.Guid) return "Webp"; return $"[ImageFormat: {_guid}]"; } } diff --git a/src/System.Drawing.Common/tests/Imaging/ImageFormatTests.cs b/src/System.Drawing.Common/tests/Imaging/ImageFormatTests.cs index c22d7b3d43f..646bccb5053 100644 --- a/src/System.Drawing.Common/tests/Imaging/ImageFormatTests.cs +++ b/src/System.Drawing.Common/tests/Imaging/ImageFormatTests.cs @@ -19,6 +19,8 @@ public class ImageFormatTests private static ImageFormat IconImageFormat = new ImageFormat(new Guid("b96b3cb5-0728-11d3-9d7b-0000f81ef32e")); private static ImageFormat JpegImageFormat = new ImageFormat(new Guid("b96b3cae-0728-11d3-9d7b-0000f81ef32e")); private static ImageFormat WmfImageFormat = new ImageFormat(new Guid("b96b3cad-0728-11d3-9d7b-0000f81ef32e")); + private static ImageFormat HeifImageFormat = new ImageFormat(new Guid("{b96b3cb6-0728-11d3-9d7b-0000f81ef32e}")); + private static ImageFormat WebpImageFormat = new ImageFormat(new Guid("{b96b3cb7-0728-11d3-9d7b-0000f81ef32e}")); private static ImageFormat CustomImageFormat = new ImageFormat(new Guid("48749428-316f-496a-ab30-c819a92b3137")); public static IEnumerable ImageFormatGuidTestData @@ -35,6 +37,10 @@ public static IEnumerable ImageFormatGuidTestData yield return new object[] { IconImageFormat.Guid, ImageFormat.Icon }; yield return new object[] { JpegImageFormat.Guid, ImageFormat.Jpeg }; yield return new object[] { WmfImageFormat.Guid, ImageFormat.Wmf }; +#if NET + yield return new object[] { HeifImageFormat.Guid, ImageFormat.Heif }; + yield return new object[] { WebpImageFormat.Guid, ImageFormat.Webp }; +#endif yield return new object[] { new Guid("48749428-316f-496a-ab30-c819a92b3137"), CustomImageFormat }; } } @@ -53,6 +59,10 @@ public static IEnumerable ImageFormatToStringTestData yield return new object[] { "Icon", ImageFormat.Icon }; yield return new object[] { "Jpeg", ImageFormat.Jpeg }; yield return new object[] { "Wmf", ImageFormat.Wmf }; +#if NET + yield return new object[] { "Heif", ImageFormat.Heif }; + yield return new object[] { "Webp", ImageFormat.Webp }; +#endif yield return new object[] { "[ImageFormat: 48749428-316f-496a-ab30-c819a92b3137]", CustomImageFormat }; } } diff --git a/src/System.Drawing.Common/tests/System/Drawing/ImageFormatConverterTests.cs b/src/System.Drawing.Common/tests/System/Drawing/ImageFormatConverterTests.cs index 53963a1ee02..b6920d66ad7 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/ImageFormatConverterTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/ImageFormatConverterTests.cs @@ -101,6 +101,10 @@ public void ConvertFrom_ShortName() Assert.Equal(ImageFormat.Icon, ConvertFromName("Icon")); Assert.Equal(ImageFormat.Jpeg, ConvertFromName("Jpeg")); Assert.Equal(ImageFormat.Wmf, ConvertFromName("Wmf")); +#if NET + Assert.Equal(ImageFormat.Heif, ConvertFromName("Heif")); + Assert.Equal(ImageFormat.Webp, ConvertFromName("Webp")); +#endif } [ConditionalFact(Helpers.IsDrawingSupported)] @@ -174,6 +178,10 @@ private void CheckStandardValues(ICollection values) bool tiff = false; bool exif = false; bool icon = false; +#if NET + bool heif = false; + bool webp = false; +#endif foreach (ImageFormat iformat in values) { @@ -209,6 +217,14 @@ private void CheckStandardValues(ICollection values) case "b96b3cb5-0728-11d3-9d7b-0000f81ef32e": icon = true; break; +#if NET + case "b96b3cb6-0728-11d3-9d7b-0000f81ef32e": + heif = true; + break; + case "b96b3cb7-0728-11d3-9d7b-0000f81ef32e": + webp = true; + break; +#endif default: throw new InvalidOperationException($"Unknown GUID {iformat.Guid}."); } @@ -223,6 +239,10 @@ private void CheckStandardValues(ICollection values) Assert.True(tiff, "Tiff"); Assert.True(exif, "Exif"); Assert.True(icon, "Icon"); +#if NET + Assert.True(heif, "Heif"); + Assert.True(webp, "Webp"); +#endif } [ConditionalFact(Helpers.IsDrawingSupported)]