0
votes

I am trying to run my first RenderScript application. Yet I am having the following problems: First are the error messages:

Description Resource Path Location Type The constructor ScriptC_simplers(RenderScript, Resources, int) is undefined MainActivity.java /SimpleRS/src/com/benchmark/simplers line 57 Java Problem

The method forEach_root(Allocation, Allocation) in the type ScriptC_simplers is not applicable for the arguments (Allocation, Allocation) MainActivity.java /SimpleRS/src/com/benchmark/simplers line 60 Java Problem

I am using Eclipse ADT, the API level is 19.1.0

The R.java file and ScriptC_simplers.java have been successfully generated. Here is the MainActivity file:

package com.benchmark.simplers;


import android.app.Activity;
import android.os.Bundle;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.renderscript.Allocation;
import android.renderscript.RenderScript;
import android.renderscript.ScriptC;
import android.widget.ImageView;

import android.support.v8.renderscript.*;


public class MainActivity extends Activity {
private Bitmap mBitmapIn;
private Bitmap mBitmapOut;


private RenderScript mRS;
private Allocation mInAllocation;
private Allocation mOutAllocation;
private ScriptC_simplers mScript;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mBitmapIn = loadBitmap(R.drawable.android);
    mBitmapOut = Bitmap.createBitmap(
    mBitmapIn.getWidth(), mBitmapIn.getHeight(), mBitmapIn.getConfig());
    ImageView in = (ImageView) findViewById(R.id.displayin);
    in.setImageBitmap(mBitmapIn);


    ImageView out = (ImageView) findViewById(R.id.displayout);
    out.setImageBitmap(mBitmapOut);


    createScript();
}

private void createScript() {
    mRS = RenderScript.create(this);


    mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
    Allocation.MipmapControl.MIPMAP_NONE,
    Allocation.USAGE_SCRIPT);
    mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());


    mScript = new ScriptC_simplers(mRS, getResources(), R.raw.simplers);


    mScript.forEach_root(mInAllocation, mOutAllocation);
    mOutAllocation.copyTo(mBitmapOut);
}

private Bitmap loadBitmap(int resource) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    return BitmapFactory.decodeResource(getResources(), resource, options);
}

}

Here is simplers.rs file:

#pragma version(1)
#pragma rs java_package_name(com.benchmark.simplers)


const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};


void root(const uchar4 *v_in, uchar4 *v_out) {
    float4 f4 = rsUnpackColor8888(*v_in);
    float3 mono = dot(f4.rgb, gMonoMult);
    *v_out = rsPackColorTo8888(mono);
}

In the generated file ScriptC_simplers.java, I can see the constructor:

public  ScriptC_simplers(RenderScript rs, Resources resources, int id) {
    super(rs, resources, id);
    __U8_4 = Element.U8_4(rs);
}

I just do not know why ADT cannot find the constructor. If you know solutions, please help me, thank u!

1

1 Answers

0
votes

You are mixing android.renderscript.* and android.support.v8.renderscript.*, which is not allowed. You end up importing two different versions of "Allocation", so you are likely not getting the one you intended. Are you trying to get a simple RS application to work using regular RS or the support library version? Remove one of those sets of imports and see if that changes the behavior.