* @param tileSize The maximum size of the tiles to use to build the bigger image
* @throws SlickException Indicates we were unable to locate the resource
*/
private void build(String ref, int filter, int tileSize) throws SlickException {
try {
final LoadableImageData data = ImageDataFactory.getImageDataFor(ref);
final ByteBuffer imageBuffer = data.loadImage(ResourceLoader.getResourceAsStream(ref), false, null);
final int dataWidth = data.getTexWidth();
final int dataHeight = data.getTexHeight();
realWidth = width = data.getWidth();
realHeight = height = data.getHeight();
if ((dataWidth <= tileSize) && (dataHeight <= tileSize)) {
images = new Image[1][1];
ImageData tempData = new ImageData() {
public int getDepth() {
return data.getDepth();
}
public int getHeight() {
return dataHeight;
}
public ByteBuffer getImageBufferData() {
return imageBuffer;
}
public int getTexHeight() {
return dataHeight;
}
public int getTexWidth() {
return dataWidth;
}
public int getWidth() {
return dataWidth;
}
};
images[0][0] = new Image(tempData, filter);
xcount = 1;
ycount = 1;
inited = true;
return;
}
xcount = ((dataWidth-1) / tileSize) + 1;
ycount = ((dataHeight-1) / tileSize) + 1;
images = new Image[xcount][ycount];
int components = data.getDepth() / 8;
for (int x=0;x<xcount;x++) {
for (int y=0;y<ycount;y++) {
final int xSize = tileSize;
final int ySize = tileSize;
final ByteBuffer subBuffer = BufferUtils.createByteBuffer(tileSize*tileSize*components);
int xo = x*tileSize*components;
byte[] byteData = new byte[xSize*components];
for (int i=0;i<ySize;i++) {
int yo = (((y * tileSize) + i) * dataWidth) * components;
imageBuffer.position(yo+xo);
imageBuffer.get(byteData, 0, xSize*components);
subBuffer.put(byteData);
}
int finalX = ((x) * tileSize);
int finalY = ((y) * tileSize);
final int imageWidth = realWidth < finalX ? realWidth % tileSize : tileSize;
final int imageHeight = realHeight < finalY ? realHeight % tileSize : tileSize;
subBuffer.flip();
ImageData imgData = new ImageData() {
public int getDepth() {
return data.getDepth();
}
public int getHeight() {
return imageHeight;
}