Search code examples
androidimage-processingrenderscript

Get RenderScript Progress


I'm using the forEach_root method to compute an image on Android.

RenderScript RS=RenderScript.create(context);

Allocation inPixelsAllocation = Allocation.createFromBitmap(RS, inBitmap,
            Allocation.MipmapControl.MIPMAP_NONE,Allocation.USAGE_SCRIPT); 
Bitmap out=Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
Allocation outPixelsAllocation = Allocation.createFromBitmap(RS, out,
Allocation.MipmapControl.MIPMAP_NONE,Allocation.USAGE_SCRIPT);

mScript.forEach_root(inPixelsAllocation,outPixelsAllocation);
outPixelsAllocation.copyTo(out);
return out;

This works fine, but however, since there can be a huge amount of data (more than 18 Million Pixels to process), it can take some time. Is there any possibility to get the current process of the RenderScript forEach-loop?


Solution

  • I assume by "current process" that you mean status (so that you can display a progress bar or something like that). There is no way to know how much work has been done, nor how much remains that is developer-visible. In fact, I don't think we could actually truly compute that, since you could make any single cell of your kernel instance take significantly longer with a simple if statement looking for that pixel coordinate. So, I have two potential suggestions for you, depending on what it is that you think the status information will get you: 1) Use a spinner if you are trying to make a progress bar and want to let the user know that you are indeed still working; 2) If you need this for synchronization, anything you do with the input/output allocations later will wait until the kernel completes (i.e. your copyTo operation will block appropriately).