使用 Android Renderscript 添加 2 个图像

Adding 2 Images with Android Renderscript

我试图通过将 2 的值添加到反向捕获来增加我的相机的曝光时间。使用 Java 计算花费的时间太长,所以我决定尝试使用 Renderscript。我似乎已经解决了所有的错误,但最终结果有一些非常奇怪的效果

这张图片中的大部分椅子和地板都很好,但大部分区域出现了亮绿色和蓝色变色。

这是 Renderscript 文件:

#pragma version(1)
#pragma rs java_package_name(edu.marquette.mcw.smartme)

rs_allocation extra_alloc;

uchar4 __attribute__((kernel)) combine(uchar4 a, uint32_t x, uint32_t y)
{
    // get second image
    uchar4 b = rsGetElementAt_uchar4(extra_alloc, x, y);

    // combine red value
    uint32_t red = a.r + b.r;
    //set to max value if it exceeds it
    if(255 - a.r < b.r)
    {
        red = 255;
    }
    a.r = red;

    // combine green value
    uint32_t green = a.g + b.g;
    if(255 - a.g < b.g)
    {
        green = 255;
    }
    a.g = green;

    // combine blue value
    uint32_t blue = a.b + b.b;
    if(255 - a.b < b.b)
    {
        blue = 255;
    }
    a.b = blue;

    // return result
    return a;
}

这里是执行 Renderscript 的 Java 代码:

// Load Script
RenderScript RS = RenderScript.create(callingFrag.getActivity());
ScriptC_combine script = new ScriptC_combine(RS);

output = Bitmap.createBitmap(combined.getWidth(), combined.getHeight(), combined.getConfig());

// Send in bitmaps
Allocation aAllocation = Allocation.createFromBitmap(RS, combined);
Allocation bAllocation = Allocation.createFromBitmap(RS, exposures.remove(0));
Allocation outputAllocation = Allocation.createFromBitmap(RS, output);
script.set_extra_alloc(bAllocation);

// Run Script
script.forEach_combine(aAllocation, outputAllocation);
App.log("Combine Time: " + (System.currentTimeMillis() - start));
outputAllocation.copyTo(output);

我在日志中找不到任何 warning/error。关于如何解决这个问题的任何想法?

我最终找到了一个库,它仅用大约 1 行就完全涵盖了我需要的内容。

easyRS 允许我将 2 张图片与以下内容组合:

Blend.add(rs, inputBitmap, inputBitmap2);