public byte[] Decode(byte[] data, byte[] uncompData, int h) {
if (data[0] == (byte)0x00 && data[1] == (byte)0x01) {
throw new InvalidOperationException("TIFF 5.0-style LZW codes are not supported.");
}
InitializeStringTable();
this.data = data;
this.h = h;
this.uncompData = uncompData;
// Initialize pointers
bytePointer = 0;
dstIndex = 0;
nextData = 0;
nextBits = 0;
int code, oldCode = 0;
byte[] strn;
while ( ((code = GetNextCode()) != 257) &&
dstIndex < uncompData.Length) {
if (code == 256) {
InitializeStringTable();
code = GetNextCode();
if (code == 257) {
break;
}
WriteString(stringTable[code]);
oldCode = code;
} else {
if (code < tableIndex) {
strn = stringTable[code];
WriteString(strn);
AddStringToTable(stringTable[oldCode], strn[0]);
oldCode = code;
} else {
strn = stringTable[oldCode];
strn = ComposeString(strn, strn[0]);
WriteString(strn);
AddStringToTable(strn);
oldCode = code;
}
}
}
// Horizontal Differencing Predictor
if (predictor == 2) {
int count;
for (int j = 0; j < h; j++) {
count = samplesPerPixel * (j * w + 1);
for (int i = samplesPerPixel; i < w * samplesPerPixel; i++) {
uncompData[count] += uncompData[count - samplesPerPixel];
count++;
}
}
}
return uncompData;
}