// Compress the palette data. public bool Compress() { if (CompressionUpToDate) { return(true); } byte [] buffer = new byte [Size]; for (int n = 0; n < ColorCount; n++) { int value = (R [n] >> 3) | (G [n] << 2) | (B [n] << 7); Tools.CopyBytes(value, buffer, 2 * n, 2); } Compressor c = new Compressor(buffer); CompressedData = c.Compress(); CompressionUpToDate = CompressedData != null; return(CompressionUpToDate); }
// Compress the level data. public bool Compress() { if (CompressionUpToDate) { return(true); } int L1Size = 2 * Layer1.Count; int UncompressedSize = 2 + 2 * Layer1.Count + Bts.Count + 2 * Layer2.Count; byte [] buffer = new byte [UncompressedSize]; Tools.CopyBytes(L1Size, buffer, 0, 2); int index = 2; for (int n = 0; n < Layer1.Count; n++) { Tools.CopyBytes(Layer1 [n], buffer, index, 2); index += 2; } for (int n = 0; n < Bts.Count; n++) { Tools.CopyBytes(Bts [n], buffer, index, 1); index++; } for (int n = 0; n < Layer2.Count; n++) { Tools.CopyBytes(Layer2 [n], buffer, index, 2); index += 2; } Compressor c = new Compressor(buffer); CompressedData = c.Compress(); CompressionUpToDate = CompressedData != null; return(CompressionUpToDate); }
// Decompress data to output. public int Decompress(out List <byte> output) { return(Compressor.Decompress(Data, ref Position, out output)); }