简体   繁体   English

Android RenderScript-语法错误

[英]Android RenderScript - Syntax Error

My current script is: 我当前的脚本是:

#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);
}

after following this advice here: Renderscript, what is the `in` parameter? 在遵循以下建议后: Renderscript,`in`参数是什么?

I replaced my code with that one (it doesnt matter if they do not do the same thing I just want it to compile for now): 我用那个替换了我的代码(如果他们不做我现在只想编译的东西,这没关系):

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;
}

and this is what I get now: 这就是我现在得到的:

/home/Projects/android/bar/app/src/main/rs/edgedetect.rs:8:17: error: expected ';' after top level declarator

What is it complaining about ? 它在抱怨什么? (line 8 btw is uchar4 RS_KERNEL root(uchar4 in, uint32_t x, uint32_t y) { ) (第8行是uchar4 RS_KERNEL root(uchar4 in, uint32_t x, uint32_t y) {

EDIT: In my build.gradle: 编辑:在我的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'
        }
    }
}

This type of error appears when you use variables which have not been defined. 当使用未定义的变量时,会出现这种类型的错误。 I'll agree that it's not very clear. 我同意这不是很清楚。

If you notice, you defined the following variable: 如果您注意到,则定义了以下变量:

uchar4 out;

Then later, you use it like this: 然后,您可以像下面这样使用它:

out.xyz = convert_uchar3(pixel);

Except, you're trying to access a property of a variable which was never defined. 除此之外,您正在尝试访问从未定义的变量的属性。

Try initializing it like this: 尝试像这样初始化它:

uchar4 out = in;

If this gets rid of your error, then this was your problem. 如果这消除了您的错误,那么这就是您的问题。 If for some reason you cant use out = in , then look into other ways of initializing the out variable. 如果由于某种原因您不能使用out = in ,那么可以考虑使用其他方式初始化out变量。

You are using 您正在使用

buildToolsVersion '19.1.0'

which doesn't have headers that support "RS_KERNEL". 没有支持“ RS_KERNEL”的标题。 Try replacing that with 尝试将其替换为

__attribute__((kernel))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM