我有两个像素的流,基本上需要做一个自定义XOR对他们最终的结果图片。它工作得很好 - 唯一的问题是它需要模拟器大约4秒来解析代码。我知道必须有一种方法来优化这个例程 - 但在测试了我的想法几天后(无济于事),我正在寻求帮助!更快的像素枚举
这是我的代码 - 在此先感谢您的任何建议!
//rawPic1Data and rawPic2Data is a stream of unsigned chars that ultimately came from a UIImage
for (int i = 0 ; i < (bufferLength); i=i+4)
{
sred = (int)(rawPic1Data[i + 0]);
sgreen = (int)(rawPic1Data[i + 1]);
sblue = (int)(rawPic1Data[i + 2]);
rred = (int)(rawPic2Data[i + 0]);
rgreen = (int)(rawPic2Data[i + 1]);
rblue = (int)(rawPic2Data[i + 2]);
fred = 0;
fgreen = 0;
fblue = 0;
falpha = 0;
if (((sred == 102) && (sgreen == 0) && (sblue == 153)) || ((rred == 102) && (rgreen == 0) && (rblue == 153)))
{
fred = 102; fgreen = 0; fblue = 153; falpha = 255;
}
else if (((sred == 153) && (sgreen == 51) && (sblue == 204)) || ((rred == 153) && (rgreen == 51) && (rblue == 204)))
{
fred = 153; fgreen = 51; fblue = 204; falpha = 255;
}
//...repeat the elseifs for another 12 colors. (14 total)
}
//Use the f values for my final output...
你平时的流程有多长? – Cyprian
没有所有if ... else ...部件有多快? – Eiko
另一个问题:Pic1中可能存在颜色匹配的可能性以及Pic2可能性如何?你检查的颜色是否有共同之处? – Eiko