From 027d448b7db10d434949115a1cfe1cceb56f9ef1 Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Wed, 23 May 2012 08:48:05 +0000 Subject: [PATCH] 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 --- .../io/LuminancePixelInputOutput.java | 73 +++++++++++++++++-- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/io/LuminancePixelInputOutput.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/io/LuminancePixelInputOutput.java index 7088210a1..7529e9164 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/io/LuminancePixelInputOutput.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/io/LuminancePixelInputOutput.java @@ -1,29 +1,88 @@ package com.jme3.scene.plugins.blender.textures.io; +import java.nio.ByteBuffer; + import com.jme3.scene.plugins.blender.textures.TexturePixel; import com.jme3.texture.Image; /** * Implemens read/write operations for luminance images. + * * @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) { - byte intensity = image.getData(layer).get(index); - pixel.fromIntensity(intensity); + ByteBuffer data = image.getData(layer); + 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) { int index = y * image.getWidth() + x; this.read(image, layer, pixel, 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) { int index = y * image.getWidth() + x; - this.write(image, layer,pixel, index); + this.write(image, layer, pixel, index); } }