簡體   English   中英

RenderScript:使用ScriptGroup進行圖像處理會導致水平條紋

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

問題描述:

我使用RenderScrip為圖像處理編寫了一個簡單的演示。 在我的演示中,當我使用one-kernal renderscript時,它工作正常。 然而,當我使用腳本組連接兩個rs-kernals執行時,我發現輸出位圖有水平條紋。 特別是當您選擇小尺寸的位圖時。

我使用one-kernal renderscript時的輸出位圖: 我使用one-kernal renderscript時的輸出位圖

當我使用腳本組連接兩個rs-kernals時的輸出位圖。 注意這兩個rs-kernals與我上面使用的相同: 我使用腳本組時的輸出位圖

代碼:

我相信我的rs-kernal代碼是正確的。 否則,當使用單內核renderscript時,我無法正確輸出圖片。 問題是關於腳本組。

以下是有關如何在腳本組中連接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();

以下是有關腳本組執行方式的一些代碼:

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

找到了一個解決方案:只使用了許多單核的renderscripts。 使用前一個腳本的輸出位圖作為后一個腳本的輸入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM