scanline[i+1] = tmp;
}
}
private Image load(InputStream in, boolean needYFlip) throws IOException{
Format format = null;
String fmtStr = readString(in);
if (fmtStr.equals("PF")){
format = Format.RGB32F;
}else if (fmtStr.equals("Pf")){
format = Format.Luminance32F;
}else{
throw new IOException("File is not PFM format");
}
String sizeStr = readString(in);
int spaceIdx = sizeStr.indexOf(" ");
if (spaceIdx <= 0 || spaceIdx >= sizeStr.length() - 1)
throw new IOException("Invalid size syntax in PFM file");
int width = Integer.parseInt(sizeStr.substring(0,spaceIdx));
int height = Integer.parseInt(sizeStr.substring(spaceIdx+1));
if (width <= 0 || height <= 0)
throw new IOException("Invalid size specified in PFM file");
String scaleStr = readString(in);
float scale = Float.parseFloat(scaleStr);
ByteOrder order = scale < 0 ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN;
boolean needEndienFlip = order != ByteOrder.nativeOrder();
// make sure all unneccessary stuff gets deleted from heap
// before allocating large amount of memory
System.gc();
int bytesPerPixel = format.getBitsPerPixel() / 8;
int scanLineBytes = bytesPerPixel * width;
ByteBuffer imageData = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
byte[] scanline = new byte[width * bytesPerPixel];