use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class HDRLoader method load.
public Object load(AssetInfo info) throws IOException {
if (!(info.getKey() instanceof TextureKey))
throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
boolean flip = ((TextureKey) info.getKey()).isFlipY();
InputStream in = null;
try {
in = info.openStream();
Image img = load(in, flip);
return img;
} finally {
if (in != null) {
in.close();
}
}
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class PFMLoader method load.
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];
for (int y = height - 1; y >= 0; y--) {
if (!needYFlip)
imageData.position(scanLineBytes * y);
int read = 0;
int off = 0;
do {
read = in.read(scanline, off, scanline.length - off);
off += read;
} while (read > 0);
if (needEndienFlip) {
flipScanline(scanline);
}
imageData.put(scanline);
}
imageData.rewind();
return new Image(format, width, height, imageData, null, ColorSpace.Linear);
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class KTXLoader method createImage.
/**
* Create an image with given parameters
* @param nbSlices
* @param byteBuffersSize
* @param imgFormat
* @param pixelWidth
* @param pixelHeight
* @param depth
* @return
*/
private Image createImage(int nbSlices, int byteBuffersSize, Image.Format imgFormat, int pixelWidth, int pixelHeight, int depth) {
ArrayList<ByteBuffer> imageData = new ArrayList<ByteBuffer>(nbSlices);
for (int i = 0; i < nbSlices; i++) {
imageData.add(BufferUtils.createByteBuffer(byteBuffersSize));
}
Image image = new Image(imgFormat, pixelWidth, pixelHeight, depth, imageData, ColorSpace.sRGB);
return image;
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class KTXLoader method getImageFormat.
/**
* returns the JME image format from gl formats and types.
* @param glFormat
* @param glInternalFormat
* @param glType
* @return
*/
private Image.Format getImageFormat(int glFormat, int glInternalFormat, int glType) {
EnumSet<Caps> caps = EnumSet.allOf(Caps.class);
GLImageFormat[][] formats = GLImageFormats.getFormatsForCaps(caps);
for (GLImageFormat[] format : formats) {
for (int j = 0; j < format.length; j++) {
GLImageFormat glImgFormat = format[j];
if (glImgFormat != null) {
if (glImgFormat.format == glFormat && glImgFormat.dataType == glType) {
if (glFormat == glInternalFormat || glImgFormat.internalFormat == glInternalFormat) {
return Image.Format.values()[j];
}
}
}
}
}
return null;
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class JmeBatchRenderBackend method loadImage.
@Override
public Image loadImage(final String filename) {
TextureKey key = new TextureKey(filename, false);
key.setAnisotropy(0);
key.setGenerateMips(false);
Texture2D texture = (Texture2D) display.getAssetManager().loadTexture(key);
return new ImageImpl(texture.getImage());
}
Aggregations