当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuffer.asIntBuffer方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:36,代码来源:CursorLoader.java

示例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);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ImageReader.java

示例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;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:19,代码来源:LWJGLCursorFactory.java

示例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();
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:8,代码来源:Shaders.java

示例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;
}
 
开发者ID:LWJGLX,项目名称:debug,代码行数:11,代码来源:RT.java

示例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);
    }


}
 
开发者ID:sean417,项目名称:LearningOfThinkInJava,代码行数:16,代码来源:IntBufferDemo.java

示例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;
}
 
开发者ID:lzmlsfe,项目名称:19porn,代码行数:9,代码来源:OpenGlUtils.java

示例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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:ByteBufferTest.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:50,代码来源:CMap.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:47,代码来源:CacheReader.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:NativeInt32Array.java

示例12: Monkey

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public Monkey(){
  ByteBuffer bb = ByteBuffer.allocateDirect(Integer.MAX_VALUE);
  buf = bb.asIntBuffer();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:5,代码来源:EscapeTest1.java

示例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);
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:29,代码来源:CursorLoader.java

示例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();
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:14,代码来源:TextureImpl.java

示例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();
}
 
开发者ID:imaTowan,项目名称:Towan,代码行数:14,代码来源:InternalTextureLoader.java


注:本文中的java.nio.ByteBuffer.asIntBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。