ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-10-04 12:23:25  阅读:271  来源: 互联网

标签:android documentation renderscript


当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);
...

标签:android,documentation,renderscript
来源: https://codeday.me/bug/20191004/1853010.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有