Bugfix: fixed a bug that raised IndexOutOfBounds exception when blending was applied to image with mipmaps. (commited once more because the previous version still had errors).

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10863 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
Kae..pl 11 years ago
parent 3dbe5fcec6
commit 1c26d91bb2
  1. 17
      engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderAWT.java
  2. 14
      engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderLuminance.java

@ -73,13 +73,15 @@ public class TextureBlenderAWT extends AbstractTextureBlender {
if (depth == 0) { if (depth == 0) {
depth = 1; depth = 1;
} }
int bytesPerPixel = image.getFormat().getBitsPerPixel() >> 3;
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(depth); ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(depth);
float[] resultPixel = new float[4]; float[] resultPixel = new float[4];
for (int dataLayerIndex = 0; dataLayerIndex < depth; ++dataLayerIndex) { for (int dataLayerIndex = 0; dataLayerIndex < depth; ++dataLayerIndex) {
ByteBuffer data = image.getData(dataLayerIndex); ByteBuffer data = image.getData(dataLayerIndex);
data.rewind(); 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; int dataIndex = 0, x = 0, y = 0, index = 0;
while (index < data.limit()) { while (index < data.limit()) {
@ -87,11 +89,16 @@ public class TextureBlenderAWT extends AbstractTextureBlender {
if (basePixelIO != null) { if (basePixelIO != null) {
basePixelIO.read(baseImage, dataLayerIndex, basePixel, x, y); basePixelIO.read(baseImage, dataLayerIndex, basePixel, x, y);
basePixel.toRGBA(materialColor); basePixel.toRGBA(materialColor);
++x;
if (x >= width) {
x = 0;
++y;
}
} }
// reading the current texture's pixel // reading the current texture's pixel
pixelReader.read(image, dataLayerIndex, pixel, index); pixelReader.read(image, dataLayerIndex, pixel, index);
index += image.getFormat().getBitsPerPixel() >> 3; index += bytesPerPixel;
pixel.toRGBA(pixelColor); pixel.toRGBA(pixelColor);
if (negateTexture) { if (negateTexture) {
pixel.negate(); pixel.negate();
@ -102,12 +109,6 @@ public class TextureBlenderAWT extends AbstractTextureBlender {
newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f)); newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f));
newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f)); newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f));
newData.put(dataIndex++, (byte) (pixelColor[3] * 255.0f)); newData.put(dataIndex++, (byte) (pixelColor[3] * 255.0f));
++x;
if (x >= width) {
x = 0;
++y;
}
} }
dataArray.add(newData); dataArray.add(newData);
} }

@ -50,7 +50,7 @@ public class TextureBlenderLuminance extends AbstractTextureBlender {
for (int dataLayerIndex = 0; dataLayerIndex < depth; ++dataLayerIndex) { for (int dataLayerIndex = 0; dataLayerIndex < depth; ++dataLayerIndex) {
ByteBuffer data = image.getData(dataLayerIndex); ByteBuffer data = image.getData(dataLayerIndex);
data.rewind(); data.rewind();
ByteBuffer newData = BufferUtils.createByteBuffer(data.limit()); ByteBuffer newData = BufferUtils.createByteBuffer(data.limit() * 4);
int dataIndex = 0, x = 0, y = 0; int dataIndex = 0, x = 0, y = 0;
while (data.hasRemaining()) { while (data.hasRemaining()) {
@ -58,6 +58,12 @@ public class TextureBlenderLuminance extends AbstractTextureBlender {
if (basePixelIO != null) { if (basePixelIO != null) {
basePixelIO.read(baseImage, dataLayerIndex, basePixel, x, y); basePixelIO.read(baseImage, dataLayerIndex, basePixel, x, y);
basePixel.toRGBA(materialColor); basePixel.toRGBA(materialColor);
++x;
if (x >= width) {
x = 0;
++y;
}
} }
this.getTinAndAlpha(data, format, negateTexture, tinAndAlpha); 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[1] * 255.0f));
newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f)); newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f));
newData.put(dataIndex++, (byte) (tinAndAlpha[1] * 255.0f)); newData.put(dataIndex++, (byte) (tinAndAlpha[1] * 255.0f));
++x;
if (x >= width) {
x = 0;
++y;
}
} }
dataArray.add(newData); dataArray.add(newData);
} }

Loading…
Cancel
Save