我目前的脚本是:
#pragma version(1)
#pragma rs java_package_name(foo.bar)
rs_allocation inPixels;
int height;
int width;
int threeBythree[];
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
float3 pixel = convert_float4(in[0]).rgb;
if(x==0 || x==width || y==0 || y==height){
pixel.r = 0;
pixel.g = 191;
pixel.b = 255;
}else{ //do image processing here
float3 pixelNH = convert_float4(rsGetElementAt_uchar4(inPixels, x+1, y)).rgb;
float3 pixelNV = convert_float4(rsGetElementAt_uchar4(inPixels, x, y+1)).rgb;
int grayAvg = (pixel.r + pixel.g + pixel.b)/3;
int grayAvgNH = (pixelNH.r + pixelNH.g + pixelNH.b)/3;
int grayAvgNV = (pixelNV.r + pixelNV.g + pixelNV.b)/3;
int edgeOperatorValue = 2*grayAvg - grayAvgNH - grayAvgNV;
if(edgeOperatorValue < 0){
edgeOperatorValue = -1 * edgeOperatorValue;
};
pixel.r = edgeOperatorValue;
pixel.g = edgeOperatorValue;
pixel.b = edgeOperatorValue;
};
out->xyz = convert_uchar3(pixel);
}
遵循此建议后: Renderscript, what is the `in` parameter?
我用那个替换了我的代码(如果他们不做我想让它现在编译的同样的事情也无关紧要):
uchar4 RS_KERNEL root(uchar4 in, uint32_t x, uint32_t y) {
// x and y aren't used, so you can remove those from the above signature too.
uchar4 out;
float3 pixel = convert_float4(in).rgb;
pixel.r = (pixel.r + pixel.g + pixel.b)/3;
// This seems buggy to me below, since pixel.r was just modified.
// I think you need another temporary variable (assuming you are trying to make this work and getting weird behavior).
pixel.g = (pixel.r + pixel.g + pixel.b)/3;
pixel.b = (pixel.r + pixel.g + pixel.b)/3;
//int topRight
//float4 f4 = rsUnpackColor8888(*(uchar*)rsGetElementAt(inPixels, x+1, y+1));
out.xyz = convert_uchar3(pixel);
return out;
}
这就是我现在得到的:
/home/Projects/android/bar/app/src/main/rs/edgedetect.rs:8:17: error: expected ';' after top level declarator
抱怨什么?
(第8行顺便说一下uchar4 RS_KERNEL root(uchar4 in, uint32_t x, uint32_t y) {
)
编辑:在我的build.gradle中:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
applicationId "foo.bar"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true //not applicable for rs targetapi 21+
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
答案 0 :(得分:0)
使用尚未定义的变量时会出现此类错误。我同意它不是很清楚。
如果您注意到,您定义了以下变量:
uchar4 out;
然后,你会像这样使用它:
out.xyz = convert_uchar3(pixel);
除此之外,您正在尝试访问从未定义的变量的属性。
尝试像这样初始化:
uchar4 out = in;
如果这样可以解决您的错误,那么这就是您的问题。如果由于某种原因您无法使用out = in
,请查看初始化out
变量的其他方法。
答案 1 :(得分:0)
您正在使用
buildToolsVersion '19.1.0'
没有支持&#34; RS_KERNEL&#34;的标题。尝试用
替换它__attribute__((kernel))