mirror of
https://github.com/Const-me/Whisper.git
synced 2026-10-26 09:39:34 +08:00
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
namespace CompressTables;
|
|
using CompressShaders;
|
|
using System.IO;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
/// <summary>Utility app to compress lookup tables data with LZ4-HC, and generate C++ source with the data</summary>
|
|
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<uint8_t, {0}> 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 );
|
|
}
|
|
} |