diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderAWT.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderAWT.java index 2a99124c9..9ebf4eeac 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderAWT.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderAWT.java @@ -73,13 +73,15 @@ public class TextureBlenderAWT extends AbstractTextureBlender { if (depth == 0) { depth = 1; } + int bytesPerPixel = image.getFormat().getBitsPerPixel() >> 3; ArrayList dataArray = new ArrayList(depth); float[] resultPixel = new float[4]; for (int dataLayerIndex = 0; dataLayerIndex < depth; ++dataLayerIndex) { ByteBuffer data = image.getData(dataLayerIndex); data.rewind(); - ByteBuffer newData = BufferUtils.createByteBuffer(data.limit()); + int imagePixelCount = data.limit() / bytesPerPixel; + ByteBuffer newData = BufferUtils.createByteBuffer(imagePixelCount * 4); int dataIndex = 0, x = 0, y = 0, index = 0; while (index < data.limit()) { @@ -87,11 +89,16 @@ public class TextureBlenderAWT extends AbstractTextureBlender { 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 += image.getFormat().getBitsPerPixel() >> 3; + index += bytesPerPixel; pixel.toRGBA(pixelColor); if (negateTexture) { pixel.negate(); @@ -102,12 +109,6 @@ public class TextureBlenderAWT extends AbstractTextureBlender { newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f)); newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f)); newData.put(dataIndex++, (byte) (pixelColor[3] * 255.0f)); - - ++x; - if (x >= width) { - x = 0; - ++y; - } } dataArray.add(newData); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderLuminance.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderLuminance.java index e5acb1bd6..eac0ae0d5 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderLuminance.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderLuminance.java @@ -50,7 +50,7 @@ public class TextureBlenderLuminance extends AbstractTextureBlender { for (int dataLayerIndex = 0; dataLayerIndex < depth; ++dataLayerIndex) { ByteBuffer data = image.getData(dataLayerIndex); data.rewind(); - ByteBuffer newData = BufferUtils.createByteBuffer(data.limit()); + ByteBuffer newData = BufferUtils.createByteBuffer(data.limit() * 4); int dataIndex = 0, x = 0, y = 0; while (data.hasRemaining()) { @@ -58,6 +58,12 @@ public class TextureBlenderLuminance extends AbstractTextureBlender { if (basePixelIO != null) { basePixelIO.read(baseImage, dataLayerIndex, basePixel, x, y); basePixel.toRGBA(materialColor); + + ++x; + if (x >= width) { + x = 0; + ++y; + } } this.getTinAndAlpha(data, format, negateTexture, tinAndAlpha); @@ -66,12 +72,6 @@ public class TextureBlenderLuminance extends AbstractTextureBlender { newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f)); newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f)); newData.put(dataIndex++, (byte) (tinAndAlpha[1] * 255.0f)); - - ++x; - if (x >= width) { - x = 0; - ++y; - } } dataArray.add(newData); }