如何让Android Render Script Group工作?

如何让Android Render Script Group工作?,第1张

概述我可以让两个独立的内在函数工作,但不能在ScriptGroup中一起工作.我发现有关如何使用Script Group的文档非常稀疏.这是我的代码: mRS = RenderScript.create(getActivity()); mInAllocation = Allocation.createFromBitmap(mRS,

我可以让两个独立的内在函数工作,但不能在ScriptGroup中一起工作.我发现有关如何使用Script Group的文档非常稀疏.

这是我的代码:

        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.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.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);
最佳答案我能够重现您所看到的问题,并使用我之前使用内在函数的实验中的注释进行交叉检查.我认为renderscript内在函数代码中存在一些错误.

-1-
如果您希望使用内在函数的脚本组,则以下序列有效.

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 2sGroup.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中的BUG

-3-
具体来说,在您的情况下,您希望在序列中使用ScriptIntrinsicBlur执行ScriptIntrinsiccolorMatrix,还有另一个问题(不一定是错误).虽然Blur内部有一个setinput函数,但colorMatrix确实有一个setinput函数.因此,您也不能使用-1-作为解决方法.

-4-
我认为renderscript中的正确修复将是弃用
intrinsic.setinput与ScriptIntrinsiccolorMatrix一样普遍,并且在脚本组中使用intrinsics时可以使ScriptGroup.setinput正常工作.

-5-
当我拥有自己的内核时,我没有看到使用scriptgroup的任何问题.换句话说,scriptGroup.setinput()和scriptGroup.setoutput()完全正常 总结

以上是内存溢出为你收集整理的如何让Android Render Script Group工作?全部内容,希望文章能够帮你解决如何让Android Render Script Group工作?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1140395.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存