Renderscript, выполняющийся к скриптам в 1 коде - PullRequest
0 голосов
/ 01 февраля 2019

Я пытаюсь сделать следующее с помощью Renderscript: - преобразовать изображение из YUV в оттенки серого (сценарий с именем root в моем коде) - выполнить некоторую обработку изображения - вывести окончательное изображение (сценарий с именем output в моем коде)в состоянии сделать первый шаг.Однако, когда я хочу вывести окончательное изображение (я сделаю обработку изображения позже), код не хочет компилироваться.Вот мой код Renderscript:

uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
    oldX = x;
    oldY = y;
    x*=3;
    y*=3;
    if (x < 480) {
        x += 2*(479-x);
    } else {
        x -= 2*(x-479);
    }
    pos = 0;
    yValue = 0;
    for (int i = -1; i <= 1; i++) {
       for (int j = -1; j <= 1; j++) {
           index[pos] = (x+i) * height + (y+j);
           yValue += (float) rsGetElementAt_uchar(yuvIn, index[pos]);
           pos += 1;
       }
    }
    yValue = (float) yValue / pos;
    tImgIndex = oldX * 426 + oldY;
    if (yValue > thresholdValue || y == 426*3) {
       out = (uchar4) {255, 255, 255, 255};
       tImg[tImgIndex] = 1;
    } else {
        out = (uchar4) {0, 0, 0, 255};
        tImg[tImgIndex] = 0;
    }
    return out;
     //rsDebug("called root", rsUptimeMillis());
}

uchar4 __attribute__((kernel)) output(uint32_t x, uint32_t y) {
    out = (uchar4) {0, 0, 0, 255};
    if (tImg[x*426+y] == 0) {
        out = (uchar4) {0, 0, 0, 255};
    } else if (tImg[x*426+y] == 1){
        out = (uchar4) {255, 255, 255, 255};
    } else {
        out = (uchar4) {0, 255, 0, 255};
    }
    return out;
     //rsDebug("called root", rsUptimeMillis());
}

И мой код Java:

rs = RenderScript.create(this);
mScript = new ScriptC_imageProc(rs);
Type t1 = Type.createX(rs, Element.U8(rs), size1);
inAllocation1 = Allocation.createTyped(rs, t1);
outAllocation1 = Allocation.createFromBitmap(rs, bitmap);
outAllocation2 = Allocation.createFromBitmap(rs, bitmap);


if (mSwitch.isChecked()) {
    // image conversion
    nv21ByteArray = frame.getImage();
    mScript.set_thresholdValue(seekBar.getProgress());
    inAllocation1.copyFromUnchecked(copyOfRange(nv21ByteArray, 0, size1));
    mScript.set_yuvIn(inAllocation1);
    mScript.forEach_root(outAllocation1);
    outAllocation1.copyTo(bitmap);

    // image processing

    // output final image
    mScript.forEach_output(outAllocation1);
    outAllocation1.copyTo(bitmap);
}
...