简体   繁体   English

Renderscript模糊警告

[英]Renderscript blur warnings

I use the renderscript support library by Google to blur a Bitmap. 我使用Google的renderscript支持库来模糊位图。 It works, but I see an error on the log: 它工作正常,但我在日志中看到错误:

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

The problem is that after the error a garbage collection is called, freezing the UI thread for a while. 问题是在错误之后调用垃圾收集,冻结UI线程一段时间。

I use this code to blur the Bitmap: 我用这段代码来模糊Bitmap:

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);

Why the No context! 为什么No context! error? 错误? How can I avoid that? 我怎么能避免这种情况?

PS: I use a Nexus 5 for the tests PS:我使用Nexus 5进行测试

I'm slightly disappointed that my previous answer was deleted since the observations clearly pointed to buggy behaviour and they allowed more people helping pinpointing the bug itself. 我之前的回答被删除了,我有点失望,因为观察结果明确指出了错误的行为,他们允许更多的人帮助查明错误本身。

However I investigated more thoroughly myself. 但是我自己调查得更彻底。 I have created bitmaps of all sizes with width and height between 350 and 450. With each of these bitmap I created an allocation. 我创建了所有大小的位图,宽度和高度在350到450之间。我使用这些位图创建了一个分配。 On a Nexus 5, the method Allocation.createFromBitmap always gives the error below in case that (bitmap width % 8) == 1,2,3 or 4 . 在Nexus 5上, 方法Allocation.createFromBitmap(bitmap width % 8) == 1,2,3或4的情况下总是给出以下错误 In all other cases, the allocation was done without errors. 在所有其他情况下,分配完成没有错误。

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

I suspect a bug, but I cannot find any source code related to rsdVendorAllocationSetupTexture to dig deeper. 我怀疑是一个错误,但我找不到任何与rsdVendorAllocationSetupTexture相关的源代码来深入挖掘。 I don't know if the error has some impact or not... (see my notes below for possible impact... for example when using the allocation in a 1 dimension way) 我不知道错误是否有一些影响...(请参阅下面的笔记,了解可能的影响......例如,以一维方式使用分配时)

Bypass of this error is possible by choosing the width of the bitmap so that width % 8 == 5,6,7 or 0. 通过选择位图的宽度使宽度%8 == 5,6,7或0,可以绕过此错误。

My previous answer that was deleted: 我之前删除的答案是:

I have the exact same problem on my Nexus 5 and I noticed some additional points: 我在Nexus 5上遇到了完全相同的问题,我注意到了一些额外的问题:

  • I only have the texture creation failed error for portrait shaped bitmaps. 我只有肖像形状位图的纹理创建失败错误。 square bitmaps, or landscape shaped bitmaps do not trigger these errors. 方形位图或横向形状的位图不会触发这些错误。
  • I always have the No Context error (portrait and landscape shaped bitmaps) 我总是有No Context错误(纵向和横向形状的位图)
  • Despite the fact that I get the error for portrait shaped bitmaps, the processing and the result from the renderscript is fine (see also next 2 points). 尽管我得到了纵向形状位图的错误,但处理和renderscript的结果都很好(另见下2点)。
  • when I was accessing the allocation in the renderscript via the one dimensional method rsGet(Set)ElementAt_uchar4(gIn,location) , with location calculated given the width and height of the bitmap, the result from the renderscript was messed up for portrait shaped bitmaps. 当我通过一维方法rsGet(Set)ElementAt_uchar4(gIn,location)访问rsGet(Set)ElementAt_uchar4(gIn,location)的分配时,在给定位图的宽度和高度的情况下计算位置,来自renderscript的结果被混淆为肖像形状的位图。
  • when I was accessing the allocation via the two dimensional method rsGet(Set)ElementAt_uchar4(gIn,x,y) , I still got the errors for portrait shaped bitmaps, but the result of the renderscript was fine. 当我通过二维方法rsGet(Set)ElementAt_uchar4(gIn,x,y)访问分配时,我仍然得到了纵向形状位图的错误,但是renderscript的结果很好。
  • With a messed up result, I mean that the result (a blur) was still recognizable, but it was distorded. 如果结果搞砸了,我的意思是结果(模糊)仍然可识别,但是它被缩小了。
  • I'm also sure that I'm not using a recycled bitmap. 我也确定我没有使用回收的位图。
  • The script was also a Blur script, but not the intrinsic one. 该脚本也是一个Blur脚本,但不是内在脚本。 ( https://github.com/kikoso/android-stackblur ) (not written by myself)... I noticed the above topics by trying to debug when I noticed that portrait shaped bitmaps were not blurred correctly. https://github.com/kikoso/android-stackblur )(不是我自己写的)......当我注意到肖像形状的位图没有正确模糊时,我通过尝试调试注意到了上述主题。

I had the same error because i used recycled bitmap. 我有同样的错误,因为我使用了回收的位图。 Check that your original bitmap is not recycled. 检查original位图是否未被回收。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM