title: Convert RGBA to ARGB pixel format
body: <p>I'm trying to convert an image to this following DDS format:</p>
  
  <pre><code>| Resource Format | dwFlags  | dwRGBBitCount | dwRBitMask | dwGBitMask | dwBBitMask | dwABitMask |
  +-----------------+----------+---------------+------------+------------+------------+------------+
  | D3DFMT_A4R4G4B4 | DDS_RGBA | 16            | 0xf00      | 0xf0       | 0xf        | 0xf000     |
  </code></pre>
  
  <blockquote>
    <p>D3DFMT_A4R4G4B4 16-bit ARGB pixel format with 4 bits for each channel.</p>
  </blockquote>
  
  <p>I have this python code (using Wand lib):</p>
  
  <pre><code># source is jpeg converted to RGBA format (wand only supports RGBA not ARGB)
  blob = img.make_blob(format="RGBA")
  
  for x in range(0, img.width * img.height * 4, 4):
      r = blob[x]
      g = blob[x + 1]
      b = blob[x + 2]
      a = blob[x + 3]
  
      # a=255 r=91 g=144 b=72
      pixel = (a &lt;&lt; 12 | r &lt;&lt; 8 | g &lt;&lt; 4 | b) &amp; 0xffff
  </code></pre>
  
  <p>The first pixel I get is <code>64328</code> but I was expecting <code>62868</code>.</p>
  
  <p>Question:</p>
  
  <ul>
  <li>Is my RGBA to ARGB conversion wrong?</li>
  <li>Why am I not getting the desired result?</li>
  </ul>
  
  <p>The expected output (left) vs the actual output (right) of my code:
  <a href="https://i.stack.imgur.com/yoAbm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yoAbm.jpg" alt="enter image description here"></a><a href="https://i.stack.imgur.com/RaadF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RaadF.jpg" alt="enter image description here"></a></p>