Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/NesTiler.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-09-28 15:56:28 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-09-28 15:56:28 +0300
commit0d50f7f46719ade1d1e06c0ab4f63ecf10fab224 (patch)
treebe2bb58c68bac7272127352ad0bf3196cd0acafd /NesTiler
parentd8a7347e0138124b75aceb7e6b65136becffe42f (diff)
Benchmarks and optimization
Diffstat (limited to 'NesTiler')
-rw-r--r--NesTiler/NesTiler.csproj24
-rw-r--r--NesTiler/Program.cs29
2 files changed, 28 insertions, 25 deletions
diff --git a/NesTiler/NesTiler.csproj b/NesTiler/NesTiler.csproj
index b0d4891..9c0f8bd 100644
--- a/NesTiler/NesTiler.csproj
+++ b/NesTiler/NesTiler.csproj
@@ -1,31 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
-
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net5.0</TargetFramework>
+ <TargetFramework>net6.0</TargetFramework>
<RootNamespace>com.clusterrr.Famicom.NesTiler</RootNamespace>
<AssemblyName>nestiler</AssemblyName>
</PropertyGroup>
-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
-
<ItemGroup>
<None Remove=".git" />
</ItemGroup>
-
<ItemGroup>
<PackageReference Include="ColorMinePortable" Version="2.0.1" />
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
+ <PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.346202">
+ <PrivateAssets>all</PrivateAssets>
+ </PackageReference>
</ItemGroup>
-
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
@@ -33,14 +30,12 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
-
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
-
<ItemGroup>
<None Update="nestiler-colors.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -48,14 +43,15 @@
</None>
<None Include="..\LICENSE">
<Pack>True</Pack>
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory><ExcludeFromSingleFile>true</ExcludeFromSingleFile>
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
<None Include="..\README.md">
<Pack>True</Pack>
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory><ExcludeFromSingleFile>true</ExcludeFromSingleFile>
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
</ItemGroup>
-
<PropertyGroup>
<DebugType>embedded</DebugType>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
@@ -68,9 +64,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Product>NesTiler</Product>
</PropertyGroup>
-
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="make commit buildtime&#xD;&#xA;" />
</Target>
-
-</Project>
+</Project> \ No newline at end of file
diff --git a/NesTiler/Program.cs b/NesTiler/Program.cs
index 9bb3452..f30c875 100644
--- a/NesTiler/Program.cs
+++ b/NesTiler/Program.cs
@@ -12,7 +12,7 @@ using System.Text.RegularExpressions;
namespace com.clusterrr.Famicom.NesTiler
{
- class Program
+ public class Program
{
private const string REPO_PATH = "https://github.com/ClusterM/nestiler";
const string DEFAULT_COLORS_FILE = @"nestiler-colors.json";
@@ -45,7 +45,7 @@ namespace com.clusterrr.Famicom.NesTiler
Console.WriteLine(" {0,-40}{1}", "--out-attribute-table-<#> <file>", "output filename for attribute table of image number #");
}
- static int Main(string[] args)
+ public static int Main(string[] args)
{
Console.WriteLine($"NesTiler v{Assembly.GetExecutingAssembly().GetName().Version.Major}.{Assembly.GetExecutingAssembly().GetName().Version.Minor}");
Console.WriteLine($" Commit {Properties.Resources.gitCommit} @ {REPO_PATH}");
@@ -87,6 +87,8 @@ namespace com.clusterrr.Famicom.NesTiler
var outNameTable = new Dictionary<int, string>();
var outAttributeTable = new Dictionary<int, string>();
+ var nesColorsCache = new Dictionary<Color, byte>();
+
var paramRegex = new Regex(@"^--?(?<param>[a-zA-Z-]+)(?<index>[0-9]*)$");
for (int i = 0; i < args.Length; i++)
{
@@ -218,7 +220,7 @@ namespace com.clusterrr.Famicom.NesTiler
if (fixedPalettes[i] == null) continue;
var colorsInPalette = fixedPalettes[i].ToArray();
for (int j = 0; j < colorsInPalette.Length; j++)
- colorsInPalette[j] = nesColors[FindSimilarColor(nesColors, colorsInPalette[j])];
+ colorsInPalette[j] = nesColors[FindSimilarColor(nesColors, colorsInPalette[j], nesColorsCache)];
fixedPalettes[i] = new Palette(colorsInPalette);
}
@@ -264,7 +266,7 @@ namespace com.clusterrr.Famicom.NesTiler
for (int x = 0; x < image.Width; x++)
{
var color = image.GetPixel(x, y);
- var similarColor = nesColors[FindSimilarColor(nesColors, color)];
+ var similarColor = nesColors[FindSimilarColor(nesColors, color, nesColorsCache)];
image.SetPixel(x, y, similarColor);
}
}
@@ -274,7 +276,7 @@ namespace com.clusterrr.Famicom.NesTiler
if (bgColor.HasValue)
{
// Manually
- bgColor = nesColors[FindSimilarColor(nesColors, bgColor.Value)];
+ bgColor = nesColors[FindSimilarColor(nesColors, bgColor.Value, nesColorsCache)];
}
else
{
@@ -453,7 +455,7 @@ namespace com.clusterrr.Famicom.NesTiler
}
// Calculate palette as color indices and save them to files
- var bgColorId = FindSimilarColor(nesColors, bgColor.Value);
+ var bgColorId = FindSimilarColor(nesColors, bgColor.Value, nesColorsCache);
for (int p = 0; p < palettes.Length; p++)
{
if (paletteEnabled[p] && outPalette.ContainsKey(p))
@@ -465,7 +467,7 @@ namespace com.clusterrr.Famicom.NesTiler
if (palettes[p] == null)
paletteRaw[c] = 0;
else if (palettes[p][c].HasValue)
- paletteRaw[c] = FindSimilarColor(nesColors, palettes[p][c].Value);
+ paletteRaw[c] = FindSimilarColor(nesColors, palettes[p][c].Value, nesColorsCache);
}
File.WriteAllBytes(outPalette[p], paletteRaw);
Console.WriteLine($"Palette #{p} saved to {outPalette[p]}");
@@ -671,16 +673,21 @@ namespace com.clusterrr.Famicom.NesTiler
catch (Exception ex)
{
#if DEBUG
- Console.WriteLine($"Error: {ex.GetType()}: {ex.Message}{ex.StackTrace}");
+ Console.Error.WriteLine($"Error: {ex.GetType()}: {ex.Message}{ex.StackTrace}");
#else
- Console.WriteLine($"Error: {ex.GetType()}: {ex.Message}");
+ Console.Error.WriteLine($"Error: {ex.GetType()}: {ex.Message}");
#endif
return 1;
}
}
- static byte FindSimilarColor(Dictionary<byte, Color> colors, Color color)
+ static byte FindSimilarColor(Dictionary<byte, Color> colors, Color color, Dictionary<Color, byte> cache = null)
{
+ if (cache != null)
+ {
+ if (cache.ContainsKey(color))
+ return cache[color];
+ }
byte result = byte.MaxValue;
double minDelta = double.MaxValue;
foreach (var index in colors.Keys)
@@ -694,6 +701,8 @@ namespace com.clusterrr.Famicom.NesTiler
}
if (result == byte.MaxValue)
throw new KeyNotFoundException("Invalid color: " + color.ToString());
+ if (cache != null)
+ cache[color] = result;
return result;
}