简单的Renderscript示例失败

时间:2014-01-07 21:27:30

标签: android image-processing renderscript

我正在尝试创建一个内置在renderscript中的图像处理库。我一直在玩android samples Renderscript。

Renderscript似乎拥有创建这个库所需的一切,遗憾的是我似乎无法让很多示例适合我。

ImageProcecssing示例是一个很好的例子,说明事情对我有用。大多数Script Intrinsics开箱即用,没有错误。但是,一旦我转到ScriptC文件,即使执行 basic thngs也会失败。而失败,我的意思是

Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 21581 (enderscripttest)

所以,为了帮助调试,我创建了一个github repo字面上我可以想出的最基本的例子。它基本上只是尝试将亮度滤镜应用于imageview。

相关代码:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageView = (ImageView)findViewById(R.id.image);

        BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inSampleSize = 8;
        originalBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.colors,opts);
        filteredBitmap = Bitmap.createBitmap(originalBitmap.getWidth(),originalBitmap.getHeight(), originalBitmap.getConfig());

        //RENDERSCRIPT ALLOCATION
        mRS = RenderScript.create(this);
        mInAllocation = Allocation.createFromBitmap(mRS, originalBitmap,Allocation.MipmapControl.MIPMAP_NONE,Allocation.USAGE_SCRIPT);
        mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
        mOutAllocation.copyFrom(originalBitmap);
        mOutAllocation.copyTo(filteredBitmap);

        ScriptC_brightnessfilter helloworldScript = new ScriptC_brightnessfilter(mRS);

        helloworldScript.set_brightnessValue(4.0f);
        helloworldScript.bind_gPixels(mInAllocation);

        helloworldScript.set_gIn(mInAllocation);
        helloworldScript.set_gOut(mOutAllocation);
        helloworldScript.set_gScript(helloworldScript);
        helloworldScript.invoke_filter();
        mOutAllocation.copyTo(filteredBitmap);

    }

然后是一个renderscript文件

#pragma version(1)
#pragma rs java_package_name(com.dss.renderscripttest)

float brightnessValue;

rs_allocation gIn;
rs_allocation gOut;
rs_script gScript;

static int mImageWidth;
const uchar4 *gPixels;

void root(const uchar4 *v_in, uchar4 *v_out, const void *usrData, uint32_t x, uint32_t y) {

    float4 apixel = rsUnpackColor8888(*v_in);
    float3 pixel = apixel.rgb;
    float factor = brightnessValue;
    pixel = pixel + factor;
    pixel = clamp(pixel,0.0f,1.0f);
    *v_out = rsPackColorTo8888(pixel.rgb);
}


void filter() {
    mImageWidth = rsAllocationGetDimX(gIn);
    rsDebug("Image size is ", rsAllocationGetDimX(gIn), rsAllocationGetDimY(gOut));
    rsForEach(gScript, gIn, gOut, 0, 0);
}

我只在Galaxy S3和S4上测试了这个。我今晚将在Nexus 4上进行测试,看看我是否得到了不同的结果。

编辑:

我已经确认此代码在Nexus 4上运行。我将通过其他一些设备进行测试。另外我会看看我是否可以一起获得一个APK,如果斯蒂芬海因斯或蒂姆默里想看,但现在似乎只有Galaxy S3和S4(均为4.3)受影响

编辑2:我认为这与over here发生的问题相同。随着两个问题的进展,我会更新

0 个答案:

没有答案