Example usage for android.renderscript Allocation createSized

List of usage examples for android.renderscript Allocation createSized

Introduction

In this page you can find the example usage for android.renderscript Allocation createSized.

Prototype

static public Allocation createSized(RenderScript rs, Element e, int count) 

Source Link

Document

Creates an Allocation with a specified number of given elements

Usage

From source file:Main.java

/**
 * Return the histograms for each color channel (interleaved).
 *
 * @param rs a {@link RenderScript} context to use.
 * @param bmap a {@link Bitmap} to generate the histograms for.
 * @return an array containing NUM_CHANNELS * COLOR_BIT_DEPTH histogram bucket values, with
 * the color channels interleaved.// w  ww .  j a va 2s  . com
 */
public static int[] calcHistograms(RenderScript rs, Bitmap bmap) {
    ScriptIntrinsicHistogram hist = ScriptIntrinsicHistogram.create(rs, Element.U8_4(rs));
    Allocation sums = Allocation.createSized(rs, Element.I32_4(rs), COLOR_BIT_DEPTH);

    // Setup input allocation (ARGB 8888 bitmap).
    Allocation input = Allocation.createFromBitmap(rs, bmap);

    hist.setOutput(sums);
    hist.forEach(input);
    int[] output = new int[COLOR_BIT_DEPTH * NUM_CHANNELS];
    sums.copyTo(output);
    return output;
}