2

例如,我从位图进行分配,然后对其应用brightnessContrastRs(),然后在该分配上应用一些具有类似实现的不同过滤器,由brightnessContrastRs() 操作更改?

public Bitmap brightnessContrastRs(Bitmap bmIn, int brightness, int contrast)
{
    Bitmap bmOut = Bitmap.createBitmap(bmIn.getWidth(), bmIn.getHeight(),
            bmIn.getConfig());
    Allocation allocIn;
    allocIn = Allocation.createFromBitmap(rs, bmIn,
            Allocation.MipmapControl.MIPMAP_NONE,
            Allocation.USAGE_SCRIPT);
    Allocation allocOut = Allocation.createTyped(rs, allocIn.getType());

    scriptCBrightnessContrast.set_in(allocIn);
    allocIn.destroy();
    scriptCBrightnessContrast.set_out(allocOut);
    scriptCBrightnessContrast.set_script(scriptCBrightnessContrast);
    float rowContrast = ((100.0f + contrast) * (100.0f + contrast) / 10000.0f);
    float rowBrightness = brightness / 255.f;
    scriptCBrightnessContrast.set_rowBrightness(rowBrightness);
    scriptCBrightnessContrast.set_rowContrast(rowContrast);
    scriptCBrightnessContrast.invoke_filter();
    allocOut.copyTo(bmOut);
    allocOut.destroy();
    return bmOut;
}

RS脚本:

rs_allocation out;
rs_allocation in;
rs_script script;

float rowBrightness;
float rowContrast;

void root(const uchar4* v_in, uchar4* v_out, const void* usrData, uint32_t x,
          uint32_t y)
{
   float4 current = rsUnpackColor8888(*v_in);

   current.r = clamp(((clamp(current.r + rowBrightness, 0.0f, 1.0f) - 0.5f) * rowContrast + 0.5f), 0.0f, 1.0f);
   current.g = clamp(((clamp(current.g + rowBrightness, 0.0f, 1.0f)- 0.5f) * rowContrast + 0.5f), 0.0f, 1.0f);
   current.b = clamp(((clamp(current.b + rowBrightness, 0.0f, 1.0f) - 0.5f) * rowContrast + 0.5f), 0.0f, 1.0f);

   *v_out = rsPackColorTo8888(current.r, current.g, current.b, current.a);
}
void filter()
{
    #if !defined(RS_VERSION) || (RS_VERSION < 14)
       rsForEach(script, in, out, 0);
    #else
       rsForEach(script, in, out);
    #endif
}
4

2 回答 2

2

您应该改用 ScriptGroup。

于 2014-07-07T16:44:21.773 回答
1

如果您问是否可以像这样传递分配并让事情正常进行,是的,您当然可以这样做。但是,您不能那么早销毁 allocIn,因为它仍然需要在脚本启动时使用。

于 2013-03-21T22:44:31.650 回答