title: Flip and crop a bitmap
body: <p>I'm getting a bytearray (32 bit or 16 bit) from a source.</p>
  
  <p>If the size width is odd, the last pixel in each row needs to be dropped.<br>
  If the height is odd, the last row needs to be dropped.<br>
  If the height is negative the bitmap needs to be flipped vertically.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>m_pbmiLast = new BITMAPINFO(*m_pbmi);
  m_pbmiLast-&gt;bmiHeader.biWidth = abs(m_pbmiLast-&gt;bmiHeader.biWidth) - (abs(m_pbmiLast-&gt;bmiHeader.biWidth) % 2);
  m_pbmiLast-&gt;bmiHeader.biHeight = abs(m_pbmiLast-&gt;bmiHeader.biHeight) - (abs(m_pbmiLast-&gt;bmiHeader.biHeight) % 2);
  
  int biWidth = m_pbmiLast-&gt;bmiHeader.biWidth;
  int biHeight = m_pbmiLast-&gt;bmiHeader.biHeight;
  int iAdjustedStride = ((((biWidth * m_pbmiLast-&gt;bmiHeader.biBitCount) + 31) &amp; ~31) &gt;&gt; 3);
  int iRealStride = ((((m_pbmi-&gt;bmiHeader.biWidth * m_pbmi-&gt;bmiHeader.biBitCount) + 31) &amp; ~31) &gt;&gt; 3);
  
  
  if (m_pbmi-&gt;bmiHeader.biHeight &lt; 0) {
      /* Copy the actual data */
      int iLineOffsetSource = 0;
      int iLineOffsetDest = (biHeight - 1) * iRealStride;
      for (int i = 0; i &lt; biHeight; ++i) {
          memcpy(&amp;pData[iLineOffsetDest], &amp;m_inputBuffer[iLineOffsetSource], iAdjustedStride);
          iLineOffsetSource += iRealStride;
          iLineOffsetDest -= iRealStride;
      }
  } else {
      int iLineOffset = 0;
      for (int i = 0; i &lt; biHeight; ++i) {
          memcpy(&amp;pData[iLineOffset], &amp;m_inputBuffer[iLineOffset], iAdjustedStride);
          iLineOffset += iRealStride;
      }
  }
  </code></pre>
  
  <p>It doesn't flip the bitmap, and when the bitmap is an odd width, it slants the bitmap.</p>