我有兩個像素的流,基本上需要做一個自定義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