* Problem: Slow. Solution? Speed.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9742 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
47563c2cf1
commit
105d27fddf
@ -36,64 +36,69 @@ public class DefaultImageRaster extends ImageRaster {
|
|||||||
|
|
||||||
@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);
|
||||||
|
|
||||||
// Check flags for grayscale
|
// Check flags for grayscale
|
||||||
if ((codec.flags & ImageCodec.FLAG_GRAY) != 0) {
|
if (codec.isGray) {
|
||||||
float gray = color.r * 0.27f + color.g * 0.67f + color.b * 0.06f;
|
float gray = color.r * 0.27f + color.g * 0.67f + color.b * 0.06f;
|
||||||
color = new ColorRGBA(gray, gray, gray, color.a);
|
color = new ColorRGBA(gray, gray, gray, color.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((codec.flags & ImageCodec.FLAG_F16) != 0) {
|
switch (codec.type) {
|
||||||
components[0] = (int) FastMath.convertFloatToHalf(color.a);
|
case ImageCodec.FLAG_F16:
|
||||||
components[1] = (int) FastMath.convertFloatToHalf(color.r);
|
components[0] = (int) FastMath.convertFloatToHalf(color.a);
|
||||||
components[2] = (int) FastMath.convertFloatToHalf(color.g);
|
components[1] = (int) FastMath.convertFloatToHalf(color.r);
|
||||||
components[3] = (int) FastMath.convertFloatToHalf(color.b);
|
components[2] = (int) FastMath.convertFloatToHalf(color.g);
|
||||||
} else if ((codec.flags & ImageCodec.FLAG_F32) != 0) {
|
components[3] = (int) FastMath.convertFloatToHalf(color.b);
|
||||||
components[0] = (int) Float.floatToIntBits(color.a);
|
break;
|
||||||
components[1] = (int) Float.floatToIntBits(color.r);
|
case ImageCodec.FLAG_F32:
|
||||||
components[2] = (int) Float.floatToIntBits(color.g);
|
components[0] = (int) Float.floatToIntBits(color.a);
|
||||||
components[3] = (int) Float.floatToIntBits(color.b);
|
components[1] = (int) Float.floatToIntBits(color.r);
|
||||||
} else {
|
components[2] = (int) Float.floatToIntBits(color.g);
|
||||||
// Convert color to bits by multiplying by size
|
components[3] = (int) Float.floatToIntBits(color.b);
|
||||||
components[0] = Math.min( (int) (color.a * codec.maxAlpha + 0.5f), codec.maxAlpha);
|
break;
|
||||||
components[1] = Math.min( (int) (color.r * codec.maxRed + 0.5f), codec.maxRed);
|
case 0:
|
||||||
components[2] = Math.min( (int) (color.g * codec.maxGreen + 0.5f), codec.maxGreen);
|
// Convert color to bits by multiplying by size
|
||||||
components[3] = Math.min( (int) (color.b * codec.maxBlue + 0.5f), codec.maxBlue);
|
components[0] = Math.min( (int) (color.a * codec.maxAlpha + 0.5f), codec.maxAlpha);
|
||||||
|
components[1] = Math.min( (int) (color.r * codec.maxRed + 0.5f), codec.maxRed);
|
||||||
|
components[2] = Math.min( (int) (color.g * codec.maxGreen + 0.5f), codec.maxGreen);
|
||||||
|
components[3] = Math.min( (int) (color.b * codec.maxBlue + 0.5f), codec.maxBlue);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
codec.writeComponents(buffer, x, y, width, components, temp);
|
codec.writeComponents(buffer, x, y, width, components, temp);
|
||||||
|
|
||||||
image.setUpdateNeeded();
|
image.setUpdateNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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(buffer, x, y, width, components, temp);
|
codec.readComponents(buffer, x, y, width, components, temp);
|
||||||
|
|
||||||
if (store == null) {
|
if (store == null) {
|
||||||
store = new ColorRGBA();
|
store = new ColorRGBA();
|
||||||
}
|
}
|
||||||
if ((codec.flags & ImageCodec.FLAG_F16) != 0) {
|
switch (codec.type) {
|
||||||
store.set(FastMath.convertHalfToFloat((short)components[1]),
|
case ImageCodec.FLAG_F16:
|
||||||
FastMath.convertHalfToFloat((short)components[2]),
|
store.set(FastMath.convertHalfToFloat((short)components[1]),
|
||||||
FastMath.convertHalfToFloat((short)components[3]),
|
FastMath.convertHalfToFloat((short)components[2]),
|
||||||
FastMath.convertHalfToFloat((short)components[0]));
|
FastMath.convertHalfToFloat((short)components[3]),
|
||||||
} else if ((codec.flags & ImageCodec.FLAG_F32) != 0) {
|
FastMath.convertHalfToFloat((short)components[0]));
|
||||||
store.set(Float.intBitsToFloat((int)components[1]),
|
break;
|
||||||
Float.intBitsToFloat((int)components[2]),
|
case ImageCodec.FLAG_F32:
|
||||||
Float.intBitsToFloat((int)components[3]),
|
store.set(Float.intBitsToFloat((int)components[1]),
|
||||||
Float.intBitsToFloat((int)components[0]));
|
Float.intBitsToFloat((int)components[2]),
|
||||||
} else {
|
Float.intBitsToFloat((int)components[3]),
|
||||||
// Convert to float and divide by bitsize to get into range 0.0 - 1.0.
|
Float.intBitsToFloat((int)components[0]));
|
||||||
store.set((float)components[1] / codec.maxRed,
|
break;
|
||||||
(float)components[2] / codec.maxGreen,
|
case 0:
|
||||||
(float)components[3] / codec.maxBlue,
|
// Convert to float and divide by bitsize to get into range 0.0 - 1.0.
|
||||||
(float)components[0] / codec.maxAlpha);
|
store.set((float)components[1] / codec.maxRed,
|
||||||
|
(float)components[2] / codec.maxGreen,
|
||||||
|
(float)components[3] / codec.maxBlue,
|
||||||
|
(float)components[0] / codec.maxAlpha);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if ((codec.flags & ImageCodec.FLAG_GRAY) != 0) {
|
if (codec.isGray) {
|
||||||
store.g = store.b = store.r;
|
store.g = store.b = store.r;
|
||||||
} else {
|
} else {
|
||||||
if (codec.maxRed == 0) {
|
if (codec.maxRed == 0) {
|
||||||
|
@ -7,14 +7,16 @@ import java.util.EnumMap;
|
|||||||
|
|
||||||
abstract class ImageCodec {
|
abstract class ImageCodec {
|
||||||
|
|
||||||
public static final int FLAG_F16 = 1, FLAG_F32 = 2, FLAG_GRAY = 4, FLAG_ALPHAONLY = 8, FLAG_SHAREDEXP = 16;
|
public static final int FLAG_F16 = 1, FLAG_F32 = 2, FLAG_GRAY = 4; //, FLAG_ALPHAONLY = 8, FLAG_SHAREDEXP = 16;
|
||||||
private static final EnumMap<Image.Format, ImageCodec> params = new EnumMap<Image.Format, ImageCodec>(Image.Format.class);
|
private static final EnumMap<Image.Format, ImageCodec> params = new EnumMap<Image.Format, ImageCodec>(Image.Format.class);
|
||||||
|
|
||||||
protected final int bpp, flags, maxAlpha, maxRed, maxGreen, maxBlue;
|
protected final int bpp, type, maxAlpha, maxRed, maxGreen, maxBlue;
|
||||||
|
protected final boolean isGray;
|
||||||
|
|
||||||
public ImageCodec(int bpp, int flags, int maxAlpha, int maxRed, int maxGreen, int maxBlue) {
|
public ImageCodec(int bpp, int flags, int maxAlpha, int maxRed, int maxGreen, int maxBlue) {
|
||||||
this.bpp = bpp;
|
this.bpp = bpp;
|
||||||
this.flags = flags;
|
this.isGray = (flags & FLAG_GRAY) != 0;
|
||||||
|
this.type = flags & ~FLAG_GRAY;
|
||||||
this.maxAlpha = maxAlpha;
|
this.maxAlpha = maxAlpha;
|
||||||
this.maxRed = maxRed;
|
this.maxRed = maxRed;
|
||||||
this.maxGreen = maxGreen;
|
this.maxGreen = maxGreen;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user