Example usage for java.nio IntBuffer allocate

List of usage examples for java.nio IntBuffer allocate

Introduction

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

Prototype

public static IntBuffer allocate(int capacity) 

Source Link

Document

Creates an int buffer based on a newly allocated int array.

Usage

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();//w w  w.ja  va 2  s .c o  m
        buf.flip();
        newBuf.put(buf);
        buf = newBuf;
        cellBeginPositions = newBuf;
    }
    buf.put(lineBuffer.position());
}

From source file:edu.iu.daal_pca.Service.java

public static void printAprioriRules(HomogenNumericTable leftItemsTable, HomogenNumericTable rightItemsTable,
        HomogenNumericTable confidenceTable) {
    int nRulesToPrint = 20;
    /* Get sizes of tables to store association rules */
    int nLeftItems = (int) leftItemsTable.getNumberOfRows();
    int nRightItems = (int) rightItemsTable.getNumberOfRows();
    int nRules = (int) confidenceTable.getNumberOfRows();

    /* Get association rules data */

    IntBuffer bufLeftItems = IntBuffer.allocate(nLeftItems * (int) leftItemsTable.getNumberOfColumns());
    bufLeftItems = leftItemsTable.getBlockOfRows(0, nLeftItems, bufLeftItems);
    int[] leftItems = new int[bufLeftItems.capacity()];
    bufLeftItems.get(leftItems);/*from  w ww . j  a va2  s .c o m*/

    IntBuffer bufRightItems = IntBuffer.allocate(nRightItems * (int) rightItemsTable.getNumberOfColumns());
    bufRightItems = rightItemsTable.getBlockOfRows(0, nRightItems, bufRightItems);
    int[] rightItems = new int[bufRightItems.capacity()];
    bufRightItems.get(rightItems);

    double[] confidence = confidenceTable.getDoubleArray();

    ArrayList<ArrayList<Integer>> leftItemsVector = new ArrayList<ArrayList<Integer>>(nRules);
    for (int i = 0; i < nRules; i++) {
        leftItemsVector.add(new ArrayList<Integer>());
    }

    if (nRules == 0) {
        System.out.println("No association rules were found ");
        return;
    }

    for (int i = 0; i < nLeftItems; i++) {
        leftItemsVector.get((leftItems[2 * i])).add(leftItems[2 * i + 1]);
    }

    ArrayList<ArrayList<Integer>> rightItemsVector = new ArrayList<ArrayList<Integer>>(nRules);
    for (int i = 0; i < nRules; i++) {
        rightItemsVector.add(new ArrayList<Integer>());
    }

    for (int i = 0; i < nRightItems; i++) {
        rightItemsVector.get((rightItems[2 * i])).add(rightItems[2 * i + 1]);
    }

    ArrayList<Double> confidenceVector = new ArrayList<Double>(nRules);
    for (int i = 0; i < nRules; i++) {
        confidenceVector.add(confidence[i]);
    }

    System.out.println("Last " + nRulesToPrint + " association rules: ");
    System.out.println("Rule" + "\t\t\t\tConfidence");

    int iMin = ((nRules > nRulesToPrint) ? (nRules - nRulesToPrint) : 0);
    for (int i = iMin; i < nRules; i++) {
        System.out.print("{");
        for (int l = 0; l < leftItemsVector.get(i).size() - 1; l++) {
            System.out.print(leftItemsVector.get(i).get(l) + ", ");
        }
        System.out.print(leftItemsVector.get(i).get(leftItemsVector.get(i).size() - 1) + "} => {");

        for (int l = 0; l < rightItemsVector.get(i).size() - 1; l++) {
            System.out.print(rightItemsVector.get(i).get(l) + ", ");
        }
        System.out.print(rightItemsVector.get(i).get(rightItemsVector.get(i).size() - 1) + "}\t\t");

        System.out.println(confidenceVector.get(i));
    }
}

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  w  w . ja v a2s.  c  om
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:org.apache.fop.complexscripts.fonts.ttx.TTXFile.java

public GlyphSequence mapCharsToGlyphs(String s) {
    Integer[] ca = UTF32.toUTF32(s, 0, true);
    int ng = ca.length;
    IntBuffer cb = IntBuffer.allocate(ng);
    IntBuffer gb = IntBuffer.allocate(ng);
    for (Integer c : ca) {
        int g = mapCharToGlyph((int) c);
        if (g >= 0) {
            cb.put(c);/*  w ww . j  a  v a2 s  . c om*/
            gb.put(g);
        } else {
            throw new IllegalArgumentException(
                    "character " + CharUtilities.format(c) + " has no corresponding glyph");
        }
    }
    cb.rewind();
    gb.rewind();
    return new GlyphSequence(cb, gb, null);
}

From source file:org.apache.fop.complexscripts.fonts.ttx.TTXFile.java

public GlyphSequence getGlyphSequence(String[] gids) {
    assert gids != null;
    int ng = gids.length;
    IntBuffer cb = IntBuffer.allocate(ng);
    IntBuffer gb = IntBuffer.allocate(ng);
    for (String gid : gids) {
        int g = mapGlyphId0(gid);
        if (g >= 0) {
            int c = mapGlyphIdToChar(gid);
            if (c < 0) {
                c = CharUtilities.NOT_A_CHARACTER;
            }/*ww w  . ja v a2s  .co m*/
            cb.put(c);
            gb.put(g);
        } else {
            throw new IllegalArgumentException("unmapped glyph id \"" + gid + "\"");
        }
    }
    cb.rewind();
    gb.rewind();
    return new GlyphSequence(cb, gb, null);
}

From source file:edu.iu.daal_pca.Service.java

private static KeyValueDataCollection computeOutBlocks(DaalContext context, int nNodes,
        CSRNumericTable dataBlock, long[] dataBlockPartition) {
    long nRows = dataBlock.getNumberOfRows();
    int iNRows = (int) nRows;
    boolean[] blockIdFlags = new boolean[iNRows * nNodes];
    for (int i = 0; i < iNRows * nNodes; i++) {
        blockIdFlags[i] = false;/*  www. j  a  v a2s.com*/
    }

    long[] rowOffsets = dataBlock.getRowOffsetsArray();
    long[] colIndices = dataBlock.getColIndicesArray();

    for (long i = 0; i < nRows; i++) {
        for (long j = rowOffsets[(int) i] - 1; j < rowOffsets[(int) i + 1] - 1; j++) {
            for (int k = 1; k < nNodes + 1; k++) {
                if (dataBlockPartition[k - 1] <= colIndices[(int) j] - 1
                        && colIndices[(int) j] - 1 < dataBlockPartition[k]) {
                    blockIdFlags[(k - 1) * iNRows + (int) i] = true;
                }
            }
        }
    }

    long[] nNotNull = new long[nNodes];
    for (int i = 0; i < nNodes; i++) {
        nNotNull[i] = 0;
        for (int j = 0; j < iNRows; j++) {
            if (blockIdFlags[i * iNRows + j]) {
                nNotNull[i] += 1;
            }
        }
    }
    KeyValueDataCollection result = new KeyValueDataCollection(context);

    for (int i = 0; i < nNodes; i++) {
        HomogenNumericTable indicesTable = new HomogenNumericTable(context, Integer.class, 1, nNotNull[i],
                NumericTable.AllocationFlag.DoAllocate);
        IntBuffer indicesBuffer = IntBuffer.allocate((int) nNotNull[i]);
        indicesBuffer = indicesTable.getBlockOfRows(0, nNotNull[i], indicesBuffer);
        int indexId = 0;
        for (int j = 0; j < iNRows; j++) {
            if (blockIdFlags[i * iNRows + j]) {
                indicesBuffer.put(indexId, j);
                indexId++;
            }
        }
        indicesTable.releaseBlockOfRows(0, nNotNull[i], indicesBuffer);
        result.set(i, indicesTable);
    }
    return result;
}

From source file:org.spoutcraft.client.gui.MCRenderDelegate.java

public void render(GenericBitmap bitmap) {
    int textureId;
    if (bitmapId.containsKey(bitmap)) {
        textureId = bitmapId.get(bitmap);
    } else {//www .  ja  va  2s. c o m
        IntBuffer tmp = IntBuffer.allocate(1);
        GL11.glGenTextures(tmp);
        textureId = tmp.get(0);
        bitmapId.put(bitmap, textureId);
    }
    int width = (int) bitmap.getActualWidth();
    int height = (int) bitmap.getActualHeight();
    int left = bitmap.getLeft();
    int top = bitmap.getTop();
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, bitmap.getRawWidth(), bitmap.getRawHeight(), 0,
            GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, bitmap.getBuffer());
    GL11.glTranslatef((float) bitmap.getScreenX(), (float) bitmap.getScreenY(), 0); // moves texture into place
    GL11.glPushMatrix();
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(770, 771);
    GL11.glDepthMask(false);
    bindColor(new Color(1.0F, 1.0F, 1.0F));
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    double tLeft = 0, tTop = 0, rWidth = bitmap.getWidth(), rHeight = bitmap.getHeight(), tWidth = rWidth,
            tHeight = rHeight;
    if (top >= 0 && left >= 0) {
        tWidth = Math.min(tWidth, width);
        tHeight = Math.min(tHeight, height);
        tLeft = Math.min(Math.max(0, left), rWidth);
        tTop = Math.min(Math.max(0, top), rHeight);
    }
    Tessellator tessellator = Tessellator.instance;
    tessellator.startDrawingQuads();
    tessellator.addVertexWithUV(0.0D, height, -90, tLeft, tTop); // draw corners
    tessellator.addVertexWithUV(width, height, -90, tWidth, tTop);
    tessellator.addVertexWithUV(width, 0.0D, -90, tWidth, tHeight);
    tessellator.addVertexWithUV(0.0D, 0.0D, -90, tLeft, tHeight);
    tessellator.draw();
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glPopMatrix();
    GL11.glDisable(GL11.GL_BLEND);
}

From source file:org.jtrfp.trcl.core.Texture.java

public static final int createTextureID(GL3 gl) {
    IntBuffer ib = IntBuffer.allocate(1);
    gl.glGenTextures(1, ib);//  w ww .  j  a v  a 2s  .  c  om
    ib.clear();
    return ib.get();
}

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   ww  w.  j  a  v  a 2s.com*/

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

From source file:com.creativeongreen.imageeffects.MainActivity.java

public static Bitmap getCartoonizedBitmap(Bitmap realBitmap, Bitmap dodgeBlendBitmap, int hueIntervalSize,
        int saturationIntervalSize, int valueIntervalSize, int saturationPercent, int valuePercent) {
    // Bitmap bitmap = Bitmap.createBitmap(scaledBitmap);
    // //fastblur(scaledBitmap, 4);
    Bitmap base = fastblur(realBitmap, 3).copy(Config.ARGB_8888, true);
    Bitmap dodge = dodgeBlendBitmap.copy(Config.ARGB_8888, false);
    try {//from w w  w  . java  2s . c o  m
        int realColor;
        int color;
        float top = 0.87f;// VALUE_TOP; // Between 0.0f .. 1.0f I use 0.87f
        IntBuffer templatePixels = IntBuffer.allocate(dodge.getWidth() * dodge.getHeight());
        IntBuffer scaledPixels = IntBuffer.allocate(base.getWidth() * base.getHeight());
        IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight());

        base.copyPixelsToBuffer(scaledPixels);
        dodge.copyPixelsToBuffer(templatePixels);

        templatePixels.rewind();
        scaledPixels.rewind();
        buffOut.rewind();

        while (buffOut.position() < buffOut.limit()) {
            color = (templatePixels.get());
            realColor = scaledPixels.get();

            float[] realHSV = new float[3];
            Color.colorToHSV(realColor, realHSV);

            realHSV[0] = getRoundedValue(realHSV[0], hueIntervalSize);

            realHSV[2] = (getRoundedValue(realHSV[2] * 100, valueIntervalSize) / 100) * (valuePercent / 100);
            realHSV[2] = realHSV[2] < 1.0 ? realHSV[2] : 1.0f;

            realHSV[1] = realHSV[1] * (saturationPercent / 100);
            realHSV[1] = realHSV[1] < 1.0 ? realHSV[1] : 1.0f;

            float[] HSV = new float[3];
            Color.colorToHSV(color, HSV);

            boolean putBlackPixel = HSV[2] <= top;

            realColor = Color.HSVToColor(realHSV);

            if (putBlackPixel) {
                buffOut.put(color);
            } else {
                buffOut.put(realColor);
            }
        } // END WHILE
        dodge.recycle();
        buffOut.rewind();
        base.copyPixelsFromBuffer(buffOut);

    } catch (Exception e) {
        // TODO: handle exception
    }

    return base;
}