Simple Renderscript Example

I am trying to create an image processing library built into renderscript. I played with android samples for renderscript here.

Renderscript has everything I need to create this library, unfortunately, I cannot get many examples to work for me.

Example ImageProcecssing is a good example of how everything works for me. Most of Script Intrinsics work out of the box, no errors. However, as soon as I go to the ScriptC file, even performing basic operations tends to fail. And unfortunately, I mean

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

So, to help debugging, I created a github repo with literally the most basic example that I could come up with. Basically this is just an attempt to apply a brightness filter to the image representation.

Relevant Code:

 @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); } 

Then renderscript file

 #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); } 

I tested this only on the Galaxy S3 and S4. I will spend on Nexus 4 tonight and see if I get a different result.

Edit:

I have confirmed that this code works on Nexus 4. I will work with some other devices for a good evaluation. I’ll also see if I can get the APK together in case Stephen Hines or Tim Murray wants to watch, but now it seems that only Galaxy S3 and S4 are implemented (both 4.3)

Edit 2: I believe this is the very problem that is happening here here . I will be updated as both issues move forward.

+1
android image-processing renderscript
source share

No one has answered this question yet.

See related questions:

880
"Conversion to Dalvik format failed with error 1" on an external JAR
687
Android error: Failed to install * .apk on device *: timeout
664
Android example for AsyncTask
560
Example: communication between activity and service using messages
2
Renderscript cannot export a static variable
2
RenderScript example for Android RenderScript example> HelloCompute does not compile
one
Renderscript throws an exception "rsAssert failed :! MElements.size ()"
0
RenderScript Variable Types and Element Types, A Simple Example
0
Renderscript Carousel Example
-one
Example Applications Using Renderscript

All Articles