Skip to content

Commit

Permalink
Switched 3D Lut generation to StringBuilder for massive speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomArrow committed Jan 23, 2021
1 parent f6f1d6f commit ac5f9d7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ColorMatch3D.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
</Reference>
<Reference Include="Ookii.Dialogs.Wpf, Version=3.0.0.0, Culture=neutral, PublicKeyToken=66aa232afad40158, processorArchitecture=MSIL">
<HintPath>packages\Ookii.Dialogs.Wpf.3.1.0\lib\net45\Ookii.Dialogs.Wpf.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll</HintPath>
Expand All @@ -72,6 +75,7 @@
<HintPath>packages\System.Console.4.3.0\lib\net46\System.Console.dll</HintPath>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -106,6 +110,7 @@
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
<Reference Include="System.Security" />
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net46\System.Security.Cryptography.Algorithms.dll</HintPath>
</Reference>
Expand Down
13 changes: 10 additions & 3 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using System.Numerics;
using Win = System.Windows;
using System.Windows.Controls;
using System.Globalization;
using System.Text;

namespace ColorMatch3D
{
Expand Down Expand Up @@ -1194,7 +1196,11 @@ private void BtnMakeLUT_Click(object sender, win.RoutedEventArgs e)
//sfd.FileName = ;
if (sfd.ShowDialog() == true)
{
string luttext = "LUT_3D_SIZE "+ outputValueCount + "\n";
//string luttext = "LUT_3D_SIZE "+ outputValueCount + "\n";

int floatStringLength = ((float)Math.PI).ToString().Length;

StringBuilder sb = new StringBuilder("LUT_3D_SIZE " + outputValueCount + "\n", cube.Length* (floatStringLength+1));

for (int b = 0; b < outputValueCount; b++)
{
Expand All @@ -1208,12 +1214,13 @@ private void BtnMakeLUT_Click(object sender, win.RoutedEventArgs e)
red = float.IsNaN(cube[r, g, b].color.X) ? 0 : cube[r, g, b].color.X/255;
green = float.IsNaN(cube[r, g, b].color.Y) ?0 : cube[r, g, b].color.Y/255;
blue = float.IsNaN(cube[r, g, b].color.Z) ? 0 : cube[r, g, b].color.Z/255;
luttext += red + " " + green + " " + blue+"\n";
//luttext += red.ToString(CultureInfo.InvariantCulture) + " " + green.ToString(CultureInfo.InvariantCulture) + " " + blue.ToString(CultureInfo.InvariantCulture) + "\n";
sb.Append( red.ToString(CultureInfo.InvariantCulture) + " " + green.ToString(CultureInfo.InvariantCulture) + " " + blue.ToString(CultureInfo.InvariantCulture) + "\n");
}
}
}

File.WriteAllText(sfd.FileName, luttext);
File.WriteAllText(sfd.FileName, sb.ToString());
}
}

Expand Down
1 change: 1 addition & 0 deletions packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<package id="Microsoft.NETCore.Platforms" version="2.2.2" targetFramework="net46" />
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net46" />
<package id="NETStandard.Library" version="2.0.3" targetFramework="net46" />
<package id="Ookii.Dialogs.Wpf" version="3.1.0" targetFramework="net462" />
<package id="System.AppContext" version="4.3.0" targetFramework="net46" />
<package id="System.Collections" version="4.3.0" targetFramework="net46" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net46" />
Expand Down

0 comments on commit ac5f9d7

Please sign in to comment.