gpt4 book ai didi

android - Renderscript 的行为不一致

转载 作者:行者123 更新时间:2023-11-30 15:00:01 25 4
gpt4 key购买 nike

我编写了以下渲染脚本:

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 代码中绑定(bind)它们。很奇怪,所以我修改了脚本的调试部分,得到了:

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,我认为问题应该消失。

关于android - Renderscript 的行为不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42393824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com