public SubchunkCompression(DataReader sourceData) { source_ = sourceData; byte version = sourceData.ReadByte(); if (version > 8) { throw new InvalidDataException($"Invalid version {version}; expected 0-8"); } version_ = version; if (version_ == 8) { int blockStorageCount = sourceData.ReadByte(); for (int i = 0; i < 1; i++) { byte type = sourceData.ReadByte(); bool networkMode = ((type & 0x1) == 1); PalettedCompressionType compressionType = (PalettedCompressionType)((type & (byte)PalettedCompressionType.BIT_MASK) >> 1); type_ = compressionType; if (GetStorageParameters(type_, out int size, out int padding)) { offsetToPalette_ = 3 + // version, block storage, compression type size + padding; } else { throw new InvalidDataException($"Unsupported compression type value {type_}"); } }
private static bool GetIndexReaderParameters(PalettedCompressionType type, out uint[] masks, out uint width, out uint count, out int initialOffset) { switch (type) { case PalettedCompressionType.Paletted1: masks = PAL1_MASKS; width = PAL1_WIDTH; initialOffset = PAL1_FIRST_OFFSET; count = 32; return(true); case PalettedCompressionType.Paletted2: masks = PAL2_MASKS; width = PAL2_WIDTH; initialOffset = PAL2_FIRST_OFFSET; count = 16; return(true); case PalettedCompressionType.Paletted3: masks = PAL3_MASKS; width = PAL3_WIDTH; initialOffset = PAL3_FIRST_OFFSET; count = 10; return(true); case PalettedCompressionType.Paletted4: masks = PAL4_MASKS; width = PAL4_WIDTH; initialOffset = PAL4_FIRST_OFFSET; count = 8; return(true); case PalettedCompressionType.Paletted5: masks = PAL5_MASKS; width = PAL5_WIDTH; initialOffset = PAL5_FIRST_OFFSET; count = 6; return(true); case PalettedCompressionType.Paletted6: masks = PAL6_MASKS; width = PAL6_WIDTH; initialOffset = PAL6_FIRST_OFFSET; count = 5; return(true); case PalettedCompressionType.Paletted8: masks = PAL8_MASKS; width = PAL8_WIDTH; initialOffset = PAL8_FIRST_OFFSET; count = 4; return(true); case PalettedCompressionType.Paletted16: masks = PAL16_MASKS; width = PAL16_WIDTH; initialOffset = PAL16_FIRST_OFFSET; count = 2; return(true); default: masks = null; width = 0; initialOffset = 0; count = 0; return(false); } }
public NumberSpan(uint n, PalettedCompressionType type) { n_ = n; type_ = type; }