in test-app/src/main/java/com/google/android/renderscript_test/IntrinsicHistogram.kt [106:154]
fun intrinsicHistogramDot(
context: RenderScript,
inputArray: ByteArray,
vectorSize: Int,
sizeX: Int,
sizeY: Int,
coefficients: FloatArray?,
restriction: Range2d?
): IntArray {
val element = renderScriptVectorElementForU8(context, vectorSize)
val scriptHistogram = ScriptIntrinsicHistogram.create(context, element)
val builder = Type.Builder(context, element)
builder.setX(sizeX)
builder.setY(sizeY)
val arrayType = builder.create()
val inputAllocation = Allocation.createTyped(context, arrayType)
val outAllocation =
Allocation.createSized(context, Element.I32(context), 256)
inputAllocation.copyFrom(inputArray)
if (coefficients != null) {
require(coefficients.size == vectorSize) {
"RenderScriptToolkit tests. $vectorSize coefficients are required for histogram. " +
"${coefficients.size} provided."
}
scriptHistogram.setDotCoefficients(
coefficients[0],
if (vectorSize > 1) coefficients[1] else 0f,
if (vectorSize > 2) coefficients[2] else 0f,
if (vectorSize > 3) coefficients[3] else 0f
)
}
scriptHistogram.setOutput(outAllocation)
if (restriction != null) {
val options = Script.LaunchOptions()
options.setX(restriction.startX, restriction.endX)
options.setY(restriction.startY, restriction.endY)
scriptHistogram.forEach_Dot(inputAllocation, options)
} else {
scriptHistogram.forEach_Dot(inputAllocation)
}
val intrinsicOutArray = IntArray(256)
outAllocation.copyTo(intrinsicOutArray)
inputAllocation.destroy()
outAllocation.destroy()
arrayType.destroy()
scriptHistogram.destroy()
return intrinsicOutArray
}