use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class FbxImage method toJmeObject.
@Override
protected Object toJmeObject() {
Image image = null;
String fileName = null;
String relativeFilePathJme;
if (filePath != null) {
fileName = getFileName(filePath);
} else if (relativeFilePath != null) {
fileName = getFileName(relativeFilePath);
}
if (fileName != null) {
try {
// Try to load filename relative to FBX folder
key = new TextureKey(sceneFolderName + fileName);
key.setGenerateMips(true);
image = loadImageSafe(assetManager, key);
// Try to load relative filepath relative to FBX folder
if (image == null && relativeFilePath != null) {
// Convert Windows paths to jME3 paths
relativeFilePathJme = relativeFilePath.replace('\\', '/');
key = new TextureKey(sceneFolderName + relativeFilePathJme);
key.setGenerateMips(true);
image = loadImageSafe(assetManager, key);
}
// Try to load embedded image
if (image == null && content != null && content.length > 0) {
key = new TextureKey(fileName);
key.setGenerateMips(true);
InputStream is = new ByteArrayInputStream(content);
image = assetManager.loadAssetFromStream(key, is).getImage();
// NOTE: embedded texture doesn't exist in the asset manager,
// so the texture key must not be saved.
key = null;
}
} catch (AssetLoadException ex) {
logger.log(Level.WARNING, "Error while attempting to load texture {0}:\n{1}", new Object[] { name, ex.toString() });
}
}
if (image == null) {
logger.log(Level.WARNING, "Cannot locate {0} for texture {1}", new Object[] { fileName, name });
image = PlaceholderAssets.getPlaceholderImage(assetManager);
}
return image;
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class FbxTexture method toJmeObject.
@Override
protected Texture toJmeObject() {
Image image = null;
TextureKey key = null;
if (media != null) {
image = (Image) media.getJmeObject();
key = media.getTextureKey();
}
if (image == null) {
image = PlaceholderAssets.getPlaceholderImage(assetManager);
}
Texture2D tex = new Texture2D(image);
if (key != null) {
tex.setKey(key);
tex.setName(key.getName());
tex.setAnisotropicFilter(key.getAnisotropy());
}
tex.setMinFilter(MinFilter.Trilinear);
tex.setMagFilter(MagFilter.Bilinear);
if (wrapModeU == 0) {
tex.setWrap(WrapAxis.S, WrapMode.Repeat);
}
if (wrapModeV == 0) {
tex.setWrap(WrapAxis.T, WrapMode.Repeat);
}
return tex;
}
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;
}
Aggregations