Package com.jme3.scene.plugins.blender.textures.io

Examples of com.jme3.scene.plugins.blender.textures.io.PixelInputOutput


    public Image blend(Image image, Image baseImage, BlenderContext blenderContext) {
        this.prepareImagesForBlending(image, baseImage);

        Format format = image.getFormat();
        PixelInputOutput basePixelIO = null;
        TexturePixel basePixel = null;
        float[] materialColor = this.materialColor;
        if (baseImage != null) {
            basePixelIO = PixelIOFactory.getPixelIO(baseImage.getFormat());
            materialColor = new float[this.materialColor.length];
            basePixel = new TexturePixel();
        }

        int width = image.getWidth();
        int height = image.getHeight();
        int depth = image.getDepth();
        if (depth == 0) {
            depth = 1;
        }
        ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(depth);

        float[] resultPixel = new float[4];
        float[] tinAndAlpha = new float[2];
        for (int dataLayerIndex = 0; dataLayerIndex < depth; ++dataLayerIndex) {
            ByteBuffer data = image.getData(dataLayerIndex);
            data.rewind();
            ByteBuffer newData = BufferUtils.createByteBuffer(data.limit() * 4);

            int dataIndex = 0, x = 0, y = 0;
            while (data.hasRemaining()) {
                // getting the proper material color if the base texture is applied
                if (basePixelIO != null) {
                    basePixelIO.read(baseImage, dataLayerIndex, basePixel, x, y);
                    basePixel.toRGBA(materialColor);
                   
                    ++x;
                    if (x >= width) {
                        x = 0;
View Full Code Here


        if (depth == 0) {
            depth = 1;
        }
        ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(depth);

        PixelInputOutput basePixelIO = null;
        float[][] compressedMaterialColor = null;
        TexturePixel[] baseTextureColors = null;
        if (baseImage != null) {
            basePixelIO = PixelIOFactory.getPixelIO(baseImage.getFormat());
            compressedMaterialColor = new float[2][4];
            baseTextureColors = new TexturePixel[] { new TexturePixel(), new TexturePixel() };
        }

        float[] resultPixel = new float[4];
        float[] pixelColor = new float[4];
        TexturePixel[] colors = new TexturePixel[] { new TexturePixel(), new TexturePixel() };
        int baseXTexelIndex = 0, baseYTexelIndex = 0;
        float[] alphas = new float[] { 1, 1 };
        for (int dataLayerIndex = 0; dataLayerIndex < depth; ++dataLayerIndex) {
            ByteBuffer data = image.getData(dataLayerIndex);
            data.rewind();
            ByteBuffer newData = BufferUtils.createByteBuffer(data.remaining());
            while (data.hasRemaining()) {
                if (format == Format.DXT3) {
                    long alpha = data.getLong();
                    // get alpha for first and last pixel that is compressed in the texel
                    byte alpha0 = (byte) (alpha << 4 & 0xFF);
                    byte alpha1 = (byte) (alpha >> 60 & 0xFF);
                    alphas[0] = alpha0 >= 0 ? alpha0 / 255.0f : 1.0f - ~alpha0 / 255.0f;
                    alphas[1] = alpha1 >= 0 ? alpha1 / 255.0f : 1.0f - ~alpha1 / 255.0f;
                    newData.putLong(alpha);
                } else if (format == Format.DXT5) {
                    byte alpha0 = data.get();
                    byte alpha1 = data.get();
                    alphas[0] = alpha0 >= 0 ? alpha0 / 255.0f : 1.0f - ~alpha0 / 255.0f;
                    alphas[1] = alpha1 >= 0 ? alpha0 / 255.0f : 1.0f - ~alpha0 / 255.0f;
                    newData.put(alpha0);
                    newData.put(alpha1);
                    // only read the next 6 bytes (these are alpha indexes)
                    newData.putInt(data.getInt());
                    newData.putShort(data.getShort());
                }
                int col0 = RGB565.RGB565_to_ARGB8(data.getShort());
                int col1 = RGB565.RGB565_to_ARGB8(data.getShort());
                colors[0].fromARGB8(col0);
                colors[1].fromARGB8(col1);

                // compressing 16 pixels from the base texture as if they belonged to a texel
                if (baseImage != null) {
                    // reading pixels (first and last of the 16 colors array)
                    basePixelIO.read(baseImage, dataLayerIndex, baseTextureColors[0], baseXTexelIndex << 2, baseYTexelIndex << 2);// first pixel
                    basePixelIO.read(baseImage, dataLayerIndex, baseTextureColors[1], baseXTexelIndex << 2 + 4, baseYTexelIndex << 2 + 4);// last pixel
                    baseTextureColors[0].toRGBA(compressedMaterialColor[0]);
                    baseTextureColors[1].toRGBA(compressedMaterialColor[1]);
                }

                // blending colors
View Full Code Here

        this.prepareImagesForBlending(image, baseImage);

        float[] pixelColor = new float[] { color[0], color[1], color[2], 1.0f };
        Format format = image.getFormat();

        PixelInputOutput basePixelIO = null, pixelReader = PixelIOFactory.getPixelIO(format);
        TexturePixel basePixel = null, pixel = new TexturePixel();
        float[] materialColor = this.materialColor;
        if (baseImage != null) {
            basePixelIO = PixelIOFactory.getPixelIO(baseImage.getFormat());
            materialColor = new float[this.materialColor.length];
            basePixel = new TexturePixel();
        }

        int width = image.getWidth();
        int height = image.getHeight();
        int depth = image.getDepth();
        if (depth == 0) {
            depth = 1;
        }
        int bytesPerPixel = image.getFormat().getBitsPerPixel() >> 3;
        ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(depth);

        float[] resultPixel = new float[4];
        for (int dataLayerIndex = 0; dataLayerIndex < depth; ++dataLayerIndex) {
            ByteBuffer data = image.getData(dataLayerIndex);
            data.rewind();
            int imagePixelCount = data.limit() / bytesPerPixel;
            ByteBuffer newData = BufferUtils.createByteBuffer(imagePixelCount * 4);

            int dataIndex = 0, x = 0, y = 0, index = 0;
            while (index < data.limit()) {
                // getting the proper material color if the base texture is applied
                if (basePixelIO != null) {
                    basePixelIO.read(baseImage, dataLayerIndex, basePixel, x, y);
                    basePixel.toRGBA(materialColor);
                    ++x;
                    if (x >= width) {
                        x = 0;
                        ++y;
View Full Code Here

        int width = maxX - minX;
        int height = maxY - minY;
        ByteBuffer data = BufferUtils.createByteBuffer(width * height * (image.getFormat().getBitsPerPixel() >> 3));

        Image result = new Image(image.getFormat(), width, height, data);
        PixelInputOutput pixelIO = PixelIOFactory.getPixelIO(image.getFormat());
        TexturePixel pixel = new TexturePixel();

        for (int x = minX; x < maxX; ++x) {
            for (int y = minY; y < maxY; ++y) {
                pixelIO.read(image, 0, pixel, x, y);
                pixelIO.write(result, 0, pixel, x - minX, y - minY);
            }
        }
        return result;
    }
View Full Code Here

        float[][] colorBand = new ColorBand(tex, blenderContext).computeValues();
        int depth = image.getDepth() == 0 ? 1 : image.getDepth();

        if (colorBand != null) {
            TexturePixel pixel = new TexturePixel();
            PixelInputOutput imageIO = PixelIOFactory.getPixelIO(image.getFormat());
            for (int layerIndex = 0; layerIndex < depth; ++layerIndex) {
                for (int x = 0; x < image.getWidth(); ++x) {
                    for (int y = 0; y < image.getHeight(); ++y) {
                        imageIO.read(image, layerIndex, pixel, x, y);

                        int colorbandIndex = (int) (pixel.alpha * 1000.0f);
                        pixel.red = colorBand[colorbandIndex][0] * rfac;
                        pixel.green = colorBand[colorbandIndex][1] * gfac;
                        pixel.blue = colorBand[colorbandIndex][2] * bfac;
                        pixel.alpha = colorBand[colorbandIndex][3];

                        imageIO.write(image, layerIndex, pixel, x, y);
                    }
                }
            }
        } else if (rfac != 1.0f || gfac != 1.0f || bfac != 1.0f) {
            TexturePixel pixel = new TexturePixel();
            PixelInputOutput imageIO = PixelIOFactory.getPixelIO(image.getFormat());
            for (int layerIndex = 0; layerIndex < depth; ++layerIndex) {
                for (int x = 0; x < image.getWidth(); ++x) {
                    for (int y = 0; y < image.getHeight(); ++y) {
                        imageIO.read(image, layerIndex, pixel, x, y);

                        pixel.red *= rfac;
                        pixel.green *= gfac;
                        pixel.blue *= bfac;

                        imageIO.write(image, layerIndex, pixel, x, y);
                    }
                }
            }
        }
    }
View Full Code Here

                    image = ImageUtils.resizeTo(image, size, size);
                }
                Image grayscaleImage = ImageUtils.convertToGrayscaleTexture(image);

                // add the sky colors to the image
                PixelInputOutput sourcePixelIO = PixelIOFactory.getPixelIO(grayscaleImage.getFormat());
                PixelInputOutput targetPixelIO = PixelIOFactory.getPixelIO(image.getFormat());
                TexturePixel texturePixel = new TexturePixel();
                for (int x = 0; x < image.getWidth(); ++x) {
                    for (int y = 0; y < image.getHeight(); ++y) {
                        sourcePixelIO.read(grayscaleImage, 0, texturePixel, x, y);
                        texturePixel.intensity = texturePixel.red;// no matter which factor we use here, in grayscale they are all equal
                        ImageUtils.color(texturePixel, horizontalColor, zenithColor);
                        targetPixelIO.write(image, 0, texturePixel, x, y);
                    }
                }

                // create the cubemap texture from the coloured image
                ByteBuffer sourceData = image.getData(0);
View Full Code Here

                    case Luminance8Alpha8:
                    case RGBA16:
                    case RGBA16F:
                    case RGBA32F:
                    case RGBA8:// with these types it is better to make sure if the texture is or is not transparent
                        PixelInputOutput pixelInputOutput = PixelIOFactory.getPixelIO(image.getFormat());
                        TexturePixel pixel = new TexturePixel();
                        int depth = image.getDepth() == 0 ? 1 : image.getDepth();
                        for (int layerIndex = 0; layerIndex < depth; ++layerIndex) {
                            for (int x = 0; x < image.getWidth(); ++x) {
                                for (int y = 0; y < image.getHeight(); ++y) {
                                    pixelInputOutput.read(image, layerIndex, pixel, x, y);
                                    if (pixel.alpha < 1.0f) {
                                        return false;
                                    }
                                }
                            }
View Full Code Here

     *            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();
        CastFunction castFunction = CAST_FUNCTIONS[blenderContext.getBlenderKey().getSkyGeneratedTextureShape().ordinal()];
        float castRadius = blenderContext.getBlenderKey().getSkyGeneratedTextureRadius();

        for (int x = 0; x < size; ++x) {
            sideV = 1;
            forwardV = 1;
            upS = 0;
            for (int y = 0; y < size; ++y) {
                castFunction.cast(tempVars.vect1.set(1, sideV, sideS), castRadius);
                textureGenerator.getPixel(pixel, tempVars.vect1.x, tempVars.vect1.y, tempVars.vect1.z);
                pixelIO.write(image, NEGATIVE_X, ImageUtils.color(pixel, horizontalColor, zenithColor), x, y);// right

                castFunction.cast(tempVars.vect1.set(0, sideV, 1 - sideS), castRadius);
                textureGenerator.getPixel(pixel, tempVars.vect1.x, tempVars.vect1.y, tempVars.vect1.z);
                pixelIO.write(image, POSITIVE_X, ImageUtils.color(pixel, horizontalColor, zenithColor), x, y);// left

                castFunction.cast(tempVars.vect1.set(forwardU, forwardV, 0), castRadius);
                textureGenerator.getPixel(pixel, tempVars.vect1.x, tempVars.vect1.y, tempVars.vect1.z);
                pixelIO.write(image, POSITIVE_Z, ImageUtils.color(pixel, horizontalColor, zenithColor), x, y);// front

                castFunction.cast(tempVars.vect1.set(1 - forwardU, forwardV, 1), castRadius);
                textureGenerator.getPixel(pixel, tempVars.vect1.x, tempVars.vect1.y, tempVars.vect1.z);
                pixelIO.write(image, NEGATIVE_Z, ImageUtils.color(pixel, horizontalColor, zenithColor), x, y);// back

                castFunction.cast(tempVars.vect1.set(forwardU, 0, upS), castRadius);
                textureGenerator.getPixel(pixel, tempVars.vect1.x, tempVars.vect1.y, tempVars.vect1.z);
                pixelIO.write(image, NEGATIVE_Y, ImageUtils.color(pixel, horizontalColor, zenithColor), x, y);// top

                castFunction.cast(tempVars.vect1.set(forwardU, 1, 1 - upS), castRadius);
                textureGenerator.getPixel(pixel, tempVars.vect1.x, tempVars.vect1.y, tempVars.vect1.z);
                pixelIO.write(image, POSITIVE_Y, ImageUtils.color(pixel, horizontalColor, zenithColor), x, y);// bottom

                sideV = FastMath.clamp(sideV - delta, 0, 1);
                forwardV = FastMath.clamp(forwardV - delta, 0, 1);
                upS = FastMath.clamp(upS + delta, 0, 1);
            }
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);
                }
            }

            LOGGER.fine("Creating bottom texture.");
            pixelIO.read(image, 0, pixel, 0, 0);
            for (int y = 0; y < size; ++y) {
                for (int x = 0; x < size; ++x) {
                    pixelIO.write(image, 2, pixel, x, y);
                }
            }

            texture = new TextureCubeMap(image);
        }
View Full Code Here

        }
        if (sourceImage.getHeight() != targetImage.getHeight()) {
            throw new IllegalArgumentException("The given images should have the same height to merge them!");
        }

        PixelInputOutput sourceIO = PixelIOFactory.getPixelIO(sourceImage.getFormat());
        PixelInputOutput targetIO = PixelIOFactory.getPixelIO(targetImage.getFormat());
        TexturePixel sourcePixel = new TexturePixel();
        TexturePixel targetPixel = new TexturePixel();
        int depth = targetImage.getDepth() == 0 ? 1 : targetImage.getDepth();

        for (int layerIndex = 0; layerIndex < depth; ++layerIndex) {
            for (int x = 0; x < sourceImage.getWidth(); ++x) {
                for (int y = 0; y < sourceImage.getHeight(); ++y) {
                    sourceIO.read(sourceImage, layerIndex, sourcePixel, x, y);
                    targetIO.read(targetImage, layerIndex, targetPixel, x, y);
                    targetPixel.merge(sourcePixel);
                    targetIO.write(targetImage, layerIndex, targetPixel, x, y);
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.jme3.scene.plugins.blender.textures.io.PixelInputOutput

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.