diff --git a/jme3-core/src/main/java/com/jme3/texture/image/BitMaskImageCodec.java b/jme3-core/src/main/java/com/jme3/texture/image/BitMaskImageCodec.java index a888dfa41..324052604 100644 --- a/jme3-core/src/main/java/com/jme3/texture/image/BitMaskImageCodec.java +++ b/jme3-core/src/main/java/com/jme3/texture/image/BitMaskImageCodec.java @@ -95,15 +95,15 @@ class BitMaskImageCodec extends ImageCodec { } @Override - public void readComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp) { - int inputPixel = readPixelRaw(buf, (x + y * width) * bpp, bpp); + public void readComponents(ByteBuffer buf, int x, int y, int width, int offset, int[] components, byte[] tmp) { + int inputPixel = readPixelRaw(buf, (x + y * width) * bpp + offset, bpp); components[0] = (inputPixel >> as) & maxAlpha; components[1] = (inputPixel >> rs) & maxRed; components[2] = (inputPixel >> gs) & maxGreen; components[3] = (inputPixel >> bs) & maxBlue; } - public void writeComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp) { + public void writeComponents(ByteBuffer buf, int x, int y, int width, int offset, int[] components, byte[] tmp) { // Shift components then mask them // Map all components into a single bitspace int outputPixel = ((components[0] & maxAlpha) << as) @@ -113,6 +113,6 @@ class BitMaskImageCodec extends ImageCodec { // Find index in image where to write pixel. // Write the resultant bitspace into the pixel. - writePixelRaw(buf, (x + y * width) * bpp, outputPixel, bpp); + writePixelRaw(buf, (x + y * width) * bpp + offset, outputPixel, bpp); } } diff --git a/jme3-core/src/main/java/com/jme3/texture/image/ByteAlignedImageCodec.java b/jme3-core/src/main/java/com/jme3/texture/image/ByteAlignedImageCodec.java index 490a44014..ac1989d5c 100644 --- a/jme3-core/src/main/java/com/jme3/texture/image/ByteAlignedImageCodec.java +++ b/jme3-core/src/main/java/com/jme3/texture/image/ByteAlignedImageCodec.java @@ -109,19 +109,19 @@ class ByteAlignedImageCodec extends ImageCodec { // } } - public void readComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp) { - readPixelRaw(buf, (x + y * width) * bpp, bpp, tmp); + public void readComponents(ByteBuffer buf, int x, int y, int width, int offset, int[] components, byte[] tmp) { + readPixelRaw(buf, (x + y * width + offset) * bpp + offset, bpp, tmp); components[0] = readComponent(tmp, ap, az); components[1] = readComponent(tmp, rp, rz); components[2] = readComponent(tmp, gp, gz); components[3] = readComponent(tmp, bp, bz); } - public void writeComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp) { + public void writeComponents(ByteBuffer buf, int x, int y, int width, int offset, int[] components, byte[] tmp) { writeComponent(components[0], ap, az, tmp); writeComponent(components[1], rp, rz, tmp); writeComponent(components[2], gp, gz, tmp); writeComponent(components[3], bp, bz, tmp); - writePixelRaw(buf, (x + y * width) * bpp, tmp, bpp); + writePixelRaw(buf, (x + y * width) * bpp + offset, tmp, bpp); } } diff --git a/jme3-core/src/main/java/com/jme3/texture/image/ByteOffsetImageCodec.java b/jme3-core/src/main/java/com/jme3/texture/image/ByteOffsetImageCodec.java index e0054d7e5..eb4f0a1f2 100644 --- a/jme3-core/src/main/java/com/jme3/texture/image/ByteOffsetImageCodec.java +++ b/jme3-core/src/main/java/com/jme3/texture/image/ByteOffsetImageCodec.java @@ -49,8 +49,8 @@ public class ByteOffsetImageCodec extends ImageCodec { } @Override - public void readComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp) { - int i = (y * width + x) * bpp; + public void readComponents(ByteBuffer buf, int x, int y, int width, int offset, int[] components, byte[] tmp) { + int i = (y * width + x) * bpp + offset; buf.position(i); buf.get(tmp, 0, bpp); if (alphaPos != -1) { @@ -68,8 +68,8 @@ public class ByteOffsetImageCodec extends ImageCodec { } @Override - public void writeComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp) { - int i = (y * width + x) * bpp; + public void writeComponents(ByteBuffer buf, int x, int y, int width, int offset, int[] components, byte[] tmp) { + int i = (y * width + x) * bpp + offset; if (alphaPos != -1) { tmp[alphaPos] = (byte) components[0]; } diff --git a/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java b/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java index 32fc99eda..4cbfc3b57 100644 --- a/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java +++ b/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java @@ -67,6 +67,11 @@ public class DefaultImageRaster extends ImageRaster { } } + public void setSlice(int slice) { + this.slice = slice; + this.buffer = image.getData(slice); + } + @Override public int getWidth() { return width; @@ -76,7 +81,7 @@ public class DefaultImageRaster extends ImageRaster { public int getHeight() { return height; } - + @Override public void setPixel(int x, int y, ColorRGBA color) { rangeCheck(x, y); @@ -108,7 +113,7 @@ public class DefaultImageRaster extends ImageRaster { components[3] = Math.min( (int) (color.b * codec.maxBlue + 0.5f), codec.maxBlue); break; } - codec.writeComponents(getBuffer(), x, y, width, components, temp); + codec.writeComponents(getBuffer(), x, y, width, 0, components, temp); image.setUpdateNeeded(); } @@ -123,7 +128,7 @@ public class DefaultImageRaster extends ImageRaster { public ColorRGBA getPixel(int x, int y, ColorRGBA store) { rangeCheck(x, y); - codec.readComponents(getBuffer(), x, y, width, components, temp); + codec.readComponents(getBuffer(), x, y, width, 0, components, temp); if (store == null) { store = new ColorRGBA(); } diff --git a/jme3-core/src/main/java/com/jme3/texture/image/ImageCodec.java b/jme3-core/src/main/java/com/jme3/texture/image/ImageCodec.java index a6acb480c..bbad96ace 100644 --- a/jme3-core/src/main/java/com/jme3/texture/image/ImageCodec.java +++ b/jme3-core/src/main/java/com/jme3/texture/image/ImageCodec.java @@ -149,9 +149,9 @@ abstract class ImageCodec { 12, 0, 4, 8)); } - public abstract void readComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp); + public abstract void readComponents(ByteBuffer buf, int x, int y, int width, int offset, int[] components, byte[] tmp); - public abstract void writeComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp); + public abstract void writeComponents(ByteBuffer buf, int x, int y, int width, int offset, int[] components, byte[] tmp); /** * Looks up the format in the codec registry.