java.nio.IntBuffer#clear ( )源码实例Demo

下面列出了java.nio.IntBuffer#clear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: imhotep   文件: FileSerializationBenchmark.java
@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;
}
 
源代码2 项目: MikuMikuStudio   文件: Screenshots.java
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;
//            }
//        }
    }
 
源代码3 项目: imhotep   文件: FileSerializationBenchmark.java
@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();
}
 
源代码4 项目: imhotep   文件: IntArraySerializer.java
@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();
    }
}
 
源代码5 项目: imhotep   文件: FileSerializationBenchmark.java
@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;
}
 
源代码6 项目: jmonkeyengine   文件: Screenshots.java
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;
//            }
//        }
    }
 
源代码7 项目: MikuMikuStudio   文件: FloatToFixed.java
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();
}
 
源代码8 项目: Ultraino   文件: BufferUtils.java
/**
 * 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;
}
 
源代码9 项目: Ultraino   文件: BufferUtils.java
/**
 * 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;
}
 
源代码10 项目: opsu-dance   文件: OpenALStreamPlayer.java
/**
 * 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();
	}
}
 
源代码11 项目: MikuMikuStudio   文件: BufferUtils.java
/**
 * 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;
}
 
源代码12 项目: OSPREY3   文件: BigForcefieldEnergy.java
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;
}
 
源代码13 项目: UltimateAndroid   文件: Image.java
public void copyPixelsFromBuffer() { //�ӻ�������copy����Լӿ����ش����ٶ�          	
	IntBuffer vbb = IntBuffer.wrap(colorArray);    	
    //vbb.put(colorArray);
    destImage.copyPixelsFromBuffer(vbb);
    vbb.clear();
    //vbb = null;
}
 
源代码14 项目: imhotep   文件: FileSerializationBenchmark.java
@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();
}
 
源代码15 项目: jmonkeyengine   文件: BufferUtils.java
/**
 * 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;
}
 
源代码16 项目: opsu   文件: OpenALStreamPlayer.java
/**
 * 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();
	}
}
 
源代码17 项目: Hyperium   文件: HyperiumScreenshotHelper.java
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...");
}
 
源代码18 项目: trekarta   文件: OffscreenRenderer.java
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;
}
 
源代码19 项目: jmonkeyengine   文件: BufferUtils.java
/**
 * 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;
}
 
源代码20 项目: MikuMikuStudio   文件: BufferUtils.java
/**
 * 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;
}