Search in sources :

Example 1 with ScriptIntrinsicHistogram

use of android.renderscript.ScriptIntrinsicHistogram in project OpenCamera by ageback.

the class HDRProcessor method computeHistogramAllocation.

/**
 * @param avg If true, compute the color value as the average of the rgb values. If false,
 *            compute the color value as the maximum of the rgb values.
 * @param floating_point Whether the allocation_in is in floating point (F32_3) format, or
 *                       RGBA_8888 format.
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private Allocation computeHistogramAllocation(Allocation allocation_in, boolean avg, boolean floating_point, long time_s) {
    if (MyDebug.LOG)
        Log.d(TAG, "computeHistogramAllocation");
    Allocation histogramAllocation = Allocation.createSized(rs, Element.I32(rs), 256);
    // final boolean use_custom_histogram = false;
    final boolean use_custom_histogram = true;
    if (use_custom_histogram) {
        /*if( histogramScript == null ) {
				if( MyDebug.LOG )
					Log.d(TAG, "create histogramScript");
				histogramScript = new ScriptC_histogram_compute(rs);
			}*/
        if (MyDebug.LOG)
            Log.d(TAG, "create histogramScript");
        ScriptC_histogram_compute histogramScript = new ScriptC_histogram_compute(rs);
        if (MyDebug.LOG)
            Log.d(TAG, "bind histogram allocation");
        histogramScript.bind_histogram(histogramAllocation);
        histogramScript.invoke_init_histogram();
        if (MyDebug.LOG)
            Log.d(TAG, "call histogramScript");
        if (MyDebug.LOG)
            Log.d(TAG, "time before histogramScript: " + (System.currentTimeMillis() - time_s));
        if (avg) {
            if (floating_point)
                histogramScript.forEach_histogram_compute_by_intensity_f(allocation_in);
            else
                histogramScript.forEach_histogram_compute_by_intensity(allocation_in);
        } else {
            if (floating_point)
                histogramScript.forEach_histogram_compute_by_value_f(allocation_in);
            else
                histogramScript.forEach_histogram_compute_by_value(allocation_in);
        }
        if (MyDebug.LOG)
            Log.d(TAG, "time after histogramScript: " + (System.currentTimeMillis() - time_s));
    } else {
        ScriptIntrinsicHistogram histogramScriptIntrinsic = ScriptIntrinsicHistogram.create(rs, Element.U8_4(rs));
        histogramScriptIntrinsic.setOutput(histogramAllocation);
        if (MyDebug.LOG)
            Log.d(TAG, "call histogramScriptIntrinsic");
        // use forEach_dot(); using forEach would simply compute a histogram for red values!
        histogramScriptIntrinsic.forEach_Dot(allocation_in);
    }
    // histogramAllocation.setAutoPadding(true);
    return histogramAllocation;
}
Also used : Allocation(android.renderscript.Allocation) ScriptIntrinsicHistogram(android.renderscript.ScriptIntrinsicHistogram) RequiresApi(android.support.annotation.RequiresApi)

Aggregations

Allocation (android.renderscript.Allocation)1 ScriptIntrinsicHistogram (android.renderscript.ScriptIntrinsicHistogram)1 RequiresApi (android.support.annotation.RequiresApi)1