RenderScript Allocation Data Access Functions
Stay organized with collections
Save and categorize content based on your preferences.
Overview
The functions below can be used to get and set the cells that comprise an allocation.
- Individual cells are accessed using the rsGetElementAt* and rsSetElementAt functions.
- Multiple cells can be copied using the rsAllocationCopy* and rsAllocationV* functions.
- For getting values through a sampler, use rsSample.
Summary
| Functions | |
|---|---|
| rsAllocationCopy1DRange | Copy consecutive cells between allocations |
| rsAllocationCopy2DRange | Copy a rectangular region of cells between allocations |
| rsAllocationVLoadX | Get a vector from an allocation of scalars |
| rsAllocationVStoreX | Store a vector into an allocation of scalars |
| rsGetElementAt | Return a cell from an allocation |
| rsGetElementAtYuv_uchar_U | Get the U component of an allocation of YUVs |
| rsGetElementAtYuv_uchar_V | Get the V component of an allocation of YUVs |
| rsGetElementAtYuv_uchar_Y | Get the Y component of an allocation of YUVs |
| rsSample | Sample a value from a texture allocation |
| rsSetElementAt | Set a cell of an allocation |
Functions
rsAllocationCopy1DRange : Copy consecutive cells between allocations
Parameters
| dstAlloc | Allocation to copy cells into. |
|---|---|
| dstOff | Offset in the destination of the first cell to be copied into. |
| dstMip | Mip level in the destination allocation. 0 if mip mapping is not used. |
| count | Number of cells to be copied. |
| srcAlloc | Source allocation. |
| srcOff | Offset in the source of the first cell to be copied. |
| srcMip | Mip level in the source allocation. 0 if mip mapping is not used. |
Copies the specified number of cells from one allocation to another.
The two allocations must be different. Using this function to copy within the same allocation yields undefined results.
The function does not validate whether the offset plus count exceeds the size of either allocation. Be careful!
This function should only be called between 1D allocations. Calling it on other allocations is undefined.
This function should not be called from inside a kernel, or from any function that may be called directly or indirectly from a kernel. Doing so would cause a runtime error.
rsAllocationCopy2DRange : Copy a rectangular region of cells between allocations
Parameters
| dstAlloc | Allocation to copy cells into. |
|---|---|
| dstXoff | X offset in the destination of the region to be set. |
| dstYoff | Y offset in the destination of the region to be set. |
| dstMip | Mip level in the destination allocation. 0 if mip mapping is not used. |
| dstFace | Cubemap face of the destination allocation. Ignored for allocations that aren't cubemaps. |
| width | Width of the incoming region to update. |
| height | Height of the incoming region to update. |
| srcAlloc | Source allocation. |
| srcXoff | X offset in the source. |
| srcYoff | Y offset in the source. |
| srcMip | Mip level in the source allocation. 0 if mip mapping is not used. |
| srcFace | Cubemap face of the source allocation. Ignored for allocations that aren't cubemaps. |
Copies a rectangular region of cells from one allocation to another. (width * height) cells are copied.
The two allocations must be different. Using this function to copy within the same allocation yields undefined results.
The function does not validate whether the source or destination region exceeds the size of its respective allocation. Be careful!
This function should only be called between 2D allocations. Calling it on other allocations is undefined.
This function should not be called from inside a kernel, or from any function that may be called directly or indirectly from a kernel. Doing so would cause a runtime error.
rsAllocationVLoadX : Get a vector from an allocation of scalars
Parameters
| a | Allocation to get the data from. |
|---|---|
| x | X offset in the allocation of the first cell to be copied from. |
| y | Y offset in the allocation of the first cell to be copied from. |
| z | Z offset in the allocation of the first cell to be copied from. |
This function returns a vector composed of successive cells of the allocation. It assumes that the allocation contains scalars.
The "X" in the name indicates that successive values are extracted by increasing the X index. There are currently no functions to get successive values incrementing other dimensions. Use multiple calls to rsGetElementAt() instead.
For example, when calling rsAllocationVLoadX_int4(a, 20, 30), an int4 composed of a[20, 30], a[21, 30], a[22, 30], and a[23, 30] is returned.
When retrieving from a three dimensional allocations, use the x, y, z variant. Similarly, use the x, y variant for two dimensional allocations and x for the mono dimensional allocations.
For efficiency, this function does not validate the inputs. Trying to wrap the X index, exceeding the size of the allocation, or using indices incompatible with the dimensionality of the allocation yields undefined results.
See also rsAllocationVStoreX().
rsAllocationVStoreX : Store a vector into an allocation of scalars
Parameters
| a | Allocation to store the data into. |
|---|---|
| val | Value to be stored. |
| x | X offset in the allocation of the first cell to be copied into. |
| y | Y offset in the allocation of the first cell to be copied into. |
| z | Z offset in the allocation of the first cell to be copied into. |
This function stores the entries of a vector into successive cells of an allocation. It assumes that the allocation contains scalars.
The "X" in the name indicates that successive values are stored by increasing the X index. There are currently no functions to store successive values incrementing other dimensions. Use multiple calls to rsSetElementAt() instead.
For example, when calling rsAllocationVStoreX_int3(a, v, 20, 30), v.x is stored at a[20, 30], v.y at a[21, 30], and v.z at a[22, 30].
When storing into a three dimensional allocations, use the x, y, z variant. Similarly, use the x, y variant for two dimensional allocations and x for the mono dimensional allocations.
For efficiency, this function does not validate the inputs. Trying to wrap the X index, exceeding the size of the allocation, or using indices incompatible with the dimensionality of the allocation yiels undefined results.
See also rsAllocationVLoadX().
rsGetElementAt : Return a cell from an allocation
This function extracts a single cell from an allocation.
When retrieving from a three dimensional allocations, use the x, y, z variant. Similarly, use the x, y variant for two dimensional allocations and x for the mono dimensional allocations.
This function has two styles. One returns the address of the value using a void*, the other returns the actual value, e.g. rsGetElementAt() vs. rsGetElementAt_int4(). For primitive types, always use the latter as it is more efficient.
rsGetElementAtYuv_uchar_U : Get the U component of an allocation of YUVs
Extracts the U component of a single YUV value from a 2D allocation of YUVs.
Inside an allocation, Y, U, and V components may be stored if different planes and at different resolutions. The x, y coordinates provided here are in the dimensions of the Y plane.
See rsGetElementAtYuv_uchar_Y().
rsGetElementAtYuv_uchar_V : Get the V component of an allocation of YUVs
Extracts the V component of a single YUV value from a 2D allocation of YUVs.
Inside an allocation, Y, U, and V components may be stored if different planes and at different resolutions. The x, y coordinates provided here are in the dimensions of the Y plane.
See rsGetElementAtYuv_uchar_Y().
rsGetElementAtYuv_uchar_Y : Get the Y component of an allocation of YUVs
Extracts the Y component of a single YUV value from a 2D allocation of YUVs.
Inside an allocation, Y, U, and V components may be stored if different planes and at different resolutions. The x, y coordinates provided here are in the dimensions of the Y plane.
See rsGetElementAtYuv_uchar_U() and rsGetElementAtYuv_uchar_V().
rsSample : Sample a value from a texture allocation
Parameters
| a | Allocation to sample from. |
|---|---|
| s | Sampler state. |
| location | Location to sample from. |
| lod | Mip level to sample from, for fractional values mip levels will be interpolated if RS_SAMPLER_LINEAR_MIP_LINEAR is used. |
Fetches a value from a texture allocation in a way described by the sampler.
If your allocation is 1D, use the variant with float for location. For 2D, use the float2 variant.
See android.renderscript.Sampler for more details.
rsSetElementAt : Set a cell of an allocation
This function stores a value into a single cell of an allocation.
When storing into a three dimensional allocations, use the x, y, z variant. Similarly, use the x, y variant for two dimensional allocations and x for the mono dimensional allocations.
This function has two styles. One passes the value to be stored using a void*, the other has the actual value as an argument, e.g. rsSetElementAt() vs. rsSetElementAt_int4(). For primitive types, always use the latter as it is more efficient.
See also rsGetElementAt().