ImageCodec and all implementations now take and additional offset in the read/writeComponent methods

DefaultImageRaster now have a setSlice method
experimental
Nehon 10 years ago
parent 7c41355cca
commit 1e9d1dd29c
  1. 8
      jme3-core/src/main/java/com/jme3/texture/image/BitMaskImageCodec.java
  2. 8
      jme3-core/src/main/java/com/jme3/texture/image/ByteAlignedImageCodec.java
  3. 8
      jme3-core/src/main/java/com/jme3/texture/image/ByteOffsetImageCodec.java
  4. 11
      jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java
  5. 4
      jme3-core/src/main/java/com/jme3/texture/image/ImageCodec.java

@ -95,15 +95,15 @@ class BitMaskImageCodec extends ImageCodec {
} }
@Override @Override
public void readComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp) { 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, bpp); int inputPixel = readPixelRaw(buf, (x + y * width) * bpp + offset, bpp);
components[0] = (inputPixel >> as) & maxAlpha; components[0] = (inputPixel >> as) & maxAlpha;
components[1] = (inputPixel >> rs) & maxRed; components[1] = (inputPixel >> rs) & maxRed;
components[2] = (inputPixel >> gs) & maxGreen; components[2] = (inputPixel >> gs) & maxGreen;
components[3] = (inputPixel >> bs) & maxBlue; 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 // Shift components then mask them
// Map all components into a single bitspace // Map all components into a single bitspace
int outputPixel = ((components[0] & maxAlpha) << as) int outputPixel = ((components[0] & maxAlpha) << as)
@ -113,6 +113,6 @@ class BitMaskImageCodec extends ImageCodec {
// Find index in image where to write pixel. // Find index in image where to write pixel.
// Write the resultant bitspace into the 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);
} }
} }

@ -109,19 +109,19 @@ class ByteAlignedImageCodec extends ImageCodec {
// } // }
} }
public void readComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp) { public void readComponents(ByteBuffer buf, int x, int y, int width, int offset, int[] components, byte[] tmp) {
readPixelRaw(buf, (x + y * width) * bpp, bpp, tmp); readPixelRaw(buf, (x + y * width + offset) * bpp + offset, bpp, tmp);
components[0] = readComponent(tmp, ap, az); components[0] = readComponent(tmp, ap, az);
components[1] = readComponent(tmp, rp, rz); components[1] = readComponent(tmp, rp, rz);
components[2] = readComponent(tmp, gp, gz); components[2] = readComponent(tmp, gp, gz);
components[3] = readComponent(tmp, bp, bz); 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[0], ap, az, tmp);
writeComponent(components[1], rp, rz, tmp); writeComponent(components[1], rp, rz, tmp);
writeComponent(components[2], gp, gz, tmp); writeComponent(components[2], gp, gz, tmp);
writeComponent(components[3], bp, bz, tmp); writeComponent(components[3], bp, bz, tmp);
writePixelRaw(buf, (x + y * width) * bpp, tmp, bpp); writePixelRaw(buf, (x + y * width) * bpp + offset, tmp, bpp);
} }
} }

@ -49,8 +49,8 @@ public class ByteOffsetImageCodec extends ImageCodec {
} }
@Override @Override
public void readComponents(ByteBuffer buf, int x, int y, int width, int[] components, byte[] tmp) { public void readComponents(ByteBuffer buf, int x, int y, int width, int offset, int[] components, byte[] tmp) {
int i = (y * width + x) * bpp; int i = (y * width + x) * bpp + offset;
buf.position(i); buf.position(i);
buf.get(tmp, 0, bpp); buf.get(tmp, 0, bpp);
if (alphaPos != -1) { if (alphaPos != -1) {
@ -68,8 +68,8 @@ public class ByteOffsetImageCodec extends ImageCodec {
} }
@Override @Override
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) {
int i = (y * width + x) * bpp; int i = (y * width + x) * bpp + offset;
if (alphaPos != -1) { if (alphaPos != -1) {
tmp[alphaPos] = (byte) components[0]; tmp[alphaPos] = (byte) components[0];
} }

@ -67,6 +67,11 @@ public class DefaultImageRaster extends ImageRaster {
} }
} }
public void setSlice(int slice) {
this.slice = slice;
this.buffer = image.getData(slice);
}
@Override @Override
public int getWidth() { public int getWidth() {
return width; return width;
@ -76,7 +81,7 @@ public class DefaultImageRaster extends ImageRaster {
public int getHeight() { public int getHeight() {
return height; return height;
} }
@Override @Override
public void setPixel(int x, int y, ColorRGBA color) { public void setPixel(int x, int y, ColorRGBA color) {
rangeCheck(x, y); 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); components[3] = Math.min( (int) (color.b * codec.maxBlue + 0.5f), codec.maxBlue);
break; break;
} }
codec.writeComponents(getBuffer(), x, y, width, components, temp); codec.writeComponents(getBuffer(), x, y, width, 0, components, temp);
image.setUpdateNeeded(); image.setUpdateNeeded();
} }
@ -123,7 +128,7 @@ public class DefaultImageRaster extends ImageRaster {
public ColorRGBA getPixel(int x, int y, ColorRGBA store) { public ColorRGBA getPixel(int x, int y, ColorRGBA store) {
rangeCheck(x, y); rangeCheck(x, y);
codec.readComponents(getBuffer(), x, y, width, components, temp); codec.readComponents(getBuffer(), x, y, width, 0, components, temp);
if (store == null) { if (store == null) {
store = new ColorRGBA(); store = new ColorRGBA();
} }

@ -149,9 +149,9 @@ abstract class ImageCodec {
12, 0, 4, 8)); 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. * Looks up the format in the codec registry.

Loading…
Cancel
Save