Renderscript Documentation and Advice - Android -


i have been following guide on how use render-script on android.

http://www.jayway.com/2014/02/11/renderscript-on-android-basics/

my code (i got wrapper class script):

public class pixelcalcscriptwrapper {      private allocation inallocation;     private allocation outallocation;     renderscript rs;     scriptc_pixelscalc script;      public pixelcalcscriptwrapper(context context){         rs = renderscript.create(context);         script = new scriptc_pixelscalc(rs, context.getresources(), r.raw.pixelscalc);     };      public void setinallocation(bitmap bmp){         inallocation = allocation.createfrombitmap(rs,bmp);     };      public void setoutallocation(bitmap bmp){         outallocation = allocation.createfrombitmap(rs,bmp);     };      public void foreach_root(){         script.foreach_root(inallocation, outallocation);     } } 

this methods calls script:

public bitmap processbmp(bitmap bmp, bitmap bmpcopy) {      pixelcalcscriptwrapper.setinallocation(bmp);     pixelcalcscriptwrapper.setoutallocation(bmpcopy);     pixelcalcscriptwrapper.foreach_root();      return bmpcopy; }; 

and here script:

#pragma version(1) #pragma rs java_package_name(test.foo)  void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {     float3 pixel = convert_float4(in[0]).rgb;      if(pixel.z < 128) {         pixel.z = 0;     }else{         pixel.z = 255;     }     if(pixel.y < 128) {         pixel.y = 0;     }else{         pixel.y = 255;     }     if(pixel.x < 128) {         pixel.x = 0;     }else{         pixel.x = 255;     }      out->xyz = convert_uchar3(pixel); } 

now can find documentation ?

for example, have these questions:

1) convert_float4(in[0]) ?

2) rgb return here convert_float4(in[0]).rgb;?

3) float3 ?

4) don't know start line out->xyz = convert_uchar3(pixel);

5) assuming in parameters, in , out allocations passed? x , y?

1) in kernel, in pointer 4-element unsigned char, is, represents pixel color r, g, b , values in 0-255 range. convert_float4 casts each of 4 uchar float. in particular code using, doesn't make sense work floats, since you're doing simple threshold, , had worked uchar data directly. using floats better aimed when doing other types of image processing algorithms need have precision (example: blurring image).

2) .rgb suffix shorthand return first 3 values of float4, i.e. r, g, , b values. if had used .r give first value regular float, if had used .g give second value float, etc... these 3 values assigned float3 variable, represents pixel 3 color channels (that is, no alpha channel).

3) see #2.

4) convert_uchar3 again cast converts float3 pixel variable uchar3 variable. assigning 3 values each of x, y, , z elements in order. time mention x, y , z interchangeable r, g , b. statement have used out->rgb, , have been more readable way. note out uchar4, , doing this, assigning first 3 "rgb" or "xyz" elements in pointer, fourth element left undefined here.

5) yes, in input pixel, out output pixel. x , y x, , y coordinates of pixel in overall image. kernel function going called once every pixel in image/allocation you're working with, , it's know coordinate you're @ when processing image. in particular example since it's thresholding pixels in same way, coordinates irrelevant.

good documentation on renderscript hard find. recommend take @ these 2 videos though, give better sense of how renderscript works:

andevcon: deep dive renderscript

google i/o 2013 - high performance applications renderscript

keep in mind both videos couple years old, minor details may have changed on recent apis, overall, best sources of information rs.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -