Android 简单Renderscript示例失败
我正在尝试创建一个图像处理库,内置renderscript。我一直在这里玩for Renderscript Renderscript似乎拥有创建此库所需的一切,不幸的是,我似乎无法获得许多示例 ImageProceCsing示例是一个很好的例子,说明了事情对我的影响。大多数脚本内部函数都是开箱即用的,没有错误。然而,一旦我移动到一个脚本文件,即使做基本的thng也会失败。我的意思是失败Android 简单Renderscript示例失败,android,image-processing,renderscript,Android,Image Processing,Renderscript,我正在尝试创建一个图像处理库,内置renderscript。我一直在这里玩for Renderscript Renderscript似乎拥有创建此库所需的一切,不幸的是,我似乎无法获得许多示例 ImageProceCsing示例是一个很好的例子,说明了事情对我的影响。大多数脚本内部函数都是开箱即用的,没有错误。然而,一旦我移动到一个脚本文件,即使做基本的thng也会失败。我的意思是失败 Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), threa
Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 21581 (enderscripttest)
因此,为了帮助调试,我创建了一个简单的示例,其中包含了我能想到的最基本的示例。它基本上只是尝试将亮度过滤器应用于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);
}
我只在星系S3和S4上测试过这个。今晚我将在Nexus4上进行测试,看看是否得到不同的结果
编辑:
我已确认此代码在Nexus 4上有效。我将仔细检查一些其他设备。另外,我会看看我是否能一起得到一个APK,以防斯蒂芬·海因斯或蒂姆·默里想看,但现在看来只有星系S3和S4(都是4.3)受到影响
编辑2:我相信这是正在发生的同一个问题。随着这两个问题的进展,我将进行更新您能为失败案例粘贴日志吗?正如在另一个线程中提到的,支持库中有很多缺少的符号,因此如果这是相同的问题,您将不得不等待新的SDK。希望SDK很快就会更新。@StephenHines这里是我的要点。galaxy S3和4非常简单,您可以从必须使用支持lib的旧设备中获得更好的错误。S3/S4运行的是什么Android版本?看起来它们正在尝试运行本机RenderScript并崩溃。是JB-MR2(4.3或更高版本)吗?“我担心三星可能已经损坏了一些东西。”斯蒂芬·海因斯我最近刚刚将这两款手机升级到4.3。所以是的,也许三星把这件事搞砸了!