Can I set input and output allocations on Renderscript to be of different sizes/dimensions?

前端 未结 2 1704
陌清茗
陌清茗 2021-01-23 00:53

Background

I\'m trying to learn Renderscript, so I wish to try to do some simple operations that I think about.

The problem

I thought of rotating a b

相关标签:
2条回答
  • 2021-01-23 01:34

    This should solve your problem

    RS

    rs_allocation *in;  
    uchar4 attribute((kernel)) rotate90CW(uint32_t x, uint32_t y){
    ...
    uchar4 curIn =rsGetElementAt_uchar4(in, x, y); 
    
    return curIn; 
     }
    
    0 讨论(0)
  • 2021-01-23 01:53

    Here goes:

    1. Does this mean I can't do this kind of operation?

    No, not really. You just have to craft things correctly.

    1. Does it mean that I can't use allocations of various sizes/dimensions?

    No, but it does mean you can't use different size allocations in the way you currently are doing things. The default kernel in/out mechanism expects the input and output sizes to match so it can iterate over all of the elements correctly. If you need something different, it's up to you to manage it. More on that below.

    1. Is it possible to overcome this issues...how?

    The easiest solution would be to create an Allocation for input and bind it to the renderscript instance rather than pass it as a parameter. Then your RS would only need an output allocation (and your kernel only take output, x and y). From there you can determine which coordinate within the input allocation you want and place it directly into the output location:

    int inX = ...;
    int inY = ...;
    uchar4 curIn = rsGetElementAt_uchar4(inAlloc, inX, inY);
    *out = curIn;
    
    1. Why do I get holes in the bitmap, for the case of a square input&output?

    It's because you cannot use the x and y parameters to offset into the input and output allocation. Those in/out parameters are already pointing to the correct (same) location in both the input and output. The indexing you're doing is unnecessary and not really supported. Each time your kernel is called, it is being called for 1 element location within the allocation. This is why the input and output sizes must be the same when provided as parameters.

    0 讨论(0)
提交回复
热议问题