api 20+ only allows simple 1d allocations to be used with bind renderscript

248 views Asked by At

I develop an application which goal is to calculate the mean of the grayscale on each column. Here is my code:

mInputAllocation=Allocation.createFromBitmap(mRs, mBitmapIn.MipMapControl.MIPMAP_NONE, allocation.USAGE_SCRIPT);
mOutputAllocation=Allocation.createSized(mRs, Element.I32, Allocation.USAGE_SCRIPT);
mScript.bind_gInPixels(mInputAllocation);
mScript.bind_gResult(mOutputAllocation);
mScript.invoke_filter();

And in myscript.rs I have:

int sum;
int32_t *gResult;
const uchar4 *gInPIxels;
void root(const uint32_t *v_in, int_32 *v_out, uint32_t x, uint32_t y){
for(int i=0;i<mImageWidth;i++){
sum=sum+gray;}
gResult[*v_out]=sum;}

void filter(){
rsForEach(gScript, gIn, gOut);}

I got this exception while executing the application on my phone: API20+ only allows simple 1D allocations to be used with bind.

1

There are 1 answers

4
Stephen Hines On

I am definitely missing something from myscript.rs, because I see references to "gray", but no actual definition. You also seem to be using *v_out as an index, but that is really not what it is intended for. As far as accessing data at a different x/y coordinate, you would be best off using rsSetElementAt_int(). Take a look at that function in http://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data.html#android_rs:rsSetElementAt.