android - Renderscript 模糊警告

标签 android bitmap renderscript

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

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 进行测试

最佳答案

我对我之前的回答被删除感到有些失望,因为观察结果清楚地指出了 bug 行为,并且它们允许更多的人帮助查明 bug 本身。

但是我自己调查得更彻底。我已经创建了宽度和高度在 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 上遇到了完全相同的问题,我注意到了一些额外的问题:

  • 我只有纵向位图的纹理创建失败错误。方形位图或横向位图不会触发这些错误。
  • 我总是遇到无上下文错误(纵向和横向位图)
  • 尽管我得到了纵向位图的错误,但渲染脚本的处理和结果都很好(另请参见接下来的 2 点)。
  • 当我通过一维方法访问渲染脚本中的分配时 rsGet(Set)ElementAt_uchar4(gIn,location) ,通过给定位图的宽度和高度计算位置,渲染脚本的结果对于纵向位图来说是困惑的。
  • 当我通过二维方法访问分配时 rsGet(Set)ElementAt_uchar4(gIn,x,y) ,我仍然遇到纵向位图的错误,但渲染脚本的结果很好。
  • 对于困惑的结果,我的意思是结果(模糊)仍然可以辨认,但它被扭曲了。
  • 我也确定我没有使用回收的位图。
  • 该脚本也是 Blur 脚本,但不是固有脚本。 ( https://github.com/kikoso/android-stackblur )(不是我自己写的)...当我注意到肖像位图没有正确模糊时,我通过尝试调试注意到了上述主题。

关于android - Renderscript 模糊警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23919383/

相关文章:

android - 无法从共享首选项中保存的 URI 加载图像

android - WebView 中的大图像导致内存不足

Android Studio 构建失败,因为它无法合并 Renderscript 文件

android - 使用 renderscript 进行处理,使用 mediacodec 进行编码

android - 如何以编程方式在 ViewPager 中显示下一个 View ?

android - 如何在android中删除EditText的onfocus文本?

vb.net - 在 VB.Net 中从头开始创建位图图像时,质量很差?

android - RenderScript 支持库在 x86 设备上崩溃

android - 同时打开android前置摄像头和后置摄像头

java - 问题重新启动finish()ed的android Activity