Search in sources :

Example 6 with Image

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();
        }
    }
}
Also used : TextureKey(com.jme3.asset.TextureKey) InputStream(java.io.InputStream) Image(com.jme3.texture.Image)

Example 7 with Image

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);
}
Also used : Format(com.jme3.texture.Image.Format) IOException(java.io.IOException) ByteOrder(java.nio.ByteOrder) Image(com.jme3.texture.Image) ByteBuffer(java.nio.ByteBuffer)

Example 8 with Image

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;
}
Also used : ArrayList(java.util.ArrayList) Image(com.jme3.texture.Image) ByteBuffer(java.nio.ByteBuffer)

Example 9 with 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;
}
Also used : GLImageFormat(com.jme3.renderer.opengl.GLImageFormat) Caps(com.jme3.renderer.Caps)

Example 10 with Image

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());
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture2D(com.jme3.texture.Texture2D)

Aggregations

Image (com.jme3.texture.Image)68 ByteBuffer (java.nio.ByteBuffer)38 Texture (com.jme3.texture.Texture)27 Texture2D (com.jme3.texture.Texture2D)19 ArrayList (java.util.ArrayList)19 Material (com.jme3.material.Material)18 TextureKey (com.jme3.asset.TextureKey)17 Vector3f (com.jme3.math.Vector3f)17 Format (com.jme3.texture.Image.Format)15 TextureCubeMap (com.jme3.texture.TextureCubeMap)14 ColorRGBA (com.jme3.math.ColorRGBA)13 PixelInputOutput (com.jme3.scene.plugins.blender.textures.io.PixelInputOutput)12 BufferedImage (java.awt.image.BufferedImage)12 Geometry (com.jme3.scene.Geometry)10 InputStream (java.io.InputStream)10 IOException (java.io.IOException)8 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)7 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)7 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)7 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)7