Renderscript模糊警告

时间:2014-05-28 18:37:39

标签: android bitmap renderscript

我使用Google的renderscript支持库来模糊位图。它有效,但我在日志中看到错误:

V/RenderScript_jni(20699): RS native mode
V/RenderScript(20699): 0x2a709a80 Launching thread(s), CPUs 4
W/Adreno-RS(20699): <rsdVendorAllocationDestroyQCOM:199>: rsdVendorAllocationDestroy: No context!
E/RenderScript(20699): Successfully loaded runtime: libRSDriver_adreno.so
W/Adreno-RS(20699): <rsdVendorAllocationSetupTexture:647>: ERROR: Runtime texture creation failed err: -30 image: 0x0 alloc: 0x82340000
W/Adreno-RS(20699): <rsdVendorAllocationSetupTexture:649>: ERROR: Runtime texture creation failed type: 8 kind: 11 eleSize: 4
W/Adreno-RS(20699): <rsdVendorAllocationSetupTexture:647>: ERROR: Runtime texture creation failed err: -30 image: 0x0 alloc: 0x93570000
W/Adreno-RS(20699): <rsdVendorAllocationSetupTexture:649>: ERROR: Runtime texture creation failed type: 8 kind: 11 eleSize: 4

问题是在错误之后调用垃圾收集,冻结UI线程一段时间。

我使用此代码来模糊位图:

final RenderScript rs = RenderScript.create(context); //context IS NOT null
final Allocation input = Allocation.createFromBitmap(rs, original, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius /* e.g. 3.f */);
script.setInput(input);
script.forEach(output);
Bitmap ret = original.copy(original.getConfig(), true);
output.copyTo(ret);

为什么No context!错误?我怎么能避免这种情况?

PS:我使用Nexus 5进行测试

2 个答案:

答案 0 :(得分:2)

我有点失望的是我的上一个答案被删除了,因为观察结果清楚地指出了错误的行为,并且他们允许更多人帮助查明错误本身。

然而,我自己进行了更彻底的调查。我创建了所有大小的位图,宽度和高度在350到450之间。我使用这些位图创建了一个分配。 在Nexus 5上,方法Allocation.createFromBitmap总是在(bitmap width % 8) == 1,2,3或4 的情况下给出错误。在所有其他情况下,分配完成没有错误。

07-31 18:48:07.902: D/Allocation(20508): Width: 417, height: 399
07-31 18:48:07.922: W/Adreno-RS(20508): <rsdVendorAllocationSetupTexture:647>: ERROR: Runtime texture creation failed err: -30 image: 0x0 alloc: 0x9dd20000
07-31 18:48:07.922: W/Adreno-RS(20508): <rsdVendorAllocationSetupTexture:649>: ERROR: Runtime texture creation failed type: 8 kind: 11 eleSize: 4

我怀疑是一个错误,但我找不到任何与rsdVendorAllocationSetupTexture相关的源代码来深入挖掘。 我不知道错误是否有影响......(请参阅下面的注释,了解可能产生的影响......例如,当以一维方式使用分配时)

通过选择位图的宽度使宽度%8 == 5,6,7或0,可以绕过此错误。

我之前删除的答案:

我在Nexus 5上遇到了完全相同的问题,我注意到了一些额外的问题:

  • 我只有肖像形状位图的纹理创建失败错误。方形位图或横向形状的位图不会触发这些错误。
  • 我总是有No Context错误(纵向和横向形状的位图)
  • 尽管我得到了纵向形状位图的错误,但处理和renderscript的结果都很好(另见下2点)。
  • 当我通过一维方法rsGet(Set)ElementAt_uchar4(gIn,location)访问renderscript中的分配时,根据位图的宽度和高度计算位置,渲染脚本的结果被搞砸为肖像形状的位图。
  • 当我通过二维方法rsGet(Set)ElementAt_uchar4(gIn,x,y)访问分配时,我仍然得到了纵向形状位图的错误,但是renderscript的结果很好。
  • 结果搞砸了,我的意思是结果(模糊)仍然可以识别,但是它被缩小了。
  • 我也确定我没有使用回收的位图。
  • 脚本也是一个Blur脚本,但不是内在脚本。 (https://github.com/kikoso/android-stackblur)(不是我自己写的)......当我注意到肖像形状的位图没有被正确模糊时,我通过尝试调试注意到了上述主题。

答案 1 :(得分:0)

我有同样的错误,因为我使用了回收的位图。检查您的original位图是否未被回收。