Java Code Examples for java.nio.ByteBuffer.asIntBuffer()

The following are Jave code examples for showing how to use asIntBuffer() of the java.nio.ByteBuffer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: trashjam2017   File: CursorLoader.java   View Source Code Vote up 6 votes
/**
 * 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);
	}
}
 
Example 2
Project: Progetto-C   File: CursorLoader.java   View Source Code Vote up 6 votes
/**
 * 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);
	}
}
 
Example 3
Project: openjdk-jdk10   File: ImageReader.java   View Source Code Vote up 6 votes
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);
        }
    }
}
 
Example 4
Project: sumo   File: LWJGLCursorFactory.java   View Source Code Vote up 6 votes
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;
}
 
Example 5
Project: trashjam2017   File: CursorLoader.java   View Source Code Vote up 5 votes
/**
 * Get a cursor based on a image reference on the classpath
 * 
 * @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)
 * @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(String ref,int x,int y) throws IOException, LWJGLException {
	LoadableImageData imageData = null;
	
	imageData = ImageDataFactory.getImageDataFor(ref);
	imageData.configureEdging(false);
	
	ByteBuffer buf = imageData.loadImage(ResourceLoader.getResourceAsStream(ref), true, true, null);
	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);
	}
}
 
Example 6
Project: Backmemed   File: Shaders.java   View Source Code Vote up 5 votes
private static IntBuffer nextIntBuffer(int size)
{
    ByteBuffer bytebuffer = bigBuffer;
    int i = bytebuffer.limit();
    bytebuffer.position(i).limit(i + size * 4);
    return bytebuffer.asIntBuffer();
}
 
Example 7
Project: debug   File: RT.java   View Source Code Vote up 5 votes
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;
}
 
Example 8
Project: Progetto-C   File: CursorLoader.java   View Source Code Vote up 5 votes
/**
 * Get a cursor based on a image reference on the classpath
 * 
 * @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)
 * @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(String ref,int x,int y) throws IOException, LWJGLException {
	LoadableImageData imageData = null;
	
	imageData = ImageDataFactory.getImageDataFor(ref);
	imageData.configureEdging(false);
	
	ByteBuffer buf = imageData.loadImage(ResourceLoader.getResourceAsStream(ref), true, true, null);
	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);
	}
}
 
Example 9
Project: LearningOfThinkInJava   File: IntBufferDemo.java   View Source Code Vote up 5 votes
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);
    }


}
 
Example 10
Project: 19porn   File: OpenGlUtils.java   View Source Code Vote up 5 votes
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;
}
 
Example 11
Project: openjdk-jdk10   File: ByteBufferTest.java   View Source Code Vote up 5 votes
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");
}
 
Example 12
Project: openjdk-jdk10   File: CMap.java   View Source Code Vote up 4 votes
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;
}
 
Example 13
Project: incubator-netbeans   File: CacheReader.java   View Source Code Vote up 4 votes
/** 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;
}
 
Example 14
Project: openjdk-jdk10   File: NativeInt32Array.java   View Source Code Vote up 4 votes
@Override
public Int32ArrayData createArrayData(final ByteBuffer nb, final int start, final int length) {
    return new Int32ArrayData(nb.asIntBuffer(), start, length);
}
 
Example 15
Project: dremio-oss   File: EscapeTest1.java   View Source Code Vote up 4 votes
public Monkey(){
  ByteBuffer bb = ByteBuffer.allocateDirect(Integer.MAX_VALUE);
  buf = bb.asIntBuffer();
}
 
Example 16
Project: trashjam2017   File: CursorLoader.java   View Source Code Vote up 3 votes
/**
 * 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);
}
 
Example 17
Project: trashjam2017   File: TextureImpl.java   View Source Code Vote up 3 votes
/**
 * 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();
}
 
Example 18
Project: Towan   File: InternalTextureLoader.java   View Source Code Vote up 3 votes
/**
 * 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();
}
 
Example 19
Project: BaseClient   File: TextureImpl.java   View Source Code Vote up 3 votes
/**
 * 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();
}
 
Example 20
Project: BaseClient   File: InternalTextureLoader.java   View Source Code Vote up 3 votes
/**
 * 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();
}