Skip to content

Commit

Permalink
Use GDI+1.1 API set in Windows 8 and later (#35169)
Browse files Browse the repository at this point in the history
* Use GDI+1.1 API set in Windows 8 and later

* PR Feedback, add meaningful test

* Update System.Drawing test package from runtime-assets

* PR Feedback and skip test on full framework
  • Loading branch information
safern committed May 2, 2020
1 parent 8650e1a commit 7bd9e4f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>4aa2a9b60112e056b61295826c2def4956b14bbc</Sha>
</Dependency>
<Dependency Name="System.Drawing.Common.TestData" Version="5.0.0-beta.20228.1">
<Dependency Name="System.Drawing.Common.TestData" Version="5.0.0-beta.20251.1">
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>4aa2a9b60112e056b61295826c2def4956b14bbc</Sha>
<Sha>205a003b723482863e26e9d29eb7c8513ae3ded1</Sha>
</Dependency>
<Dependency Name="System.IO.Compression.TestData" Version="5.0.0-beta.20228.1">
<Uri>https://github.com/dotnet/runtime-assets</Uri>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<runtimenativeSystemIOPortsVersion>5.0.0-alpha.1.19563.3</runtimenativeSystemIOPortsVersion>
<!-- Runtime-Assets dependencies -->
<SystemComponentModelTypeConverterTestDataVersion>5.0.0-beta.20228.1</SystemComponentModelTypeConverterTestDataVersion>
<SystemDrawingCommonTestDataVersion>5.0.0-beta.20228.1</SystemDrawingCommonTestDataVersion>
<SystemDrawingCommonTestDataVersion>5.0.0-beta.20251.1</SystemDrawingCommonTestDataVersion>
<SystemIOCompressionTestDataVersion>5.0.0-beta.20228.1</SystemIOCompressionTestDataVersion>
<SystemIOPackagingTestDataVersion>5.0.0-beta.20228.1</SystemIOPackagingTestDataVersion>
<SystemNetTestDataVersion>5.0.0-beta.20228.1</SystemNetTestDataVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,12 @@ internal struct StartupInput

public static StartupInput GetDefault()
{
OperatingSystem os = Environment.OSVersion;
StartupInput result = default;
result.GdiplusVersion = 1;

// In Windows 7 GDI+1.1 story is different as there are different binaries per GDI+ version.
bool isWindows7 = os.Platform == PlatformID.Win32NT && os.Version.Major == 6 && os.Version.Minor == 1;
result.GdiplusVersion = isWindows7 ? 1 : 2;
// result.DebugEventCallback = null;
result.SuppressBackgroundThread = false;
result.SuppressExternalCodecs = false;
Expand Down
31 changes: 30 additions & 1 deletion src/libraries/System.Drawing.Common/tests/BitmapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;

namespace System.Drawing.Tests
Expand Down Expand Up @@ -804,6 +805,34 @@ public void GetHicon_Disposed_ThrowsArgumentException()
AssertExtensions.Throws<ArgumentException>(null, () => bitmap.GetHicon());
}

[ConditionalFact(Helpers.IsDrawingSupported)]
[PlatformSpecific(TestPlatforms.Windows)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "In .NET Framework we use GDI 1.0")]
public void SaveWmfAsPngDoesntChangeImageBoundaries()
{
if (PlatformDetection.IsWindows7)
{
throw new SkipTestException("GDI+ 1.1 is not supported");
}

string output = GetTestFilePath() + ".png";
using Stream wmfStream = File.OpenRead(Helpers.GetTestBitmapPath("gdiwmfboundariesbug.wmf"));
using Image bitmapFromWmf = Bitmap.FromStream(wmfStream);
bitmapFromWmf.Save(output, ImageFormat.Png);

using Stream expectedPngStream = File.OpenRead(Helpers.GetTestBitmapPath("gdiwmfboundariesbug-output.png"));
using Image expectedPngBitmap = Bitmap.FromStream(expectedPngStream);
using MemoryStream expectedMemoryStream = new MemoryStream();
expectedPngBitmap.Save(expectedMemoryStream, ImageFormat.Png);

using Stream outputPngStream = File.OpenRead(output);
using Image outputPngBitmap = Bitmap.FromStream(outputPngStream);
using MemoryStream outputMemoryStream = new MemoryStream();
outputPngBitmap.Save(outputMemoryStream, ImageFormat.Png);

Assert.Equal(expectedMemoryStream.ToArray(), outputMemoryStream.ToArray());
}

// This test causes an AV on Linux
[ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)]
[ConditionalFact(Helpers.IsDrawingSupported)]
Expand Down Expand Up @@ -1091,7 +1120,7 @@ public void SetResolution_Disposed_ThrowsArgumentException()
public static IEnumerable<object[]> LockBits_NotUnix_TestData()
{
Bitmap bitmap() => new Bitmap(2, 2, PixelFormat.Format32bppArgb);
yield return new object[] { bitmap(), new Rectangle(1, 1, 1,1), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb, 8, 1 };
yield return new object[] { bitmap(), new Rectangle(1, 1, 1, 1), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb, 8, 1 };
yield return new object[] { bitmap(), new Rectangle(1, 1, 1, 1), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb, 8, 3 };
yield return new object[] { bitmap(), new Rectangle(1, 1, 1, 1), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb, 8, 2 };

Expand Down
3 changes: 0 additions & 3 deletions src/libraries/System.Drawing.Common/tests/GdiplusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Text;
using Xunit;

namespace System.Drawing.Tests
Expand Down

0 comments on commit 7bd9e4f

Please sign in to comment.