Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/bobbahbrown/DMISharp
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbah committed Jul 22, 2024
2 parents fe5e863 + 56e662d commit 4aa723f
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 28 deletions.
17 changes: 15 additions & 2 deletions DMISharp.Benchmark/DMIBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@
using System.IO;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;

namespace DMISharp.Benchmark;

[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net70)]
[MemoryDiagnoser, Config(typeof(DMIBenchmarkConfig))]
[SuppressMessage("Performance", "CA1822:Mark members as static")]
public class DMIBenchmarks
{
private class DMIBenchmarkConfig : ManualConfig
{
public DMIBenchmarkConfig()
{
var baseJob = Job.Default;

AddJob(baseJob.WithNuGet("DMISharp", "2.0.2").WithRuntime(CoreRuntime.Core70).AsBaseline());
AddJob(baseJob.WithRuntime(CoreRuntime.Core70));
AddJob(baseJob.WithRuntime(CoreRuntime.Core80));
}
}

[Benchmark]
public DMIFile ReadSmallDMIFile() => new("Data/Input/small.dmi");

Expand Down
4 changes: 2 additions & 2 deletions DMISharp.Benchmark/DMISharp.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>


Expand Down
12 changes: 6 additions & 6 deletions DMISharp.Tests/DMISharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.2">
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
17 changes: 9 additions & 8 deletions DMISharp/DMIFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ public void Save(Stream dataStream)
{
var sourceSpan = targetAccessor.GetRowSpan(ypx);
var destSpan = imgAccessor.GetRowSpan(ypx + yCap * Metadata.FrameHeight);
for (var xpx = 0; xpx < Metadata.FrameWidth; xpx++)
{
ref var sourcePixel = ref sourceSpan[xpx];
ref var destPixel = ref destSpan[xpx + xCap * Metadata.FrameWidth];
destPixel = sourcePixel;
}
sourceSpan.CopyTo(destSpan.Slice(xCap * Metadata.FrameWidth, Metadata.FrameWidth));
}
});
}
Expand Down Expand Up @@ -362,7 +357,10 @@ public void SortStates()
{
_states = _states.OrderBy(x => x.Name).ToList();
Metadata.States.Clear();
Metadata.States.AddRange(_states.Select(x => x.Data).ToList());
foreach (var state in _states)
{
Metadata.States.Add(state.Data);
}
}

/// <summary>
Expand All @@ -373,7 +371,10 @@ public void SortStates(IComparer<DMIState> comparer)
{
_states = _states.OrderBy(x => x, comparer).ToList();
Metadata.States.Clear();
Metadata.States.AddRange(_states.Select(x => x.Data).ToList());
foreach (var state in _states)
{
Metadata.States.Add(state.Data);
}
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions DMISharp/DMISharp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>DMISharp</PackageId>
Expand Down Expand Up @@ -37,17 +37,17 @@
</Target>

<ItemGroup>
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.2.2" />
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.HighPerformance" Version="7.1.2" />
<PackageReference Include="MinVer" Version="4.3.0">
<PackageReference Include="MinVer" Version="5.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
17 changes: 14 additions & 3 deletions DMISharp/Metadata/DMITokenizer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.HighPerformance.Enumerables;
using Microsoft.Toolkit.HighPerformance;
using CommunityToolkit.HighPerformance;
using CommunityToolkit.HighPerformance.Enumerables;

namespace DMISharp.Metadata;

Expand Down Expand Up @@ -85,7 +85,8 @@ public ReadOnlySpan<char> CurrentValue
/// </summary>
/// <param name="value">The value to compare against</param>
/// <returns>If the two values are equal</returns>
public readonly bool KeyEquals(ReadOnlySpan<char> value) => CurrentKey.Equals(value, StringComparison.OrdinalIgnoreCase);
public readonly bool KeyEquals(ReadOnlySpan<char> value) =>
CurrentKey.Equals(value, StringComparison.OrdinalIgnoreCase);


/// <summary>
Expand Down Expand Up @@ -140,7 +141,12 @@ public readonly double[] ValueAsDoubleArray()
{
try
{
#if (NET8_0_OR_GREATER)
var toReturn = new double[System.MemoryExtensions.Count(CurrentValue, ',') + 1];
#else
var toReturn = new double[CurrentValue.Count(',') + 1];
#endif

var span = new Span<double>(toReturn);
var currIdx = 0;
foreach (var token in CurrentValue.Tokenize(','))
Expand All @@ -166,7 +172,12 @@ public readonly int[] ValueAsIntArray()
{
try
{
#if (NET8_0_OR_GREATER)
var toReturn = new int[System.MemoryExtensions.Count(CurrentValue, ',') + 1];
#else
var toReturn = new int[CurrentValue.Count(',') + 1];
#endif

var span = new Span<int>(toReturn);
var currIdx = 0;
foreach (var token in CurrentValue.Tokenize(','))
Expand Down
2 changes: 1 addition & 1 deletion DMISharp/Quantization/NoFrillsQuantizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public NoFrillsQuantizer(Configuration configuration, QuantizerOptions options,
public ReadOnlyMemory<TPixel> Palette { get; }

public IndexedImageFrame<TPixel> QuantizeFrame(ImageFrame<TPixel> source, Rectangle bounds)
=> QuantizerUtilities.QuantizeFrame(ref Unsafe.AsRef(this), source, bounds);
=> QuantizerUtilities.QuantizeFrame(ref Unsafe.AsRef(in this), source, bounds);

public void AddPaletteColors(Buffer2DRegion<TPixel> pixelRegion)
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
DMISharp
</h1>

### **DMISharp** is a .NET 7.0 library for easily interacting with the BYOND DMI file format.
### **DMISharp** is a .NET 8.0 library for easily interacting with the BYOND DMI file format.

Developed with ease-of-use in mind, this library provides a simple means for importing, modifying, and exporting DMI files. Internally, images are handled using [ImageSharp](https://github.com/SixLabors/ImageSharp), a fantastic open-source library from SixLabors.

Expand Down

0 comments on commit 4aa723f

Please sign in to comment.