private void writeRGBE(byte[] rgbe){ if (writeRGBE){ dataStore.put(rgbe); }else{ convertRGBEtoFloat(rgbe, tempF); dataStore.putShort(FastMath.convertFloatToHalf(tempF[0])) .putShort(FastMath.convertFloatToHalf(tempF[1])). putShort(FastMath.convertFloatToHalf(tempF[2])); } }
public static void main(String[] args){ Scanner scan = new Scanner(System.in); while (true){ System.out.println("Enter float to convert or 'x' to exit: "); String s = scan.nextLine(); if (s.equals("x")) break; float flt = Float.valueOf(s); short half = FastMath.convertFloatToHalf(flt); float flt2 = FastMath.convertHalfToFloat(half); System.out.println("Input float: "+flt); System.out.println("Result float: "+flt2); } } }
components[0] = (int) FastMath.convertFloatToHalf(color.a); components[1] = (int) FastMath.convertFloatToHalf(color.r); components[2] = (int) FastMath.convertFloatToHalf(color.g); components[3] = (int) FastMath.convertFloatToHalf(color.b); break; case ImageCodec.FLAG_F32:
public void write(Image image, int layer, TexturePixel pixel, int index) { 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 Luminance16F: data.putShort(index, FastMath.convertFloatToHalf(pixel.intensity)); break; case Luminance16FAlpha16F: data.putShort(index, FastMath.convertFloatToHalf(pixel.intensity)); data.putShort(index + 2, FastMath.convertFloatToHalf(pixel.alpha)); break; case Luminance32F: data.putInt(index, Float.floatToIntBits(pixel.intensity)); break; default: throw new IllegalStateException("Unknown luminance format type."); } }
components[0] = (int) FastMath.convertFloatToHalf(color.a); components[1] = (int) FastMath.convertFloatToHalf(color.r); components[2] = (int) FastMath.convertFloatToHalf(color.g); components[3] = (int) FastMath.convertFloatToHalf(color.b); break; case ImageCodec.FLAG_F32:
/** * Converts single floating-point data to {@link Format#Half half} floating-point data. */ public void convertToHalf(){ if (id != -1) { throw new UnsupportedOperationException("Data has already been sent."); } if (format != Format.Float) { throw new IllegalStateException("Format must be float!"); } int numElements = data.limit() / components; format = Format.Half; this.componentsLength = components * format.getComponentSize(); ByteBuffer halfData = BufferUtils.createByteBuffer(componentsLength * numElements); halfData.rewind(); FloatBuffer floatData = (FloatBuffer) data; floatData.rewind(); for (int i = 0; i < floatData.limit(); i++){ float f = floatData.get(i); short half = FastMath.convertFloatToHalf(f); halfData.putShort(half); } this.data = halfData; setUpdateNeeded(); dataSizeChanged = true; }
case RGB16F_to_RGB111110F: case RGB16F_to_RGB9E5: data.putShort(index, FastMath.convertFloatToHalf(pixel.red)); data.putShort(index + 2, FastMath.convertFloatToHalf(pixel.green)); data.putShort(index + 4, FastMath.convertFloatToHalf(pixel.blue)); break; case RGBA16F: data.putShort(index, FastMath.convertFloatToHalf(pixel.red)); data.putShort(index + 2, FastMath.convertFloatToHalf(pixel.green)); data.putShort(index + 4, FastMath.convertFloatToHalf(pixel.blue)); data.putShort(index + 6, FastMath.convertFloatToHalf(pixel.blue)); break; case RGB32F:
private void writeRGBE(byte[] rgbe){ if (writeRGBE){ dataStore.put(rgbe); }else{ convertRGBEtoFloat(rgbe, tempF); dataStore.putShort(FastMath.convertFloatToHalf(tempF[0])) .putShort(FastMath.convertFloatToHalf(tempF[1])). putShort(FastMath.convertFloatToHalf(tempF[2])); } }
private void writeRGBE(byte[] rgbe){ if (writeRGBE){ dataStore.put(rgbe); }else{ convertRGBEtoFloat(rgbe, tempF); dataStore.putShort(FastMath.convertFloatToHalf(tempF[0])) .putShort(FastMath.convertFloatToHalf(tempF[1])). putShort(FastMath.convertFloatToHalf(tempF[2])); } }
components[0] = (int) FastMath.convertFloatToHalf(color.a); components[1] = (int) FastMath.convertFloatToHalf(color.r); components[2] = (int) FastMath.convertFloatToHalf(color.g); components[3] = (int) FastMath.convertFloatToHalf(color.b); break; case ImageCodec.FLAG_F32:
components[0] = (int) FastMath.convertFloatToHalf(color.a); components[1] = (int) FastMath.convertFloatToHalf(color.r); components[2] = (int) FastMath.convertFloatToHalf(color.g); components[3] = (int) FastMath.convertFloatToHalf(color.b); break; case ImageCodec.FLAG_F32:
components[0] = (int) FastMath.convertFloatToHalf(color.a); components[1] = (int) FastMath.convertFloatToHalf(color.r); components[2] = (int) FastMath.convertFloatToHalf(color.g); components[3] = (int) FastMath.convertFloatToHalf(color.b); break; case ImageCodec.FLAG_F32:
/** * Converts single floating-point data to {@link Format#Half half} floating-point data. */ public void convertToHalf(){ if (id != -1) throw new UnsupportedOperationException("Data has already been sent."); if (format != Format.Float) throw new IllegalStateException("Format must be float!"); int numElements = data.limit() / components; format = Format.Half; this.componentsLength = components * format.getComponentSize(); ByteBuffer halfData = BufferUtils.createByteBuffer(componentsLength * numElements); halfData.rewind(); FloatBuffer floatData = (FloatBuffer) data; floatData.rewind(); for (int i = 0; i < floatData.limit(); i++){ float f = floatData.get(i); short half = FastMath.convertFloatToHalf(f); halfData.putShort(half); } this.data = halfData; setUpdateNeeded(); dataSizeChanged = true; }
/** * Converts single floating-point data to {@link Format#Half half} floating-point data. */ public void convertToHalf(){ if (id != -1) throw new UnsupportedOperationException("Data has already been sent."); if (format != Format.Float) throw new IllegalStateException("Format must be float!"); int numElements = data.capacity() / components; format = Format.Half; this.componentsLength = components * format.getComponentSize(); ByteBuffer halfData = BufferUtils.createByteBuffer(componentsLength * numElements); halfData.rewind(); FloatBuffer floatData = (FloatBuffer) data; floatData.rewind(); for (int i = 0; i < floatData.capacity(); i++){ float f = floatData.get(i); short half = FastMath.convertFloatToHalf(f); halfData.putShort(half); } this.data = halfData; setUpdateNeeded(); dataSizeChanged = true; }