From c90c59f11d167f37d479b330dbb4ca169d1505db Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Wed, 26 Feb 2020 17:49:26 +0100 Subject: [PATCH 1/3] Update System.Drawing to reflect GDI+ changes - Add support ValueTypePointer encoder parameters - Support ColorSpace, ImageItems and SaveAsCmyk encoders --- .../ref/System.Drawing.Common.cs | 4 ++++ .../src/System/Drawing/Imaging/Encoder.cs | 3 +++ .../src/System/Drawing/Imaging/EncoderParameter.cs | 3 +++ .../Drawing/Imaging/EncoderParameterValueType.cs | 6 +++++- .../System.Drawing.Common/tests/ImageTests.cs | 13 +++++++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs index 6e05c9b7c7e86a..4c91c651b28e43 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs @@ -2105,6 +2105,9 @@ public sealed partial class Encoder public static readonly System.Drawing.Imaging.Encoder ScanMethod; public static readonly System.Drawing.Imaging.Encoder Transformation; public static readonly System.Drawing.Imaging.Encoder Version; + public static readonly System.Drawing.Imaging.Encoder ColorSpace; + public static readonly System.Drawing.Imaging.Encoder ImageItems; + public static readonly System.Drawing.Imaging.Encoder SaveAsCmyk; public Encoder(System.Guid guid) { } public System.Guid Guid { get { throw null; } } } @@ -2152,6 +2155,7 @@ public enum EncoderParameterValueType ValueTypeLongRange = 6, ValueTypeUndefined = 7, ValueTypeRationalRange = 8, + ValueTypePointer = 9, } public enum EncoderValue { diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Encoder.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Encoder.cs index 30b92a8a34c103..737f248ee23a5b 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Encoder.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Encoder.cs @@ -16,6 +16,9 @@ public sealed class Encoder public static readonly Encoder LuminanceTable = new Encoder(new Guid(unchecked((int)0xedb33bce), unchecked((short)0x0266), unchecked((short)0x4a77), new byte[] { 0xb9, 0x04, 0x27, 0x21, 0x60, 0x99, 0xe7, 0x17 })); public static readonly Encoder ChrominanceTable = new Encoder(new Guid(unchecked((int)0xf2e455dc), unchecked((short)0x09b3), unchecked((short)0x4316), new byte[] { 0x82, 0x60, 0x67, 0x6a, 0xda, 0x32, 0x48, 0x1c })); public static readonly Encoder SaveFlag = new Encoder(new Guid(unchecked((int)0x292266fc), unchecked((short)0xac40), unchecked((short)0x47bf), new byte[] { 0x8c, 0xfc, 0xa8, 0x5b, 0x89, 0xa6, 0x55, 0xde })); + public static readonly Encoder ColorSpace = new Encoder(new Guid(unchecked((int)0xae7a62a0), unchecked((short)0xee2c), unchecked((short)0x49d8), new byte[] { 0x9d, 0x07, 0x1b, 0xa8, 0xa9, 0x27, 0x59, 0x6e })); + public static readonly Encoder ImageItems = new Encoder(new Guid(unchecked((int)0x63875e13), unchecked((short)0x1f1d), unchecked((short)0x45ab), new byte[] { 0x91, 0x95, 0xa2, 0x9b, 0x60, 0x66, 0xa6, 0x50 })); + public static readonly Encoder SaveAsCmyk = new Encoder(new Guid(unchecked((int)0xa219bbc9), unchecked((short)0x0a9d), unchecked((short)0x4005), new byte[] { 0xa3, 0xee, 0x3a, 0x42, 0x1b, 0x8b, 0xb0, 0x6c })); private Guid _guid; diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/EncoderParameter.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/EncoderParameter.cs index 55a04fe2b6b8d5..51011d5557d8fb 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/EncoderParameter.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/EncoderParameter.cs @@ -381,6 +381,9 @@ public EncoderParameter(Encoder encoder, int numberValues, EncoderParameterValue case EncoderParameterValueType.ValueTypeRationalRange: size = 2 * 2 * 4; break; + case EncoderParameterValueType.ValueTypePointer: + size = IntPtr.Size; + break; default: throw Gdip.StatusException(Gdip.WrongState); } diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/EncoderParameterValueType.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/EncoderParameterValueType.cs index 9b9f073d63032b..78950e22ce8e60 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/EncoderParameterValueType.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/EncoderParameterValueType.cs @@ -44,6 +44,10 @@ public enum EncoderParameterValueType /// Two Rationals. The first Rational specifies the lower end and the second specifies the higher end. /// All values are inclusive at both ends /// - ValueTypeRationalRange = 8 + ValueTypeRationalRange = 8, + /// + /// The parameter is a pointer to a block of custom metadata. + /// + ValueTypePointer = 9, } } diff --git a/src/libraries/System.Drawing.Common/tests/ImageTests.cs b/src/libraries/System.Drawing.Common/tests/ImageTests.cs index c9147dc81b216c..bead54e4017193 100644 --- a/src/libraries/System.Drawing.Common/tests/ImageTests.cs +++ b/src/libraries/System.Drawing.Common/tests/ImageTests.cs @@ -157,6 +157,19 @@ public static IEnumerable GetEncoderParameterList_ReturnsExpected_Test new Guid(unchecked((int)0xa219bbc9), unchecked((short)0x0a9d), unchecked((short)0x4005), new byte[] { 0xa3, 0xee, 0x3a, 0x42, 0x1b, 0x8b, 0xb0, 0x6c }) /* Encoder.SaveAsCmyk.Guid */ } }; + + yield return new object[] + { + ImageFormat.Jpeg, + new Guid[] + { + Encoder.Transformation.Guid, + Encoder.Quality.Guid, + Encoder.LuminanceTable.Guid, + Encoder.ChrominanceTable.Guid, + Encoder.ImageItems.Guid + } + }; } [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)] From 24bf7dffa15fdc5a1336fb1dcff710c548da64cb Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Thu, 27 Feb 2020 11:23:10 +0100 Subject: [PATCH 2/3] Skip test on NetFx --- src/libraries/System.Drawing.Common/tests/ImageTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libraries/System.Drawing.Common/tests/ImageTests.cs b/src/libraries/System.Drawing.Common/tests/ImageTests.cs index bead54e4017193..ebf65b2235a23c 100644 --- a/src/libraries/System.Drawing.Common/tests/ImageTests.cs +++ b/src/libraries/System.Drawing.Common/tests/ImageTests.cs @@ -158,6 +158,9 @@ public static IEnumerable GetEncoderParameterList_ReturnsExpected_Test } }; +#if !NETFRAMEWORK + // NetFX doesn't support pointer-type encoder parameters, and doesn't define Encoder.ImageItems. Skip this test + // on NetFX. yield return new object[] { ImageFormat.Jpeg, @@ -170,6 +173,7 @@ public static IEnumerable GetEncoderParameterList_ReturnsExpected_Test Encoder.ImageItems.Guid } }; +#endif } [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)] From b9f76ee4ba08d5274c572d29b2931f85735ef1e8 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Fri, 13 Mar 2020 18:35:42 +0100 Subject: [PATCH 3/3] Add XML documentation --- .../src/System/Drawing/Imaging/Encoder.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Encoder.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Encoder.cs index 737f248ee23a5b..a9c401cdb81d50 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Encoder.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Encoder.cs @@ -16,8 +16,20 @@ public sealed class Encoder public static readonly Encoder LuminanceTable = new Encoder(new Guid(unchecked((int)0xedb33bce), unchecked((short)0x0266), unchecked((short)0x4a77), new byte[] { 0xb9, 0x04, 0x27, 0x21, 0x60, 0x99, 0xe7, 0x17 })); public static readonly Encoder ChrominanceTable = new Encoder(new Guid(unchecked((int)0xf2e455dc), unchecked((short)0x09b3), unchecked((short)0x4316), new byte[] { 0x82, 0x60, 0x67, 0x6a, 0xda, 0x32, 0x48, 0x1c })); public static readonly Encoder SaveFlag = new Encoder(new Guid(unchecked((int)0x292266fc), unchecked((short)0xac40), unchecked((short)0x47bf), new byte[] { 0x8c, 0xfc, 0xa8, 0x5b, 0x89, 0xa6, 0x55, 0xde })); + + /// + /// An object that is initialized with the globally unique identifier for the color space category. + /// public static readonly Encoder ColorSpace = new Encoder(new Guid(unchecked((int)0xae7a62a0), unchecked((short)0xee2c), unchecked((short)0x49d8), new byte[] { 0x9d, 0x07, 0x1b, 0xa8, 0xa9, 0x27, 0x59, 0x6e })); + + /// + /// An object that is initialized with the globally unique identifier for the image items category. + /// public static readonly Encoder ImageItems = new Encoder(new Guid(unchecked((int)0x63875e13), unchecked((short)0x1f1d), unchecked((short)0x45ab), new byte[] { 0x91, 0x95, 0xa2, 0x9b, 0x60, 0x66, 0xa6, 0x50 })); + + /// + /// An object that is initialized with the globally unique identifier for the save as CMYK category. + /// public static readonly Encoder SaveAsCmyk = new Encoder(new Guid(unchecked((int)0xa219bbc9), unchecked((short)0x0a9d), unchecked((short)0x4005), new byte[] { 0xa3, 0xee, 0x3a, 0x42, 0x1b, 0x8b, 0xb0, 0x6c })); private Guid _guid;