本文介绍了filterscript文档在哪里(如何使用它)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个月前公布了Jelly Bean 4.2时,Filterscript也被公布。它似乎是一种语言,它是具有不同文件扩展名的Renderscript的下标。这是关于语言的所有知识。



我已经在整个互联网上阅读了关于Filterscript的两个总段落,并创建了一个小的 .fs 文件与 pragma rs_fp_relaxed ,但ADT构建器不能像普通的 .rs 文件位于相同的位置。



我的ADT是最新的公开版本(21.0.0),对于Filterscript来说似乎太低了。 似乎拥有21.0.1预览版,但在发行说明中没有提到Filterscript (其实它只是一个bug修复版本)。没有任何文件!



如何使用Filterscript?其文档在哪里?



我尝试过的:









解决方案

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




  • 指针不可用

  • 内核函数需要属性 __属性__((内核))否则编译器会生气,期望指针类型,这是非法的

  • 可以使用(至少我所尝试的一切工作正在工作)

  • 属性Min SDK版本必须在AndroidManifest.xml中设置为17 - >使用Sdk



在阅读。任何进一步信息或链接到Filterscript的真实文档将不胜感激!



输出分配



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

  uchar4 __attribute __((内核))root(uint32_t x,uint32_t y)
pre>

生成:

  public void forEach_root(Allocation aout) 



输入分配



您可以选择手动通过输入分配作为参数:

  uchar4 __attribute __((内核))根(const uchar4 in,uint32_t x,uint32_t y) 

生成:

  public void forEach_root(分配ain,分配aout)

哪些仅在



全局配置



如果你想在输入分配上做随机访问,而不是你需要的话余额分配这是一个使用全局分配的窗口运算符的小例子,它适用于我。



blur.fs:

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

rs_allocation;

uint32_t width;
uint32_t height;

uchar4 __attribute __((kernel))root(uint32_t x,uint32_t y){
uint4 sum = 0;
uint count = 0; (int yi = y-1; yi for(int 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);
...


When Jelly Bean 4.2 was announced a month ago, Filterscript was also announced. It appears to be a language that is a subscript of Renderscript with a different file extension. And that's about all I know about the language.

I have read the two total paragraphs that exist about Filterscript on the entire Internet and created a small .fs file with pragma rs_fp_relaxed, but it does not get picked up by the ADT builders like a normal .rs file is in the same location.

My ADT is the latest public version (21.0.0), which seems to be too low for Filterscript. tools.android.com appears to have 21.0.1 Preview, but there is no mention of Filterscript in the release notes (in fact its just a bugfix release). There's just no documentation anywhere!

How can I use Filterscript? Where is its documentation?

What I have tried:

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

解决方案

I have not found any documentation but maybe I can give you some useful information about what I have investigated so far:

  • Pointers are not available
  • Kernel functions need the attribute __attribute__((kernel)) otherwise compiler goes mad and expects pointer types, which are illegal
  • Renderscript API can be used (at least everything I tried so far was working)
  • Attribute "Min SDK version" must be set to "17" in AndroidManifest.xml -> "Uses Sdk"

I discovered most of the following information while reading the sources of the llvm-rs-cc compiler. Any further information or a link to a real documentation for Filterscript would appreciated!

Output allocation

In Filterscript you dont have a parameter for the output allocation. Instead you return the value to write at current position (this is the global thread id x and y):

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

generates into:

public void forEach_root(Allocation aout)

Input allocation

You can optionally hand over an input allocation as parameter:

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

generates into:

public void forEach_root(Allocation ain, Allocation aout)

Which is useful in only rare cases (e.g. point operators) because you can access the input allocation only at the current position.

Global allocation

If you want to do random access at input allocations than you will need global allocations. Here is a small example of a window operator using a global allocation that works for me.

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

这篇关于filterscript文档在哪里(如何使用它)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 10:31