private static void DecodeColumn(ByteStream stream, byte[] columnOut, int compressed)
{
if (compressed == 0) {
// uncompressed.
for (int y = 0; y < columnOut.Length; ++y) {
columnOut[y] = (byte)stream.ReadByte();
}
} else if (compressed == 1) {
// rle1
for (int y = 0; y < columnOut.Length; ) {
int code = stream.ReadByte();
if (code > 128) {
byte color = (byte)stream.ReadByte();
int repeat = code & 0x7f;
while (repeat-- > 0) {
columnOut[y++] = color;
}
} else {
while (code-- > 0) {
columnOut[y++] = (byte)stream.ReadByte();
}
}
}
} else if (compressed == 2) {
// rle2 (transparent coding)
for (int y = 0; y < columnOut.Length; ) {
int code = stream.ReadByte();
if (code > 128) {
int skip = code & 0x7f;
while (skip-- > 0) {
columnOut[y++] = 0;
}
} else {
while (code-- > 0) {
columnOut[y++] = (byte)stream.ReadByte();
}
}
}
}
}