* @return Gump
* @throws IOException
* if an io error occurs
*/
public Gump read(GumpIdx idx) throws IOException {
Gump gump = new Gump(idx, this);
BufferedImage image = new BufferedImage(idx.getWidth(),
idx.getHeight(), BufferedImage.TYPE_INT_ARGB);
WritableRaster wr = image.getRaster();
byte[] gumpData = new byte[idx.getSize()];
System.arraycopy(data, idx.getOffset(), gumpData, 0, idx.getSize());
String hash = generateHash(gumpData);
gump.setHash(hash);
BlockIterator blockIt = new BlockIterator(gumpData);
int x = idx.getWidth();
int y = idx.getHeight() - 1;
byte[] block = null;
// at the beginning of the gump there is only crap :) so
// draw image from end to start
while ((block = blockIt.getNextBlockFromEnd()) != null) {
Color color = getColor(block);
int length = getLength(block);
x = x - length;
drawBlock(wr, color, length, x, y);
if (x == 0) {
y = y - 1;
x = idx.getWidth();
}
if (y == -1) {
break;
}
}
gump.setImage(image);
return gump;
}