I want to count the pixels of a bitmap using the following RenderScript code
RenderScript
Filename: counter.rs
#pragma version(1)
#pragma rs java_package_name(com.mypackage)
#pragma rs_fp_relaxed
uint count; // initialized in Java
void countPixels(uchar4* unused, uint x, uint y) {
rsAtomicInc(&count);
}
Java
Application context = ...; // The application context
RenderScript rs = RenderScript.create(applicationContext);
Bitmap bitmap = ...; // A random bitmap
Allocation allocation = Allocation.createFromBitmap(rs, bitmap);
ScriptC_Counter script = new ScriptC_Counter(rs);
script.set_count(0);
script.forEach_countPixels(allocation);
allocation.syncAll(Allocation.USAGE_SCRIPT);
long count = script.get_count();
Error
This is the error message I get:
ERROR: Address not found for count
Questions
- Why doesn't my code work?
- How can I fix it?
Here is my working solution.
RenderScript
Filename:
counter.rs
rsAtomicInc()
rsSetElementAt_int()
Java