ここで何が起こっているのか理解できないようです。次の警告アイコンがあります。
K_USHORT usaAlertIcon[16] = { 0x0000, 0x0000, 0x0180, 0x03C0, 0x03C0, 0x0660, 0x0660, 0x0E70, 0x0E70, 0x1E78, 0x3E7C, 0x3FFC, 0x7E7E, 0x7E7E, 0xFFFF, 0x0000 };
ここで、配列が 8 ビット データ (unsigned char) であると見なすコードで使用したいと思います。
//---------------------------------------------------------------------------
void GraphicsDriver::Stamp(DrawStamp_t *pstStamp_)
{
K_USHORT usRow;
K_USHORT usCol;
K_USHORT usShift;
K_USHORT usIndex;
DrawPoint_t stPoint;
usIndex = 0;
for (usRow = pstStamp_->usY; usRow < (pstStamp_->usY + pstStamp_->usHeight); usRow++)
{
usShift = 0x80;
for (usCol = pstStamp_->usX; usCol < (pstStamp_->usX + pstStamp_->usWidth); usCol++)
{
// If the packed bit in the bitmap is a "1", draw the color.
if (pstStamp_->pucData[usIndex] & usShift)
{
stPoint.usX = usCol;
stPoint.usY = usRow;
stPoint.uColor = pstStamp_->uColor;
DrawPixel(&stPoint);
}
// Stamps are opaque, don't fill in the BG
// Shift to the next bit in the field
usShift >>= 1;
// Rollover - next bit in the bitmap.
// This obviously works best for stamps that are multiples of 8x8
if (usShift == 0)
{
usShift = 0x80;
usIndex++;
}
}
}
}
この関数に送信されるデータ構造に配列を割り当てるとき、次のようにキャストします。
stStamp.pucData = (K_UCHAR*)usaAlertIcon;
ただし、これを行うと、バイトが反転するようです。最初に左半分を描画し、次に右半分を描画します。そのため、画像を途中で切り取り、左側のピースを右側のピースと交換しました。
健全性チェックとして、自分で配列を明示的に分割した場合。
K_UCHAR ucaAlertIcon[32] = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x03, 0xC0, 0x03, 0xC0, 0x06, 0x60, 0x06, 0x60, 0x0E, 0x70, 0x0E, 0x70, 0x1E, 0x78, 0x3E, 0x7C, 0x3F, 0xFC, 0x7E, 0x7E, 0x7E, 0x7E, 0xFF, 0xFF, 0x00, 0x00 };
すべてが期待どおりに機能します。
型キャストを行うと、これらのバイトが反転しているように見える理由を誰かが説明できますか?