void HuffmanDecompress(HuffmanTree tree, byte[] output) { for (int dst = 0; dst < output.Length; dst++) { output[dst] = (byte)tree.DecodeToken(this); } }
public void UnpackBlock(int offset, int length, int dst) { using (var input = new MemoryStream(this.Input, offset, length)) using (var reader = new MsbBitStream(input)) { int block_size = CbgReader.ReadInteger(input); if (-1 == block_size) { return; } var color_data = new short[block_size]; int acc = 0; for (int i = 0; i < block_size && input.Position < input.Length; i += 64) { int count = Tree1.DecodeToken(reader); if (count != 0) { int v = reader.GetBits(count); if (0 == (v >> (count - 1))) { v = (-1 << count | v) + 1; } acc += v; } color_data[i] = (short)acc; } if (0 != (reader.CacheSize & 7)) { reader.GetBits(reader.CacheSize & 7); } for (int i = 0; i < block_size && input.Position < input.Length; i += 64) { int index = 1; while (index < 64 && input.Position < input.Length) { int code = Tree2.DecodeToken(reader); if (0 == code) { break; } if (0xF == code) { index += 0x10; continue; } index += code & 0xF; if (index >= block_fill_order.Length) { break; } code >>= 4; int v = reader.GetBits(code); if (code != 0 && 0 == (v >> (code - 1))) { v = (-1 << code | v) + 1; } color_data[i + block_fill_order[index]] = (short)v; ++index; } } if (8 == BPP) { DecodeGrayscale(color_data, dst); } else { DecodeRGB(color_data, dst); } } }
void HuffmanDecompress(HuffmanTree tree, byte[] output) { for (int dst = 0; dst < output.Length; dst++) { output[dst] = (byte)tree.DecodeToken (this); } }