ループで実行するよりも高速な short[] の各 short を左シフト (ビット単位) するメソッド (c#/.net) はありますか?
デジタル カメラ (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);
}
}
}
}
何か案は?