Search in sources :

Example 11 with PixelInputOutput

use of com.jme3.scene.plugins.blender.textures.io.PixelInputOutput in project jmonkeyengine by jMonkeyEngine.

the class TriangulatedTexture method draw.

/**
     * This method draws the source image on the target image starting with the
     * specified positions.
     * 
     * @param target
     *            the target image
     * @param source
     *            the source image
     * @param targetXPos
     *            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);
        }
    }
}
Also used : PixelInputOutput(com.jme3.scene.plugins.blender.textures.io.PixelInputOutput)

Example 12 with PixelInputOutput

use of com.jme3.scene.plugins.blender.textures.io.PixelInputOutput in project jmonkeyengine by jMonkeyEngine.

the class TextureBlenderAWT method blend.

@Override
public Image blend(Image image, Image baseImage, BlenderContext blenderContext) {
    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;
                }
            }
            // reading the current texture's pixel
            pixelReader.read(image, dataLayerIndex, pixel, index);
            index += bytesPerPixel;
            pixel.toRGBA(pixelColor);
            if (negateTexture) {
                pixel.negate();
            }
            this.blendPixel(resultPixel, materialColor, pixelColor, blenderContext);
            newData.put(dataIndex++, (byte) (resultPixel[0] * 255.0f));
            newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f));
            newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f));
            newData.put(dataIndex++, (byte) (pixelColor[3] * 255.0f));
        }
        dataArray.add(newData);
    }
    Image result = depth > 1 ? new Image(Format.RGBA8, width, height, depth, dataArray, ColorSpace.Linear) : new Image(Format.RGBA8, width, height, dataArray.get(0), ColorSpace.Linear);
    if (image.getMipMapSizes() != null) {
        result.setMipMapSizes(image.getMipMapSizes().clone());
    }
    return result;
}
Also used : Format(com.jme3.texture.Image.Format) PixelInputOutput(com.jme3.scene.plugins.blender.textures.io.PixelInputOutput) ArrayList(java.util.ArrayList) Image(com.jme3.texture.Image) TexturePixel(com.jme3.scene.plugins.blender.textures.TexturePixel) ByteBuffer(java.nio.ByteBuffer)

Aggregations

PixelInputOutput (com.jme3.scene.plugins.blender.textures.io.PixelInputOutput)12 Image (com.jme3.texture.Image)8 ByteBuffer (java.nio.ByteBuffer)5 ArrayList (java.util.ArrayList)5 TexturePixel (com.jme3.scene.plugins.blender.textures.TexturePixel)4 Format (com.jme3.texture.Image.Format)3 TextureCubeMap (com.jme3.texture.TextureCubeMap)3 BufferedImage (java.awt.image.BufferedImage)2 ColorRGBA (com.jme3.math.ColorRGBA)1 ColorBand (com.jme3.scene.plugins.blender.textures.ColorBand)1 CombinedTexture (com.jme3.scene.plugins.blender.textures.CombinedTexture)1 TextureHelper (com.jme3.scene.plugins.blender.textures.TextureHelper)1 Texture2D (com.jme3.texture.Texture2D)1 TempVars (com.jme3.util.TempVars)1