Example usage for java.nio IntBuffer position

List of usage examples for java.nio IntBuffer position

Introduction

In this page you can find the example usage for java.nio IntBuffer position.

Prototype

public final Buffer position(int newPosition) 

Source Link

Document

Sets the position of this buffer.

Usage

From source file:org.jcodec.codecs.mjpeg.JpegDecoder.java

/** Corner case of putBlock */
private static void putBlock(IntBuffer result, int width, MCU block, int bx, int by, int blockH, int blockV) {
    IntBuffer rgb = block.getRgb24();
    int bY = by * block.v * width;
    int bX = bx * block.h;
    int blockPtr = bY + bX;
    for (int j = 0; j < blockV; j++) {
        result.position(blockPtr);
        for (int i = 0; i < blockH; i++) {
            result.put(rgb.get());//from ww w.  j a  v  a  2  s  . c  o m
        }
        rgb.position(rgb.position() + (block.h - blockH));
        blockPtr += width;
    }
}

From source file:org.jcodec.codecs.mjpeg.JpegDecoder.java

private static void putBlock(IntBuffer result, int width, MCU block, int bx, int by) {
    int blockH = block.h;
    int blockV = block.v;
    IntBuffer rgb = block.getRgb24();
    int bY = by * blockV * width;
    int bX = bx * blockH;
    int blockPtr = bY + bX;
    for (int j = 0; j < blockV; j++) {
        result.position(blockPtr);
        for (int i = 0; i < blockH; i++) {
            result.put(rgb.get());// w ww  .  j a  v  a2 s  . com
        }
        blockPtr += width;
    }
}

From source file:org.jcodec.codecs.mjpeg.JpegDecoder.java

private static void decodeBlock(MCU block, QuantTable qLum, QuantTable qChrom) {

    zigzagDecodeAll(block.lum.data);//from w w w  .j  a va 2s. co  m
    zigzagDecodeAll(block.cb.data);
    zigzagDecodeAll(block.cr.data);

    dequantAll(block.lum.data, qLum);
    dequantAll(block.cb.data, qChrom);
    dequantAll(block.cr.data, qChrom);

    dct.decodeAll(block.lum.data);
    dct.decodeAll(block.cb.data);
    dct.decodeAll(block.cr.data);

    IntBuffer rgb = block.getRgb24();
    IntBuffer Cb = IntBuffer.wrap(block.cb.data[0]);
    IntBuffer Cr = IntBuffer.wrap(block.cr.data[0]);
    if (block.is420()) {
        IntBuffer y00 = IntBuffer.wrap(block.lum.data[0]);
        IntBuffer y01 = IntBuffer.wrap(block.lum.data[1]);
        IntBuffer y10 = IntBuffer.wrap(block.lum.data[2]);
        IntBuffer y11 = IntBuffer.wrap(block.lum.data[3]);

        for (int j = 0; j < 8; j++) {
            Cb.position((j & ~1) << 2);
            Cr.position((j & ~1) << 2);
            lineToRgb(y00, Cb, Cr, rgb);
            lineToRgb(y01, Cb, Cr, rgb);
        }
        for (int j = 8; j < 16; j++) {
            Cb.position((j & ~1) << 2);
            Cr.position((j & ~1) << 2);
            lineToRgb(y10, Cb, Cr, rgb);
            lineToRgb(y11, Cb, Cr, rgb);
        }
    } else if (block.is422()) {
        IntBuffer y00 = IntBuffer.wrap(block.lum.data[0]);
        IntBuffer y01 = IntBuffer.wrap(block.lum.data[1]);
        for (int j = 0; j < 8; j++) {
            Cb.position(j << 3);
            Cr.position(j << 3);
            lineToRgb(y00, Cb, Cr, rgb);
            lineToRgb(y01, Cb, Cr, rgb);
        }
    } else if (block.is444()) {
        IntBuffer Y = IntBuffer.wrap(block.lum.data[0]);
        while (rgb.hasRemaining()) {
            rgb.put(ImageConvert.ycbcr_to_rgb24(Y.get(), Cb.get(), Cr.get()));
        }
    } else {
        throw new IllegalStateException("unsupported MCU");
    }

}

From source file:org.grouplens.lenskit.data.dao.packed.BinaryIndexTable.java

private IntList getEntryInternal(int idx) {
    int offset = offsets[idx];
    int size = sizes[idx];
    IntBuffer buf = buffer.duplicate();
    buf.position(offset).limit(offset + size);
    return BufferBackedIntList.create(buf);
}

From source file:org.lenskit.data.packed.BinaryIndexTable.java

private IntList getEntryInternal(int idx) {
    int offset = offsets[idx];
    int size = sizes[idx];
    IntBuffer buf = indexStore.duplicate();
    buf.position(offset).limit(offset + size);
    return BufferBackedIntList.create(buf);
}

From source file:com.adobe.plugins.FastCanvasRenderer.java

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    Log.i("CANVAS", "CanvasRenderer onSurfaceCreated. config:" + config.toString() + " gl:" + gl.toString());

    IntBuffer ib = IntBuffer.allocate(100);
    ib.position(0);
    GLES10.glGetIntegerv(GLES10.GL_RED_BITS, ib);
    int red = ib.get(0);
    GLES10.glGetIntegerv(GLES10.GL_GREEN_BITS, ib);
    int green = ib.get(0);
    GLES10.glGetIntegerv(GLES10.GL_BLUE_BITS, ib);
    int blue = ib.get(0);
    GLES10.glGetIntegerv(GLES10.GL_STENCIL_BITS, ib);
    int stencil = ib.get(0);
    GLES10.glGetIntegerv(GLES10.GL_DEPTH_BITS, ib);
    int depth = ib.get(0);

    Log.i("CANVAS", "CanvasRenderer R=" + red + " G=" + green + " B=" + blue + " DEPETH=" + depth + " STENCIL="
            + stencil);//from  w w  w. j av  a 2  s  .com
}

From source file:org.hobbit.core.rabbit.FileStreamingTest.java

private void generateFiles(String sendInputDir) {
    System.out.println("Generating files...");
    if (!sendInputDir.endsWith(File.separator)) {
        sendInputDir += File.separator;
    }//from w  w w .ja va  2  s  .c om

    OutputStream os = null;
    // create first file
    try {
        os = new BufferedOutputStream(new FileOutputStream(sendInputDir + "file1.dat"));
        ByteBuffer buffer = ByteBuffer.allocate(4000);
        IntBuffer intBuffer = buffer.asIntBuffer();
        int number = 0;
        // for (int i = 0; i < 200; ++i) {
        for (int j = 0; j < 1000; ++j) {
            intBuffer.put(number);
            ++number;
        }
        os.write(buffer.array());
        buffer.position(0);
        intBuffer.position(0);
        // }
        os.flush();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    } finally {
        IOUtils.closeQuietly(os);
    }
    // create second file
    try {
        os = new BufferedOutputStream(new FileOutputStream(sendInputDir + "file2.txt"));
        byte data[] = "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                .getBytes(Charsets.UTF_8);
        for (int i = 0; i < 200; ++i) {
            os.write(data);
        }
        os.flush();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    } finally {
        IOUtils.closeQuietly(os);
    }
    // create third file
    try {
        os = new BufferedOutputStream(new FileOutputStream(sendInputDir + "file3.dat"));
        ByteBuffer buffer = ByteBuffer.allocate(400);
        IntBuffer intBuffer = buffer.asIntBuffer();
        Random random = new Random();
        // for (int i = 0; i < 200; ++i) {
        for (int j = 0; j < 100; ++j) {
            intBuffer.put(random.nextInt());
        }
        os.write(buffer.array());
        buffer.position(0);
        intBuffer.position(0);
        // }
        os.flush();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    } finally {
        IOUtils.closeQuietly(os);
    }
}

From source file:com.rnd.snapsplit.view.OcrCaptureFragment.java

public Bitmap byteStreamToBitmap(byte[] data) {
    int imageWidth = mCameraSource.getPreviewSize().getWidth();
    int imageHeight = mCameraSource.getPreviewSize().getHeight();
    //            YuvImage yuvimage=new YuvImage(data, ImageFormat.NV16, previewSizeW, previewSizeH, null);
    //            ByteArrayOutputStream baos = new ByteArrayOutputStream();
    //            yuvimage.compressToJpeg(new Rect(0, 0, previewSizeW, previewSizeH), 80, baos);
    //            byte[] jdata = baos.toByteArray();

    Bitmap bitmap = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888);
    int numPixels = imageWidth * imageHeight;

    // the buffer we fill up which we then fill the bitmap with
    IntBuffer intBuffer = IntBuffer.allocate(imageWidth * imageHeight);
    // If you're reusing a buffer, next line imperative to refill from the start,
    // if not good practice
    intBuffer.position(0);

    // Set the alpha for the image: 0 is transparent, 255 fully opaque
    final byte alpha = (byte) 255;

    // Get each pixel, one at a time
    for (int y = 0; y < imageHeight; y++) {
        for (int x = 0; x < imageWidth; x++) {
            // Get the Y value, stored in the first block of data
            // The logical "AND 0xff" is needed to deal with the signed issue
            int Y = data[y * imageWidth + x] & 0xff;

            // Get U and V values, stored after Y values, one per 2x2 block
            // of pixels, interleaved. Prepare them as floats with correct range
            // ready for calculation later.
            int xby2 = x / 2;
            int yby2 = y / 2;

            // make this V for NV12/420SP
            float U = (float) (data[numPixels + 2 * xby2 + yby2 * imageWidth] & 0xff) - 128.0f;

            // make this U for NV12/420SP
            float V = (float) (data[numPixels + 2 * xby2 + 1 + yby2 * imageWidth] & 0xff) - 128.0f;

            // Do the YUV -> RGB conversion
            float Yf = 1.164f * ((float) Y) - 16.0f;
            int R = (int) (Yf + 1.596f * V);
            int G = (int) (Yf - 0.813f * V - 0.391f * U);
            int B = (int) (Yf + 2.018f * U);

            // Clip rgb values to 0-255
            R = R < 0 ? 0 : R > 255 ? 255 : R;
            G = G < 0 ? 0 : G > 255 ? 255 : G;
            B = B < 0 ? 0 : B > 255 ? 255 : B;

            // Put that pixel in the buffer
            intBuffer.put(alpha * 16777216 + R * 65536 + G * 256 + B);
        }//from   www .j  a  v a2s  .  com
    }

    // Get buffer ready to be read
    intBuffer.flip();

    // Push the pixel information from the buffer onto the bitmap.
    bitmap.copyPixelsFromBuffer(intBuffer);

    Matrix matrix = new Matrix();
    matrix.postRotate(90);
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, imageWidth, imageHeight, true);
    Bitmap rotatedBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(),
            scaledBitmap.getHeight(), matrix, true);
    return rotatedBitmap;
}