Example usage for android.renderscript ScriptIntrinsicHistogram create

List of usage examples for android.renderscript ScriptIntrinsicHistogram create

Introduction

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

Prototype

public static ScriptIntrinsicHistogram create(RenderScript rs, Element e) 

Source Link

Document

Create an intrinsic for calculating the histogram of an uchar or uchar4 image.

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 w  w w. j a v  a 2  s .  c  o  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;
}