From a2b2a85cce35d6d89b346ff68c319155736d9eb6 Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Fri, 25 May 2012 12:34:03 +0000 Subject: [PATCH] Extending TexturePixel functionality. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9430 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../blender/textures/TexturePixel.java | 49 ++++++++++++++++++- .../textures/blending/TextureBlenderDDS.java | 2 +- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TexturePixel.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TexturePixel.java index d1d46809e..e0598de5c 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TexturePixel.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TexturePixel.java @@ -51,7 +51,7 @@ public class TexturePixel implements Cloneable { * @param b * the blue value */ - public void fromARGB8(float a, float r, float g, float b) { + public void fromARGB(float a, float r, float g, float b) { this.alpha = a; this.red = r; this.green = g; @@ -77,6 +77,25 @@ public class TexturePixel implements Cloneable { this.blue = b >= 0 ? b / 255.0f : 1.0f - ~b / 255.0f; } + /** + * Copies the values from the given values. + * + * @param a + * the alpha value + * @param r + * the red value + * @param g + * the green value + * @param b + * the blue value + */ + public void fromARGB16(short a, short r, short g, short b) { + this.alpha = a >= 0 ? a / 65535.0f : 1.0f - ~a / 65535.0f; + this.red = r >= 0 ? r / 65535.0f : 1.0f - ~r / 65535.0f; + this.green = g >= 0 ? g / 65535.0f : 1.0f - ~g / 65535.0f; + this.blue = b >= 0 ? b / 65535.0f : 1.0f - ~b / 65535.0f; + } + /** * Copies the intensity from the given value. * @@ -215,6 +234,34 @@ public class TexturePixel implements Cloneable { return (byte) (this.blue * 255.0f); } + /** + * @return the alpha value of the pixel + */ + public short getA16() { + return (byte) (this.alpha * 65535.0f); + } + + /** + * @return the alpha red of the pixel + */ + public short getR16() { + return (byte) (this.red * 65535.0f); + } + + /** + * @return the green value of the pixel + */ + public short getG16() { + return (byte) (this.green * 65535.0f); + } + + /** + * @return the blue value of the pixel + */ + public short getB16() { + return (byte) (this.blue * 65535.0f); + } + /** * Merges two pixels (adds the values of each color). * diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderDDS.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderDDS.java index 4593f1ffe..7fa9ad064 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderDDS.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderDDS.java @@ -99,7 +99,7 @@ public class TextureBlenderDDS extends TextureBlenderAWT { colors[i].toRGBA(pixelColor); pixelColor[3] = alphas[i]; this.blendPixel(resultPixel, compressedMaterialColor != null ? compressedMaterialColor[i] : materialColor, pixelColor, blenderContext); - colors[i].fromARGB8(1, resultPixel[0], resultPixel[1], resultPixel[2]); + colors[i].fromARGB(1, resultPixel[0], resultPixel[1], resultPixel[2]); int argb8 = colors[i].toARGB8(); short rgb565 = RGB565.ARGB8_to_RGB565(argb8); newData.putShort(rgb565);