Package com.jme3.texture

Examples of com.jme3.texture.Image


               if (flipY)
                   flipImage(dataBuf1, width, height, 32);
               
               ByteBuffer data1 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*4);
               data1.put(dataBuf1);
               return new Image(Format.ABGR8, width, height, data1);
            case BufferedImage.TYPE_3BYTE_BGR: // most common in JPEG images
               byte[] dataBuf2 = (byte[]) extractImageData(img);
               if (flipY)
                   flipImage(dataBuf2, width, height, 24);
              
               ByteBuffer data2 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*3);
               data2.put(dataBuf2);
               return new Image(Format.BGR8, width, height, data2);
            case BufferedImage.TYPE_BYTE_GRAY: // grayscale fonts
                byte[] dataBuf3 = (byte[]) extractImageData(img);
                if (flipY)
                    flipImage(dataBuf3, width, height, 8);
                ByteBuffer data3 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight());
                data3.put(dataBuf3);
                return new Image(Format.Luminance8, width, height, data3);
            case BufferedImage.TYPE_USHORT_GRAY: // grayscale heightmap
                short[] dataBuf4 = (short[]) extractImageData(img);
                if (flipY)
                    flipImage(dataBuf4, width, height, 16);
               
                ByteBuffer data4 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*2);
                data4.asShortBuffer().put(dataBuf4);
                return new Image(Format.Luminance16, width, height, data4);
            default:
                break;
        }

        if (img.getTransparency() == Transparency.OPAQUE){
            ByteBuffer data = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*3);
            // no alpha
            for (int y = 0; y < height; y++){
                for (int x = 0; x < width; x++){
                    int ny = y;
                    if (flipY){
                        ny = height - y - 1;
                    }

                    int rgb = img.getRGB(x,ny);
                    byte r = (byte) ((rgb & 0x00FF0000) >> 16);
                    byte g = (byte) ((rgb & 0x0000FF00) >> 8);
                    byte b = (byte) ((rgb & 0x000000FF));
                    data.put(r).put(g).put(b);
                }
            }
            data.flip();
            return new Image(Format.RGB8, width, height, data);
        }else{
            ByteBuffer data = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*4);
            // no alpha
            for (int y = 0; y < height; y++){
                for (int x = 0; x < width; x++){
                    int ny = y;
                    if (flipY){
                        ny = height - y - 1;
                    }

                    int rgb = img.getRGB(x,ny);
                    byte a = (byte) ((rgb & 0xFF000000) >> 24);
                    byte r = (byte) ((rgb & 0x00FF0000) >> 16);
                    byte g = (byte) ((rgb & 0x0000FF00) >> 8);
                    byte b = (byte) ((rgb & 0x000000FF));
                    data.put(r).put(g).put(b).put(a);
                }
            }
            data.flip();
            return new Image(Format.RGBA8, width, height, data);
        }
    }
View Full Code Here


        if (ImageIO.getImageReadersBySuffix(info.getKey().getExtension()) != null){
            boolean flip = ((TextureKey) info.getKey()).isFlipY();
            InputStream in = null;
            try {
                in = info.openStream();
                Image img = load(in, flip);
                if (img == null){
                    throw new AssetLoadException("The given image cannot be loaded " + info.getKey());
                }
                return img;
            } finally {
View Full Code Here

        int potSize = Math.max(potWidth, potHeight);

        BufferedImage scaled = scaleDown(original, potSize, potSize);

        AWTLoader loader = new AWTLoader();
        Image output = loader.load(scaled, false);

        image.setWidth(potSize);
        image.setHeight(potSize);
        image.setDepth(0);
        image.setData(output.getData(0));
        image.setFormat(output.getFormat());
        image.setMipMapSizes(null);
    }
View Full Code Here

        ArrayList<ByteBuffer> output = new ArrayList<ByteBuffer>();
        int totalSize = 0;
        Format format = null;
       
        while (height >= 1 || width >= 1){
            Image converted = loader.load(current, false);
            format = converted.getFormat();
            output.add(converted.getData(0));
            totalSize += converted.getData(0).capacity();

            if(height == 1 || width == 1) {
              break;
            }
View Full Code Here

        }
        //TODO: all buffers?
        ByteBuffer sourceData = source.getData(0);
        int height = source.getHeight();
        int width = source.getWidth();
        Image newImage = null;
        for (int yPos = 0; yPos < height; yPos++) {
            for (int xPos = 0; xPos < width; xPos++) {
                int i = ((xPos + x) + (yPos + y) * atlasWidth) * 4;
                if (source.getFormat() == Format.ABGR8) {
                    int j = (xPos + yPos * width) * 4;
 
View Full Code Here

        try {
            Class clazz = Class.forName("jme3tools.converters.ImageToAwt");
            if (clazz == null) {
                return null;
            }
            Image newImage = new Image(format, source.getWidth(), source.getHeight(), BufferUtils.createByteBuffer(source.getWidth() * source.getHeight() * 4));
            clazz.getMethod("convert", Image.class, Image.class).invoke(clazz.newInstance(), source, newImage);
            return newImage;
        } catch (InstantiationException ex) {
        } catch (IllegalAccessException ex) {
        } catch (IllegalArgumentException ex) {
View Full Code Here

        if (images == null) {
            return null;
        }
        byte[] image = images.get(mapName);
        if (image != null) {
            Texture2D tex = new Texture2D(new Image(format, atlasWidth, atlasHeight, BufferUtils.createByteBuffer(image)));
            tex.setMagFilter(Texture.MagFilter.Bilinear);
            tex.setMinFilter(Texture.MinFilter.BilinearNearestMipMap);
            tex.setWrap(Texture.WrapMode.Clamp);
            return tex;
        }
View Full Code Here

     *            the blender context
     */
    public void blend(TextureBlender textureBlender, TriangulatedTexture baseTexture, BlenderContext blenderContext) {
        Format newFormat = null;
        for (TriangleTextureElement triangleTextureElement : this.faceTextures) {
            Image baseImage = baseTexture == null ? null : baseTexture.getFaceTextureElement(triangleTextureElement.faceIndex).image;
            triangleTextureElement.image = textureBlender.blend(triangleTextureElement.image, baseImage, blenderContext);
            if (newFormat == null) {
                newFormat = triangleTextureElement.image.getFormat();
            } else if (newFormat != triangleTextureElement.image.getFormat()) {
                throw new IllegalArgumentException("Face texture element images MUST have the same image format!");
View Full Code Here

            Graphics2D g = targetImage.createGraphics();
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g.drawImage(sourceImage, affineTransform, null);
            g.dispose();

            Image output = imageLoader.load(targetImage, false);
            entry.image = output;
            entry.uv[0].set(dest[0]);
            entry.uv[1].set(dest[1]);
            entry.uv[2].set(dest[2]);
        }
View Full Code Here

                resultUVS.set(entry.getKey().faceIndex * 3, uvs[0]);
                resultUVS.set(entry.getKey().faceIndex * 3 + 1, uvs[1]);
                resultUVS.set(entry.getKey().faceIndex * 3 + 2, uvs[2]);
            }

            Image resultImage = new Image(format, resultImageWidth, resultImageHeight, BufferUtils.createByteBuffer(resultImageWidth * resultImageHeight * (format.getBitsPerPixel() >> 3)));
            resultTexture = new Texture2D(resultImage);
            for (Entry<TriangleTextureElement, Integer[]> entry : imageLayoutData.entrySet()) {
                if (!duplicatedFaceIndexes.contains(entry.getKey().faceIndex)) {
                    this.draw(resultImage, entry.getKey().image, entry.getValue()[0], entry.getValue()[1]);
                }
View Full Code Here

TOP

Related Classes of com.jme3.texture.Image

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.