Example usage for android.renderscript ScriptIntrinsicHistogram forEach

List of usage examples for android.renderscript ScriptIntrinsicHistogram forEach

Introduction

In this page you can find the example usage for android.renderscript ScriptIntrinsicHistogram forEach.

Prototype

public void forEach(Allocation ain) 

Source Link

Document

Process an input buffer and place the histogram into the output allocation.

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./*from www .j  a v  a 2  s.co m*/
 */
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;
}