private void decode(ByteBuffer buffer, int stride, boolean flip) throws IOException {
final int offset = buffer.position();
byte[] curLine = new byte[width*bytesPerPixel+1];
byte[] prevLine = new byte[width*bytesPerPixel+1];
final Inflater inflater = new Inflater();
try {
for(int yIndex=0 ; yIndex<height ; yIndex++) {
int y = yIndex;
if (flip) {
y = height - 1 - yIndex;
}
readChunkUnzip(inflater, curLine, 0, curLine.length);
unfilter(curLine, prevLine);
buffer.position(offset + y*stride);
switch (colorType) {
case COLOR_TRUECOLOR:
case COLOR_TRUEALPHA:
copy(buffer, curLine);
break;
case COLOR_INDEXED:
copyExpand(buffer, curLine);
break;
default:
throw new UnsupportedOperationException("Not yet implemented");
}
byte[] tmp = curLine;
curLine = prevLine;
prevLine = tmp;
}
} finally {
inflater.end();
}
bitDepth = hasAlpha() ? 32 : 24;
}