0

I looked at this example https://github.com/googlesamples/android-BasicRenderScript. In that project, they have the following line:

mInAllocation = Allocation.createFromBitmap(rs, mBitmapIn);

where mBitmapIn is of type Bitmap representing the image to process. Later, they call the kernel function named saturation in the .rs file asynchronously via an AsyncTask:

mScript.forEach_saturation(mInAllocation, mOutAllocations[index]);

In saturation.rs file, they have:

uchar4 __attribute__((kernel)) saturation(uchar4 in)
{
    float4 f4 = rsUnpackColor8888(in);
    ... 

From this thread Renderscript, what is the `in` parameter? I know that the parameter 'in' points to the data to be processed (which in our case is a pixel, right ? ) So, I know that a pixel consists of 4 color channels and therefore they use uchar4 which is a vector of 4 uchars (see https://developer.android.com/guide/topics/renderscript/reference/rs_value_types.html#android_rs:uchar4 ). But why uchar ? Why not, let's say, uint4 ? Or directly ufloat4 ??

ebeninki
  • 909
  • 1
  • 12
  • 34

1 Answers1

0

Renderscript is defined with the C99 standard and lists the sizeof values for types here:

https://developer.android.com/guide/topics/renderscript/reference/rs_value_types

So from that chart:

uchar has a 8 bit unsigned value size

uint has a 32 bit unsigned value size

float has 32 bit size

Android bitmaps are typically configured ARGB_8888 format so each pixel has 3 color channels along with alpha and those made up of 8 bits.

Even in your example you can see the transformation into floats for computation purposes:

float4 f4 = rsUnpackColor8888(in);

For a more comprehensive discussion on C type sizes see: Is the size of C “int” 2 bytes or 4 bytes?

Morrison Chang
  • 11,691
  • 3
  • 41
  • 77