简体   繁体   English

RenderScript:使用ScriptGroup进行图像处理会导致水平条纹

[英]RenderScript: Using ScriptGroup for image process causes horizontal stripes

Problem Description: 问题描述:

I write a simple demo using RenderScrip for image process. 我使用RenderScrip为图像处理编写了一个简单的演示。 In my demo, when I use a one-kernal renderscript, it works fine. 在我的演示中,当我使用one-kernal renderscript时,它工作正常。 Yet when I use a script group to connect two rs-kernals for execution, I found the output bitmap with horizontal stripes. 然而,当我使用脚本组连接两个rs-kernals执行时,我发现输出位图有水平条纹。 Especially when you chose a bitmap with small size. 特别是当您选择小尺寸的位图时。

The output bitmap when I use a one-kernal renderscript: 我使用one-kernal renderscript时的输出位图: 我使用one-kernal renderscript时的输出位图

The output bitmap when I use a script group to connect two rs-kernals. 当我使用脚本组连接两个rs-kernals时的输出位图。 Note these two rs-kernals are just the same as the one I use above: 注意这两个rs-kernals与我上面使用的相同: 我使用脚本组时的输出位图

Codes: 代码:

I believe my codes in rs-kernal are correct. 我相信我的rs-kernal代码是正确的。 Otherwise I can't can't the right output picture when using a single-kernal renderscript. 否则,当使用单内核renderscript时,我无法正确输出图片。 The problem is about script group. 问题是关于脚本组。

Here is some codes about how I connect the rs-kernals in script group: 以下是有关如何在脚本组中连接rs-kernals的一些代码:

    Type.Builder tb = new Type.Builder(mRs, Element.RGBA_8888(mRs));
    tb.setX(baseBitmapWidth);// the size of bitmap never changes during the whole process
    tb.setY(baseBitmapHeight);
    Type t = tb.create();

    ScriptGroup.Builder b = new ScriptGroup.Builder(mRs);

    int i = 0;
    for (i = 0; i < mOps.size(); i++) {
        RSOp op = mOps.get(i);
        b.addKernel(op.rsGetKernalID());
    }

    for (i = 1; i < mOps.size(); i++) {
        b.addConnection(t, mOps.get(i - 1).rsGetKernalID(), mOps.get(i)
                .rsGetKernalID());
    }

    mScriptGroup = b.create();

Here is some codes about how the script group is executed: 以下是有关脚本组执行方式的一些代码:

    Bitmap preparedBitmap = baseBitmap.copy(baseBitmap.getConfig(), true);
    mInAllocation = Allocation.createFromBitmap(mRs, baseBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
    mOutAllocation = Allocation.createTyped(mRs, mInAllocation.getType());

    mScriptGroup.setInput(mOps.get(0).rsGetKernalID(), mInAllocation);
    mScriptGroup.setOutput(mOps.get(mOps.size() - 1).rsGetKernalID(),
            mOutAllocation);

    mScriptGroup.execute();

    mOutAllocation.copyTo(preparedBitmap);

Have found a solution: Just used many one-kernal renderscripts instead. 找到了一个解决方案:只使用了许多单核的renderscripts。 Use the output bitmap of the previous script as the input of the later. 使用前一个脚本的输出位图作为后一个脚本的输入。

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

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