use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.
the class HDRLoader method load.
public Image load(InputStream in, boolean flipY) throws IOException {
float gamma = -1f;
float exposure = -1f;
float[] colorcorr = new float[] { -1f, -1f, -1f };
int width = -1, height = -1;
boolean verifiedFormat = false;
while (true) {
String ln = readString(in);
ln = ln.trim();
if (ln.startsWith("#") || ln.equals("")) {
if (ln.equals("#?RADIANCE") || ln.equals("#?RGBE"))
verifiedFormat = true;
// comment or empty statement
continue;
} else if (ln.startsWith("+") || ln.startsWith("-")) {
// + or - mark image resolution and start of data
String[] resData = ln.split("\\s");
if (resData.length != 4) {
throw new IOException("Invalid resolution string in HDR file");
}
if (!resData[0].equals("-Y") || !resData[2].equals("+X")) {
logger.warning("Flipping/Rotating attributes ignored!");
}
//if (resData[0].endsWith("X")){
// first width then height
// width = Integer.parseInt(resData[1]);
// height = Integer.parseInt(resData[3]);
//}else{
width = Integer.parseInt(resData[3]);
height = Integer.parseInt(resData[1]);
break;
} else {
// regular command
int index = ln.indexOf("=");
if (index < 1) {
logger.log(Level.FINE, "Ignored string: {0}", ln);
continue;
}
String var = ln.substring(0, index).trim().toLowerCase();
String value = ln.substring(index + 1).trim().toLowerCase();
if (var.equals("format")) {
if (!value.equals("32-bit_rle_rgbe") && !value.equals("32-bit_rle_xyze")) {
throw new IOException("Unsupported format in HDR picture");
}
} else if (var.equals("exposure")) {
exposure = Float.parseFloat(value);
} else if (var.equals("gamma")) {
gamma = Float.parseFloat(value);
} else {
logger.log(Level.WARNING, "HDR Command ignored: {0}", ln);
}
}
}
assert width != -1 && height != -1;
if (!verifiedFormat)
logger.warning("Unsure if specified image is Radiance HDR");
// some HDR images can get pretty big
System.gc();
// each pixel times size of component times # of components
Format pixelFormat;
if (writeRGBE) {
pixelFormat = Format.RGBA8;
} else {
pixelFormat = Format.RGB16F;
}
dataStore = BufferUtils.createByteBuffer(width * height * pixelFormat.getBitsPerPixel());
int bytesPerPixel = pixelFormat.getBitsPerPixel() / 8;
int scanLineBytes = bytesPerPixel * width;
for (int y = height - 1; y >= 0; y--) {
if (flipY)
dataStore.position(scanLineBytes * y);
decodeScanline(in, width);
}
in.close();
dataStore.rewind();
//HDR files color data is actually stored in linear space.
return new Image(pixelFormat, width, height, dataStore, ColorSpace.Linear);
}
use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.
the class FilterPostProcessor method initialize.
public void initialize(RenderManager rm, ViewPort vp) {
renderManager = rm;
renderer = rm.getRenderer();
viewPort = vp;
fsQuad = new Picture("filter full screen quad");
fsQuad.setWidth(1);
fsQuad.setHeight(1);
if (fbFormat == Format.RGB111110F && !renderer.getCaps().contains(Caps.PackedFloatTexture)) {
fbFormat = Format.RGB8;
}
Camera cam = vp.getCamera();
//save view port diensions
left = cam.getViewPortLeft();
right = cam.getViewPortRight();
top = cam.getViewPortTop();
bottom = cam.getViewPortBottom();
originalWidth = cam.getWidth();
originalHeight = cam.getHeight();
//first call to reshape
reshape(vp, cam.getWidth(), cam.getHeight());
}
use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.
the class Picture method setTexture.
/**
* Set the texture to put on the picture.
*
* @param assetManager The {@link AssetManager} to use to load the material.
* @param tex The texture
* @param useAlpha If true, the picture will appear transparent and allow
* objects behind it to appear through. If false, the transparent
* portions will be the image's color at that pixel.
*/
public void setTexture(AssetManager assetManager, Texture2D tex, boolean useAlpha) {
if (getMaterial() == null) {
Material mat = new Material(assetManager, "Common/MatDefs/Gui/Gui.j3md");
mat.setColor("Color", ColorRGBA.White);
setMaterial(mat);
}
material.getAdditionalRenderState().setBlendMode(useAlpha ? BlendMode.Alpha : BlendMode.Off);
material.setTexture("Texture", tex);
}
use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.
the class Picture method setImage.
/**
* Set the image to put on the picture.
*
* @param assetManager The {@link AssetManager} to use to load the image.
* @param imgName The image name.
* @param useAlpha If true, the picture will appear transparent and allow
* objects behind it to appear through. If false, the transparent
* portions will be the image's color at that pixel.
*/
public void setImage(AssetManager assetManager, String imgName, boolean useAlpha) {
TextureKey key = new TextureKey(imgName, true);
Texture2D tex = (Texture2D) assetManager.loadTexture(key);
setTexture(assetManager, tex, useAlpha);
}
use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.
the class Picture method setHeight.
/**
* Set the height in pixels of the picture, if the height
* does not match the texture's height, then the texture will
* be scaled to fit the picture.
*
* @param height the height to set.
*/
public void setHeight(float height) {
this.height = height;
setLocalScale(new Vector3f(width, height, 1f));
}
Aggregations