public static void DecodePackbits(byte[] data, byte[] dst)
{
int srcCount = 0, dstCount = 0;
sbyte repeat, b;
try {
while (dstCount < dst.Length) {
b = (sbyte)data[srcCount++];
if (b >= 0 && b <= 127) {
// literal run packet
for (int i=0; i<(b + 1); i++) {
dst[dstCount++] = data[srcCount++];
}
} else if (b <= -1 && b >= -127) {
// 2 byte encoded run packet
repeat = (sbyte)data[srcCount++];
for (int i=0; i<(-b + 1); i++) {
dst[dstCount++] = (byte)repeat;
}
} else {
// no-op packet. Do nothing
srcCount++;
}
}
}
catch {
}
}