Examples of PixelInputOutput


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

     *            start X position on the target image
     * @param targetYPos
     *            start Y position on the target image
     */
    private void draw(Image target, Image source, int targetXPos, int targetYPos) {
        PixelInputOutput sourceIO = PixelIOFactory.getPixelIO(source.getFormat());
        PixelInputOutput targetIO = PixelIOFactory.getPixelIO(target.getFormat());
        TexturePixel pixel = new TexturePixel();

        for (int x = 0; x < source.getWidth(); ++x) {
            for (int y = 0; y < source.getHeight(); ++y) {
                sourceIO.read(source, 0, pixel, x, y);
                targetIO.write(target, 0, pixel, targetXPos + x, targetYPos + y);
            }
        }
    }
View Full Code Here

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

            if (height == 0) {
                height = 1;
            }

            // copy the pixel from the texture to the result image
            PixelInputOutput pixelReader = PixelIOFactory.getPixelIO(sourceImage.getFormat());
            TexturePixel pixel = new TexturePixel();
            ByteBuffer data = BufferUtils.createByteBuffer(width * height * 4);
            for (int y = minY; y < maxY; ++y) {
                for (int x = minX; x < maxX; ++x) {
                    int xPos = x >= sourceImage.getWidth() ? x - sourceImage.getWidth() : x;
                    int yPos = y >= sourceImage.getHeight() ? y - sourceImage.getHeight() : y;
                    pixelReader.read(sourceImage, 0, pixel, xPos, yPos);
                    data.put(pixel.getR8());
                    data.put(pixel.getG8());
                    data.put(pixel.getB8());
                    data.put(pixel.getA8());
                }
View Full Code Here

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

            }
            ByteBuffer data = BufferUtils.createByteBuffer(imageWidth * imageHeight * (imageFormat.getBitsPerPixel() >> 3));
            image = new Image(texture.getImage().getFormat(), imageWidth, imageHeight, data);

            // computing the pixels
            PixelInputOutput pixelWriter = PixelIOFactory.getPixelIO(imageFormat);
            TexturePixel pixel = new TexturePixel();
            float[] uvs = new float[3];
            Vector3f point = new Vector3f(envelope.min);
            Vector3f vecY = new Vector3f();
            Vector3f wDelta = new Vector3f(envelope.w).multLocal(1.0f / imageWidth);
            Vector3f hDelta = new Vector3f(envelope.h).multLocal(1.0f / imageHeight);
            for (int x = 0; x < imageWidth; ++x) {
                for (int y = 0; y < imageHeight; ++y) {
                    this.toTextureUV(boundingBox, point, uvs);
                    texture.getPixel(pixel, uvs[0], uvs[1], uvs[2]);
                    pixelWriter.write(image, 0, pixel, x, y);
                    point.addLocal(hDelta);
                }

                vecY.addLocal(wDelta);
                point.set(envelope.min).addLocal(vecY);
View Full Code Here

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

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

        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

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

        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

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

        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

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

        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

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

                    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

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

                    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
TOP
Copyright © 2018 www.massapi.com. 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.