Example usage for java.nio IntBuffer flip

List of usage examples for java.nio IntBuffer flip

Introduction

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

Prototype

public final Buffer flip() 

Source Link

Document

Flips this buffer.

Usage

From source file:Main.java

/**
 * Creates a {@link IntBuffer} based on the given data.
 *
 * @param data the data for the buffer// w w  w .  ja v a2 s .co m
 * @return the int buffer
 */
public static IntBuffer createIntBuffer(final float[] data) {
    final int[] tmpData = new int[data.length];
    for (int i = 0; i < tmpData.length; i++) {
        tmpData[i] = Float.floatToRawIntBits(data[i]);
    }
    final ByteBuffer bbVertices = ByteBuffer.allocateDirect(tmpData.length * 4);
    bbVertices.order(ByteOrder.nativeOrder());
    final IntBuffer intBuffer = bbVertices.asIntBuffer();
    intBuffer.put(tmpData);
    intBuffer.flip();
    return intBuffer;
}

From source file:Main.java

public static IntBuffer createIntBuffer(final int... data) {
    if (data == null) {
        return null;
    }//from   w  w w .  j a  va2  s  .  c o m
    final IntBuffer buff = createIntBuffer(data.length);
    buff.clear();
    buff.put(data);
    buff.flip();
    return buff;
}

From source file:org.smurn.jply.lwjgldemo.LWJGLDemo.java

/**
 * Helper to get the log messages from the shader compiler.
 *///from w  w  w. j a  v a 2  s .c  o m
private static boolean printLogInfo(int obj) {
    IntBuffer iVal = BufferUtils.createIntBuffer(1);
    ARBShaderObjects.glGetObjectParameterARB(obj, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal);

    int length = iVal.get();
    if (length > 1) {
        // We have some info we need to output.
        ByteBuffer infoLog = BufferUtils.createByteBuffer(length);
        iVal.flip();
        ARBShaderObjects.glGetInfoLogARB(obj, iVal, infoLog);
        byte[] infoBytes = new byte[length];
        infoLog.get(infoBytes);
        String out = new String(infoBytes);
        System.out.println("Info log:\n" + out);
    } else {
        return true;
    }
    return false;
}

From source file:com.asakusafw.runtime.io.csv.CsvParser.java

private void addSeparator() {
    IntBuffer buf = cellBeginPositions;
    if (buf.remaining() == 0) {
        IntBuffer newBuf = IntBuffer.allocate(buf.capacity() * 2);
        newBuf.clear();/*ww  w  .  j a  v a  2  s.co  m*/
        buf.flip();
        newBuf.put(buf);
        buf = newBuf;
        cellBeginPositions = newBuf;
    }
    buf.put(lineBuffer.position());
}

From source file:org.tsho.dmc2.core.chart.AbsorbingAreaRenderer.java

public void copyDisplay() {
    IntBuffer buffer = IntBuffer.allocate(grid.length);
    buffer.put(grid);
    buffer.flip();
    buffer.get(gridBackup);
}

From source file:org.tsho.dmc2.core.chart.AbsorbingAreaRenderer.java

public void plotCopiedDisplay() {
    IntBuffer buffer = IntBuffer.allocate(grid.length);
    buffer.put(gridBackup);
    buffer.flip();
    buffer.get(grid);
}

From source file:org.apache.fop.fonts.MultiByteFont.java

/**
 * Map sequence CS, comprising a sequence of UTF-16 encoded Unicode Code Points, to
 * an output character sequence GS, comprising a sequence of Glyph Indices. N.B. Unlike
 * mapChar(), this method does not make use of embedded subset encodings.
 * @param cs a CharSequence containing UTF-16 encoded Unicode characters
 * @returns a CharSequence containing glyph indices
 *///from  w  ww. j av a  2s.co m
private GlyphSequence mapCharsToGlyphs(CharSequence cs) {
    IntBuffer cb = IntBuffer.allocate(cs.length());
    IntBuffer gb = IntBuffer.allocate(cs.length());
    int gi;
    int giMissing = findGlyphIndex(Typeface.NOT_FOUND);
    for (int i = 0, n = cs.length(); i < n; i++) {
        int cc = cs.charAt(i);
        if ((cc >= 0xD800) && (cc < 0xDC00)) {
            if ((i + 1) < n) {
                int sh = cc;
                int sl = cs.charAt(++i);
                if ((sl >= 0xDC00) && (sl < 0xE000)) {
                    cc = 0x10000 + ((sh - 0xD800) << 10) + ((sl - 0xDC00) << 0);
                } else {
                    throw new IllegalArgumentException(
                            "ill-formed UTF-16 sequence, " + "contains isolated high surrogate at index " + i);
                }
            } else {
                throw new IllegalArgumentException(
                        "ill-formed UTF-16 sequence, " + "contains isolated high surrogate at end of sequence");
            }
        } else if ((cc >= 0xDC00) && (cc < 0xE000)) {
            throw new IllegalArgumentException(
                    "ill-formed UTF-16 sequence, " + "contains isolated low surrogate at index " + i);
        }
        notifyMapOperation();
        gi = findGlyphIndex(cc);
        if (gi == SingleByteEncoding.NOT_FOUND_CODE_POINT) {
            warnMissingGlyph((char) cc);
            gi = giMissing;
        }
        cb.put(cc);
        gb.put(gi);
    }
    cb.flip();
    gb.flip();
    return new GlyphSequence(cb, gb, null);
}

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);//from   w ww. ja  v a 2s.  co m

    // 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);
        }
    }

    // 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;
}