繁体   English   中英

渲染脚本的行为不一致

[英]Inconsistent behavior of Renderscript

我写了以下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?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如何更改其值?

局部变量out_h,out_s,out_v未初始化,因此行为未定义。

ushort out_h, out_s, out_v;

如果将它们初始化为0,我认为问题应该消失了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM