Java Code Examples for java.nio.IntBuffer#clear()

The following examples show how to use java.nio.IntBuffer#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileSerializationBenchmark.java    From imhotep with Apache License 2.0 6 votes vote down vote up
@Override
public int[] deserialize(File file) throws IOException {
    FileChannel ch = new RandomAccessFile(file, "r").getChannel();
    int[] ret = new int[(int)(file.length() / 4)];
    ByteBuffer buffer = ByteBuffer.allocateDirect(8192);
    buffer.order(ByteOrder.BIG_ENDIAN);
    IntBuffer intBuffer = buffer.asIntBuffer();
    for (int i = 0; i < ret.length; i += 2048) {
        buffer.clear();
        int lim = ch.read(buffer) / 4;
        intBuffer.clear();
        intBuffer.get(ret, i, lim);
    }
    ch.close();
    return ret;
}
 
Example 2
Source File: Screenshots.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void convertScreenShot2(IntBuffer bgraBuf, BufferedImage out){
        WritableRaster wr = out.getRaster();
        DataBufferInt db = (DataBufferInt) wr.getDataBuffer();
        
        int[] cpuArray = db.getData();
        
        bgraBuf.clear();
        bgraBuf.get(cpuArray);
        
//        int width  = wr.getWidth();
//        int height = wr.getHeight();
//
//        // flip the components the way AWT likes them
//        for (int y = 0; y < height / 2; y++){
//            for (int x = 0; x < width; x++){
//                int inPtr  = (y * width + x);
//                int outPtr = ((height-y-1) * width + x);
//                int pixel = cpuArray[inPtr];
//                cpuArray[inPtr] = cpuArray[outPtr];
//                cpuArray[outPtr] = pixel;
//            }
//        }
    }
 
Example 3
Source File: FileSerializationBenchmark.java    From imhotep with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(int[] a, File file) throws IOException {
    FileChannel ch = new RandomAccessFile(file, "rw").getChannel();
    ByteBuffer buffer = ByteBuffer.allocateDirect(8192);
    buffer.order(ByteOrder.BIG_ENDIAN);
    IntBuffer intBuffer = buffer.asIntBuffer();
    for (int i = 0; i < a.length; i += 2048) {
        intBuffer.clear();
        int lim = Math.min(2048, a.length - i);
        for (int j = 0; j < lim; ++j) {
            intBuffer.put(j, a[i+j]);
        }
        buffer.position(0).limit(4*lim);
        ch.write(buffer);
    }
    ch.close();
}
 
Example 4
Source File: Screenshots.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void convertScreenShot2(IntBuffer bgraBuf, BufferedImage out){
        WritableRaster wr = out.getRaster();
        DataBufferInt db = (DataBufferInt) wr.getDataBuffer();
        
        int[] cpuArray = db.getData();
        
        bgraBuf.clear();
        bgraBuf.get(cpuArray);
        
//        int width  = wr.getWidth();
//        int height = wr.getHeight();
//
//        // flip the components the way AWT likes them
//        for (int y = 0; y < height / 2; y++){
//            for (int x = 0; x < width; x++){
//                int inPtr  = (y * width + x);
//                int outPtr = ((height-y-1) * width + x);
//                int pixel = cpuArray[inPtr];
//                cpuArray[inPtr] = cpuArray[outPtr];
//                cpuArray[outPtr] = pixel;
//            }
//        }
    }
 
Example 5
Source File: IntArraySerializer.java    From imhotep with Apache License 2.0 6 votes vote down vote up
@Override
public int[] deserialize(File file) throws IOException {
    FileChannel ch = new RandomAccessFile(file, "r").getChannel();
    try {
        int[] ret = new int[(int)(file.length() / 4)];
        ByteBuffer buffer = ByteBuffer.allocateDirect(8192);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        IntBuffer intBuffer = buffer.asIntBuffer();
        for (int i = 0; i < ret.length; i += 2048) {
            buffer.clear();
            int lim = ch.read(buffer) / 4;
            intBuffer.clear();
            intBuffer.get(ret, i, lim);
        }
        return ret;
    } finally {
        ch.close();
    }
}
 
Example 6
Source File: FileSerializationBenchmark.java    From imhotep with Apache License 2.0 6 votes vote down vote up
@Override
public int[] deserialize(File file) throws IOException {
    FileChannel ch = new RandomAccessFile(file, "r").getChannel();
    int[] ret = new int[(int)(file.length() / 4)];
    ByteBuffer buffer = ByteBuffer.allocateDirect(8192);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    IntBuffer intBuffer = buffer.asIntBuffer();
    for (int i = 0; i < ret.length; i += 2048) {
        buffer.clear();
        int lim = ch.read(buffer) / 4;
        intBuffer.clear();
        intBuffer.get(ret, i, lim);
    }
    ch.close();
    return ret;
}
 
Example 7
Source File: BufferUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a new int[] array and populate it with the given IntBuffer's
 * contents.
 *
 * @param buff
 *            the IntBuffer to read from
 * @return a new int array populated from the IntBuffer
 */
public static int[] getIntArray(IntBuffer buff) {
    if (buff == null) {
        return null;
    }
    buff.clear();
    int[] inds = new int[buff.limit()];
    for (int x = 0; x < inds.length; x++) {
        inds[x] = buff.get();
    }
    return inds;
}
 
Example 8
Source File: FileSerializationBenchmark.java    From imhotep with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(int[] a, File file) throws IOException {
    FileChannel ch = new RandomAccessFile(file, "rw").getChannel();
    ByteBuffer buffer = ByteBuffer.allocateDirect(8192);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    IntBuffer intBuffer = buffer.asIntBuffer();
    for (int i = 0; i < a.length; i += 2048) {
        intBuffer.clear();
        int lim = Math.min(2048, a.length - i);
        intBuffer.put(a, i, lim);
        buffer.position(0).limit(4*lim);
        ch.write(buffer);
    }
    ch.close();
}
 
Example 9
Source File: Image.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public void copyPixelsFromBuffer() { //�ӻ�������copy����Լӿ����ش����ٶ�          	
	IntBuffer vbb = IntBuffer.wrap(colorArray);    	
    //vbb.put(colorArray);
    destImage.copyPixelsFromBuffer(vbb);
    vbb.clear();
    //vbb = null;
}
 
Example 10
Source File: BigForcefieldEnergy.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
private IntBuffer makeOrResizeBuffer(IntBuffer buf, int size) {
	if (buf == null || buf.capacity() < size) {
		buf = bufferType.makeInt(size);
	} else {
		buf.clear();
	}
	assert (buf.capacity() >= size);
	return buf;
}
 
Example 11
Source File: OpenALStreamPlayer.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Clean up the buffers applied to the sound source
 */
private synchronized void removeBuffers() {
	AL10.alSourceStop(source);
	IntBuffer buffer = BufferUtils.createIntBuffer(1);

	while (AL10.alGetSourcei(source, AL10.AL_BUFFERS_QUEUED) > 0) {
		AL10.alSourceUnqueueBuffers(source, buffer);
		buffer.clear();
	}
}
 
Example 12
Source File: BufferUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Generate a new IntBuffer using the given array of ints. The IntBuffer
 * will be data.length long and contain the int data as data[0], data[1]...
 * etc.
 *
 * @param data
 *            array of ints to place into a new IntBuffer
 */
public static IntBuffer createIntBuffer(int... data) {
    if (data == null) {
        return null;
    }
    IntBuffer buff = createIntBuffer(data.length);
    buff.clear();
    buff.put(data);
    buff.flip();
    return buff;
}
 
Example 13
Source File: OpenALStreamPlayer.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Clean up the buffers applied to the sound source
 */
private synchronized void removeBuffers() {
	AL10.alSourceStop(source);
	IntBuffer buffer = BufferUtils.createIntBuffer(1);

	while (AL10.alGetSourcei(source, AL10.AL_BUFFERS_QUEUED) > 0) {
		AL10.alSourceUnqueueBuffers(source, buffer);
		buffer.clear();
	}
}
 
Example 14
Source File: BufferUtils.java    From Ultraino with MIT License 5 votes vote down vote up
/**
 * Create a new int[] array and populate it with the given IntBuffer's
 * contents.
 *
 * @param buff
 *            the IntBuffer to read from
 * @return a new int array populated from the IntBuffer
 */
public static int[] getIntArray(IntBuffer buff) {
    if (buff == null) {
        return null;
    }
    buff.clear();
    int[] inds = new int[buff.limit()];
    for (int x = 0; x < inds.length; x++) {
        inds[x] = buff.get();
    }
    return inds;
}
 
Example 15
Source File: BufferUtils.java    From Ultraino with MIT License 5 votes vote down vote up
/**
 * Generate a new IntBuffer using the given array of ints. The IntBuffer
 * will be data.length long and contain the int data as data[0], data[1]...
 * etc.
 *
 * @param data
 *            array of ints to place into a new IntBuffer
 * @return a new direct, flipped IntBuffer, or null if data was null
 */
public static IntBuffer createIntBuffer(int... data) {
    if (data == null) {
        return null;
    }
    IntBuffer buff = createIntBuffer(data.length);
    buff.clear();
    buff.put(data);
    buff.flip();
    return buff;
}
 
Example 16
Source File: FloatToFixed.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void convertToFloat(IntBuffer input, FloatBuffer output){
    if (output.capacity() < input.capacity())
        throw new RuntimeException("Output must be at least as large as input!");

    input.clear();
    output.clear();
    for (int i = 0; i < input.capacity(); i++){
        output.put( ((float)input.get() / (float)(1<<16)) );
    }
    output.flip();
}
 
Example 17
Source File: HyperiumScreenshotHelper.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static IChatComponent saveScreenshot(int width, int height, Framebuffer buffer, IntBuffer pixelBuffer, int[] pixelValues) {
    final File file1 = new File(Minecraft.getMinecraft().mcDataDir, "screenshots");
    file1.mkdir();

    if (OpenGlHelper.isFramebufferEnabled()) {
        width = buffer.framebufferTextureWidth;
        height = buffer.framebufferTextureHeight;
    }

    final int i = width * height;

    if (pixelBuffer == null || pixelBuffer.capacity() < i) {
        pixelBuffer = BufferUtils.createIntBuffer(i);
        pixelValues = new int[i];
    }

    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    pixelBuffer.clear();

    if (OpenGlHelper.isFramebufferEnabled()) {
        GlStateManager.bindTexture(buffer.framebufferTexture);
        GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer);
    } else {
        GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer);
    }

    boolean upload = true;
    pixelBuffer.get(pixelValues);

    if (!Settings.DEFAULT_UPLOAD_SS) {
        HyperiumBind uploadBind = Hyperium.INSTANCE.getHandlers().getKeybindHandler().getBinding("Upload Screenshot");
        int keyCode = uploadBind.getKeyCode();
        upload = keyCode < 0 ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode);
    }

    new Thread(new AsyncScreenshotSaver(width, height, pixelValues, Minecraft.getMinecraft().getFramebuffer(),
        new File(Minecraft.getMinecraft().mcDataDir, "screenshots"), upload)).start();
    if (!upload) {
        return Settings.HYPERIUM_CHAT_PREFIX ? new ChatComponentText(ChatColor.RED + "[Hyperium] " + ChatColor.WHITE + "Capturing...") :
            new ChatComponentText(ChatColor.WHITE + "Capturing...");
    }
    return Settings.HYPERIUM_CHAT_PREFIX ? new ChatComponentText(ChatColor.RED + "[Hyperium] " + ChatColor.WHITE + "Uploading...") :
        new ChatComponentText(ChatColor.WHITE + "Uploading...");
}
 
Example 18
Source File: OffscreenRenderer.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
protected boolean setupFBO(GLViewport viewport) {
    IntBuffer buf = MapRenderer.getIntBuffer(1);

    texW = (int) viewport.getWidth();
    texH = (int) viewport.getHeight();

    gl.genFramebuffers(1, buf);
    fb = buf.get(0);

    buf.clear();
    gl.genTextures(1, buf);
    renderTex = buf.get(0);

    GLUtils.checkGlError("0");

    gl.bindFramebuffer(GL.FRAMEBUFFER, fb);

    // generate color texture
    gl.bindTexture(GL.TEXTURE_2D, renderTex);

    GLUtils.setTextureParameter(
            GL.LINEAR,
            GL.LINEAR,
            //GL20.NEAREST,
            //GL20.NEAREST,
            GL.CLAMP_TO_EDGE,
            GL.CLAMP_TO_EDGE);

    gl.texImage2D(GL.TEXTURE_2D, 0,
            GL.RGBA, texW, texH, 0, GL.RGBA,
            GL.UNSIGNED_BYTE, null);

    gl.framebufferTexture2D(GL.FRAMEBUFFER,
            GL.COLOR_ATTACHMENT0,
            GL.TEXTURE_2D,
            renderTex, 0);
    GLUtils.checkGlError("1");

    if (useDepthTexture) {
        buf.clear();
        gl.genTextures(1, buf);
        renderDepth = buf.get(0);
        gl.bindTexture(GL.TEXTURE_2D, renderDepth);
        GLUtils.setTextureParameter(GL.NEAREST,
                GL.NEAREST,
                GL.CLAMP_TO_EDGE,
                GL.CLAMP_TO_EDGE);

        gl.texImage2D(GL.TEXTURE_2D, 0,
                GL.DEPTH_COMPONENT,
                texW, texH, 0,
                GL.DEPTH_COMPONENT,
                GL.UNSIGNED_SHORT, null);

        gl.framebufferTexture2D(GL.FRAMEBUFFER,
                GL.DEPTH_ATTACHMENT,
                GL.TEXTURE_2D,
                renderDepth, 0);
    } else {
        buf.clear();
        gl.genRenderbuffers(1, buf);
        int depthRenderbuffer = buf.get(0);

        gl.bindRenderbuffer(GL.RENDERBUFFER, depthRenderbuffer);

        gl.renderbufferStorage(GL.RENDERBUFFER,
                GL.DEPTH_COMPONENT16,
                texW, texH);

        gl.framebufferRenderbuffer(GL.FRAMEBUFFER,
                GL.DEPTH_ATTACHMENT,
                GL.RENDERBUFFER,
                depthRenderbuffer);
    }

    GLUtils.checkGlError("2");

    int status = gl.checkFramebufferStatus(GL.FRAMEBUFFER);
    gl.bindFramebuffer(GL.FRAMEBUFFER, 0);
    gl.bindTexture(GL.TEXTURE_2D, 0);

    if (status != GL.FRAMEBUFFER_COMPLETE) {
        log.debug("invalid framebuffer! " + status);
        return false;
    }
    return true;
}
 
Example 19
Source File: BufferUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Create a new IntBuffer of the specified size.
 *
 * @param size
 *            required number of ints to store.
 * @return the new IntBuffer
 */
public static IntBuffer createIntBuffer(int size) {
    IntBuffer buf = allocator.allocate(4 * size).order(ByteOrder.nativeOrder()).asIntBuffer();
    buf.clear();
    onBufferAllocated(buf);
    return buf;
}
 
Example 20
Source File: BufferUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Create a new IntBuffer of the specified size.
 *
 * @param size
 *            required number of ints to store.
 * @return the new IntBuffer
 */
public static IntBuffer createIntBuffer(int size) {
    IntBuffer buf = ByteBuffer.allocateDirect(4 * size).order(ByteOrder.nativeOrder()).asIntBuffer();
    buf.clear();
    onBufferAllocated(buf);
    return buf;
}