Add everything from qtm.h

This commit is contained in:
Matt Nadareski
2023-09-19 12:37:42 -04:00
parent a3dae1b5e4
commit b4650010e0
4 changed files with 240 additions and 0 deletions

60
libmspack/qtm.cs Normal file
View File

@@ -0,0 +1,60 @@
namespace SabreTools.Compression.libmspack
{
public static class qtm
{
public const int QTM_FRAME_SIZE = 32768;
/// <summary>
/// Allocates Quantum decompression state for decoding the given stream.
///
/// - returns NULL if window_bits is outwith the range 10 to 21 (inclusive).
///
/// - uses system->alloc() to allocate memory
///
/// - returns NULL if not enough memory
///
/// - window_bits is the size of the Quantum window, from 1Kb (10) to 2Mb (21).
///
/// - input_buffer_size is the number of bytes to use to store bitstream data.
/// </summary>
/// <param name="system"></param>
/// <param name="input"></param>
/// <param name="output"></param>
/// <param name="window_bits"></param>
/// <param name="input_buffer_size"></param>
/// <returns></returns>
public static qtmd_stream qtmd_init(mspack_system system, mspack_file input, mspack_file output, int window_bits, int input_buffer_size) => null;
/// <summary>
/// Decompresses, or decompresses more of, a Quantum stream.
///
/// - out_bytes of data will be decompressed and the function will return
/// with an MSPACK_ERR_OK return code.
///
/// - decompressing will stop as soon as out_bytes is reached. if the true
/// amount of bytes decoded spills over that amount, they will be kept for
/// a later invocation of qtmd_decompress().
///
/// - the output bytes will be passed to the system->write() function given in
/// qtmd_init(), using the output file handle given in qtmd_init(). More
/// than one call may be made to system->write()
///
/// - Quantum will read input bytes as necessary using the system->read()
/// function given in qtmd_init(), using the input file handle given in
/// qtmd_init(). This will continue until system->read() returns 0 bytes,
/// or an error.
/// </summary>
/// <param name="qtm"></param>
/// <param name="out_bytes"></param>
/// <returns></returns>
public static MSPACK_ERR qtmd_decompress(qtmd_stream qtm, long out_bytes) => MSPACK_ERR.MSPACK_ERR_OK;
/// <summary>
/// Frees all state associated with a Quantum data stream
///
/// - calls system->free() using the system pointer given in qtmd_init()
/// </summary>
/// <param name="qtm"></param>
public static void qtmd_free(qtmd_stream qtm) { }
}
}

11
libmspack/qtmd_model.cs Normal file
View File

@@ -0,0 +1,11 @@
namespace SabreTools.Compression.libmspack
{
public unsafe class qtmd_model
{
public int shiftsleft { get; set; }
public int entries { get; set; }
public qtmd_modelsym** syms { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace SabreTools.Compression.libmspack
{
public class qtmd_modelsym
{
public ushort sym { get; set; }
public ushort cumfreq { get; set; }
}
}

160
libmspack/qtmd_stream.cs Normal file
View File

@@ -0,0 +1,160 @@
namespace SabreTools.Compression.libmspack
{
public unsafe class qtmd_stream
{
/// <summary>
/// I/O routines
/// </summary>
public mspack_system sys { get; set; }
/// <summary>
/// Input file handle
/// </summary>
public mspack_file input { get; set; }
/// <summary>
/// Output file handle
/// </summary>
public mspack_file output { get; set; }
/// <summary>
/// Decoding window
/// </summary>
public byte* window { get; set; }
/// <summary>
/// Window size
/// </summary>
public uint window_size { get; set; }
/// <summary>
/// Decompression offset within window
/// </summary>
public uint window_posn { get; set; }
/// <summary>
/// Bytes remaining for current frame
/// </summary>
public uint frame_todo { get; set; }
/// <summary>
/// High arith coding state
/// </summary>
public ushort H { get; set; }
/// <summary>
/// Low arith coding state
/// </summary>
public ushort L { get; set; }
/// <summary>
/// Current arith coding state
/// </summary>
public ushort C { get; set; }
/// <summary>
/// Have we started decoding a new frame?
/// </summary>
public byte header_read { get; set; }
public MSPACK_ERR error { get; set; }
#region I/O buffering
public byte* inbuf { get; set; }
public byte* i_ptr { get; set; }
public byte* i_end { get; set; }
public byte* o_ptr { get; set; }
public byte* o_end { get; set; }
public uint bit_buffer { get; set; }
public uint inbuf_size { get; set; }
public byte bits_left { get; set; }
public byte input_end { get; set; }
#endregion
#region Models
#region Four literal models, each representing 64 symbols
/// <summary>
/// model0 for literals from 0 to 63 (selector = 0)
/// </summary>
public qtmd_model model0 { get; set; }
/// <summary>
/// model1 for literals from 64 to 127 (selector = 1)
/// </summary>
public qtmd_model model1 { get; set; }
/// <summary>
/// model2 for literals from 128 to 191 (selector = 2)
/// </summary>
public qtmd_model model2 { get; set; }
/// <summary>
/// model3 for literals from 129 to 255 (selector = 3)
/// </summary>
public qtmd_model model3 { get; set; }
#endregion
#region Three match models
/// <summary>
/// model4 for match with fixed length of 3 bytes
/// </summary>
public qtmd_model model4 { get; set; }
/// <summary>
/// model5 for match with fixed length of 4 bytes
/// </summary>
public qtmd_model model5 { get; set; }
/// <summary>
/// model6 for variable length match, encoded with model6len model
/// </summary>
public qtmd_model model6 { get; set; }
public qtmd_model model6len { get; set; }
#endregion
/// <summary>
/// selector model. 0-6 to say literal (0,1,2,3) or match (4,5,6)
/// </summary>
public qtmd_model model7 { get; set; }
#endregion
#region Symbol arrays for all models
public qtmd_modelsym[] m0sym { get; set; } = new qtmd_modelsym[64 + 1];
public qtmd_modelsym[] m1sym { get; set; } = new qtmd_modelsym[64 + 1];
public qtmd_modelsym[] m2sym { get; set; } = new qtmd_modelsym[64 + 1];
public qtmd_modelsym[] m3sym { get; set; } = new qtmd_modelsym[64 + 1];
public qtmd_modelsym[] m4sym { get; set; } = new qtmd_modelsym[24 + 1];
public qtmd_modelsym[] m5sym { get; set; } = new qtmd_modelsym[36 + 1];
public qtmd_modelsym[] m6sym { get; set; } = new qtmd_modelsym[42 + 1];
public qtmd_modelsym[] m6lsym { get; set; } = new qtmd_modelsym[27 + 1];
public qtmd_modelsym[] m7sym { get; set; } = new qtmd_modelsym[7 + 1];
#endregion
}
}