From 47563c2cf15658b8e843f3a8161887443f38e126 Mon Sep 17 00:00:00 2001 From: "Sha..rd" Date: Sun, 16 Sep 2012 01:13:40 +0000 Subject: [PATCH] * .. and here's the change that makes the previous change actually faster git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9741 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../texture/image/ByteOffsetImageCodec.java | 20 +++++++++++-------- .../texture/image/DefaultImageRaster.java | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/engine/src/core/com/jme3/texture/image/ByteOffsetImageCodec.java b/engine/src/core/com/jme3/texture/image/ByteOffsetImageCodec.java index 116f902c8..3f2175dbd 100644 --- a/engine/src/core/com/jme3/texture/image/ByteOffsetImageCodec.java +++ b/engine/src/core/com/jme3/texture/image/ByteOffsetImageCodec.java @@ -20,17 +20,19 @@ 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; + buf.position(i); + buf.get(tmp, 0, bpp); if (alphaPos != -1) { - components[0] = buf.get(i + alphaPos) & 0xff; + components[0] = tmp[alphaPos] & 0xff; } if (redPos != -1) { - components[1] = buf.get(i + redPos) & 0xff; + components[1] = tmp[redPos] & 0xff; } if (greenPos != -1) { - components[2] = buf.get(i + greenPos) & 0xff; + components[2] = tmp[greenPos] & 0xff; } if (bluePos != -1) { - components[3] = buf.get(i + bluePos) & 0xff; + components[3] = tmp[bluePos] & 0xff; } } @@ -38,17 +40,19 @@ public class ByteOffsetImageCodec extends ImageCodec { public void writeComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp) { int i = (y * width + x) * bpp; if (alphaPos != -1) { - buf.put(i + alphaPos, (byte) components[0]); + tmp[alphaPos] = (byte) components[0]; } if (redPos != -1) { - buf.put(i + redPos, (byte) components[1]); + tmp[redPos] = (byte) components[1]; } if (greenPos != -1) { - buf.put(i + greenPos, (byte) components[2]); + tmp[greenPos] = (byte) components[2]; } if (bluePos != -1) { - buf.put(i + bluePos, (byte) components[3]); + tmp[bluePos] = (byte) components[3]; } + buf.position(i); + buf.put(tmp, 0, bpp); } } diff --git a/engine/src/core/com/jme3/texture/image/DefaultImageRaster.java b/engine/src/core/com/jme3/texture/image/DefaultImageRaster.java index 1eafa0a63..08ed4881c 100644 --- a/engine/src/core/com/jme3/texture/image/DefaultImageRaster.java +++ b/engine/src/core/com/jme3/texture/image/DefaultImageRaster.java @@ -27,7 +27,7 @@ public class DefaultImageRaster extends ImageRaster { this.codec = ImageCodec.lookup(image.getFormat()); this.width = image.getWidth(); this.height = image.getHeight(); - if (codec instanceof ByteAlignedImageCodec) { + if (codec instanceof ByteAlignedImageCodec || codec instanceof ByteOffsetImageCodec) { this.temp = new byte[codec.bpp]; } else { this.temp = null;