Search in sources :

Example 6 with Format

use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.

the class Image method read.

public void read(JmeImporter e) throws IOException {
    InputCapsule capsule = e.getCapsule(this);
    format = capsule.readEnum("format", Format.class, Format.RGBA8);
    width = capsule.readInt("width", 0);
    height = capsule.readInt("height", 0);
    depth = capsule.readInt("depth", 0);
    mipMapSizes = capsule.readIntArray("mipMapSizes", null);
    multiSamples = capsule.readInt("multiSamples", 1);
    data = (ArrayList<ByteBuffer>) capsule.readByteBufferArrayList("data", null);
    colorSpace = capsule.readEnum("colorSpace", ColorSpace.class, null);
    if (mipMapSizes != null) {
        needGeneratedMips = false;
        mipsWereGenerated = true;
    }
}
Also used : InputCapsule(com.jme3.export.InputCapsule) ColorSpace(com.jme3.texture.image.ColorSpace) ByteBuffer(java.nio.ByteBuffer)

Example 7 with Format

use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.

the class ImageTileLoader method getHeightMapAt.

/**
     * Lets you specify the type of images that are being loaded. All images
     * must be the same type.
     * @param imageType eg. BufferedImage.TYPE_USHORT_GRAY
     */
/*public void setImageType(int imageType) {
        this.imageType = imageType;
    }*/
/**
     * The ImageHeightmap that will parse the image type that you 
     * specify with setImageType().
     * @param customImageHeightmap must extend AbstractHeightmap
     */
/*public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) {
        if (!(customImageHeightmap instanceof AbstractHeightMap)) {
            throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!");
        }
        this.customImageHeightmap = customImageHeightmap;
    }*/
private HeightMap getHeightMapAt(Vector3f location) {
    // HEIGHTMAP image (for the terrain heightmap)
    int x = (int) location.x;
    int z = (int) location.z;
    AbstractHeightMap heightmap = null;
    //BufferedImage im = null;
    String name = null;
    try {
        name = namer.getName(x, z);
        logger.log(Level.FINE, "Loading heightmap from file: {0}", name);
        final Texture texture = assetManager.loadTexture(new TextureKey(name));
        heightmap = new ImageBasedHeightMap(texture.getImage());
        /*if (assetInfo != null){
                InputStream in = assetInfo.openStream();
                im = ImageIO.read(in);
            } else {
                im = new BufferedImage(patchSize, patchSize, imageType);
                logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name);
            }*/
        // CREATE HEIGHTMAP
        /*if (imageType == BufferedImage.TYPE_USHORT_GRAY) {
                heightmap = new Grayscale16BitHeightMap(im);
            } else if (imageType == BufferedImage.TYPE_3BYTE_BGR) {
                heightmap = new ImageBasedHeightMap(im);
            } else if (customImageHeightmap != null && customImageHeightmap instanceof AbstractHeightMap) {
                // If it gets here, it means you have specified a different image type, and you must
                // then also supply a custom image heightmap class that can parse that image into
                // a heightmap.
                customImageHeightmap.setImage(im);
                heightmap = (AbstractHeightMap) customImageHeightmap;
            } else {
                // error, no supported image format and no custom image heightmap specified
                if (customImageHeightmap == null)
                    logger.log(Level.SEVERE, "Custom image type specified [{0}] but no customImageHeightmap declared! Use setCustomImageHeightmap()",imageType);
                if (!(customImageHeightmap instanceof AbstractHeightMap))
                    logger.severe("customImageHeightmap must be an AbstractHeightMap!");
                return null;
            }*/
        heightmap.setHeightScale(1);
        heightmap.load();
    //} catch (IOException e) {
    //    e.printStackTrace();
    } catch (AssetNotFoundException e) {
        logger.log(Level.WARNING, "Asset {0} not found, loading zero heightmap instead", name);
    }
    return heightmap;
}
Also used : TextureKey(com.jme3.asset.TextureKey) AssetNotFoundException(com.jme3.asset.AssetNotFoundException) Texture(com.jme3.texture.Texture)

Example 8 with Format

use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.

the class HDRRenderer method initialize.

public void initialize(RenderManager rm, ViewPort vp) {
    if (!enabled)
        return;
    renderer = rm.getRenderer();
    renderManager = rm;
    viewPort = vp;
    // loadInitial()
    fsQuad = new Picture("HDR Fullscreen Quad");
    Format lumFmt = Format.RGB8;
    scene64FB = new FrameBuffer(64, 64, 1);
    scene64 = new Texture2D(64, 64, lumFmt);
    scene64FB.setColorTexture(scene64);
    scene64.setMagFilter(fbMagFilter);
    scene64.setMinFilter(fbMinFilter);
    scene8FB = new FrameBuffer(8, 8, 1);
    scene8 = new Texture2D(8, 8, lumFmt);
    scene8FB.setColorTexture(scene8);
    scene8.setMagFilter(fbMagFilter);
    scene8.setMinFilter(fbMinFilter);
    scene1FB[0] = new FrameBuffer(1, 1, 1);
    scene1[0] = new Texture2D(1, 1, lumFmt);
    scene1FB[0].setColorTexture(scene1[0]);
    scene1FB[1] = new FrameBuffer(1, 1, 1);
    scene1[1] = new Texture2D(1, 1, lumFmt);
    scene1FB[1].setColorTexture(scene1[1]);
    // prepare tonemap shader
    tone = new Material(manager, "Common/MatDefs/Hdr/ToneMap.j3md");
    tone.setFloat("A", 0.18f);
    tone.setFloat("White", 100);
    // load();
    int w = vp.getCamera().getWidth();
    int h = vp.getCamera().getHeight();
    reshape(vp, w, h);
}
Also used : Texture2D(com.jme3.texture.Texture2D) Format(com.jme3.texture.Image.Format) Picture(com.jme3.ui.Picture) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 9 with Format

use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.

the class TextureUtil method initialize.

public void initialize(EnumSet<Caps> caps) {
    this.formats = GLImageFormats.getFormatsForCaps(caps);
    if (logger.isLoggable(Level.FINE)) {
        StringBuilder sb = new StringBuilder();
        sb.append("Supported texture formats: \n");
        for (int i = 0; i < Format.values().length; i++) {
            Format format = Format.values()[i];
            if (formats[0][i] != null) {
                boolean srgb = formats[1][i] != null;
                sb.append("\t").append(format.toString());
                sb.append(" (Linear");
                if (srgb)
                    sb.append("/sRGB");
                sb.append(")\n");
            }
        }
        logger.log(Level.FINE, sb.toString());
    }
}
Also used : Format(com.jme3.texture.Image.Format)

Example 10 with Format

use of com.jme3.scene.VertexBuffer.Format 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)

Aggregations

Image (com.jme3.texture.Image)20 ByteBuffer (java.nio.ByteBuffer)19 Format (com.jme3.texture.Image.Format)13 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 ColorRGBA (com.jme3.math.ColorRGBA)7 BufferedImage (java.awt.image.BufferedImage)7 TextureCubeMap (com.jme3.texture.TextureCubeMap)6 Vector3f (com.jme3.math.Vector3f)4 TexturePixel (com.jme3.scene.plugins.blender.textures.TexturePixel)4 PixelInputOutput (com.jme3.scene.plugins.blender.textures.io.PixelInputOutput)4 Texture2D (com.jme3.texture.Texture2D)4 DataInputStream (java.io.DataInputStream)4 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)3 LittleEndien (com.jme3.util.LittleEndien)3 InputStream (java.io.InputStream)3 TextureKey (com.jme3.asset.TextureKey)2 VRAPI (com.jme3.input.vr.VRAPI)2 MatParam (com.jme3.material.MatParam)2 Material (com.jme3.material.Material)2