1 32 package com.imagero.uio.buffer.arrays; 33 34 import com.imagero.uio.buffer.MemoryAccessManager; 35 36 37 44 public class FloatArrayBufferManager extends AbstractArrayBufferManager { 45 46 float[] data; 47 48 53 public FloatArrayBufferManager(float[] data) { 54 this(data, Math.min(TILE_SIZE, data.length)); 55 } 56 57 63 public FloatArrayBufferManager(float[] data, int size) { 64 this(data, 0, data.length, size); 65 } 66 67 74 public FloatArrayBufferManager(float[] data, int offset, int length) { 75 this(data, offset, length, TILE_SIZE); 76 } 77 78 86 public FloatArrayBufferManager(float[] data, int offset, int length, int size) { 87 this.data = data; 88 this.tileSize = size; 89 this.unitSize = 4; 90 this.length = length; 91 this.offset = offset; 92 accessManager = MemoryAccessManager.createMemoryAccessManager(); 93 } 94 95 104 protected int writeUnitLE(byte[] source, int sourceOffset, int destOffset) { 105 int v = ((source[sourceOffset++] & 0xFF)) 106 | (((source[sourceOffset++] & 0xFF)) << 8) 107 | (((source[sourceOffset++] & 0xFF)) << 16) 108 | (((source[sourceOffset++] & 0xFF)) << 24); 109 data[destOffset] = Float.intBitsToFloat(v); 110 return sourceOffset; 111 } 112 113 122 protected int writeUnitBE(byte[] source, int sourceOffset, int destOffset) { 123 int v = ((source[sourceOffset++] & 0xFF) << 24) 124 | ((source[sourceOffset++] & 0xFF) << 16) 125 | ((source[sourceOffset++] & 0xFF) << 8) 126 | (source[sourceOffset++] & 0xFF); 127 data[destOffset] = Float.intBitsToFloat(v); 128 return sourceOffset; 129 } 130 131 140 protected int readUnitBE(int offset, byte[] dest, int destOffset) { 141 float f = data[offset]; 142 int v = Float.floatToIntBits(f); 143 dest[destOffset++] = (byte) ((v >>> 24) & 0xFF); 144 dest[destOffset++] = (byte) ((v >>> 16) & 0xFF); 145 dest[destOffset++] = (byte) ((v >>> 8) & 0xFF); 146 dest[destOffset++] = (byte) (v & 0xFF); 147 return destOffset; 148 } 149 150 159 protected int readUnitLE(int offset, byte[] dest, int destOffset) { 160 float f = data[offset]; 161 int v = Float.floatToIntBits(f); 162 dest[destOffset++] = (byte) (v & 0xFF); 163 dest[destOffset++] = (byte) ((v >>> 8) & 0xFF); 164 dest[destOffset++] = (byte) ((v >>> 16) & 0xFF); 165 dest[destOffset++] = (byte) ((v >>> 24) & 0xFF); 166 return destOffset; 167 } 168 } 169 | Popular Tags |