我一直在關注如何在Android上使用Render腳本的指南。Renderscript文檔和建議 - Android
http://www.jayway.com/2014/02/11/renderscript-on-android-basics/
我的代碼是這樣的(我的劇本的包裝類):
public class PixelCalcScriptWrapper {
private Allocation inAllocation;
private Allocation outAllocation;
RenderScript rs;
ScriptC_pixelsCalc script;
public PixelCalcScriptWrapper(Context context){
rs = RenderScript.create(context);
script = new ScriptC_pixelsCalc(rs, context.getResources(), R.raw.pixelscalc);
};
public void setInAllocation(Bitmap bmp){
inAllocation = Allocation.createFromBitmap(rs,bmp);
};
public void setOutAllocation(Bitmap bmp){
outAllocation = Allocation.createFromBitmap(rs,bmp);
};
public void forEach_root(){
script.forEach_root(inAllocation, outAllocation);
}
}
此方法調用腳本:
public Bitmap processBmp(Bitmap bmp, Bitmap bmpCopy) {
pixelCalcScriptWrapper.setInAllocation(bmp);
pixelCalcScriptWrapper.setOutAllocation(bmpCopy);
pixelCalcScriptWrapper.forEach_root();
return bmpCopy;
};
,這裏是我的腳本:
#pragma version(1)
#pragma rs java_package_name(test.foo)
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
float3 pixel = convert_float4(in[0]).rgb;
if(pixel.z < 128) {
pixel.z = 0;
}else{
pixel.z = 255;
}
if(pixel.y < 128) {
pixel.y = 0;
}else{
pixel.y = 255;
}
if(pixel.x < 128) {
pixel.x = 0;
}else{
pixel.x = 255;
}
out->xyz = convert_uchar3(pixel);
}
現在我可以在哪裏找到關於此的一些文檔?
例如,我有以下問題:
1)這是什麼convert_float4(in[0])
呢?
2)rgb
這裏返回convert_float4(in[0]).rgb;
?
3)什麼是float3
?
4)我不知道這條線out->xyz = convert_uchar3(pixel);
5)我假設中的參數,in
和out
是在分配傳遞開始? 什麼是x
和y
?