0

Background

I'm new to renderscript, and I would like to try some experiments with it (but small ones and not the complex ones we find in the SDK), so I thought of an exercise to try out, which is based on a previous question of mine (using NDK).

What I want to do

In short, I would like to pass a bitmap data to renderscript, and then I would like it to copy the data to another bitmap that has the dimensions opposite to the previous one, so that the second bitmap would be a rotation of the first one.

For illustration: From this bitmap (width:2 , height:4):

01
23 
45
67

I would like it to rotate (counter clock-wise of 90 degrees) to:

1357
0246

The problem

I've noticed that when I try to change the signature of the root function, Eclipse gives me errors about it.

Even making new functions creates new errors. I've even tried the same code written on Google's blog (here ), but I couldn't find out how he got to create the functions he used, and how come I can't change the filter function to have the input and output bitmap arrays.

What can I do in order to customize the parameters I send to renderscript, and use the data inside it?

Is it ok not to use "filter" or "root" functions (API 11 and above)? What can I do in order to have more flexibility about what I can do there?

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270

1 Answers1

1

You are asking a bunch of separate questions here, so I will answer them in order. 1) You want to rotate a non-square bitmap. Unfortunately, the bitmap model for Renderscript won't allow you to do this easily. The reason for this is that that input and output allocations must have the same shape (i.e. same number of dimensions and values of those dimensions, even if the Types are different). In order to get the effect you want, you should use a root function that only has an output allocation of the new shape (i.e. input columns X input rows). You can create an rs_allocation global variable for holding your input bitmap (which you can then create/bind on the Java side). The kernel then merely needs to set the output cell to the result of rsGetElementAt(globalInAlloc, y, x).

2) If you are using API 11, you can't adjust the signature of the root() function (you can pass NULL allocations as input, output on the Java side if you are not using them). You also can't create more than 1 kernel per source file on these older API levels, so you are forced to only have a single "root()" function. If you want to use more kernels per source file, consider targeting a higher API level.

Stephen Hines
  • 2,612
  • 1
  • 13
  • 12
  • ok , sorry for the multiple questions. it's just that one came because of the other . about 1, can you please show how you offer to do it by code?also , since the bitmaps have just opposite dimensions, isn't it possible to just set the target pixels to different locations ? about 2 , you mean to tell me i can't pass anything to renerscript other than bitmap data ? how could it be ? i saw some amazing samples of renderscript and i can't believe they all work per pixel . even for pixels that need to look near them , they need to know how many pixels to go for one pixel up/down ... – android developer Jan 21 '13 at 19:58