Could someone please enlighten me on what the purpose of the following code from the TextureLoader class is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| 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:
1
| bb.get(im.getBackingStore()); |