Added support for the following texture types import:
- Luminance8Alpha8 - Luminance16 - Luminance16Alpha16 - Luminance16F - Luminance16FAlpha16A - Luminance32F git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9413 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
4a39f5f37a
commit
027d448b7d
@ -1,29 +1,88 @@
|
|||||||
package com.jme3.scene.plugins.blender.textures.io;
|
package com.jme3.scene.plugins.blender.textures.io;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import com.jme3.scene.plugins.blender.textures.TexturePixel;
|
import com.jme3.scene.plugins.blender.textures.TexturePixel;
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implemens read/write operations for luminance images.
|
* Implemens read/write operations for luminance images.
|
||||||
|
*
|
||||||
* @author Marcin Roguski (Kaelthas)
|
* @author Marcin Roguski (Kaelthas)
|
||||||
*/
|
*/
|
||||||
/*package*/ class LuminancePixelInputOutput implements PixelInputOutput {
|
/* package */class LuminancePixelInputOutput implements PixelInputOutput {
|
||||||
public void read(Image image, int layer, TexturePixel pixel, int index) {
|
public void read(Image image, int layer, TexturePixel pixel, int index) {
|
||||||
byte intensity = image.getData(layer).get(index);
|
ByteBuffer data = image.getData(layer);
|
||||||
pixel.fromIntensity(intensity);
|
switch (image.getFormat()) {
|
||||||
|
case Luminance8:
|
||||||
|
pixel.fromIntensity(data.get(index));
|
||||||
|
break;
|
||||||
|
case Luminance8Alpha8:
|
||||||
|
pixel.fromIntensity(data.get(index));
|
||||||
|
pixel.setAlpha(data.get(index + 1));
|
||||||
|
break;
|
||||||
|
case Luminance16:
|
||||||
|
pixel.fromIntensity(data.getShort(index));
|
||||||
|
break;
|
||||||
|
case Luminance16Alpha16:
|
||||||
|
pixel.fromIntensity(data.getShort(index));
|
||||||
|
pixel.setAlpha(data.getShort(index + 2));
|
||||||
|
break;
|
||||||
|
case Luminance16F:
|
||||||
|
pixel.intensity = Float.intBitsToFloat(data.getShort(index));
|
||||||
|
break;
|
||||||
|
case Luminance16FAlpha16F:
|
||||||
|
pixel.intensity = Float.intBitsToFloat(data.getShort(index));
|
||||||
|
pixel.alpha = Float.intBitsToFloat(data.getShort(index + 2));
|
||||||
|
break;
|
||||||
|
case Luminance32F:
|
||||||
|
pixel.intensity = Float.intBitsToFloat(data.getInt(index));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unknown luminance format type.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(Image image, int layer, TexturePixel pixel, int x, int y) {
|
public void read(Image image, int layer, TexturePixel pixel, int x, int y) {
|
||||||
int index = y * image.getWidth() + x;
|
int index = y * image.getWidth() + x;
|
||||||
this.read(image, layer, pixel, index);
|
this.read(image, layer, pixel, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(Image image, int layer, TexturePixel pixel, int index) {
|
public void write(Image image, int layer, TexturePixel pixel, int index) {
|
||||||
image.getData(layer).put(index, pixel.getInt());
|
ByteBuffer data = image.getData(layer);
|
||||||
|
data.put(index, pixel.getInt());
|
||||||
|
switch (image.getFormat()) {
|
||||||
|
case Luminance8:
|
||||||
|
data.put(index, pixel.getInt());
|
||||||
|
break;
|
||||||
|
case Luminance8Alpha8:
|
||||||
|
data.put(index, pixel.getInt());
|
||||||
|
data.put(index + 1, pixel.getA8());
|
||||||
|
break;
|
||||||
|
case Luminance16:
|
||||||
|
data.putShort(index, (short) (pixel.intensity * 65535.0f));
|
||||||
|
break;
|
||||||
|
case Luminance16Alpha16:
|
||||||
|
data.putShort(index, (short) (pixel.intensity * 65535.0f));
|
||||||
|
data.putShort(index + 2, (short) (pixel.alpha * 65535.0f));
|
||||||
|
break;
|
||||||
|
case Luminance16F:
|
||||||
|
pixel.intensity = Float.intBitsToFloat(data.getShort(index));
|
||||||
|
break;
|
||||||
|
case Luminance16FAlpha16F:
|
||||||
|
pixel.intensity = Float.intBitsToFloat(data.getShort(index));
|
||||||
|
pixel.alpha = Float.intBitsToFloat(data.getShort(index + 2));
|
||||||
|
break;
|
||||||
|
case Luminance32F:
|
||||||
|
data.putInt(index, Float.floatToIntBits(pixel.intensity));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unknown luminance format type.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(Image image, int layer, TexturePixel pixel, int x, int y) {
|
public void write(Image image, int layer, TexturePixel pixel, int x, int y) {
|
||||||
int index = y * image.getWidth() + x;
|
int index = y * image.getWidth() + x;
|
||||||
this.write(image, layer,pixel, index);
|
this.write(image, layer, pixel, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user