* @return texture or null if given index has length -1
* @throws IOException
* if an io error occurs
*/
public Texture read(TexIdx idx) throws IOException {
Texture texture = new Texture(idx);
if (idx.getLength() == -1) {
return null;
}
int width = 0;
int height = 0;
switch (idx.getLength()) {
case -1:
return null;
case TexIdx.SMALL_TEXTURE:
width = 64;
height = 64;
break;
case TexIdx.BIG_TEXTURE:
width = 128;
height = 128;
break;
default:
return null;
}
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
WritableRaster wr = image.getRaster();
// get texture data for index
byte[] texData = new byte[idx.getLength()];
System.arraycopy(data, idx.getStart(), texData, 0, idx.getLength());
// draw data to image
drawData(wr, texData, width, height);
texture.setImage(image);
return texture;
}