namespace CompressTables;
using CompressShaders;
using System.IO;
using System.Runtime.CompilerServices;
/// Utility app to compress lookup tables data with LZ4-HC, and generate C++ source with the data
internal class Program
{
static string getSolutionRoot( [CallerFilePath] string? path = null )
{
string? dir = Path.GetDirectoryName( path );
dir = Path.GetDirectoryName( dir );
dir = Path.GetDirectoryName( dir );
return dir ?? throw new ApplicationException();
}
static void writeArray( byte[] compressed, string path )
{
using var stream = File.CreateText( path );
stream.WriteLine( "// This source file is generated by a tool" );
stream.Write( @"static const std::array s_tableData = {{", compressed.Length );
for( int i = 0; i < compressed.Length; i++ )
{
if( 0 == i % 32 )
stream.Write( "\r\n\t" );
else
stream.Write( ' ' );
stream.Write( "0x{0:X02},", compressed[ i ] );
}
stream.Write( @"
};" );
}
static void Main( string[] args )
{
byte[] source = File.ReadAllBytes( @"C:\Temp\2remove\Whisper\tables.bin" );
byte[] result = LZ4.compressBuffer( source );
string root = getSolutionRoot();
string path = Path.Combine( root, "Whisper", "ML", "LookupTablesData.inl" );
writeArray( result, path );
}
}