Skip to content

Commit

Permalink
Remove references to System.Drawing in EOLib.Graphics.Test
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Feb 10, 2022
1 parent 7745fd4 commit a477871
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
9 changes: 3 additions & 6 deletions EOLib.Graphics.Test/EOLib.Graphics.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<OutputPath>..\bin\$(Configuration)\test\</OutputPath>
<NoWarn>CA1416</NoWarn> <!-- TODO: Remove when using cross-platform graphics library instead of System.Drawing -->
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration.Contains(`Debug`))'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -20,7 +16,8 @@
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.0.0" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
</ItemGroup>
</Project>
12 changes: 0 additions & 12 deletions EOLib.Graphics.Test/GraphicsDeviceTestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel.Design;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

Expand All @@ -10,25 +9,15 @@ namespace EOLib.Graphics.Test
[ExcludeFromCodeCoverage]
internal sealed class GraphicsDeviceTestHelper : IDisposable
{
private readonly Form _form;
private readonly Game _game;
//private readonly ServiceContainer _serviceContainer;

public GraphicsDeviceManager GraphicsDeviceManager { get; }

public GraphicsDeviceTestHelper()
{
_form = new Form();
_game = new Game();
GraphicsDeviceManager = new GraphicsDeviceManager(_game);
_game.RunOneFrame();

//var gds = GraphicsDeviceServiceTestHelper.AddRef(_form.Handle, _form.ClientSize.Width, _form.ClientSize.Height);

//_serviceContainer = new ServiceContainer();
//_serviceContainer.AddService(typeof(IGraphicsDeviceService), gds);

//GraphicsDeviceManager.ApplyChanges();
}

public void Dispose()
Expand All @@ -48,7 +37,6 @@ private void Dispose(bool disposing)
{
GraphicsDeviceManager.Dispose();
_game.Dispose();
_form.Dispose();
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions EOLib.Graphics.Test/NativeGraphicsLoaderTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using NUnit.Framework;
using Moq;
using PELoaderLib;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Formats.Bmp;

namespace EOLib.Graphics.Test
{
Expand Down Expand Up @@ -60,11 +61,11 @@ public void WhenLoadGFX_EmptyDataArray_ThrowsException()
private byte[] CreateDataArrayForBitmap()
{
byte[] array;
using (var retBmp = new Bitmap(10, 10))
using (var retBmp = new Image<Rgb24>(10, 10))
{
using (var ms = new MemoryStream())
{
retBmp.Save(ms, ImageFormat.Bmp);
retBmp.Save(ms, new BmpEncoder());
array = ms.ToArray();
}
}
Expand Down
21 changes: 11 additions & 10 deletions EOLib.Graphics.Test/NativeGraphicsManagerTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using NUnit.Framework;
using Microsoft.Xna.Framework.Graphics;
using Moq;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Drawing.Processing;

namespace EOLib.Graphics.Test
{
Expand Down Expand Up @@ -161,7 +163,7 @@ public void WhenLoadTexture_MaleHat_Transparent_SetsSpecialColorToTransparent()
Texture2D resultTexture;
using (var bmp = LoadGFXReturnsBitmap(GFXTypes.MaleHat, requestedResource))
{
FillBitmapWithColor(bmp, Color.FromArgb(0xff, 0x08, 0x00, 0x00));
FillBitmapWithColor(bmp, Color.FromRgba(0x08, 0x00, 0x00, 0xff));
resultTexture = _nativeGraphicsManager.TextureFromResource(GFXTypes.MaleHat, requestedResource, true);
}

Expand All @@ -179,7 +181,7 @@ public void WhenLoadTexture_FemaleHat_Transparent_SetsSpecialColorToTransparent(
Texture2D resultTexture;
using (var bmp = LoadGFXReturnsBitmap(GFXTypes.FemaleHat, requestedResource))
{
FillBitmapWithColor(bmp, Color.FromArgb(0xff, 0x08, 0x00, 0x00));
FillBitmapWithColor(bmp, Color.FromRgba(0x08, 0x00, 0x00, 0xff));
resultTexture = _nativeGraphicsManager.TextureFromResource(GFXTypes.FemaleHat, requestedResource, true);
}

Expand All @@ -201,9 +203,9 @@ public void WhenLoadTexture_RaceCondition_DisposesExistingCachedTextureAndReturn
Assert.IsFalse(resultTexture.IsDisposed);
}

private Bitmap LoadGFXReturnsBitmap(GFXTypes whichFile, int requestedResource, Action loadCallback = null)
private IImage LoadGFXReturnsBitmap(GFXTypes whichFile, int requestedResource, Action loadCallback = null)
{
var bitmapToReturn = new Bitmap(10, 10, PixelFormat.Format24bppRgb);
var bitmapToReturn = new Image<Rgba32>(10, 10);

var graphicsLoaderMock = Mock.Get(_graphicsLoader);
graphicsLoaderMock.Setup(x => x.LoadGFX(whichFile, requestedResource))
Expand All @@ -213,11 +215,10 @@ private Bitmap LoadGFXReturnsBitmap(GFXTypes whichFile, int requestedResource, A
return bitmapToReturn;
}

private static void FillBitmapWithColor(Bitmap bitmap, Color color)
private static void FillBitmapWithColor(IImage image, Color color)
{
for(int row = 0; row < bitmap.Height; ++row)
for (int col = 0; col < bitmap.Width; ++col)
bitmap.SetPixel(col, row, color);
var colorBrush = new SolidBrush(color);
((Image)image).Mutate(x => x.Clear(colorBrush));
}

private void GetTextureAgain(GFXTypes whichFile, int requestedResource)
Expand Down
1 change: 0 additions & 1 deletion EOLib.Graphics/EOLib.Graphics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.0.0" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>
</Project>

0 comments on commit a477871

Please sign in to comment.