android – filterscript文档在哪里(我该如何使用它)?

当Jelly Bean 4.2在一个月前宣布时,Filterscript也宣布了.它似乎是一种语言,是Renderscript的下标,具有不同的文件扩展名.这就是我对语言的全部了解.

我已经阅读了整个Internet上存在的关于Filterscript的两个段落,并创建了一个带有pragma rs_fp_relaxed的小.fs文件,但ADT构建器没有像正常的.rs文件一样在同一位置拾取它.

我的ADT是最新的公共版本(21.0.0),对于Filterscript来说似乎太低了. tools.android.com似乎有21.0.1预览版,但在发行说明中没有提到Filterscript(事实上它只是一个bug修复版本).在任何地方都没有文档!

我如何使用Filterscript?它的文件在哪里?

我尝试过的:

https://www.google.com/search?q=filterscript+site:android.com&tbs=li:1

http://developer.android.com/about/versions/android-4.2.html#Renderscript

http://developer.android.com/tools/sdk/eclipse-adt.html#notes

http://tools.android.com/recent/2101preview1

解决方法:

我还没有找到任何文档,但也许我可以给你一些有关我迄今为止所调查的内容的有用信息:

>指针不可用
>内核函数需要属性__attribute __((kernel))否则编译器会生气并且需要指针类型,这些都是非法的
> Renderscript API可以使用(至少我到目前为止所尝试的一切都在工作)
> AndroidManifest.xml中的属性“Min SDK version”必须设置为“17” – > “使用Sdk”

我在阅读sources of the llvm-rs-cc compiler时发现了以下大部分信息.任何进一步的信息或指向Filtercript真实文档的链接都将受到赞赏!

产出分配

在Filterscript中,您没有输出分配的参数.而是返回值以在当前位置写入(这是全局线程id x和y):

uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y)

生成:

public void forEach_root(Allocation aout)

输入分配

您可以选择将输入分配作为参数进行切换:

uchar4 __attribute__((kernel)) root(const uchar4 in, uint32_t x, uint32_t y)

生成:

public void forEach_root(Allocation ain, Allocation aout)

这在极少数情况下很有用(例如点运算符),因为您只能在当前位置访问输入分配.

全球分配

如果要在输入分配中进行随机访问,则需要进行全局分配.这是一个使用适合我的全局分配的窗口运算符的小例子.

blur.fs:

#pragma version(1)
#pragma rs java_package_name(com.example.myproject)

rs_allocation in;

uint32_t width;
uint32_t height;

uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
    uint4 sum = 0;
    uint count = 0;
    for (int yi = y-1; yi <= y+1; ++yi) {
        for (int xi = x-1; xi <= x+1; ++xi) {
            if (xi >= 0 && xi < width && yi >= 0 && yi < height) {
                sum += convert_uint4(rsGetElementAt_uchar4(in, xi, yi));
                ++count;
            }
        }
    }
    return convert_uchar4(sum/count);
}

MainActivity.java:

...
mRS = RenderScript.create(this);

mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
                    Allocation.MipmapControl.MIPMAP_NONE,
                    Allocation.USAGE_SCRIPT);
mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());

mScript = new ScriptC_blur(mRS, getResources(), R.raw.blur);
mScript.set_in(mInAllocation);
mScript.set_width(mBitmapIn.getWidth());
mScript.set_height(mBitmapIn.getHeight());

mScript.forEach_root(mOutAllocation);

mOutAllocation.copyTo(mBitmapOut);
...
上一篇:php – 我应该使用@return self,this还是当前的类?


下一篇:Python C扩展:文档的方法签名?