我写了以下renderscript:
ushort* curve_hth;
ushort* curve_hts;
ushort* curve_htv;
ushort* curve_sth;
ushort* curve_sts;
ushort* curve_stv;
ushort* curve_vth;
ushort* curve_vts;
ushort* curve_vtv;
uchar4 RS_KERNEL transform(uchar4 in, uint32_t x, uint32_t y)
{
if(!isSelected(x, y)) return in;
ushort3 in_rgb = { (ushort) in.r, (ushort) in.g, (ushort) in.b };
ushort3 in_hsv = rgb_to_hsv(in_rgb);
ushort in_h = in_hsv.r;
ushort in_s = in_hsv.g;
ushort in_v = in_hsv.b;
ushort out_h, out_s, out_v;
rsDebug("out1", out_s);
if(curve_hth != NULL) out_h += curve_hth[in_h]; else out_h += in_h;
rsDebug("out2", out_s);
if(curve_hts != NULL) out_s += curve_hts[in_h];
rsDebug("out3", out_s);
if(curve_htv != NULL) out_v += curve_htv[in_h];
rsDebug("out4", out_s);
if(curve_sth != NULL) out_h += curve_sth[in_s];
rsDebug("out5", out_s);
if(curve_sts != NULL) out_s += curve_sts[in_s]; else out_s += in_s;
rsDebug("out6", out_s);
if(curve_stv != NULL) out_v += curve_stv[in_s];
rsDebug("out7", out_s);
if(curve_vth != NULL) out_h += curve_vth[in_v];
rsDebug("out8", out_s);
if(curve_vts != NULL) out_s += curve_vts[in_v];
rsDebug("out9", out_s);
if(curve_vtv != NULL) out_v += curve_vtv[in_v]; else out_v += in_v;
rsDebug("out10", out_s);
out_h = min((float) out_h, (float) 360);
out_s = min((float) out_s, (float) 100);
out_v = min((float) out_v, (float) 100);
ushort3 out_hsv = { out_h, out_s, out_v };
ushort3 out_rgb = hsv_to_rgb(out_hsv);
uchar4 out = { out_rgb.r, out_rgb.g, out_rgb.b, in.a };
return out;
}
当我运行该脚本时,我会进入logcat:
D/RenderScript: out1 0 0x0
D/RenderScript: out2 0 0x0
D/RenderScript: out3 255 0xff
D/RenderScript: out4 255 0xff
D/RenderScript: out5 255 0xff
D/RenderScript: out6 255 0xff
D/RenderScript: out7 255 0xff
D/RenderScript: out8 255 0xff
D/RenderScript: out9 255 0xff
D/RenderScript: out10 255 0xff
它让我感到很惊讶,因为所有curve_?t?
指针都应为null,我不会在Java代码中绑定它们。这很奇怪,所以我修改了脚本的调试部分,我得到了:
if(curve_hth != NULL) out_h += curve_hth[in_h]; else out_h += in_h;
rsDebug("out1", out_s);
rsDebug("out2", curve_hts == NULL);
if(curve_hts != NULL)
{
out_s += curve_hts[in_h];
rsDebug("out3", 1);
}
rsDebug("out4", out_s);
if(curve_htv != NULL) out_v += curve_htv[in_h];
if(curve_sth != NULL) out_h += curve_sth[in_s];
if(curve_sts != NULL) out_s += curve_sts[in_s]; else out_s += in_s;
if(curve_stv != NULL) out_v += curve_stv[in_s];
if(curve_vth != NULL) out_h += curve_vth[in_v];
if(curve_vts != NULL) out_s += curve_vts[in_v];
if(curve_vtv != NULL) out_v += curve_vtv[in_v]; else out_v += in_v;
rsDebug("out5", out_s);
logcat的结果是:
D/RenderScript: out1 0 0x0
D/RenderScript: out2 1 0x1
D/RenderScript: out4 25004 0x61ac
D/RenderScript: out5 25004 0x61ac
out2
为1,因此curve_hts
为NULL。没有out3
日志,if
指令未被调用,那么out_s
如何更改其值?