例如,我从位图进行分配,然后对其应用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
}