是否有一种方法(在 c#/.net 中)可以左移(按位)short[] 中的每个短路,这比在循环中执行更快?
我说的是来自数码相机(16 位灰色)的数据,相机只使用低 12 位。所以要在渲染数据时看到一些东西,它需要向左移动 4。
到目前为止,这就是我正在做的事情:
byte[] RawData; // from camera along with the other info
if (pf == PixelFormats.Gray16)
{
fixed (byte* ptr = RawData)
{
short* wptr = (short*)ptr;
short temp;
for (int line = 0; line < ImageHeight; line++)
{
for (int pix = 0; pix < ImageWidth; pix++)
{
temp = *(wptr + (pix + line * ImageWidth));
*(wptr + (pix + line * ImageWidth)) = (short)(temp << 4);
}
}
}
}
有任何想法吗?