public void SetPixel(int X, int Y, uint Value) { if ((X < 0) || (X >= m_Width) || (Y < 0) || (Y >= m_Height)) { return; } if (m_ImageData.Empty()) { return; } switch (BitsPerPixel) { case 1: unsafe { int pitch = (Width + 7) / 8; byte origValue = m_ImageData.ByteAt(Y * pitch + X / 8); byte newValue = origValue; if (Value != 0) { newValue = (byte)(origValue | (128 >> (X % 8))); } else { newValue = (byte)(origValue & (~(128 >> (X % 8)))); } m_ImageData.SetU8At(Y * pitch + X / 8, newValue); } break; case 4: unsafe { int pitch = Width / 2; byte origValue = m_ImageData.ByteAt(Y * pitch + X / 2); byte newValue = 0; if ((X % 2) == 0) { newValue = (byte)((origValue & 0x0f) | ((byte)Value << 4)); } else { newValue = (byte)((origValue & 0xf0) | (byte)Value); } m_ImageData.SetU8At(Y * pitch + X / 2, newValue); }; break; case 8: m_ImageData.SetU8At(Y * m_Width + X, (byte)Value); break; case 16: m_ImageData.SetU16At(2 * (Y * m_Width + X), (ushort)((((Value & 0xff0000) >> 19) << 10) + (((Value & 0x00ff00) >> 11) << 5) + (((Value & 0x0000ff) >> 3)))); break; case 24: m_ImageData.SetU8At(3 * (Y * m_Width + X) + 0, (byte)(Value & 0xff)); m_ImageData.SetU8At(3 * (Y * m_Width + X) + 1, (byte)((Value & 0xff00) >> 8)); m_ImageData.SetU8At(3 * (Y * m_Width + X) + 2, (byte)((Value & 0xff0000) >> 16)); break; case 32: m_ImageData.SetU32At(4 * (Y * m_Width + X), Value); break; default: throw new NotSupportedException("Bitdepth " + BitsPerPixel + " not supported yet"); } }