Skip to content

Commit

Permalink
Clean-up System.Drawing.Common and remove the Unix code. (#64623)
Browse files Browse the repository at this point in the history
* Remove all Unix-specific files.

* Throw PNSE on non-Windows.

* Merge the Windows-specific files into their formerly cross-platform counterparts.

* Remove all mentions of Unix in the tests.

* Remove two always-on defines.

* Merge two item groups in the project file.
No reason to sort them; the list is already unsorted.
And rename a remaining formerly Windows-specific file.

* Remove the NoCOMWrappers files.

* Fail on unsupported platforms when a library is trying to be loaded.

* Fix compile errors.

* Small changes in the project file.

* Remove two meaningless asserts.

* Run BinaryFormatter tests on SDC types only on Windows.

* Use `[ThreadStatic]` in Gdip.ThreadData.

* Remove `TargetsAnyOS`.

Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>

* SDC project file clean-up

* Remove `!!` from System.Drawing.Common.

Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
  • Loading branch information
teo-tsirpanis and ViktorHofer committed Apr 20, 2022
1 parent aabd04f commit 5b55b06
Show file tree
Hide file tree
Showing 143 changed files with 4,993 additions and 13,976 deletions.
164 changes: 50 additions & 114 deletions src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

38 changes: 34 additions & 4 deletions src/libraries/System.Drawing.Common/src/System/Drawing/Bitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.ComponentModel;
using System.Drawing.Imaging;
using System.Drawing.Internal;
using System.IO;
using System.Runtime.InteropServices;
using Gdip = System.Drawing.SafeNativeMethods.Gdip;
Expand All @@ -14,7 +15,7 @@ namespace System.Drawing
"System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public sealed partial class Bitmap : Image
public sealed class Bitmap : Image
{
private static readonly Color s_defaultTransparentColor = Color.LightGray;

Expand Down Expand Up @@ -53,12 +54,37 @@ public Bitmap(Stream stream) : this(stream, false)
{
}

public unsafe Bitmap(Stream stream, bool useIcm)
{
ArgumentNullException.ThrowIfNull(stream);

using DrawingCom.IStreamWrapper streamWrapper = DrawingCom.GetComWrapper(new GPStream(stream));

IntPtr bitmap = IntPtr.Zero;
if (useIcm)
{
Gdip.CheckStatus(Gdip.GdipCreateBitmapFromStreamICM(streamWrapper.Ptr, &bitmap));
}
else
{
Gdip.CheckStatus(Gdip.GdipCreateBitmapFromStream(streamWrapper.Ptr, &bitmap));
}

ValidateImage(bitmap);

SetNativeImage(bitmap);
EnsureSave(this, null, stream);
}

public Bitmap(Type type, string resource) : this(GetResourceStream(type, resource))
{
}

private static Stream GetResourceStream(Type type!!, string resource!!)
private static Stream GetResourceStream(Type type, string resource)
{
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(resource);

Stream? stream = type.Module.Assembly.GetManifestResourceStream(type, resource);
if (stream == null)
{
Expand All @@ -72,8 +98,10 @@ public Bitmap(int width, int height) : this(width, height, PixelFormat.Format32b
{
}

public Bitmap(int width, int height, Graphics g!!)
public Bitmap(int width, int height, Graphics g)
{
ArgumentNullException.ThrowIfNull(g);

IntPtr bitmap;
int status = Gdip.GdipCreateBitmapFromGraphics(width, height, new HandleRef(g, g.NativeGraphics), out bitmap);
Gdip.CheckStatus(status);
Expand Down Expand Up @@ -107,8 +135,10 @@ public Bitmap(Image original, Size newSize) : this(original, newSize.Width, newS
{
}

public Bitmap(Image original!!, int width, int height) : this(width, height, PixelFormat.Format32bppArgb)
public Bitmap(Image original, int width, int height) : this(width, height, PixelFormat.Format32bppArgb)
{
ArgumentNullException.ThrowIfNull(original);

using (Graphics g = Graphics.FromImage(this))
{
g.Clear(Color.Transparent);
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5b55b06

Please sign in to comment.