From 973a94b3408bb4457600ef1b67df51c3eadc495f Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 22 Sep 2025 10:33:33 -0400 Subject: [PATCH] Move LZX models to IO --- .../Compression/LZX/AlignedOffsetBlockData.cs | 58 ------------------- SabreTools.Models/Compression/LZX/Block.cs | 24 -------- .../Compression/LZX/BlockData.cs | 8 --- .../Compression/LZX/BlockHeader.cs | 33 ----------- SabreTools.Models/Compression/LZX/Chunk.cs | 25 -------- .../Compression/LZX/ChunkHeader.cs | 46 --------------- .../Compression/LZX/Constants.cs | 38 ------------ SabreTools.Models/Compression/LZX/Enums.cs | 48 --------------- .../Compression/LZX/UncompressedBlockData.cs | 54 ----------------- .../Compression/LZX/VerbatimBlockData.cs | 51 ---------------- 10 files changed, 385 deletions(-) delete mode 100644 SabreTools.Models/Compression/LZX/AlignedOffsetBlockData.cs delete mode 100644 SabreTools.Models/Compression/LZX/Block.cs delete mode 100644 SabreTools.Models/Compression/LZX/BlockData.cs delete mode 100644 SabreTools.Models/Compression/LZX/BlockHeader.cs delete mode 100644 SabreTools.Models/Compression/LZX/Chunk.cs delete mode 100644 SabreTools.Models/Compression/LZX/ChunkHeader.cs delete mode 100644 SabreTools.Models/Compression/LZX/Constants.cs delete mode 100644 SabreTools.Models/Compression/LZX/Enums.cs delete mode 100644 SabreTools.Models/Compression/LZX/UncompressedBlockData.cs delete mode 100644 SabreTools.Models/Compression/LZX/VerbatimBlockData.cs diff --git a/SabreTools.Models/Compression/LZX/AlignedOffsetBlockData.cs b/SabreTools.Models/Compression/LZX/AlignedOffsetBlockData.cs deleted file mode 100644 index 4f0e193..0000000 --- a/SabreTools.Models/Compression/LZX/AlignedOffsetBlockData.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace SabreTools.Models.Compression.LZX -{ - /// - /// An aligned offset block is identical to the verbatim block except for the presence of the aligned offset - /// tree preceding the other trees. - /// - /// - public class AlignedOffsetBlockData : BlockData - { - /// - /// Aligned offset tree - /// - /// 8 elements, 3 bits each - public byte[]? AlignedOffsetTree { get; set; } - - /// - /// Pretree for first 256 elements of main tree - /// - /// 20 elements, 4 bits each - public byte[]? PretreeFirst256 { get; set; } - - /// - /// Path lengths of first 256 elements of main tree - /// - /// Encoded using pretree - public int[]? PathLengthsFirst256 { get; set; } - - /// - /// Pretree for remainder of main tree - /// - /// 20 elements, 4 bits each - public byte[]? PretreeRemainder { get; set; } - - /// - /// Path lengths of remaining elements of main tree - /// - /// Encoded using pretree - public int[]? PathLengthsRemainder { get; set; } - - /// - /// Pretree for length tree - /// - /// 20 elements, 4 bits each - public byte[]? PretreeLengthTree { get; set; } - - /// - /// Path lengths of elements in length tree - /// - /// Encoded using pretree - public int[]? PathLengthsLengthTree { get; set; } - - /// - /// Token sequence (matches and literals) - /// - /// Variable - public byte[]? TokenSequence { get; set; } - } -} \ No newline at end of file diff --git a/SabreTools.Models/Compression/LZX/Block.cs b/SabreTools.Models/Compression/LZX/Block.cs deleted file mode 100644 index 2bdb7d5..0000000 --- a/SabreTools.Models/Compression/LZX/Block.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace SabreTools.Models.Compression.LZX -{ - /// - /// An LZXD block represents a sequence of compressed data that is encoded with the same set of - /// Huffman trees, or a sequence of uncompressed data. There can be one or more LZXD blocks in a - /// compressed stream, each with its own set of Huffman trees. Blocks do not have to start or end on a - /// chunk boundary; blocks can span multiple chunks, or a single chunk can contain multiple blocks. The - /// number of chunks is related to the size of the data being compressed, while the number of blocks is - /// related to how well the data is compressed. - /// - /// - public class Block - { - /// - /// Block header - /// - public BlockHeader? Header { get; set; } - - /// - /// Block data - /// - public BlockData? BlockData { get; set; } - } -} \ No newline at end of file diff --git a/SabreTools.Models/Compression/LZX/BlockData.cs b/SabreTools.Models/Compression/LZX/BlockData.cs deleted file mode 100644 index 939f9c9..0000000 --- a/SabreTools.Models/Compression/LZX/BlockData.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SabreTools.Models.Compression.LZX -{ - /// - public abstract class BlockData - { - // No common fields between all block data - } -} \ No newline at end of file diff --git a/SabreTools.Models/Compression/LZX/BlockHeader.cs b/SabreTools.Models/Compression/LZX/BlockHeader.cs deleted file mode 100644 index bd10219..0000000 --- a/SabreTools.Models/Compression/LZX/BlockHeader.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace SabreTools.Models.Compression.LZX -{ - /// - /// The Block Type field, as specified in section 2.3.1.1, indicates which type of block follows, - /// and the Block Size field, as specified in section 2.3.1.2, indicates the number of - /// uncompressed bytes represented by the block. Following the generic block - /// header is a type-specific header that describes the remainder of the block. - /// - /// - public class BlockHeader - { - /// 3 bits - public BlockType BlockType { get; set; } - - /// - /// Block size is the high 8 bits of 24 - /// - /// 8 bits - public byte BlockSizeMSB { get; set; } - - /// - /// Block size is the middle 8 bits of 24 - /// - /// 8 bits - public byte BlockSizeByte2 { get; set; } - - /// - /// Block size is the low 8 bits of 24 - /// - /// 8 bits - public byte BlocksizeLSB { get; set; } - } -} \ No newline at end of file diff --git a/SabreTools.Models/Compression/LZX/Chunk.cs b/SabreTools.Models/Compression/LZX/Chunk.cs deleted file mode 100644 index dc64180..0000000 --- a/SabreTools.Models/Compression/LZX/Chunk.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace SabreTools.Models.Compression.LZX -{ - /// - /// The LZXD compressor emits chunks of compressed data. A chunk represents exactly 32 KB of - /// uncompressed data until the last chunk in the stream, which can represent less than 32 KB. To - /// ensure that an exact number of input bytes represent an exact number of output bytes for each - /// chunk, after each 32 KB of uncompressed data is represented in the output compressed bitstream, the - /// output bitstream is padded with up to 15 bits of zeros to realign the bitstream on a 16-bit boundary - /// (even byte boundary) for the next 32 KB of data. This results in a compressed chunk of a byte-aligned - /// size. The compressed chunk could be smaller than 32 KB or larger than 32 KB if the data is - /// incompressible when the chunk is not the last one. - /// - public class Chunk - { - /// - /// Chunk header - /// - public ChunkHeader? Header { get; set; } - - /// - /// Block headers and data - /// - public Block[]? Blocks { get; set; } - } -} \ No newline at end of file diff --git a/SabreTools.Models/Compression/LZX/ChunkHeader.cs b/SabreTools.Models/Compression/LZX/ChunkHeader.cs deleted file mode 100644 index bebe36d..0000000 --- a/SabreTools.Models/Compression/LZX/ChunkHeader.cs +++ /dev/null @@ -1,46 +0,0 @@ -namespace SabreTools.Models.Compression.LZX -{ - /// - /// The LZXD compressor emits chunks of compressed data. A chunk represents exactly 32 KB of - /// uncompressed data until the last chunk in the stream, which can represent less than 32 KB. To - /// ensure that an exact number of input bytes represent an exact number of output bytes for each - /// chunk, after each 32 KB of uncompressed data is represented in the output compressed bitstream, the - /// output bitstream is padded with up to 15 bits of zeros to realign the bitstream on a 16-bit boundary - /// (even byte boundary) for the next 32 KB of data. This results in a compressed chunk of a byte-aligned - /// size. The compressed chunk could be smaller than 32 KB or larger than 32 KB if the data is - /// incompressible when the chunk is not the last one. - /// - public class ChunkHeader - { - /// - /// The LZXD engine encodes a compressed, chunk-size prefix field preceding each compressed chunk in - /// the compressed byte stream. The compressed, chunk-size prefix field is a byte aligned, little-endian, - /// 16-bit field. The chunk prefix chain could be followed in the compressed stream without - /// decompressing any data. The next chunk prefix is at a location computed by the absolute byte offset - /// location of this chunk prefix plus 2 (for the size of the chunk-size prefix field) plus the current chunk - /// size. - /// - public ushort ChunkSize { get; set; } - - /// - /// The first bit in the first chunk in the LZXD bitstream (following the 2-byte, chunk-size prefix described - /// in section 2.2.1) indicates the presence or absence of two 16-bit fields immediately following the - /// single bit. If the bit is set, E8 translation is enabled for all the following chunks in the stream using the - /// 32-bit value derived from the two 16-bit fields as the E8_file_size provided to the compressor when E8 - /// translation was enabled. Note that E8_file_size is completely independent of the length of the - /// uncompressed data. E8 call translation is disabled after the 32,768th chunk (after 1 gigabyte (GB) of - /// uncompressed data). - /// - public byte E8Translation { get; set; } - - /// - /// E8 translation size, high WORD - /// - public ushort? TranslationSizeHighWord { get; set; } - - /// - /// E8 translation size, low WORD - /// - public ushort? TranslationSizeLowWord { get; set; } - } -} \ No newline at end of file diff --git a/SabreTools.Models/Compression/LZX/Constants.cs b/SabreTools.Models/Compression/LZX/Constants.cs deleted file mode 100644 index 07c0330..0000000 --- a/SabreTools.Models/Compression/LZX/Constants.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace SabreTools.Models.Compression.LZX -{ - public static class Constants - { - /* some constants defined by the LZX specification */ - public const int LZX_MIN_MATCH = 2; - public const int LZX_MAX_MATCH = 257; - public const int LZX_NUM_CHARS = 256; - public const int LZX_PRETREE_NUM_ELEMENTS = 20; - - /// - /// aligned offset tree #elements - /// - public const int LZX_ALIGNED_NUM_ELEMENTS = 8; - - /// - /// this one missing from spec! - /// - public const int LZX_NUM_PRIMARY_LENGTHS = 7; - - /// - /// length tree #elements - /// - public const int LZX_NUM_SECONDARY_LENGTHS = 249; - - /* LZX huffman defines: tweak tablebits as desired */ - public const int LZX_PRETREE_MAXSYMBOLS = LZX_PRETREE_NUM_ELEMENTS; - public const int LZX_PRETREE_TABLEBITS = 6; - public const int LZX_MAINTREE_MAXSYMBOLS = LZX_NUM_CHARS + 50 * 8; - public const int LZX_MAINTREE_TABLEBITS = 12; - public const int LZX_LENGTH_MAXSYMBOLS = LZX_NUM_SECONDARY_LENGTHS + 1; - public const int LZX_LENGTH_TABLEBITS = 12; - public const int LZX_ALIGNED_MAXSYMBOLS = LZX_ALIGNED_NUM_ELEMENTS; - public const int LZX_ALIGNED_TABLEBITS = 7; - - public const int LZX_LENTABLE_SAFETY = 64; /* we allow length table decoding overruns */ - } -} \ No newline at end of file diff --git a/SabreTools.Models/Compression/LZX/Enums.cs b/SabreTools.Models/Compression/LZX/Enums.cs deleted file mode 100644 index dffa0ef..0000000 --- a/SabreTools.Models/Compression/LZX/Enums.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace SabreTools.Models.Compression.LZX -{ - /// - /// 3-bit block type - /// - public enum BlockType : byte - { - /// - /// Not valid - /// - INVALID_0 = 0b000, - - /// - /// Verbatim block - /// - Verbatim = 0b001, - - /// - /// Aligned offset block - /// - AlignedOffset = 0b010, - - /// - /// Uncompressed block - /// - Uncompressed = 0b011, - - /// - /// Not valid - /// - INVALID_4 = 0b100, - - /// - /// Not valid - /// - INVALID_5 = 0b101, - - /// - /// Not valid - /// - INVALID_6 = 0b110, - - /// - /// Not valid - /// - INVALID_7 = 0b111, - } -} diff --git a/SabreTools.Models/Compression/LZX/UncompressedBlockData.cs b/SabreTools.Models/Compression/LZX/UncompressedBlockData.cs deleted file mode 100644 index 1a36299..0000000 --- a/SabreTools.Models/Compression/LZX/UncompressedBlockData.cs +++ /dev/null @@ -1,54 +0,0 @@ -namespace SabreTools.Models.Compression.LZX -{ - /// - /// Following the generic block header, an uncompressed block begins with 1 to 16 bits of zero padding - /// to align the bit buffer on a 16-bit boundary. At this point, the bitstream ends and a byte stream - /// begins. Following the zero padding, new 32-bit values for R0, R1, and R2 are output in little-endian - /// form, followed by the uncompressed data bytes themselves. Finally, if the uncompressed data length - /// is odd, one extra byte of zero padding is encoded to realign the following bitstream. - /// - /// Then the bitstream of byte-swapped 16-bit integers resumes for the next Block Type field (if there - /// are subsequent blocks). - /// - /// The decoded R0, R1, and R2 values are used as initial repeated offset values to decode the - /// subsequent compressed block if present. - /// - /// - public class UncompressedBlockData : BlockData - { - /// - /// Padding to align following field on 16-bit boundary - /// - /// Bits have a value of zero - public ushort PaddingBits { get; set; } - - /// - /// Least significant to most significant byte (little-endian DWORD ([MS-DTYP])) - /// - /// Encoded directly in the byte stream, not in the bitstream of byte-swapped 16-bit words - public uint R0 { get; set; } - - /// - /// Least significant to most significant byte (little-endian DWORD) - /// - /// Encoded directly in the byte stream, not in the bitstream of byte-swapped 16-bit words - public uint R1 { get; set; } - - /// - /// Least significant to most significant byte (little-endian DWORD) - /// - /// Encoded directly in the byte stream, not in the bitstream of byte-swapped 16-bit words - public uint R2 { get; set; } - - /// - /// Can use the direct memcpy function, as specified in [IEEE1003.1] - /// - /// Encoded directly in the byte stream, not in the bitstream of byte-swapped 16-bit words - public byte[]? RawDataBytes { get; set; } - - /// - /// Only if uncompressed size is odd - /// - public byte AlignmentByte { get; set; } - } -} \ No newline at end of file diff --git a/SabreTools.Models/Compression/LZX/VerbatimBlockData.cs b/SabreTools.Models/Compression/LZX/VerbatimBlockData.cs deleted file mode 100644 index 82c625e..0000000 --- a/SabreTools.Models/Compression/LZX/VerbatimBlockData.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace SabreTools.Models.Compression.LZX -{ - /// - /// The fields of a verbatim block that follow the generic block header - /// - /// - public class VerbatimBlockData : BlockData - { - /// - /// Pretree for first 256 elements of main tree - /// - /// 20 elements, 4 bits each - public byte[]? PretreeFirst256 { get; set; } - - /// - /// Path lengths of first 256 elements of main tree - /// - /// Encoded using pretree - public int[]? PathLengthsFirst256 { get; set; } - - /// - /// Pretree for remainder of main tree - /// - /// 20 elements, 4 bits each - public byte[]? PretreeRemainder { get; set; } - - /// - /// Path lengths of remaining elements of main tree - /// - /// Encoded using pretree - public int[]? PathLengthsRemainder { get; set; } - - /// - /// Pretree for length tree - /// - /// 20 elements, 4 bits each - public byte[]? PretreeLengthTree { get; set; } - - /// - /// Path lengths of elements in length tree - /// - /// Encoded using pretree - public int[]? PathLengthsLengthTree { get; set; } - - /// - /// Token sequence (matches and literals) - /// - /// Variable - public byte[]? TokenSequence { get; set; } - } -} \ No newline at end of file