本文整理汇总了Java中java.nio.ByteBuffer.asIntBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.asIntBuffer方法的具体用法?Java ByteBuffer.asIntBuffer怎么用?Java ByteBuffer.asIntBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.asIntBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCursor
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Get a cursor based on a set of image data
*
* @param imageData The data from which the cursor can read it's contents
* @param x The x-coordinate of the cursor hotspot (left -> right)
* @param y The y-coordinate of the cursor hotspot (bottom -> top)
* @return The create cursor
* @throws IOException Indicates a failure to load the image
* @throws LWJGLException Indicates a failure to create the hardware cursor
*/
public Cursor getCursor(ImageData imageData,int x,int y) throws IOException, LWJGLException {
ByteBuffer buf = imageData.getImageBufferData();
for (int i=0;i<buf.limit();i+=4) {
byte red = buf.get(i);
byte green = buf.get(i+1);
byte blue = buf.get(i+2);
byte alpha = buf.get(i+3);
buf.put(i+2, red);
buf.put(i+1, green);
buf.put(i, blue);
buf.put(i+3, alpha);
}
try {
int yspot = imageData.getHeight() - y - 1;
if (yspot < 0) {
yspot = 0;
}
return new Cursor(imageData.getTexWidth(), imageData.getTexHeight(), x, yspot, 1, buf.asIntBuffer(), null);
} catch (Throwable e) {
Log.info("Chances are you cursor is too small for this platform");
throw new LWJGLException(e);
}
}
示例2: visitPackageLocation
import java.nio.ByteBuffer; //导入方法依赖的package包/类
void visitPackageLocation(ImageLocation loc) {
// Retrieve package name
String pkgName = getBaseExt(loc);
// Content is array of offsets in Strings table
byte[] stringsOffsets = getResource(loc);
ByteBuffer buffer = ByteBuffer.wrap(stringsOffsets);
buffer.order(getByteOrder());
IntBuffer intBuffer = buffer.asIntBuffer();
// For each module, create a link node.
for (int i = 0; i < stringsOffsets.length / SIZE_OF_OFFSET; i++) {
// skip empty state, useless.
intBuffer.get(i);
i++;
int offset = intBuffer.get(i);
String moduleName = getString(offset);
Node targetNode = findNode("/modules/" + moduleName);
if (targetNode != null) {
String pkgDirName = packagesDir.getName() + "/" + pkgName;
Directory pkgDir = (Directory) nodes.get(pkgDirName);
newLinkNode(pkgDir, pkgDir.getName() + "/" + moduleName, targetNode);
}
}
}
示例3: convertMask
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static IntBuffer convertMask(int[][] cursorMask)
{
ByteBuffer bb = ByteBuffer.allocateDirect(cursorMask.length*cursorMask[0].length*4);
bb.order(ByteOrder.nativeOrder());
IntBuffer ib = bb.asIntBuffer();
for(int y = cursorMask.length - 1; y >= 0; y--)
{
for(int x = 0; x < cursorMask[0].length; x++)
{
ib.put(cursorMask[y][x]);
}
}
ib.flip();
return ib;
}
示例4: nextIntBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static IntBuffer nextIntBuffer(int size)
{
ByteBuffer bytebuffer = bigBuffer;
int i = bytebuffer.limit();
bytebuffer.position(i).limit(i + size * 4);
return bytebuffer.asIntBuffer();
}
示例5: asIntBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static IntBuffer asIntBuffer(ByteBuffer buf) {
IntBuffer buffer = buf.asIntBuffer();
Buffer viewedBuffer = bufferViews.get(buf);
if (viewedBuffer != null) {
bufferViews.put(buffer, viewedBuffer);
} else {
bufferViews.put(buffer, buf);
}
return buffer;
}
示例6: main
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static void main(String[] args) {
ByteBuffer bb=ByteBuffer.allocate(BSIZE);
IntBuffer ib=bb.asIntBuffer();
ib.put(new int[]{11,42,47,99,143,811,1016});
System.out.println(ib.getClass().getName());
System.out.println(ib.get(3));
ib.put(3,1811);
ib.flip();
while (ib.hasRemaining()){
int i=ib.get();
System.out.println(i);
}
}
示例7: createIntBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static IntBuffer createIntBuffer(int[] coords) {
ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * SIZEOF_INT);
bb.order(ByteOrder.nativeOrder());
IntBuffer ib = bb.asIntBuffer();
ib.put(coords);
ib.position(0);
return ib;
}
示例8: asView
import java.nio.ByteBuffer; //导入方法依赖的package包/类
Buffer asView(ByteBuffer b, PrimitiveType t) {
switch (t) {
case BYTE: return b;
case CHAR: return b.asCharBuffer();
case SHORT: return b.asShortBuffer();
case INT: return b.asIntBuffer();
case LONG: return b.asLongBuffer();
case FLOAT: return b.asFloatBuffer();
case DOUBLE: return b.asDoubleBuffer();
}
throw new InternalError("Should not reach here");
}
示例9: CMapFormat12
import java.nio.ByteBuffer; //导入方法依赖的package包/类
CMapFormat12(ByteBuffer buffer, int offset, char[] xlat) {
if (xlat != null) {
throw new RuntimeException("xlat array for cmap fmt=12");
}
numGroups = buffer.getInt(offset+12);
startCharCode = new long[numGroups];
endCharCode = new long[numGroups];
startGlyphID = new int[numGroups];
buffer.position(offset+16);
buffer = buffer.slice();
IntBuffer ibuffer = buffer.asIntBuffer();
for (int i=0; i<numGroups; i++) {
startCharCode[i] = ibuffer.get() & INTMASK;
endCharCode[i] = ibuffer.get() & INTMASK;
startGlyphID[i] = ibuffer.get() & INTMASK;
}
/* Finds the high bit by binary searching through the bits */
int value = numGroups;
if (value >= 1 << 16) {
value >>= 16;
highBit += 16;
}
if (value >= 1 << 8) {
value >>= 8;
highBit += 8;
}
if (value >= 1 << 4) {
value >>= 4;
highBit += 4;
}
if (value >= 1 << 2) {
value >>= 2;
highBit += 2;
}
if (value >= 1 << 1) {
value >>= 1;
highBit += 1;
}
power = 1 << highBit;
extra = numGroups - power;
}
示例10: findMetadataFor
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/** Locates metadata related to the passed id (converted into a byte
* array). Returns either a bytebuffer with the position set to the
* start of the metadata or null. */
private ByteBuffer findMetadataFor (byte[] id) throws IOException {
System.err.println("FindMetadataFor " + new String(id));
long result = -1;
//Get a buffer clone so we don't have threading problems - never
//use the master buffer
ByteBuffer buf = getMetaBuffer().asReadOnlyBuffer();
IntBuffer ibuf = buf.asIntBuffer();
do {
//First, see if the ID (image filename) length matches the ID
//we received - if it doesn't, no need to examine the record
int thisIdLength = ibuf.get();
System.err.println("pos:" + ibuf.position() + " idLen: " + thisIdLength + " looking for len: " + id.length);
if (thisIdLength == id.length) {
//Mark the start of this metadata record and position to
//the start of the ID entry
System.err.println("Length match. Putting mark at " + (buf.position()) + " and moving to " + (buf.position() + ID_OFFSET) + " to check data");
buf.mark().position (buf.position() + ID_OFFSET);
byte[] chars = new byte[id.length];
//Fetch the ID into the array, and reset the buffer position
//for either returning or skipping to the next record
buf.get(chars).reset();
System.err.println(" id from metadata: " + new String(chars));
//Compare it with the id we were passed
if (Arrays.equals(chars, id)) {
System.err.println(" MATCHED - position: " + buf.position());
return buf;
}
}
//Skip ahead to the next record
buf.position(buf.position() + METAENTRY_LENGTH);
ibuf.position(buf.position() / 4);
System.err.println("Buffer pos: " + buf.position() + " ibuf: " + ibuf.position());
} while (buf.position() <= buf.limit() - METAENTRY_LENGTH);
return null;
}
示例11: createArrayData
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public Int32ArrayData createArrayData(final ByteBuffer nb, final int start, final int length) {
return new Int32ArrayData(nb.asIntBuffer(), start, length);
}
示例12: Monkey
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public Monkey(){
ByteBuffer bb = ByteBuffer.allocateDirect(Integer.MAX_VALUE);
buf = bb.asIntBuffer();
}
示例13: getAnimatedCursor
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Get a cursor based on a image reference on the classpath. The image
* is assumed to be a set/strip of cursor animation frames running from top to
* bottom.
*
* @param ref The reference to the image to be loaded
* @param x The x-coordinate of the cursor hotspot (left -> right)
* @param y The y-coordinate of the cursor hotspot (bottom -> top)
* @param width The x width of the cursor
* @param height The y height of the cursor
* @param cursorDelays image delays between changing frames in animation
*
* @return The created cursor
* @throws IOException Indicates a failure to load the image
* @throws LWJGLException Indicates a failure to create the hardware cursor
*/
public Cursor getAnimatedCursor(String ref,int x,int y, int width, int height, int[] cursorDelays) throws IOException, LWJGLException {
IntBuffer cursorDelaysBuffer = ByteBuffer.allocateDirect(cursorDelays.length*4).order(ByteOrder.nativeOrder()).asIntBuffer();
for (int i=0;i<cursorDelays.length;i++) {
cursorDelaysBuffer.put(cursorDelays[i]);
}
cursorDelaysBuffer.flip();
LoadableImageData imageData = new TGAImageData();
ByteBuffer buf = imageData.loadImage(ResourceLoader.getResourceAsStream(ref), false, null);
return new Cursor(width, height, x, y, cursorDelays.length, buf.asIntBuffer(), cursorDelaysBuffer);
}
示例14: createIntBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Creates an integer buffer to hold specified ints
* - strictly a utility method
*
* @param size how many int to contain
* @return created IntBuffer
*/
protected IntBuffer createIntBuffer(int size) {
ByteBuffer temp = ByteBuffer.allocateDirect(4 * size);
temp.order(ByteOrder.nativeOrder());
return temp.asIntBuffer();
}
示例15: createIntBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Creates an integer buffer to hold specified ints
* - strictly a utility method
*
* @param size how many int to contain
* @return created IntBuffer
*/
public static IntBuffer createIntBuffer(int size) {
ByteBuffer temp = ByteBuffer.allocateDirect(4 * size);
temp.order(ByteOrder.nativeOrder());
return temp.asIntBuffer();
}