本文整理了Java中java.nio.ByteBuffer.asFloatBuffer()
方法的一些代码示例,展示了ByteBuffer.asFloatBuffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuffer.asFloatBuffer()
方法的具体详情如下:
包路径:java.nio.ByteBuffer
类名称:ByteBuffer
方法名:asFloatBuffer
[英]Returns a float buffer which is based on the remaining content of this byte buffer.
The new buffer's position is zero, its limit and capacity is the number of remaining bytes divided by four, and its mark is not set. The new buffer's read-only property and byte order are the same as this buffer's. The new buffer is direct if this byte buffer is direct.
The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the other. The two buffer's position, limit and mark are independent.
[中]
代码示例来源:origin: libgdx/libgdx
public static FloatBuffer newFloatBuffer (int numFloats) {
ByteBuffer buffer = ByteBuffer.allocateDirect(numFloats * 4);
buffer.order(ByteOrder.nativeOrder());
return buffer.asFloatBuffer();
}
代码示例来源:origin: apache/incubator-druid
public EntireLayoutColumnarFloatsSupplier(int totalSize, ByteBuffer fromBuffer, ByteOrder order)
{
this.totalSize = totalSize;
this.buffer = fromBuffer.asReadOnlyBuffer().order(order).asFloatBuffer();
}
代码示例来源:origin: apache/incubator-druid
private static byte[] floatArrayToByteArray(float[] input)
{
final ByteBuffer buffer = ByteBuffer.allocate(Float.BYTES * input.length);
buffer.asFloatBuffer().put(input);
return buffer.array();
}
代码示例来源:origin: google/ExoPlayer
/** Allocates a FloatBuffer with the given data. */
public static FloatBuffer createBuffer(float[] data) {
ByteBuffer bb = ByteBuffer.allocateDirect(data.length * C.BYTES_PER_FLOAT);
bb.order(ByteOrder.nativeOrder());
FloatBuffer buffer = bb.asFloatBuffer();
buffer.put(data);
buffer.position(0);
return buffer;
}
代码示例来源:origin: opensourceBIM/BIMserver
public static byte[] floatToByteArray(Float inFloat) {
byte[] bArray = new byte[4];
ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
bBuffer.order(ByteOrder.LITTLE_ENDIAN);
FloatBuffer lBuffer = bBuffer.asFloatBuffer();
lBuffer.put(inFloat);
return bArray;
}
代码示例来源:origin: google/ExoPlayer
private static FloatBuffer nativeFloatBuffer(float... array) {
FloatBuffer buffer = ByteBuffer.allocateDirect(array.length * 4).order(
ByteOrder.nativeOrder()).asFloatBuffer();
buffer.put(array);
buffer.flip();
return buffer;
}
代码示例来源:origin: libgdx/libgdx
public static FloatBuffer newFloatBuffer (int numFloats) {
ByteBuffer buffer = ByteBuffer.allocateDirect(numFloats * 4);
buffer.order(ByteOrder.nativeOrder());
return buffer.asFloatBuffer();
}
代码示例来源:origin: deeplearning4j/nd4j
switch (_dtype) {
case DOUBLE: {
val db = bb.order(_order).asDoubleBuffer();
for (int e = 0; e < prod; e++)
doubles[e] = db.get(e);
val fb = bb.order(_order).asFloatBuffer();
for (int e = 0; e < prod; e++)
doubles[e] = (double) fb.get(e);
val sb = bb.order(_order).asShortBuffer();
for (int e = 0; e < prod; e++)
doubles[e] = (double) HalfIndexer.toFloat((int) sb.get(e));
代码示例来源:origin: opensourceBIM/BIMserver
public static byte[] floatArrayToByteArray(float[] vertices) {
if (vertices == null) {
return null;
}
ByteBuffer buffer = ByteBuffer.wrap(new byte[vertices.length * 4]);
buffer.order(ByteOrder.LITTLE_ENDIAN);
FloatBuffer asFloatBuffer = buffer.asFloatBuffer();
for (float f : vertices) {
asFloatBuffer.put(f);
}
return buffer.array();
}
代码示例来源:origin: apache/incubator-druid
@Override
public byte[] getCacheKey()
{
byte[] fieldNameBytes = StringUtils.toUtf8(fieldName);
ByteBuffer buf = ByteBuffer
.allocate(1 + fieldNameBytes.length + Float.BYTES * breaks.length)
.put(AggregatorUtil.HIST_CACHE_TYPE_ID)
.put(fieldNameBytes)
.put((byte) 0xFF);
buf.asFloatBuffer().put(breaks);
return buf.array();
}
代码示例来源:origin: cats-oss/android-gpuimage
public GPUImageRenderer(final GPUImageFilter filter) {
this.filter = filter;
runOnDraw = new LinkedList<>();
runOnDrawEnd = new LinkedList<>();
glCubeBuffer = ByteBuffer.allocateDirect(CUBE.length * 4)
.order(ByteOrder.nativeOrder())
.asFloatBuffer();
glCubeBuffer.put(CUBE).position(0);
glTextureBuffer = ByteBuffer.allocateDirect(TEXTURE_NO_ROTATION.length * 4)
.order(ByteOrder.nativeOrder())
.asFloatBuffer();
setRotation(Rotation.NORMAL, false, false);
}
代码示例来源:origin: runelite/runelite
static FloatBuffer allocateDirect(int size)
{
return ByteBuffer.allocateDirect(size * Float.BYTES)
.order(ByteOrder.nativeOrder())
.asFloatBuffer();
}
}
代码示例来源:origin: opensourceBIM/BIMserver
public static float[] toFloatArray(byte[] data) {
ByteBuffer buffer = ByteBuffer.wrap(data);
buffer.order(ByteOrder.LITTLE_ENDIAN);
FloatBuffer floatBuffer = buffer.asFloatBuffer();
float[] result = new float[data.length / 4];
for (int i=0; i<data.length / 4; i++) {
result[i] = floatBuffer.get();
}
return result;
}
代码示例来源:origin: apache/incubator-druid
@Override
public byte[] getCacheKey()
{
ByteBuffer minCoordsBuffer = ByteBuffer.allocate(minCoords.length * Float.BYTES);
minCoordsBuffer.asFloatBuffer().put(minCoords);
final byte[] minCoordsCacheKey = minCoordsBuffer.array();
ByteBuffer maxCoordsBuffer = ByteBuffer.allocate(maxCoords.length * Float.BYTES);
maxCoordsBuffer.asFloatBuffer().put(maxCoords);
final byte[] maxCoordsCacheKey = maxCoordsBuffer.array();
final ByteBuffer cacheKey = ByteBuffer
.allocate(1 + minCoordsCacheKey.length + maxCoordsCacheKey.length + Integer.BYTES)
.put(minCoordsCacheKey)
.put(maxCoordsCacheKey)
.putInt(limit)
.put(CACHE_TYPE_ID);
return cacheKey.array();
}
}
代码示例来源:origin: Rajawali/Rajawali
private FloatBuffer alocateBuffer(FloatBuffer buffer, float[] data) {
if (buffer == null) {
buffer = ByteBuffer
.allocateDirect(data.length * Geometry3D.FLOAT_SIZE_BYTES * 4)
.order(ByteOrder.nativeOrder()).asFloatBuffer();
buffer.put(data);
buffer.position(0);
} else {
buffer.put(data);
}
return buffer;
}
代码示例来源:origin: robovm/robovm
@MarshalsArray
public static FloatBuffer toFloatBuffer(Class<?> cls, long handle, long flags, int d1) {
return VM.newDirectByteBuffer(handle, d1 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
}
@MarshalsArray
代码示例来源:origin: opensourceBIM/BIMserver
private boolean matchExactlyTheSame(GeometryData geometryDate, GeometryData d) {
ByteBuffer bb1 = ByteBuffer.wrap(geometryDate.getVertices().getData());
bb1.order(ByteOrder.LITTLE_ENDIAN);
FloatBuffer buffer1 = bb1.asFloatBuffer();
ByteBuffer bb2 = ByteBuffer.wrap(d.getVertices().getData());
bb2.order(ByteOrder.LITTLE_ENDIAN);
FloatBuffer buffer2 = bb2.asFloatBuffer();
if (buffer1.capacity() != buffer2.capacity()) {
return false;
}
for (int i=0; i<buffer1.capacity(); i++) {
float a = buffer1.get();
float b = buffer1.get();
if (b != a) {
return false;
}
}
return true;
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public byte[] getCacheKey()
{
final ByteBuffer minCoordsBuffer = ByteBuffer.allocate(coords.length * Float.BYTES);
minCoordsBuffer.asFloatBuffer().put(coords);
final byte[] minCoordsCacheKey = minCoordsBuffer.array();
final ByteBuffer cacheKey = ByteBuffer
.allocate(1 + minCoordsCacheKey.length + Integer.BYTES + Float.BYTES)
.put(minCoordsCacheKey)
.putFloat(radius)
.putInt(getLimit())
.put(CACHE_TYPE_ID);
return cacheKey.array();
}
}
代码示例来源:origin: Rajawali/Rajawali
public void setColors(float[] colors, boolean override) {
final BufferInfo colorInfo = mBuffers.get(COLOR_BUFFER_KEY);
if (colorInfo.buffer == null || override == true) {
colorInfo.buffer = ByteBuffer
.allocateDirect(colors.length * FLOAT_SIZE_BYTES)
.order(ByteOrder.nativeOrder()).asFloatBuffer();
((FloatBuffer) colorInfo.buffer).put(colors);
colorInfo.buffer.position(0);
} else {
((FloatBuffer) colorInfo.buffer).put(colors);
colorInfo.buffer.position(0);
}
}
代码示例来源:origin: robovm/robovm
/**
* Returns a {@link FloatBuffer} which reads and writes to the same memory
* location pointed to by this {@link FloatPtr}.
*
* @param n the maximum number of floats the {@link FloatBuffer} can
* read/write. This will be the {@link FloatBuffer}'s
* <code>capacity</code>.
* @return the {@link FloatBuffer}.
*/
public FloatBuffer asFloatBuffer(int n) {
return as(BytePtr.class).asByteBuffer(n << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
}
内容来源于网络,如有侵权,请联系作者删除!