Package com.jme3.texture

Examples of com.jme3.texture.Image


    private void scale(Texture2D texture, int width, int height) {
        // first determine if scaling is required
        boolean scaleRequired = texture.getImage().getWidth() != width || texture.getImage().getHeight() != height;

        if (scaleRequired) {
            Image image = texture.getImage();
            BufferedImage sourceImage = ImageToAwt.convert(image, false, true, 0);

            int sourceWidth = sourceImage.getWidth();
            int sourceHeight = sourceImage.getHeight();

            BufferedImage targetImage = new BufferedImage(width, height, sourceImage.getType());

            Graphics2D g = targetImage.createGraphics();
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g.drawImage(sourceImage, 0, 0, width, height, 0, 0, sourceWidth, sourceHeight, null);
            g.dispose();

            Image output = new ImageLoader().load(targetImage, false);
            image.setWidth(width);
            image.setHeight(height);
            image.setData(output.getData(0));
            image.setFormat(output.getFormat());
        }
    }
View Full Code Here


     * @param blenderContext
     *            the blender context
     * @return the sky texture
     */
    public TextureCubeMap generateSkyTexture(int size, ColorRGBA horizontalColor, ColorRGBA zenithColor, BlenderContext blenderContext) {
        Image image = ImageUtils.createEmptyImage(Format.RGB8, size, size, 6);
        PixelInputOutput pixelIO = PixelIOFactory.getPixelIO(image.getFormat());
        TexturePixel pixel = new TexturePixel();

        float delta = 1 / (float) (size - 1);
        float sideV, sideS = 1, forwardU = 1, forwardV, upS;
        TempVars tempVars = TempVars.get();
View Full Code Here

     * @return loaded image or null if it could not be loaded
     */
    public Image loadImage(BlenderInputStream inputStream, int startPosition, boolean flipY) {
        // loading using AWT loader
        inputStream.setPosition(startPosition);
        Image result = this.loadImage(inputStream, ImageType.AWT, flipY);
        // loading using TGA loader
        if (result == null) {
            inputStream.setPosition(startPosition);
            result = this.loadImage(inputStream, ImageType.TGA, flipY);
        }
View Full Code Here

     * @param flipY
     *            if the image should be flipped (does not work with DirectX image)
     * @return loaded image or null if it could not be loaded
     */
    public Image loadImage(InputStream inputStream, ImageType imageType, boolean flipY) {
        Image result = null;
        switch (imageType) {
            case AWT:
                try {
                    result = this.load(inputStream, flipY);
                } catch (Exception e) {
View Full Code Here

            }

            LOGGER.fine("Generating sky texture.");
            float[][] values = new ColorBand(colorbandType, colorbandColors, positions, size).computeValues();

            Image image = ImageUtils.createEmptyImage(Format.RGB8, size, size, 6);
            PixelInputOutput pixelIO = PixelIOFactory.getPixelIO(image.getFormat());
            TexturePixel pixel = new TexturePixel();

            LOGGER.fine("Creating side textures.");
            int[] sideImagesIndexes = new int[] { 0, 1, 4, 5 };
            for (int i : sideImagesIndexes) {
                for (int y = 0; y < size; ++y) {
                    pixel.red = values[y][0];
                    pixel.green = values[y][1];
                    pixel.blue = values[y][2];

                    for (int x = 0; x < size; ++x) {
                        pixelIO.write(image, i, pixel, x, y);
                    }
                }
            }

            LOGGER.fine("Creating top texture.");
            pixelIO.read(image, 0, pixel, 0, image.getHeight() - 1);
            for (int y = 0; y < size; ++y) {
                for (int x = 0; x < size; ++x) {
                    pixelIO.write(image, 3, pixel, x, y);
                }
            }
View Full Code Here

     * @return the new image instance
     */
    public static Image createEmptyImage(Format format, int width, int height, int depth) {
        int bufferSize = width * height * (format.getBitsPerPixel() >> 3);
        if (depth < 2) {
            return new Image(format, width, height, BufferUtils.createByteBuffer(bufferSize));
        }
        ArrayList<ByteBuffer> data = new ArrayList<ByteBuffer>(depth);
        for (int i = 0; i < depth; ++i) {
            data.add(BufferUtils.createByteBuffer(bufferSize));
        }
        return new Image(Format.RGB8, width, height, depth, data);
    }
View Full Code Here

                offset += texelData.getSizeInBytes();
            }
            dataArray.add(BufferUtils.createByteBuffer(bytes));
        }

        Image result = depth > 1 ? new Image(Format.RGBA8, image.getWidth(), image.getHeight(), depth, dataArray) : new Image(Format.RGBA8, image.getWidth(), image.getHeight(), dataArray.get(0));
        if (newMipmapSizes != null) {
            result.setMipMapSizes(newMipmapSizes);
        }
        return result;
    }
View Full Code Here

     * @return the jme image
     */
    private static Image toJmeImage(BufferedImage bufferedImage, Format format) {
        ByteBuffer byteBuffer = BufferUtils.createByteBuffer(bufferedImage.getWidth() * bufferedImage.getHeight() * 3);
        ImageToAwt.convert(bufferedImage, format, byteBuffer);
        return new Image(format, bufferedImage.getWidth(), bufferedImage.getHeight(), byteBuffer);
    }
View Full Code Here

        MatParam diffuseMap = material.getParam("DiffuseMap");
        if (diffuseMap != null) {
            Texture texture = ((Texture) diffuseMap.getValue()).clone();

            // applying alpha mask to the texture
            Image image = texture.getImage();
            ByteBuffer sourceBB = image.getData(0);
            sourceBB.rewind();
            int w = image.getWidth();
            int h = image.getHeight();
            ByteBuffer bb = BufferUtils.createByteBuffer(w * h * 4);
            IAlphaMask iAlphaMask = alphaMasks.get(alphaMaskIndex);
            iAlphaMask.setImageSize(w, h);

            for (int x = 0; x < w; ++x) {
                for (int y = 0; y < h; ++y) {
                    bb.put(sourceBB.get());
                    bb.put(sourceBB.get());
                    bb.put(sourceBB.get());
                    bb.put(iAlphaMask.getAlpha(x, y));
                }
            }

            image = new Image(Format.RGBA8, w, h, bb);
            texture.setImage(image);

            result.setTextureParam("Texture", VarType.Texture2D, texture);
        }

View Full Code Here

        return GL_COLOR_ATTACHMENT0_EXT + attachmentSlot;
    }

    public void updateRenderTexture(FrameBuffer fb, RenderBuffer rb) {
        Texture tex = rb.getTexture();
        Image image = tex.getImage();
        if (image.isUpdateNeeded()) {
            updateTexImageData(image, tex.getType(), 0);

            // NOTE: For depth textures, sets nearest/no-mips mode
            // Required to fix "framebuffer unsupported"
            // for old NVIDIA drivers!
            setupTextureParams(tex);
        }

        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
                convertAttachmentSlot(rb.getSlot()),
                convertTextureType(tex.getType(), image.getMultiSamples(), rb.getFace()),
                image.getId(),
                0);
    }
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.