Could someone please enlighten me on what the purpose of the following code from the TextureLoader class is:
private synchronized BufferedImage loadImageFast(String name, boolean expectAlpha) {
try {
String cacheName = null;
if (cachePath != null) {
File f = new File(name);
cacheName = cachePath+f.getName() + ".img";
f = new File(cacheName);
if (f.exists()) {
FileInputStream fs = new FileInputStream(f);
FileChannel fc = fs.getChannel();
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY,0,f.length());
boolean hasAlpha = (bb.getInt()==1) ? true : false;
int width = bb.getInt();
int height = bb.getInt();
DirectBufferedImage im = null;
if (hasAlpha) im = (DirectBufferedImage)DirectBufferedImage.getDirectImageRGBA(width,height);
else im = (DirectBufferedImage)DirectBufferedImage.getDirectImageRGB(width,height);
bb.get(im.getBackingStore());
return im;
}
}
I don’t understand the purpose of the MappedByteBuffer and FileChannel objects. Why not simply read the width and height from the FileInputStream. and what is the point of the following line:
bb.get(im.getBackingStore());
