How to get working with Android Render Script?

I can get two separate built-in functions, but not together in a ScriptGroup. I found a document on how to use the Script Group, extremely meager.

Here is my code:

mRS = RenderScript.create(getActivity());

mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
        Allocation.MipmapControl.MIPMAP_NONE,
        Allocation.USAGE_SCRIPT |
                Allocation.USAGE_GRAPHICS_TEXTURE |
                Allocation.USAGE_SHARED);

mOutAllocation = Allocation.createFromBitmap(mRS, mBitmapOut,
        Allocation.MipmapControl.MIPMAP_NONE,
        Allocation.USAGE_SCRIPT |
                Allocation.USAGE_SHARED);

ScriptIntrinsicColorMatrix gray = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
gray.setGreyscale();

ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS));
blur.setRadius(20.f);
blur.setInput(mInAllocation);

//gray.forEach(mInAllocation, mOutAllocation);
blur.forEach(mOutAllocation);

mOutAllocation.copyTo(mBitmapOut);

Gray and blurry work. And then I tried to connect them, the result is empty. Code:

// gray.forEach(mInAllocation, mOutAllocation);
// blur.forEach(mOutAllocation);
// mOutAllocation.copyTo(mBitmapOut);

ScriptGroup.Builder builder = new ScriptGroup.Builder(mRS);
builder.addKernel(gray.getKernelID());
builder.addKernel(blur.getKernelID());
builder.addConnection(mInAllocation.getType(), gray.getKernelID(), blur.getKernelID());

ScriptGroup group = builder.create();
group.setInput(gray.getKernelID(), mInAllocation);
group.setOutput(blur.getKernelID(), mOutAllocation);
group.execute();

mOutAllocation.copyTo(mBitmapOut);
+6
source share
1 answer

I was able to reproduce the problem you encountered and double-check it from the records of my previous experiments with the insides. I think there are a few bugs in the internal Renderscript code.

-1- If you want the scripting group to work with internal components, the sequence below works.

mBlur.setInput(mInAllocation);
sBuilder = new ScriptGroup.Builder(mRS);
sBuilder.addKernel(mBlur.getKernelID());
sBuilder.addKernel(mColor.getKernelID());
sBuilder.addConnection(connect, mBlur.getKernelID(), mColor.getKernelID());

sGroup = sBuilder.create();
//  sGroup.setInput(mBlur.getKernelID(), mInAllocation); //See point 2
sGroup.setOutput(mColor.getKernelID(), mOutAllocation);
sGroup.execute();

mOutAllocation.copyTo(outBitmap);
mRS.finish();

-2- . mBlur.setInput(), sGroup.setInput(). sGroup.setInput(), , , , .

E/RenderScript(12023): rsAssert failed: !"ScriptGroup:setInput kid not found", in frameworks/rs/rsScriptGroup.cpp at 267

-1- , sGroup.setInput() mBlur.setInput()

E/RenderScript(12023): Blur executed without input, skipping

, () Renderscript

-3- , , ScriptIntrinsicColorMatrix ScriptIntrinsicBlur , ( ). Blur intrinsic setInput, colorMatrix setInput. -1- .

-4- , Renderscript intrinsic.setInput , ScriptIntrinsicColorMatrix, ScriptGroup.setInput .

-5- scriptgroup, . , scriptGroup.setInput() scriptGroup.setOutput()

+5

All Articles