Skip to content

Commit

Permalink
Removed System.Drawing dependency as it did not behave well on Mac or…
Browse files Browse the repository at this point in the history
… Linux
  • Loading branch information
carljohnsen committed Feb 5, 2024
1 parent 8f80620 commit 0c30d39
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/Examples/ColorBin/ColorBin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
</ItemGroup>

<PropertyGroup>
Expand Down
11 changes: 6 additions & 5 deletions src/Examples/ColorBin/ImageInputSimulator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using SME;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SME;
using System;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -56,18 +58,17 @@ public override async Task Run()
{
Debug.Assert(System.IO.File.Exists(file), $"File not found: {file}");

using (var img = System.Drawing.Image.FromFile(file))
using (var bmp = new System.Drawing.Bitmap(img))
using (var img = Image.Load<Rgb24>(file))
{
Console.WriteLine($"Writing {bmp.Width * bmp.Height} pixels from {file}");
Console.WriteLine($"Writing {img.Width * img.Height} pixels from {file}");

Data.IsValid = true;

for (var i = 0; i < img.Height; i++)
{
for (var j = 0; j < img.Width; j++)
{
var pixel = bmp.GetPixel(j, i);
var pixel = img[j, i];
Data.R = pixel.R;
Data.G = pixel.G;
Data.B = pixel.B;
Expand Down
18 changes: 9 additions & 9 deletions src/Examples/NoiseFilter/ImageInputSimulator.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SME;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using SME;


namespace NoiseFilter
Expand Down Expand Up @@ -65,14 +66,13 @@ public override async Task Run()
while (!Delay.IsReady)
await ClockAsync();

using (var img = Image.FromFile(file))
using (var bmp = new Bitmap(img))
using (var img = Image.Load<Rgb24>(file))
{
Console.WriteLine($"Writing {bmp.Width * bmp.Height} pixels from {file}");
Console.WriteLine($"Writing {img.Width * img.Height} pixels from {file}");

Configuration.IsValid = true;
Configuration.Width = (ushort)bmp.Width;
Configuration.Height = (ushort)bmp.Height;
Configuration.Width = (ushort)img.Width;
Configuration.Height = (ushort)img.Height;

await ClockAsync();

Expand All @@ -83,7 +83,7 @@ public override async Task Run()
{
for (var j = 0; j < img.Width; j++)
{
var pixel = bmp.GetPixel(j, i);
var pixel = img[j, i];
Data.Color[0] = pixel.R;
Data.Color[1] = pixel.G;
Data.Color[2] = pixel.B;
Expand Down
23 changes: 12 additions & 11 deletions src/Examples/NoiseFilter/ImageOutputSink.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SME;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
using SME;

namespace NoiseFilter
{
Expand All @@ -23,22 +24,22 @@ public class ImageOutputSink : SimulationProcess

private class Item : IDisposable
{
private readonly Bitmap m_image;
private Bitmap m_image_expected;
private readonly Image<Rgb24> m_image;
private Image<Rgb24> m_image_expected;
private int m_index;
private static int _imageIndex;

public Item(int width, int height, string filename)
{
m_image = new Bitmap(width, height);
m_image_expected = new Bitmap(Image.FromFile(filename));
m_image = new Image<Rgb24>(width, height);
m_image_expected = Image.Load<Rgb24>(filename);
}

public void WritePixel(byte r, byte g, byte b)
{
var color = Color.FromArgb(r, g, b);
Debug.Assert(m_image_expected.GetPixel(X, Y).Equals(color), $"Error when comparing pixels, expected {m_image_expected.GetPixel(X,Y)}, got {color}");
m_image.SetPixel(X, Y, color);
var color = new Rgb24(r, g, b);
Debug.Assert(m_image_expected[X, Y].Equals(color), $"Error when comparing pixels, expected {m_image_expected[X, Y]}, got {color}");
m_image[X, Y] = color;
m_index++;
}

Expand All @@ -48,7 +49,7 @@ public void Dispose()
{
System.IO.Directory.CreateDirectory("output");
var filename = string.Format("output/output-{0}.png", System.Threading.Interlocked.Increment(ref _imageIndex));
m_image.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
m_image.SaveAsPng(filename);
m_image.Dispose();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Examples/NoiseFilter/NoiseFilter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
</ItemGroup>

<PropertyGroup>
Expand Down

0 comments on commit 0c30d39

Please sign in to comment.