Example usage for java.nio IntBuffer put

List of usage examples for java.nio IntBuffer put

Introduction

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

Prototype

public IntBuffer put(IntBuffer src) 

Source Link

Document

Writes all the remaining ints of the src int buffer to this buffer's current position, and increases both buffers' position by the number of ints copied.

Usage

From source file:org.shaman.terrain.polygonal.PolygonalMapGenerator.java

private void updateGraphNode() {
    if (graphNode == null) {
        return;/* w  ww  .j  a va2  s .  c  o  m*/
    }

    //edges
    Mesh edgeMesh = new Mesh();
    FloatBuffer pos = BufferUtils.createVector3Buffer(graph.corners.size());
    IntBuffer index = BufferUtils.createIntBuffer(graph.edges.size() * 2);
    pos.rewind();
    for (Graph.Corner c : graph.corners) {
        pos.put(c.point.x).put(c.point.y).put(0);
    }
    pos.rewind();
    index.rewind();
    for (Graph.Edge e : graph.edges) {
        index.put(e.v0.index).put(e.v1.index);
    }
    index.rewind();
    edgeMesh.setBuffer(VertexBuffer.Type.Position, 3, pos);
    edgeMesh.setBuffer(VertexBuffer.Type.Index, 1, index);
    edgeMesh.setMode(Mesh.Mode.Lines);
    edgeMesh.setLineWidth(1);
    edgeMesh.updateCounts();
    edgeMesh.updateBound();
    Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Gray);
    Geometry edgeGeom = new Geometry("edgeGeom", edgeMesh);
    edgeGeom.setMaterial(mat);
    edgeGeom.setCullHint(Spatial.CullHint.Never);
    edgeNode.detachAllChildren();
    edgeNode.attachChild(edgeGeom);
    LOG.info("edge geometry updated");
}

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 ww .  ja va  2 s  .  com*/
        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;
}

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

public static Bitmap colorDodgeBlend(Bitmap source, Bitmap layer) {
    Bitmap base = source.copy(Config.ARGB_8888, true);
    Bitmap blend = layer.copy(Config.ARGB_8888, false);

    IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight());
    base.copyPixelsToBuffer(buffBase);//ww w . j a va 2  s . c  o m
    buffBase.rewind();

    IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight());
    blend.copyPixelsToBuffer(buffBlend);
    buffBlend.rewind();

    IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight());
    buffOut.rewind();

    while (buffOut.position() < buffOut.limit()) {
        int filterInt = buffBlend.get();
        int srcInt = buffBase.get();

        int redValueFilter = Color.red(filterInt);
        int greenValueFilter = Color.green(filterInt);
        int blueValueFilter = Color.blue(filterInt);

        int redValueSrc = Color.red(srcInt);
        int greenValueSrc = Color.green(srcInt);
        int blueValueSrc = Color.blue(srcInt);

        int redValueFinal = colordodge(redValueFilter, redValueSrc);
        int greenValueFinal = colordodge(greenValueFilter, greenValueSrc);
        int blueValueFinal = colordodge(blueValueFilter, blueValueSrc);

        int pixel = Color.argb(255, redValueFinal, greenValueFinal, blueValueFinal);

        /*
         * float[] hsv = new float[3]; Color.colorToHSV(pixel, hsv); hsv[1] = 0.0f; float top =
         * VALUE_TOP; // Setting this as 0.95f gave the best result so far if (hsv[2] <= top) {
         * hsv[2] = 0.0f; } else { hsv[2] = 1.0f; } pixel = Color.HSVToColor(hsv);
         */

        buffOut.put(pixel);
    }

    buffOut.rewind();

    base.copyPixelsFromBuffer(buffOut);
    blend.recycle();

    return base;
}

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   ww w. ja v  a  2  s. c  o 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);/*  w  w w  . j av  a  2 s  .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;
}

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);
            gb.put(g);/*  ww  w . java2 s  . com*/
        } 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;
            }//from  w ww.ja v  a2s .c  om
            cb.put(c);
            gb.put(g);
        } else {
            throw new IllegalArgumentException("unmapped glyph id \"" + gid + "\"");
        }
    }
    cb.rewind();
    gb.rewind();
    return new GlyphSequence(cb, gb, null);
}