private bool readTables() { byte[] bitLength = new byte[Compress.BC]; byte[] table = new byte[Compress.HUFF_TABLE_SIZE]; if (inAddr > readTop - 25) { if (!unpReadBuf()) { return(false); } } AddBits((8 - inBit) & 7); long bitField = GetBits() & unchecked ((int)0xffFFffFF); if ((bitField & 0x8000) != 0) { unpBlockType = BlockTypes.BLOCK_PPM; return(ppm.decodeInit(this, PpmEscChar)); } unpBlockType = BlockTypes.BLOCK_LZ; prevLowDist = 0; lowDistRepCount = 0; if ((bitField & 0x4000) == 0) { Utility.Fill(unpOldTable, (byte)0); // memset(UnpOldTable,0,sizeof(UnpOldTable)); } AddBits(2); for (int i = 0; i < Compress.BC; i++) { int length = (Utility.URShift(GetBits(), 12)) & 0xFF; AddBits(4); if (length == 15) { int zeroCount = (Utility.URShift(GetBits(), 12)) & 0xFF; AddBits(4); if (zeroCount == 0) { bitLength[i] = 15; } else { zeroCount += 2; while (zeroCount-- > 0 && i < bitLength.Length) { bitLength[i++] = 0; } i--; } } else { bitLength[i] = (byte)length; } } UnpackUtility.makeDecodeTables(bitLength, 0, BD, Compress.BC); int TableSize = Compress.HUFF_TABLE_SIZE; for (int i = 0; i < TableSize;) { if (inAddr > readTop - 5) { if (!unpReadBuf()) { return(false); } } int Number = this.decodeNumber(BD); if (Number < 16) { table[i] = (byte)((Number + unpOldTable[i]) & 0xf); i++; } else if (Number < 18) { int N; if (Number == 16) { N = (Utility.URShift(GetBits(), 13)) + 3; AddBits(3); } else { N = (Utility.URShift(GetBits(), 9)) + 11; AddBits(7); } while (N-- > 0 && i < TableSize) { table[i] = table[i - 1]; i++; } } else { int N; if (Number == 18) { N = (Utility.URShift(GetBits(), 13)) + 3; AddBits(3); } else { N = (Utility.URShift(GetBits(), 9)) + 11; AddBits(7); } while (N-- > 0 && i < TableSize) { table[i++] = 0; } } } tablesRead = true; if (inAddr > readTop) { return(false); } UnpackUtility.makeDecodeTables(table, 0, LD, Compress.NC); UnpackUtility.makeDecodeTables(table, Compress.NC, DD, Compress.DC); UnpackUtility.makeDecodeTables(table, Compress.NC + Compress.DC, LDD, Compress.LDC); UnpackUtility.makeDecodeTables(table, Compress.NC + Compress.DC + Compress.LDC, RD, Compress.RC); // memcpy(unpOldTable,table,sizeof(unpOldTable)); Buffer.BlockCopy(table, 0, unpOldTable, 0, unpOldTable.Length); return(true); }
private bool ReadTables20() { byte[] BitLength = new byte[Compress.BC20]; byte[] Table = new byte[Compress.MC20 * 4]; int TableSize, N, I; if (inAddr > readTop - 25) { if (!unpReadBuf()) { return(false); } } int BitField = GetBits(); UnpAudioBlock = (BitField & 0x8000); if (0 == (BitField & 0x4000)) { // memset(UnpOldTable20,0,sizeof(UnpOldTable20)); Utility.Fill(UnpOldTable20, (byte)0); } AddBits(2); if (UnpAudioBlock != 0) { UnpChannels = ((Utility.URShift(BitField, 12)) & 3) + 1; if (UnpCurChannel >= UnpChannels) { UnpCurChannel = 0; } AddBits(2); TableSize = Compress.MC20 * UnpChannels; } else { TableSize = Compress.NC20 + Compress.DC20 + Compress.RC20; } for (I = 0; I < Compress.BC20; I++) { BitLength[I] = (byte)(Utility.URShift(GetBits(), 12)); AddBits(4); } UnpackUtility.makeDecodeTables(BitLength, 0, BD, Compress.BC20); I = 0; while (I < TableSize) { if (inAddr > readTop - 5) { if (!unpReadBuf()) { return(false); } } int Number = this.decodeNumber(BD); if (Number < 16) { Table[I] = (byte)((Number + UnpOldTable20[I]) & 0xf); I++; } else if (Number == 16) { N = (Utility.URShift(GetBits(), 14)) + 3; AddBits(2); while (N-- > 0 && I < TableSize) { Table[I] = Table[I - 1]; I++; } } else { if (Number == 17) { N = (Utility.URShift(GetBits(), 13)) + 3; AddBits(3); } else { N = (Utility.URShift(GetBits(), 9)) + 11; AddBits(7); } while (N-- > 0 && I < TableSize) { Table[I++] = 0; } } } if (inAddr > readTop) { return(true); } if (UnpAudioBlock != 0) { for (I = 0; I < UnpChannels; I++) { UnpackUtility.makeDecodeTables(Table, I * Compress.MC20, MD[I], Compress.MC20); } } else { UnpackUtility.makeDecodeTables(Table, 0, LD, Compress.NC20); UnpackUtility.makeDecodeTables(Table, Compress.NC20, DD, Compress.DC20); UnpackUtility.makeDecodeTables(Table, Compress.NC20 + Compress.DC20, RD, Compress.RC20); } // memcpy(UnpOldTable20,Table,sizeof(UnpOldTable20)); for (int i = 0; i < UnpOldTable20.Length; i++) { UnpOldTable20[i] = Table[i]; } return(true); }